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

Side by Side Diff: pkg/analyzer/lib/src/task/dart.dart

Issue 1403293006: Fix the dependencies for constant evaluation (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 1 month 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 | no next file » | 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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 library analyzer.src.task.dart; 5 library analyzer.src.task.dart;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/src/context/cache.dart'; 9 import 'package:analyzer/src/context/cache.dart';
10 import 'package:analyzer/src/generated/ast.dart'; 10 import 'package:analyzer/src/generated/ast.dart';
(...skipping 1538 matching lines...) Expand 10 before | Expand all | Expand 10 after
1549 AnalysisContext context, AnalysisTarget target) { 1549 AnalysisContext context, AnalysisTarget target) {
1550 return new BuildTypeProviderTask(context, target); 1550 return new BuildTypeProviderTask(context, target);
1551 } 1551 }
1552 } 1552 }
1553 1553
1554 /** 1554 /**
1555 * A task that computes [CONSTANT_DEPENDENCIES] for a constant. 1555 * A task that computes [CONSTANT_DEPENDENCIES] for a constant.
1556 */ 1556 */
1557 class ComputeConstantDependenciesTask extends ConstantEvaluationAnalysisTask { 1557 class ComputeConstantDependenciesTask extends ConstantEvaluationAnalysisTask {
1558 /** 1558 /**
1559 * The name of the [RESOLVED_UNIT9] input.
1560 */
1561 static const String UNIT_INPUT = 'UNIT_INPUT';
1562
1563 /**
1564 * The name of the [TYPE_PROVIDER] input. 1559 * The name of the [TYPE_PROVIDER] input.
1565 */ 1560 */
1566 static const String TYPE_PROVIDER_INPUT = 'TYPE_PROVIDER_INPUT'; 1561 static const String TYPE_PROVIDER_INPUT = 'TYPE_PROVIDER_INPUT';
1567 1562
1568 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( 1563 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
1569 'ComputeConstantDependenciesTask', 1564 'ComputeConstantDependenciesTask',
1570 createTask, 1565 createTask,
1571 buildInputs, 1566 buildInputs,
1572 <ResultDescriptor>[CONSTANT_DEPENDENCIES]); 1567 <ResultDescriptor>[CONSTANT_DEPENDENCIES]);
1573 1568
1574 ComputeConstantDependenciesTask( 1569 ComputeConstantDependenciesTask(
1575 InternalAnalysisContext context, ConstantEvaluationTarget constant) 1570 InternalAnalysisContext context, ConstantEvaluationTarget constant)
1576 : super(context, constant); 1571 : super(context, constant);
1577 1572
1578 @override 1573 @override
1579 TaskDescriptor get descriptor => DESCRIPTOR; 1574 TaskDescriptor get descriptor => DESCRIPTOR;
1580 1575
1581 @override 1576 @override
1582 void internalPerform() { 1577 void internalPerform() {
1583 // 1578 //
1584 // Prepare inputs. 1579 // Prepare inputs.
1585 // 1580 //
1586 // Note: UNIT_INPUT is not needed. It is merely a bookkeeping dependency
1587 // to ensure that resolution has occurred before we attempt to determine
1588 // constant dependencies.
1589 //
1590 ConstantEvaluationTarget constant = target; 1581 ConstantEvaluationTarget constant = target;
1591 TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT); 1582 TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT);
1592 // 1583 //
1593 // Compute dependencies. 1584 // Compute dependencies.
1594 // 1585 //
1595 List<ConstantEvaluationTarget> dependencies = <ConstantEvaluationTarget>[]; 1586 List<ConstantEvaluationTarget> dependencies = <ConstantEvaluationTarget>[];
1596 new ConstantEvaluationEngine(typeProvider, context.declaredVariables, 1587 new ConstantEvaluationEngine(typeProvider, context.declaredVariables,
1597 typeSystem: context.typeSystem) 1588 typeSystem: context.typeSystem)
1598 .computeDependencies(constant, dependencies.add); 1589 .computeDependencies(constant, dependencies.add);
1599 // 1590 //
1600 // Record outputs. 1591 // Record outputs.
1601 // 1592 //
1602 outputs[CONSTANT_DEPENDENCIES] = dependencies; 1593 outputs[CONSTANT_DEPENDENCIES] = dependencies;
1603 } 1594 }
1604 1595
1605 /** 1596 /**
1606 * Return a map from the names of the inputs of this kind of task to the task 1597 * Return a map from the names of the inputs of this kind of task to the task
1607 * input descriptors describing those inputs for a task with the 1598 * input descriptors describing those inputs for a task with the
1608 * given [target]. 1599 * given [target].
1609 */ 1600 */
1610 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 1601 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
1602 //
1603 // We need to force the computation of the RESOLVED_UNIT9 for each unit
1604 // reachable from the target's library so that all of the AST's for the
1605 // contructor initializers that we might encounter have been copied into
1606 // the element model.
1607 //
1608 // TODO(brianwilkerson) This could be improved by computing a more accurate
1609 // list of the sources containing constructors that are actually referenced.
1610 //
1611 if (target is Element) { 1611 if (target is Element) {
1612 CompilationUnitElementImpl unit = target 1612 CompilationUnitElementImpl unit = target
1613 .getAncestor((Element element) => element is CompilationUnitElement); 1613 .getAncestor((Element element) => element is CompilationUnitElement);
1614 Source librarySource = unit.librarySource;
1614 return <String, TaskInput>{ 1615 return <String, TaskInput>{
1615 UNIT_INPUT: RESOLVED_UNIT9 1616 'resolvedUnits': IMPORT_EXPORT_SOURCE_CLOSURE.of(librarySource).toList(
1616 .of(new LibrarySpecificUnit(unit.librarySource, target.source)), 1617 (Source library) => UNITS.of(library).toList((Source source) =>
1618 RESOLVED_UNIT9.of(new LibrarySpecificUnit(library, source)))),
1617 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request) 1619 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request)
1618 }; 1620 };
1619 } else if (target is ConstantEvaluationTarget_Annotation) { 1621 } else if (target is ConstantEvaluationTarget_Annotation) {
1622 Source librarySource = target.librarySource;
1620 return <String, TaskInput>{ 1623 return <String, TaskInput>{
1621 UNIT_INPUT: RESOLVED_UNIT9 1624 'resolvedUnits': IMPORT_EXPORT_SOURCE_CLOSURE.of(librarySource).toList(
1622 .of(new LibrarySpecificUnit(target.librarySource, target.source)), 1625 (Source library) => UNITS.of(library).toList((Source source) =>
1626 RESOLVED_UNIT9.of(new LibrarySpecificUnit(library, source)))),
1623 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request) 1627 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request)
1624 }; 1628 };
1625 } 1629 }
1626 throw new AnalysisException( 1630 throw new AnalysisException(
1627 'Cannot build inputs for a ${target.runtimeType}'); 1631 'Cannot build inputs for a ${target.runtimeType}');
1628 } 1632 }
1629 1633
1630 /** 1634 /**
1631 * Create a [ComputeConstantDependenciesTask] based on the given [target] in 1635 * Create a [ComputeConstantDependenciesTask] based on the given [target] in
1632 * the given [context]. 1636 * the given [context].
(...skipping 2286 matching lines...) Expand 10 before | Expand all | Expand 10 after
3919 // Resolve everything. 3923 // Resolve everything.
3920 // 3924 //
3921 CompilationUnitElement unitElement = unit.element; 3925 CompilationUnitElement unitElement = unit.element;
3922 RecordingErrorListener errorListener = new RecordingErrorListener(); 3926 RecordingErrorListener errorListener = new RecordingErrorListener();
3923 ResolverVisitor visitor = new ResolverVisitor( 3927 ResolverVisitor visitor = new ResolverVisitor(
3924 libraryElement, unitElement.source, typeProvider, errorListener); 3928 libraryElement, unitElement.source, typeProvider, errorListener);
3925 unit.accept(visitor); 3929 unit.accept(visitor);
3926 // 3930 //
3927 // Record outputs. 3931 // Record outputs.
3928 // 3932 //
3933 // TODO(brianwilkerson) This task modifies the element model (by copying the
3934 // AST's for constructor initializers into it) but does not produce an
3935 // updated version of the element model.
3936 //
3929 outputs[RESOLVE_UNIT_ERRORS] = errorListener.errors; 3937 outputs[RESOLVE_UNIT_ERRORS] = errorListener.errors;
3930 outputs[RESOLVED_UNIT9] = unit; 3938 outputs[RESOLVED_UNIT9] = unit;
3931 } 3939 }
3932 3940
3933 /** 3941 /**
3934 * Return a map from the names of the inputs of this kind of task to the task 3942 * Return a map from the names of the inputs of this kind of task to the task
3935 * input descriptors describing those inputs for a task with the given 3943 * input descriptors describing those inputs for a task with the given
3936 * [target]. 3944 * [target].
3937 */ 3945 */
3938 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 3946 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
(...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after
4574 4582
4575 @override 4583 @override
4576 bool moveNext() { 4584 bool moveNext() {
4577 if (_newSources.isEmpty) { 4585 if (_newSources.isEmpty) {
4578 return false; 4586 return false;
4579 } 4587 }
4580 currentTarget = _newSources.removeLast(); 4588 currentTarget = _newSources.removeLast();
4581 return true; 4589 return true;
4582 } 4590 }
4583 } 4591 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698