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

Side by Side Diff: pkg/analyzer/lib/src/summary/link.dart

Issue 2015833004: Fix circularity detection for AST-based type inference in the presence of closures. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 6 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 unified diff | Download patch
« no previous file with comments | « no previous file | pkg/analyzer/test/src/summary/resynthesize_ast_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 /** 5 /**
6 * This library is capable of producing linked summaries from unlinked 6 * This library is capable of producing linked summaries from unlinked
7 * ones (or prelinked ones). It functions by building a miniature 7 * ones (or prelinked ones). It functions by building a miniature
8 * element model to represent the contents of the summaries, and then 8 * element model to represent the contents of the summaries, and then
9 * scanning the element model to gather linked information and adding 9 * scanning the element model to gather linked information and adding
10 * it to the summary data structures. 10 * it to the summary data structures.
(...skipping 4312 matching lines...) Expand 10 before | Expand all | Expand 10 after
4323 * node refers. 4323 * node refers.
4324 */ 4324 */
4325 final VariableElementForLink variableElement; 4325 final VariableElementForLink variableElement;
4326 4326
4327 TypeInferenceNode(this.variableElement); 4327 TypeInferenceNode(this.variableElement);
4328 4328
4329 @override 4329 @override
4330 bool get isEvaluated => variableElement._inferredType != null; 4330 bool get isEvaluated => variableElement._inferredType != null;
4331 4331
4332 /** 4332 /**
4333 * Collect the type inference dependencies in [unlinkedConst] (which should be 4333 * Collect the type inference dependencies in [unlinkedExecutable] (which
4334 * interpreted relative to [compilationUnit]) and store them in 4334 * should be interpreted relative to [compilationUnit]) and store them in
4335 * [dependencies]. 4335 * [dependencies].
4336 */ 4336 */
4337 void collectDependencies( 4337 void collectDependencies(
4338 List<TypeInferenceNode> dependencies, 4338 List<TypeInferenceNode> dependencies,
4339 UnlinkedConst unlinkedConst, 4339 UnlinkedExecutable unlinkedExecutable,
4340 CompilationUnitElementForLink compilationUnit) { 4340 CompilationUnitElementForLink compilationUnit) {
4341 UnlinkedConst unlinkedConst = unlinkedExecutable?.bodyExpr;
4341 if (unlinkedConst == null) { 4342 if (unlinkedConst == null) {
4342 return; 4343 return;
4343 } 4344 }
4344 int refPtr = 0; 4345 int refPtr = 0;
4346 int intPtr = 0;
4345 4347
4346 for (UnlinkedConstOperation operation in unlinkedConst.operations) { 4348 for (UnlinkedConstOperation operation in unlinkedConst.operations) {
4347 switch (operation) { 4349 switch (operation) {
4350 case UnlinkedConstOperation.pushInt:
4351 intPtr++;
4352 break;
4353 case UnlinkedConstOperation.pushLongInt:
4354 int numInts = unlinkedConst.ints[intPtr++];
4355 intPtr += numInts;
4356 break;
4357 case UnlinkedConstOperation.concatenate:
4358 intPtr++;
4359 break;
4348 case UnlinkedConstOperation.pushReference: 4360 case UnlinkedConstOperation.pushReference:
4349 EntityRef ref = unlinkedConst.references[refPtr++]; 4361 EntityRef ref = unlinkedConst.references[refPtr++];
4350 // TODO(paulberry): cache these resolved references for 4362 // TODO(paulberry): cache these resolved references for
4351 // later use by evaluate(). 4363 // later use by evaluate().
4352 TypeInferenceNode dependency = 4364 TypeInferenceNode dependency =
4353 compilationUnit.resolveRef(ref.reference).asTypeInferenceNode; 4365 compilationUnit.resolveRef(ref.reference).asTypeInferenceNode;
4354 if (dependency != null) { 4366 if (dependency != null) {
4355 dependencies.add(dependency); 4367 dependencies.add(dependency);
4356 } 4368 }
4357 break; 4369 break;
4358 case UnlinkedConstOperation.makeTypedList:
4359 case UnlinkedConstOperation.invokeConstructor: 4370 case UnlinkedConstOperation.invokeConstructor:
4360 refPtr++; 4371 refPtr++;
4372 intPtr += 2;
4373 break;
4374 case UnlinkedConstOperation.makeUntypedList:
4375 case UnlinkedConstOperation.makeUntypedMap:
4376 intPtr++;
4377 break;
4378 case UnlinkedConstOperation.makeTypedList:
4379 refPtr++;
4380 intPtr++;
4361 break; 4381 break;
4362 case UnlinkedConstOperation.makeTypedMap: 4382 case UnlinkedConstOperation.makeTypedMap:
4363 refPtr += 2; 4383 refPtr += 2;
4384 intPtr++;
4364 break; 4385 break;
4365 case UnlinkedConstOperation.assignToRef: 4386 case UnlinkedConstOperation.assignToRef:
4366 // TODO(paulberry): if this reference refers to a variable, should it 4387 // TODO(paulberry): if this reference refers to a variable, should it
4367 // be considered a type inference dependency? 4388 // be considered a type inference dependency?
4368 refPtr++; 4389 refPtr++;
4369 break; 4390 break;
4370 case UnlinkedConstOperation.invokeMethodRef: 4391 case UnlinkedConstOperation.invokeMethodRef:
4371 // TODO(paulberry): if this reference refers to a variable, should it 4392 // TODO(paulberry): if this reference refers to a variable, should it
4372 // be considered a type inference dependency? 4393 // be considered a type inference dependency?
4373 refPtr++; 4394 refPtr++;
4395 intPtr += 2;
4396 break;
4397 case UnlinkedConstOperation.invokeMethod:
4398 intPtr += 2;
4374 break; 4399 break;
4375 case UnlinkedConstOperation.typeCast: 4400 case UnlinkedConstOperation.typeCast:
4376 case UnlinkedConstOperation.typeCheck: 4401 case UnlinkedConstOperation.typeCheck:
4377 refPtr++; 4402 refPtr++;
4378 break; 4403 break;
4404 case UnlinkedConstOperation.pushLocalFunctionReference:
4405 int popCount = unlinkedConst.ints[intPtr++];
4406 assert(popCount == 0); // TODO(paulberry): handle the nonzero case.
4407 collectDependencies(
4408 dependencies,
4409 unlinkedExecutable.localFunctions[unlinkedConst.ints[intPtr++]],
4410 compilationUnit);
4411 break;
4379 default: 4412 default:
4380 break; 4413 break;
4381 } 4414 }
4382 } 4415 }
4383 assert(refPtr == unlinkedConst.references.length); 4416 assert(refPtr == unlinkedConst.references.length);
4417 assert(intPtr == unlinkedConst.ints.length);
4384 } 4418 }
4385 4419
4386 @override 4420 @override
4387 List<TypeInferenceNode> computeDependencies() { 4421 List<TypeInferenceNode> computeDependencies() {
4388 List<TypeInferenceNode> dependencies = <TypeInferenceNode>[]; 4422 List<TypeInferenceNode> dependencies = <TypeInferenceNode>[];
4389 collectDependencies( 4423 collectDependencies(
4390 dependencies, 4424 dependencies,
4391 variableElement.unlinkedVariable.initializer?.bodyExpr, 4425 variableElement.unlinkedVariable.initializer,
4392 variableElement.compilationUnit); 4426 variableElement.compilationUnit);
4393 return dependencies; 4427 return dependencies;
4394 } 4428 }
4395 4429
4396 void evaluate(bool inCycle) { 4430 void evaluate(bool inCycle) {
4397 if (inCycle) { 4431 if (inCycle) {
4398 variableElement._inferredType = DynamicTypeImpl.instance; 4432 variableElement._inferredType = DynamicTypeImpl.instance;
4399 } else { 4433 } else {
4400 variableElement._inferredType = 4434 variableElement._inferredType =
4401 new ExprTypeComputer(variableElement).compute(); 4435 new ExprTypeComputer(variableElement).compute();
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
4712 * there are no type parameters in scope. 4746 * there are no type parameters in scope.
4713 */ 4747 */
4714 TypeParameterizedElementMixin get _typeParameterContext; 4748 TypeParameterizedElementMixin get _typeParameterContext;
4715 4749
4716 @override 4750 @override
4717 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); 4751 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
4718 4752
4719 @override 4753 @override
4720 String toString() => '$enclosingElement.$name'; 4754 String toString() => '$enclosingElement.$name';
4721 } 4755 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/src/summary/resynthesize_ast_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698