Skip to content

Commit baf4639

Browse files
johnniwintherCommit Queue
authored andcommitted
[kernel] Add *InternalNodeMixin visitor mixins
This adds mixins for visitors that implement handling of internal nodes. These nodes are replaced during constant evaluation and should there not be handle by backends. TEST=existing Change-Id: Iec76af357c11fd54e97a4db82c7aa52e31ba9dd3 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/456680 Reviewed-by: Nicholas Shahan <[email protected]> Reviewed-by: Chloe Stefantsova <[email protected]> Reviewed-by: Alexander Markov <[email protected]> Reviewed-by: Ömer Ağacan <[email protected]> Commit-Queue: Johnni Winther <[email protected]>
1 parent 3a46c47 commit baf4639

File tree

8 files changed

+625
-134
lines changed

8 files changed

+625
-134
lines changed

pkg/dart2wasm/lib/target.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,9 @@ class WasmTarget extends Target {
453453
@override
454454
bool get supportsSetLiterals => true;
455455

456+
@override
457+
bool get supportsFileUriExpression => true;
458+
456459
@override
457460
int get enabledLateLowerings => LateLowering.all;
458461

pkg/dev_compiler/lib/src/kernel/compiler.dart

Lines changed: 2 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ abstract class Compiler {
7878
class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
7979
with
8080
OnceConstantVisitorDefaultMixin<js_ast.Expression>,
81+
StatementVisitorInternalNodeMixin<js_ast.Statement>,
8182
StatementVisitorExperimentExclusionMixin<js_ast.Statement>,
83+
ExpressionVisitorInternalNodeMixin<js_ast.Expression>,
8284
ExpressionVisitorExperimentExclusionMixin<js_ast.Expression>
8385
implements
8486
StatementVisitor<js_ast.Statement>,
@@ -7685,36 +7687,6 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
76857687
return js_ast.Expression.binary(parts, '+');
76867688
}
76877689

7688-
@override
7689-
js_ast.Expression visitListConcatenation(ListConcatenation node) {
7690-
// Only occurs inside unevaluated constants.
7691-
throw UnsupportedError('List concatenation');
7692-
}
7693-
7694-
@override
7695-
js_ast.Expression visitSetConcatenation(SetConcatenation node) {
7696-
// Only occurs inside unevaluated constants.
7697-
throw UnsupportedError('Set concatenation');
7698-
}
7699-
7700-
@override
7701-
js_ast.Expression visitMapConcatenation(MapConcatenation node) {
7702-
// Only occurs inside unevaluated constants.
7703-
throw UnsupportedError('Map concatenation');
7704-
}
7705-
7706-
@override
7707-
js_ast.Expression visitInstanceCreation(InstanceCreation node) {
7708-
// Only occurs inside unevaluated constants.
7709-
throw UnsupportedError('Instance creation');
7710-
}
7711-
7712-
@override
7713-
js_ast.Expression visitFileUriExpression(FileUriExpression node) {
7714-
// Only occurs inside unevaluated constants.
7715-
throw UnsupportedError('File URI expression');
7716-
}
7717-
77187690
@override
77197691
js_ast.Expression visitConstructorTearOff(ConstructorTearOff node) {
77207692
throw UnsupportedError('Constructor tear off');
@@ -8547,43 +8519,6 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
85478519
return header;
85488520
}
85498521

8550-
@override
8551-
js_ast.Statement visitIfCaseStatement(IfCaseStatement node) {
8552-
// This node is internal to the front end and removed by the constant
8553-
// evaluator.
8554-
throw UnsupportedError('ProgramCompiler.visitIfCaseStatement');
8555-
}
8556-
8557-
@override
8558-
js_ast.Expression visitPatternAssignment(PatternAssignment node) {
8559-
// This node is internal to the front end and removed by the constant
8560-
// evaluator.
8561-
throw UnsupportedError('ProgramCompiler.visitPatternAssignment');
8562-
}
8563-
8564-
@override
8565-
js_ast.Statement visitPatternSwitchStatement(PatternSwitchStatement node) {
8566-
// This node is internal to the front end and removed by the constant
8567-
// evaluator.
8568-
throw UnsupportedError('ProgramCompiler.visitPatternSwitchStatement');
8569-
}
8570-
8571-
@override
8572-
js_ast.Statement visitPatternVariableDeclaration(
8573-
PatternVariableDeclaration node,
8574-
) {
8575-
// This node is internal to the front end and removed by the constant
8576-
// evaluator.
8577-
throw UnsupportedError('ProgramCompiler.visitPatternVariableDeclaration');
8578-
}
8579-
8580-
@override
8581-
js_ast.Expression visitSwitchExpression(SwitchExpression node) {
8582-
// This node is internal to the front end and removed by the constant
8583-
// evaluator.
8584-
throw UnsupportedError('ProgramCompiler.visitSwitchExpression');
8585-
}
8586-
85878522
@override
85888523
js_ast.Expression visitAuxiliaryExpression(AuxiliaryExpression node) {
85898524
throw UnsupportedError(

pkg/dev_compiler/lib/src/kernel/compiler_new.dart

Lines changed: 2 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,9 @@ enum HotReloadBranchState {
274274
class LibraryCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
275275
with
276276
OnceConstantVisitorDefaultMixin<js_ast.Expression>,
277+
StatementVisitorInternalNodeMixin<js_ast.Statement>,
277278
StatementVisitorExperimentExclusionMixin<js_ast.Statement>,
279+
ExpressionVisitorInternalNodeMixin<js_ast.Expression>,
278280
ExpressionVisitorExperimentExclusionMixin<js_ast.Expression>
279281
implements
280282
StatementVisitor<js_ast.Statement>,
@@ -8550,36 +8552,6 @@ class LibraryCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
85508552
return js_ast.Expression.binary(parts, '+');
85518553
}
85528554

8553-
@override
8554-
js_ast.Expression visitListConcatenation(ListConcatenation node) {
8555-
// Only occurs inside unevaluated constants.
8556-
throw UnsupportedError('List concatenation');
8557-
}
8558-
8559-
@override
8560-
js_ast.Expression visitSetConcatenation(SetConcatenation node) {
8561-
// Only occurs inside unevaluated constants.
8562-
throw UnsupportedError('Set concatenation');
8563-
}
8564-
8565-
@override
8566-
js_ast.Expression visitMapConcatenation(MapConcatenation node) {
8567-
// Only occurs inside unevaluated constants.
8568-
throw UnsupportedError('Map concatenation');
8569-
}
8570-
8571-
@override
8572-
js_ast.Expression visitInstanceCreation(InstanceCreation node) {
8573-
// Only occurs inside unevaluated constants.
8574-
throw UnsupportedError('Instance creation');
8575-
}
8576-
8577-
@override
8578-
js_ast.Expression visitFileUriExpression(FileUriExpression node) {
8579-
// Only occurs inside unevaluated constants.
8580-
throw UnsupportedError('File URI expression');
8581-
}
8582-
85838555
@override
85848556
js_ast.Expression visitConstructorTearOff(ConstructorTearOff node) {
85858557
throw UnsupportedError('Constructor tear off');
@@ -9472,43 +9444,6 @@ class LibraryCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
94729444
return jsReceiver;
94739445
}
94749446

9475-
@override
9476-
js_ast.Statement visitIfCaseStatement(IfCaseStatement node) {
9477-
// This node is internal to the front end and removed by the constant
9478-
// evaluator.
9479-
throw UnsupportedError('ProgramCompiler.visitIfCaseStatement');
9480-
}
9481-
9482-
@override
9483-
js_ast.Expression visitPatternAssignment(PatternAssignment node) {
9484-
// This node is internal to the front end and removed by the constant
9485-
// evaluator.
9486-
throw UnsupportedError('ProgramCompiler.visitPatternAssignment');
9487-
}
9488-
9489-
@override
9490-
js_ast.Statement visitPatternSwitchStatement(PatternSwitchStatement node) {
9491-
// This node is internal to the front end and removed by the constant
9492-
// evaluator.
9493-
throw UnsupportedError('ProgramCompiler.visitPatternSwitchStatement');
9494-
}
9495-
9496-
@override
9497-
js_ast.Statement visitPatternVariableDeclaration(
9498-
PatternVariableDeclaration node,
9499-
) {
9500-
// This node is internal to the front end and removed by the constant
9501-
// evaluator.
9502-
throw UnsupportedError('ProgramCompiler.visitPatternVariableDeclaration');
9503-
}
9504-
9505-
@override
9506-
js_ast.Expression visitSwitchExpression(SwitchExpression node) {
9507-
// This node is internal to the front end and removed by the constant
9508-
// evaluator.
9509-
throw UnsupportedError('ProgramCompiler.visitSwitchExpression');
9510-
}
9511-
95129447
@override
95139448
js_ast.Expression visitAuxiliaryExpression(AuxiliaryExpression node) {
95149449
throw UnsupportedError(

pkg/front_end/test/spell_checking_list_code.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,7 @@ delegating
454454
delim
455455
delimit
456456
delimiting
457+
delivered
457458
demands
458459
demangle
459460
demangled

pkg/kernel/lib/target/targets.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,16 @@ abstract class Target {
383383
/// literals (for const set literals).
384384
bool get supportsSetLiterals => true;
385385

386+
/// Whether [FileUriExpression] nodes are supported by this target after
387+
/// constant evaluation.
388+
///
389+
/// [FileUriExpression] are used internally in the CFE to handle annotations
390+
/// on patches, and are replaced with [FileUriConstantExpression] nodes during
391+
/// constant evaluation.
392+
///
393+
/// Targets can opt in to using this node for general inlining.
394+
bool get supportsFileUriExpression => false;
395+
386396
/// Bit mask of [LateLowering] values for the late lowerings that should
387397
/// be performed by the CFE.
388398
///

pkg/kernel/lib/verifier.dart

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1794,6 +1794,116 @@ class VerifyingVisitor extends RecursiveResultVisitor<void> {
17941794
}
17951795
super.visitSwitchStatement(node);
17961796
}
1797+
1798+
@override
1799+
void visitListConcatenation(ListConcatenation node) {
1800+
if (stage >= VerificationStage.afterConstantEvaluation) {
1801+
if (!inUnevaluatedConstant) {
1802+
problem(node, "Unexpected internal node $node.");
1803+
}
1804+
}
1805+
}
1806+
1807+
@override
1808+
void visitSetConcatenation(SetConcatenation node) {
1809+
if (stage >= VerificationStage.afterConstantEvaluation) {
1810+
if (!inUnevaluatedConstant) {
1811+
problem(node, "Unexpected internal node $node.");
1812+
}
1813+
}
1814+
}
1815+
1816+
@override
1817+
void visitMapConcatenation(MapConcatenation node) {
1818+
if (stage >= VerificationStage.afterConstantEvaluation) {
1819+
if (!inUnevaluatedConstant) {
1820+
problem(node, "Unexpected internal node $node.");
1821+
}
1822+
}
1823+
}
1824+
1825+
@override
1826+
void visitInstanceCreation(InstanceCreation node) {
1827+
if (stage >= VerificationStage.afterConstantEvaluation) {
1828+
if (!inUnevaluatedConstant) {
1829+
problem(node, "Unexpected internal node $node.");
1830+
}
1831+
}
1832+
}
1833+
1834+
@override
1835+
void visitFileUriExpression(FileUriExpression node) {
1836+
if (!target.supportsFileUriExpression) {
1837+
if (stage >= VerificationStage.afterConstantEvaluation) {
1838+
if (!inUnevaluatedConstant) {
1839+
problem(node, "Unexpected internal node $node.");
1840+
}
1841+
}
1842+
}
1843+
}
1844+
1845+
@override
1846+
void visitPatternAssignment(PatternAssignment node) {
1847+
if (stage >= VerificationStage.afterConstantEvaluation) {
1848+
problem(node, "Unexpected internal node $node.");
1849+
}
1850+
}
1851+
1852+
@override
1853+
void visitPatternVariableDeclaration(PatternVariableDeclaration node) {
1854+
if (stage >= VerificationStage.afterConstantEvaluation) {
1855+
problem(node, "Unexpected internal node $node.");
1856+
}
1857+
}
1858+
1859+
@override
1860+
void visitIfCaseStatement(IfCaseStatement node) {
1861+
if (stage >= VerificationStage.afterConstantEvaluation) {
1862+
problem(node, "Unexpected internal node $node.");
1863+
}
1864+
}
1865+
1866+
@override
1867+
void visitPatternSwitchStatement(PatternSwitchStatement node) {
1868+
if (stage >= VerificationStage.afterConstantEvaluation) {
1869+
problem(node, "Unexpected internal node $node.");
1870+
}
1871+
}
1872+
1873+
@override
1874+
void defaultPattern(Pattern node) {
1875+
if (stage >= VerificationStage.afterConstantEvaluation) {
1876+
problem(node, "Unexpected internal node $node.");
1877+
}
1878+
}
1879+
1880+
@override
1881+
void visitSwitchExpression(SwitchExpression node) {
1882+
if (stage >= VerificationStage.afterConstantEvaluation) {
1883+
problem(node, "Unexpected internal node $node.");
1884+
}
1885+
}
1886+
1887+
@override
1888+
void visitSwitchExpressionCase(SwitchExpressionCase node) {
1889+
if (stage >= VerificationStage.afterConstantEvaluation) {
1890+
problem(node, "Unexpected internal node $node.");
1891+
}
1892+
}
1893+
1894+
@override
1895+
void visitPatternGuard(PatternGuard node) {
1896+
if (stage >= VerificationStage.afterConstantEvaluation) {
1897+
problem(node, "Unexpected internal node $node.");
1898+
}
1899+
}
1900+
1901+
@override
1902+
void visitPatternSwitchCase(PatternSwitchCase node) {
1903+
if (stage >= VerificationStage.afterConstantEvaluation) {
1904+
problem(node, "Unexpected internal node $node.");
1905+
}
1906+
}
17971907
}
17981908

17991909
class VerifyGetStaticType extends RecursiveVisitor {

0 commit comments

Comments
 (0)