Skip to content

Commit 7194e88

Browse files
iinozemtsevcommit-bot@chromium.org
authored andcommitted
Revert submission 181620
Reason for revert: b/179155154 Reverted Changes: I17bd9d9e0:[dart2js] Refactor closure data to use AST nodes i... I6578b727d:[dart2js] Remove GlobalsLocalsMap from JClosedWorl... Change-Id: I6cb48937220d2ed3814002254c0717feebe78a94 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/182502 Commit-Queue: Ivan Inozemtsev <[email protected]> Reviewed-by: Ivan Inozemtsev <[email protected]> Reviewed-by: Johnni Winther <[email protected]>
1 parent ae4631e commit 7194e88

28 files changed

+445
-678
lines changed

pkg/compiler/lib/src/backend_strategy.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import 'js_backend/backend.dart';
1616
import 'js_backend/enqueuer.dart';
1717
import 'js_backend/inferred_data.dart';
1818
import 'js_emitter/code_emitter_task.dart';
19-
import 'js_model/locals.dart';
2019
import 'serialization/serialization.dart';
2120
import 'ssa/ssa.dart';
2221
import 'universe/codegen_world_builder.dart';
@@ -66,8 +65,8 @@ abstract class BackendStrategy {
6665
SourceSpan spanFromSpannable(Spannable spannable, Entity currentElement);
6766

6867
/// Creates the [TypesInferrer] used by this strategy.
69-
TypesInferrer createTypesInferrer(JClosedWorld closedWorld,
70-
GlobalLocalsMap globalLocalsMap, InferredDataBuilder inferredDataBuilder);
68+
TypesInferrer createTypesInferrer(
69+
JClosedWorld closedWorld, InferredDataBuilder inferredDataBuilder);
7170

7271
/// Calls [f] for every member that needs to be serialized for modular code
7372
/// generation and returns an [EntityWriter] for encoding these members in

pkg/compiler/lib/src/closure.dart

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,6 @@ abstract class ClosureData {
3535
/// Accessor to the information about scopes that closures capture. Used by
3636
/// the SSA builder.
3737
CapturedScope getCapturedScope(MemberEntity entity);
38-
39-
/// If [entity] is a closure call method or closure signature method, the
40-
/// original enclosing member is returned. Otherwise [entity] is returned.
41-
///
42-
/// A member and its nested closure share the underlying AST, we need to
43-
/// ensure that locals are shared between them. We therefore store the
44-
/// locals in the global locals map using the enclosing member as key.
45-
MemberEntity getEnclosingMember(MemberEntity entity);
4638
}
4739

4840
/// Enum used for identifying [ScopeInfo] subclasses in serialization.
@@ -76,7 +68,7 @@ class ScopeInfo {
7668
case ScopeInfoKind.capturedLoopScope:
7769
return new JsCapturedLoopScope.readFromDataSource(source);
7870
case ScopeInfoKind.closureRepresentationInfo:
79-
return new JsClosureClassInfo.readFromDataSource(source);
71+
return new KernelClosureClassInfo.readFromDataSource(source);
8072
}
8173
throw new UnsupportedError('Unexpected ScopeInfoKind $kind');
8274
}
@@ -100,8 +92,7 @@ class ScopeInfo {
10092
/// Also parameters to a `sync*` generator must be boxed, because of the way
10193
/// we rewrite sync* functions. See also comments in
10294
/// [ClosureClassMap.useLocal].
103-
bool localIsUsedInTryOrSync(KernelToLocalsMap localsMap, Local variable) =>
104-
false;
95+
bool localIsUsedInTryOrSync(Local variable) => false;
10596

10697
/// Loop through each variable that has been defined in this scope, modified
10798
/// anywhere (this scope or another scope) and used in another scope. Because
@@ -113,11 +104,10 @@ class ScopeInfo {
113104
/// In the case of loops, this is the set of iteration variables (or any
114105
/// variables declared in the for loop expression (`for (...here...)`) that
115106
/// need to be boxed to snapshot their value.
116-
void forEachBoxedVariable(
117-
KernelToLocalsMap localsMap, f(Local local, FieldEntity field)) {}
107+
void forEachBoxedVariable(f(Local local, FieldEntity field)) {}
118108

119109
/// True if [variable] has been mutated and is also used in another scope.
120-
bool isBoxedVariable(KernelToLocalsMap localsMap, Local variable) => false;
110+
bool isBoxedVariable(Local variable) => false;
121111
}
122112

123113
/// Class representing the usage of a scope that has been captured in the
@@ -151,7 +141,7 @@ class CapturedScope extends ScopeInfo {
151141
/// executed. This will encapsulate the value of any variables that have been
152142
/// scoped into this context from outside. This is an accessor to the
153143
/// contextBox that [requiresContextBox] is testing is required.
154-
Local get contextBox => null;
144+
Local get context => null;
155145
}
156146

157147
/// Class that describes the actual mechanics of how values of variables
@@ -205,8 +195,7 @@ class CapturedLoopScope extends CapturedScope {
205195
///
206196
/// `i` would be a part of the boxedLoopVariables AND boxedVariables, but b
207197
/// would only be a part of boxedVariables.
208-
List<Local> getBoxedLoopVariables(KernelToLocalsMap localsMap) =>
209-
const <Local>[];
198+
List<Local> get boxedLoopVariables => const <Local>[];
210199
}
211200

212201
/// Class that describes the actual mechanics of how the converted, rewritten
@@ -250,15 +239,15 @@ class ClosureRepresentationInfo extends ScopeInfo {
250239
throw new UnsupportedError(
251240
'Unexpected ClosureRepresentationInfo kind $kind');
252241
case ScopeInfoKind.closureRepresentationInfo:
253-
return new JsClosureClassInfo.readFromDataSource(source);
242+
return new KernelClosureClassInfo.readFromDataSource(source);
254243
}
255244
throw new UnsupportedError('Unexpected ScopeInfoKind $kind');
256245
}
257246

