Skip to content

Commit cad0aae

Browse files
chloestefantsovaCommit Queue
authored andcommitted
[cfe] Introduce Kernel AST node for the closure expreiment
Part of #61572 Change-Id: Iee3c2a223f4c44f5528016082cf3a068b401d87d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/454061 Reviewed-by: Alexander Markov <alexmarkov@google.com> Reviewed-by: Johnni Winther <johnniwinther@google.com> Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
1 parent a478a44 commit cad0aae

29 files changed

+2095
-45
lines changed

pkg/front_end/lib/src/kernel/hierarchy/mixin_inferrer.dart

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import 'package:kernel/type_algebra.dart';
1010

1111
import '../../base/messages.dart'
1212
show Message, codeMixinInferenceNoMatchingClass;
13-
import '../../base/problems.dart' show unexpected, unsupported;
13+
import '../../base/problems.dart' show unexpected, unimplemented, unsupported;
1414
import '../../source/source_class_builder.dart';
1515
import '../../type_inference/type_schema.dart';
1616

@@ -223,6 +223,15 @@ class BuilderMixinInferrer {
223223
classBuilder.fileUri,
224224
);
225225
}
226+
227+
// Coverage-ignore(suite): Not run.
228+
Never reportUnimplementedProblem(String operation) {
229+
return unimplemented(
230+
operation,
231+
classBuilder.fileOffset,
232+
classBuilder.fileUri,
233+
);
234+
}
226235
}
227236

228237
class _MixinInferenceSolution {
@@ -447,6 +456,22 @@ class _MixinInferenceSolution {
447456
} else {
448457
return <TypeParameter, DartType>{};
449458
}
459+
case FunctionTypeParameterType():
460+
// Coverage-ignore(suite): Not run.
461+
// Type variable types are currently an experiment aren't fully
462+
// implemented.
463+
return unsupportedErrorReporter.reportUnimplementedProblem(
464+
"_MixinInferenceSolution._solveForEquality"
465+
"(${type1.runtimeType}, ${type2.runtimeType})",
466+
);
467+
case ClassTypeParameterType():
468+
// Coverage-ignore(suite): Not run.
469+
// Class type parameter types are currently an experiment aren't fully
470+
// implemented.
471+
return unsupportedErrorReporter.reportUnimplementedProblem(
472+
"_MixinInferenceSolution._solveForEquality"
473+
"(${type1.runtimeType}, ${type2.runtimeType})",
474+
);
450475
case RecordType():
451476
// Coverage-ignore(suite): Not run.
452477
if (type2 is! RecordType) {

pkg/front_end/lib/src/kernel/internal_ast.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ class Cascade extends InternalExpression {
398398
printer.newLine();
399399
}
400400
printer.write('} => ');
401-
printer.write(printer.getVariableName(variable));
401+
printer.write(printer.getVariableDeclarationName(variable));
402402
}
403403
}
404404

pkg/front_end/lib/src/type_inference/inference_visitor.dart

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import '../base/compiler_context.dart';
2626
import '../base/messages.dart';
2727
import '../base/problems.dart'
2828
as problems
29-
show internalProblem, unhandled, unsupported;
29+
show internalProblem, unhandled, unimplemented, unsupported;
3030
import '../base/uri_offset.dart';
3131
import '../builder/library_builder.dart';
3232
import '../dill/dill_library_builder.dart';
@@ -1100,6 +1100,20 @@ class InferenceVisitorImpl extends InferenceVisitorBase
11001100
return _isIncompatibleWithAwait(type.parameter.bound);
11011101
case IntersectionType():
11021102
return _isIncompatibleWithAwait(type.right);
1103+
case FunctionTypeParameterType():
1104+
// Coverage-ignore(suite): Not run.
1105+
return problems.unimplemented(
1106+
"_isIncompatibleWithAwait(FunctionTypeParameterType)",
1107+
-1,
1108+
fileUri,
1109+
);
1110+
case ClassTypeParameterType():
1111+
// Coverage-ignore(suite): Not run.
1112+
return problems.unimplemented(
1113+
"_isIncompatibleWithAwait(ClassTypeParameterType)",
1114+
-1,
1115+
fileUri,
1116+
);
11031117
case DynamicType():
11041118
case VoidType():
11051119
case FutureOrType():

