Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Unified Diff: pkg/front_end/lib/src/fasta/kernel/kernel_shadow_ast.dart

Issue 2877253003: Don't type promote local functions. (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/front_end/lib/src/fasta/kernel/kernel_shadow_ast.dart
diff --git a/pkg/front_end/lib/src/fasta/kernel/kernel_shadow_ast.dart b/pkg/front_end/lib/src/fasta/kernel/kernel_shadow_ast.dart
index 65f2bba6383a0caaef4b4382d3583c21a5a21531..937242b4458a1f7cc9e2a0d77be297cda6e94f50 100644
--- a/pkg/front_end/lib/src/fasta/kernel/kernel_shadow_ast.dart
+++ b/pkg/front_end/lib/src/fasta/kernel/kernel_shadow_ast.dart
@@ -274,6 +274,19 @@ class KernelField extends Field {
}
}
+/// Concrete shadow object representing a local function declaration in kernel
+/// form.
+class KernelFunctionDeclaration extends FunctionDeclaration
+ implements KernelStatement {
+ KernelFunctionDeclaration(VariableDeclaration variable, FunctionNode function)
+ : super(variable, function);
+
+ @override
+ void _inferStatement(KernelTypeInferrer inferrer) {
+ inferrer.inferFunctionDeclaration(function.body);
+ }
+}
+
/// Concrete shadow object representing a function expression in kernel form.
class KernelFunctionExpression extends FunctionExpression
implements KernelExpression {
@@ -853,6 +866,19 @@ class KernelTypePromoter
}
}
+ @override
+ bool isPromotionCandidate(VariableDeclaration variable) {
+ if (variable is KernelVariableDeclaration) {
+ return !variable._isLocalFunction;
+ } else {
+ // Hack to deal with the fact that BodyBuilder still creates raw
+ // VariableDeclaration objects sometimes.
+ // TODO(paulberry): get rid of this once the type parameter is
+ // KernelVariableDeclaration.
+ return true;
+ }
+ }
+
@override
bool sameExpressions(Expression a, Expression b) {
return identical(a, b);
@@ -907,12 +933,16 @@ class KernelVariableDeclaration extends VariableDeclaration
bool _mutatedAnywhere = false;
+ final bool _isLocalFunction;
+
KernelVariableDeclaration(String name, this._functionNestingLevel,
{Expression initializer,
DartType type,
bool isFinal: false,
- bool isConst: false})
+ bool isConst: false,
+ bool isLocalFunction: false})
: _implicitlyTyped = type == null,
+ _isLocalFunction = isLocalFunction,
super(name,
initializer: initializer,
type: type ?? const DynamicType(),

Powered by Google App Engine
This is Rietveld 408576698