258247
/// The original local function before any translation.
259248
///
260249
/// Will be null for methods.
261-
Local getClosureEntity(KernelToLocalsMap localsMap) => null;
250+
Local get closureEntity => null;
262251

263252
/// The entity for the class used to represent the rewritten closure in the
264253
/// emitted JavaScript.
@@ -277,14 +266,13 @@ class ClosureRepresentationInfo extends ScopeInfo {
277266
/// List of locals that this closure class has created corresponding field
278267
/// entities for.
279268
@deprecated
280-
List<Local> getCreatedFieldEntities(KernelToLocalsMap localsMap) =>
281-
const <Local>[];
269+
List<Local> get createdFieldEntities => const <Local>[];
282270

283271
/// As shown in the example in the comments at the top of this class, we
284272
/// create fields in the closure class for each captured variable. This is an
285273
/// accessor the [local] for which [field] was created.
286274
/// Returns the [local] for which [field] was created.
287-
Local getLocalForField(KernelToLocalsMap localsMap, FieldEntity field) {
275+
Local getLocalForField(FieldEntity field) {
288276
failedAt(field, "No local for $field.");
289277
return null;
290278
}
@@ -301,14 +289,12 @@ class ClosureRepresentationInfo extends ScopeInfo {
301289
/// strictly variables defined in this closure, unlike the behavior in
302290
/// the superclass ScopeInfo.
303291
@override
304-
void forEachBoxedVariable(
305-
KernelToLocalsMap localsMap, f(Local local, FieldEntity field)) {}
292+
void forEachBoxedVariable(f(Local local, FieldEntity field)) {}
306293

307294
/// Loop through each free variable in this closure. Free variables are the
308295
/// variables that have been captured *just* in this closure, not in nested
309296
/// scopes.
310-
void forEachFreeVariable(
311-
KernelToLocalsMap localsMap, f(Local variable, FieldEntity field)) {}
297+
void forEachFreeVariable(f(Local variable, FieldEntity field)) {}
312298

313299
// TODO(efortuna): Remove this method. The old system was using
314300
// ClosureClassMaps for situations other than closure class maps, and that's

pkg/compiler/lib/src/compiler.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ import 'js_backend/backend.dart' show CodegenInputs, JavaScriptImpactStrategy;
3939
import 'js_backend/inferred_data.dart';
4040
import 'js_model/js_strategy.dart';
4141
import 'js_model/js_world.dart';
42-
import 'js_model/locals.dart';
4342
import 'kernel/kernel_strategy.dart';
4443
import 'kernel/loader.dart' show KernelLoaderTask, KernelResult;
4544
import 'null_compiler_output.dart' show NullCompilerOutput;
@@ -402,12 +401,10 @@ abstract class Compiler {
402401
JClosedWorld closedWorld) {
403402
FunctionEntity mainFunction = closedWorld.elementEnvironment.mainFunction;
404403
reporter.log('Performing global type inference');
405-
GlobalLocalsMap globalLocalsMap =
406-
new GlobalLocalsMap(closedWorld.closureDataLookup.getEnclosingMember);
407404
InferredDataBuilder inferredDataBuilder =
408405
new InferredDataBuilderImpl(closedWorld.annotationsData);
409406
return globalInference.runGlobalTypeInference(
410-
mainFunction, closedWorld, globalLocalsMap, inferredDataBuilder);
407+
mainFunction, closedWorld, inferredDataBuilder);
411408
}
412409

413410
void runCodegenEnqueuer(CodegenResults codegenResults) {

pkg/compiler/lib/src/dump_info.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ class ElementInfoCollector {
271271
List<String> inferredParameterTypes = <String>[];
272272

273273
closedWorld.elementEnvironment.forEachParameterAsLocal(
274-
_globalInferenceResults.globalLocalsMap, function, (parameter) {
274+
closedWorld.globalLocalsMap, function, (parameter) {
275275
inferredParameterTypes.add('${_resultOfParameter(parameter)}');
276276
});
277277
int parameterIndex = 0;

pkg/compiler/lib/src/inferrer/builder_kernel.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ class KernelTypeGraphBuilder extends ir.Visitor<TypeInformation> {
218218
// each update, and reading them yields the type that was found in a
219219
// previous analysis of [outermostElement].
220220
ScopeInfo scopeInfo = _closureDataLookup.getScopeInfo(_analyzedMember);
221-
scopeInfo.forEachBoxedVariable(_localsMap, (variable, field) {
221+
scopeInfo.forEachBoxedVariable((variable, field) {
222222
_capturedAndBoxed[variable] = field;
223223
});
224224

@@ -1722,8 +1722,8 @@ class KernelTypeGraphBuilder extends ir.Visitor<TypeInformation> {
17221722
// Record the types of captured non-boxed variables. Types of
17231723
// these variables may already be there, because of an analysis of
17241724
// a previous closure.
1725-
info.forEachFreeVariable(_localsMap, (Local variable, FieldEntity field) {
1726-
if (!info.isBoxedVariable(_localsMap, variable)) {
1725+
info.forEachFreeVariable((Local variable, FieldEntity field) {
1726+
if (!info.isBoxedVariable(variable)) {
17271727
if (variable == info.thisLocal) {
17281728
_inferrer.recordTypeOfField(field, thisType);
17291729
}

pkg/compiler/lib/src/inferrer/inferrer_engine.dart

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ class InferrerEngine {
6464

6565
final TypeSystem types;
6666
final Map<ir.TreeNode, TypeInformation> concreteTypes = {};
67-
final GlobalLocalsMap globalLocalsMap;
6867
final InferredDataBuilder inferredDataBuilder;
6968

7069
final FunctionEntity mainElement;
@@ -115,10 +114,9 @@ class InferrerEngine {
115114
this._compilerOutput,
116115
this.closedWorld,
117116
this.mainElement,
118-
this.globalLocalsMap,
119117
this.inferredDataBuilder)
120-
: this.types = new TypeSystem(closedWorld,
121-
new KernelTypeSystemStrategy(closedWorld, globalLocalsMap));
118+
: this.types = new TypeSystem(
119+
closedWorld, new KernelTypeSystemStrategy(closedWorld));
122120

123121
/// Applies [f] to all elements in the universe that match [selector] and
124122
/// [mask]. If [f] returns false, aborts the iteration.
@@ -636,7 +634,7 @@ class InferrerEngine {
636634
this,
637635
member,
638636
body,
639-
globalLocalsMap.getLocalsMap(member),
637+
closedWorld.globalLocalsMap.getLocalsMap(member),
640638
closedWorld.elementMap.getStaticTypeProvider(member));
641639
return visitor.run();
642640
}
@@ -1226,9 +1224,8 @@ class _InferrerEngineMetrics extends MetricsBase {
12261224

12271225
class KernelTypeSystemStrategy implements TypeSystemStrategy {
12281226
final JsClosedWorld _closedWorld;
1229-
final GlobalLocalsMap _globalLocalsMap;
12301227

1231-
KernelTypeSystemStrategy(this._closedWorld, this._globalLocalsMap);
1228+
KernelTypeSystemStrategy(this._closedWorld);
12321229

12331230
JElementEnvironment get _elementEnvironment =>
12341231
_closedWorld.elementEnvironment;
@@ -1255,8 +1252,8 @@ class KernelTypeSystemStrategy implements TypeSystemStrategy {
12551252
@override
12561253
void forEachParameter(FunctionEntity function, void f(Local parameter)) {
12571254
forEachOrderedParameterAsLocal(
1258-
_globalLocalsMap, _closedWorld.elementMap, function, (Local parameter,
1259-
{bool isElided}) {
1255+
_closedWorld.globalLocalsMap, _closedWorld.elementMap, function,
1256+
(Local parameter, {bool isElided}) {
12601257
f(parameter);
12611258
});
12621259
}
@@ -1267,7 +1264,8 @@ class KernelTypeSystemStrategy implements TypeSystemStrategy {
12671264
covariant JLocal parameter,
12681265
TypeSystem types) {
12691266
MemberEntity context = parameter.memberContext;
1270-
KernelToLocalsMap localsMap = _globalLocalsMap.getLocalsMap(context);
1267+
KernelToLocalsMap localsMap =
1268+
_closedWorld.globalLocalsMap.getLocalsMap(context);
12711269
ir.FunctionNode functionNode =
12721270
localsMap.getFunctionNodeForParameter(parameter);
12731271
DartType type = localsMap.getLocalType(_closedWorld.elementMap, parameter);

pkg/compiler/lib/src/inferrer/type_graph_inferrer.dart

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import '../compiler.dart';
1313
import '../elements/entities.dart';
1414
import '../js_backend/inferred_data.dart';
1515
import '../js_model/elements.dart' show JClosureCallMethod;
16-
import '../js_model/locals.dart';
1716
import '../world.dart';
1817
import 'abstract_value_domain.dart';
1918
import 'inferrer_engine.dart';
@@ -54,12 +53,11 @@ class TypeGraphInferrer implements TypesInferrer {
5453
final JClosedWorld closedWorld;
5554

5655
final Compiler _compiler;
57-
final GlobalLocalsMap _globalLocalsMap;
5856
final InferredDataBuilder _inferredDataBuilder;
5957
Metrics /*?*/ _metrics;
6058

61-
TypeGraphInferrer(this._compiler, this.closedWorld, this._globalLocalsMap,
62-
this._inferredDataBuilder);
59+
TypeGraphInferrer(
60+
this._compiler, this.closedWorld, this._inferredDataBuilder);
6361

6462
String get name => 'Graph inferrer';
6563

@@ -84,7 +82,6 @@ class TypeGraphInferrer implements TypesInferrer {
8482
_compiler.outputProvider,
8583
closedWorld,
8684
main,
87-
_globalLocalsMap,
8885
_inferredDataBuilder);
8986
}
9087

@@ -137,8 +134,7 @@ class TypeGraphInferrer implements TypesInferrer {
137134
if (member is JClosureCallMethod) {
138135
ClosureRepresentationInfo info =
139136
closedWorld.closureDataLookup.getScopeInfo(member);
140-
info.forEachFreeVariable(_globalLocalsMap.getLocalsMap(member),
141-
(Local from, FieldEntity to) {
137+
info.forEachFreeVariable((Local from, FieldEntity to) {
142138
freeVariables.add(to);
143139
});
144140
}
@@ -171,7 +167,6 @@ class TypeGraphInferrer implements TypesInferrer {
171167

172168
GlobalTypeInferenceResults results = new GlobalTypeInferenceResultsImpl(
173169
closedWorld,
174-
_globalLocalsMap,
175170
_inferredDataBuilder.close(closedWorld),
176171
memberResults,
177172
parameterResults,

0 commit comments

Comments
 (0)