pkg/front_end/test/spell_checking_list_common.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -948,6 +948,7 @@ distinct
948948
distinction
949949
distinguish
950950
distinguishes
951+
distinguishing
951952
divide
952953
division
953954
divisor
@@ -1084,6 +1085,7 @@ enumeration
10841085
enumerations
10851086
enums
10861087
environment
1088+
environments
10871089
equal
10881090
equalities
10891091
equality
@@ -1129,6 +1131,7 @@ examined
11291131
examining
11301132
example
11311133
examples
1134+
exceed
11321135
exceeded
11331136
except
11341137
exception
@@ -2953,6 +2956,7 @@ spending
29532956
split
29542957
splits
29552958
splitter
2959+
spot
29562960
spread
29572961
spreadable
29582962
spreads
@@ -3461,6 +3465,7 @@ visiting
34613465
visitor
34623466
visitor's
34633467
visual
3468+
visually
34643469
vm
34653470
void
34663471
vowel

pkg/front_end/tool/ast_model.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ const Map<String?, Map<String, FieldRule?>> _fieldRuleMap = {
148148
'VariablePattern': {'variable': FieldRule(isDeclaration: true)},
149149
'PatternSwitchCase': {'jointVariables': FieldRule(isDeclaration: true)},
150150
'PatternSwitchStatement': {'cases': FieldRule(isDeclaration: true)},
151+
'TypeVariable': {'parameter': FieldRule(isDeclaration: false)},
152+
'ClassTypeParameterType': {'parameter': FieldRule(isDeclaration: false)},
151153
};
152154

153155
/// Data that determines exceptions to how fields are used.

pkg/kernel/lib/ast.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,4 @@ part 'src/ast/patterns.dart';
124124
part 'src/ast/statements.dart';
125125
part 'src/ast/typedefs.dart';
126126
part 'src/ast/types.dart';
127+
part 'src/ast/variables.dart';

pkg/kernel/lib/src/ast/expressions.dart

Lines changed: 116 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ class VariableGet extends Expression {
242242

243243
@override
244244
void toTextInternal(AstPrinter printer) {
245-
printer.write(printer.getVariableName(variable));
245+
printer.write(printer.getVariableDeclarationName(variable));
246246
if (promotedType != null) {
247247
printer.write('{');
248248
printer.writeType(promotedType!);
@@ -301,7 +301,7 @@ class VariableSet extends Expression {
301301

302302
@override
303303
void toTextInternal(AstPrinter printer) {
304-
printer.write(printer.getVariableName(variable));
304+
printer.write(printer.getVariableDeclarationName(variable));
305305
printer.write(' = ');
306306
printer.writeExpression(value);
307307
}
@@ -2211,7 +2211,7 @@ class LocalFunctionInvocation extends InvocationExpression {
22112211

22122212
@override
22132213
void toTextInternal(AstPrinter printer) {
2214-
printer.write(printer.getVariableName(variable));
2214+
printer.write(printer.getVariableDeclarationName(variable));
22152215
printer.writeArguments(arguments);
22162216
}
22172217
}
@@ -4764,10 +4764,13 @@ class Let extends Expression {
47644764
}
47654765
}
47664766

4767-
class BlockExpression extends Expression {
4767+
class BlockExpression extends Expression implements ScopeProvider {
47684768
Block body;
47694769
Expression value;
47704770

4771+
@override
4772+
Scope? scope;
4773+
47714774
BlockExpression(this.body, this.value) {
47724775
body.parent = this;
47734776
value.parent = this;
@@ -5101,3 +5104,112 @@ class TypedefTearOff extends Expression {
51015104
printer.write(")");
51025105
}
51035106
}
5107+
5108+
/// [VariableRead] nodes are the replacement for the VariableGet nodes.
5109+
///
5110+
/// Despite of the name, [VariableRead] can't read [TypeVariable]s,
5111+
/// which are also [Variable]s.
5112+
class VariableRead extends Expression {
5113+
final ExpressionVariable variable;
5114+
5115+
VariableRead({required this.variable});
5116+
5117+
@override
5118+
R accept<R>(ExpressionVisitor<R> v) {
5119+
// TODO(cstefantsova): Implement accept.
5120+
throw UnimplementedError();
5121+
}
5122+
5123+
@override
5124+
R accept1<R, A>(ExpressionVisitor1<R, A> v, A arg) {
5125+
// TODO(cstefantsova): Implement accept1.
5126+
throw UnimplementedError();
5127+
}
5128+
5129+
@override
5130+
DartType getStaticTypeInternal(StaticTypeContext context) {
5131+
// TODO(cstefantsova): Implement getStaticTypeInternal.
5132+
throw UnimplementedError();
5133+
}
5134+
5135+
@override
5136+
void transformChildren(Transformer v) {
5137+
// TODO(cstefantsova): Implement transformChildren.
5138+
}
5139+
5140+
@override
5141+
void transformOrRemoveChildren(RemovingTransformer v) {
5142+
// TODO(cstefantsova): Implement transformOrRemoveChildren.
5143+
}
5144+
5145+
@override
5146+
void visitChildren(Visitor v) {
5147+
// TODO(cstefantsova): Implement visitChildren.
5148+
}
5149+
5150+
@override
5151+
String toString() {
5152+
return "VariableRead(${toStringInternal()})";
5153+
}
5154+
5155+
@override
5156+
void toTextInternal(AstPrinter printer) {
5157+
printer.write(printer.getVariableName(variable));
5158+
}
5159+
}
5160+
5161+
/// [VariableWrite] nodes are the replacement for the VariableSet nodes.
5162+
///
5163+
/// Despite of the name, [VariableWrite] can't write into
5164+
/// [TypeVariable]s, which are also [Variable]s.
5165+
class VariableWrite extends Expression {
5166+
final ExpressionVariable variable;
5167+
final Expression value;
5168+
5169+
VariableWrite({required this.variable, required this.value});
5170+
5171+
@override
5172+
R accept<R>(ExpressionVisitor<R> v) {
5173+
// TODO(cstefantsova): Implement accept.
5174+
throw UnimplementedError();
5175+
}
5176+
5177+
@override
5178+
R accept1<R, A>(ExpressionVisitor1<R, A> v, A arg) {
5179+
// TODO(cstefantsova): Implement accept1.
5180+
throw UnimplementedError();
5181+
}
5182+
5183+
@override
5184+
DartType getStaticTypeInternal(StaticTypeContext context) {
5185+
// TODO(cstefantsova): Implement getStaticTypeInternal.
5186+
throw UnimplementedError();
5187+
}
5188+
5189+
@override
5190+
void transformChildren(Transformer v) {
5191+
// TODO(cstefantsova): Implement transformChildren.
5192+
}
5193+
5194+
@override
5195+
void transformOrRemoveChildren(RemovingTransformer v) {
5196+
// TODO(cstefantsova): Implement transformOrRemoveChildren.
5197+
}
5198+
5199+
@override
5200+
void visitChildren(Visitor v) {
5201+
// TODO(cstefantsova): Implement visitChildren.
5202+
}
5203+
5204+
@override
5205+
String toString() {
5206+
return "VariableWrite(${toStringInternal()})";
5207+
}
5208+
5209+
@override
5210+
void toTextInternal(AstPrinter printer) {
5211+
printer.write(printer.getVariableName(variable));
5212+
printer.write(' = ');
5213+
printer.writeExpression(value);
5214+
}
5215+
}

pkg/kernel/lib/src/ast/functions.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ part of '../../ast.dart';
1212
///
1313
/// This may occur in a procedure, constructor, function expression, or local
1414
/// function declaration.
15-
class FunctionNode extends TreeNode {
15+
class FunctionNode extends TreeNode implements ScopeProvider {
1616
/// End offset in the source file it comes from. Valid values are from 0 and
1717
/// up, or -1 ([TreeNode.noOffset]) if the file end offset is not available
1818
/// (this is the default if none is specifically set).
@@ -44,6 +44,9 @@ class FunctionNode extends TreeNode {
4444
DartType returnType; // Not null.
4545
Statement? _body;
4646

47+
@override
48+
Scope? scope;
49+
4750
/// The emitted value of non-sync functions
4851
///
4952
/// For `async` functions [emittedValueType] is the future value type, that

0 commit comments

Comments
 (0)