Skip to content

Commit 41f8eae

Browse files
committed
Issue 26466. Limited fix to pass on the dart:html test case.
Eventually we might want to go over all of the code and sprinkle it with checks like with to avoid re-resolving what we already know, and to avoid updating parts of element model which cannot be updated because the element model is resynthesized from a summary. [email protected] BUG= #26466 Review URL: https://codereview.chromium.org/2003863002 .
1 parent cb6b40d commit 41f8eae

File tree

2 files changed

+61
-9
lines changed

2 files changed

+61
-9
lines changed

pkg/analyzer/lib/src/dart/element/element.dart

+44
Original file line numberDiff line numberDiff line change
@@ -3975,6 +3975,11 @@ class LibraryElementImpl extends ElementImpl implements LibraryElement {
39753975
*/
39763976
Namespace _publicNamespace;
39773977

3978+
/**
3979+
* A bit-encoded form of the capabilities associated with this library.
3980+
*/
3981+
int _resolutionCapabilities = 0;
3982+
39783983
/**
39793984
* Initialize a newly created library element in the given [context] to have
39803985
* the given [name] and [offset].
@@ -4002,6 +4007,10 @@ class LibraryElementImpl extends ElementImpl implements LibraryElement {
40024007
: super.forSerialized(null) {
40034008
_name = name;
40044009
_nameOffset = offset;
4010+
setResolutionCapability(
4011+
LibraryResolutionCapability.resolvedTypeNames, true);
4012+
setResolutionCapability(
4013+
LibraryResolutionCapability.constantExpressions, true);
40054014
}
40064015

40074016
@override
@@ -4507,6 +4516,16 @@ class LibraryElementImpl extends ElementImpl implements LibraryElement {
45074516
return _safeIsUpToDate(this, timeStamp, visitedLibraries);
45084517
}
45094518

4519+
/**
4520+
* Set whether the library has the given [capability] to
4521+
* correspond to the given [value].
4522+
*/
4523+
void setResolutionCapability(
4524+
LibraryResolutionCapability capability, bool value) {
4525+
_resolutionCapabilities =
4526+
BooleanArray.set(_resolutionCapabilities, capability.index, value);
4527+
}
4528+
45104529
@override
45114530
void visitChildren(ElementVisitor visitor) {
45124531
super.visitChildren(visitor);
@@ -4546,6 +4565,15 @@ class LibraryElementImpl extends ElementImpl implements LibraryElement {
45464565
}
45474566
}
45484567

4568+
/**
4569+
* Return `true` if the [library] has the given [capability].
4570+
*/
4571+
static bool hasResolutionCapability(
4572+
LibraryElement library, LibraryResolutionCapability capability) {
4573+
return library is LibraryElementImpl &&
4574+
BooleanArray.get(library._resolutionCapabilities, capability.index);
4575+
}
4576+
45494577
/**
45504578
* Return `true` if the given [library] is up to date with respect to the
45514579
* given [timeStamp]. The set of [visitedLibraries] is used to prevent
@@ -4585,6 +4613,22 @@ class LibraryElementImpl extends ElementImpl implements LibraryElement {
45854613
}
45864614
}
45874615

4616+
/**
4617+
* Enum of possible resolution capabilities that a [LibraryElementImpl] has.
4618+
*/
4619+
enum LibraryResolutionCapability {
4620+
/**
4621+
* All elements have their types resolved.
4622+
*/
4623+
resolvedTypeNames,
4624+
4625+
/**
4626+
* All (potentially) constants expressions are set into corresponding
4627+
* elements.
4628+
*/
4629+
constantExpressions,
4630+
}
4631+
45884632
/**
45894633
* The context in which the library is resynthesized.
45904634
*/

pkg/analyzer/lib/src/generated/resolver.dart

+17-9
Original file line numberDiff line numberDiff line change
@@ -6301,8 +6301,11 @@ class ResolverVisitor extends ScopedVisitor {
63016301
}
63026302
// Clone the ASTs for default formal parameters, so that we can use them
63036303
// during constant evaluation.
6304-
(element as ConstVariableElement).constantInitializer =
6305-
new ConstantAstCloner().cloneNode(node.defaultValue);
6304+
if (!LibraryElementImpl.hasResolutionCapability(
6305+
definingLibrary, LibraryResolutionCapability.constantExpressions)) {
6306+
(element as ConstVariableElement).constantInitializer =
6307+
new ConstantAstCloner().cloneNode(node.defaultValue);
6308+
}
63066309
return null;
63076310
}
63086311

@@ -9190,15 +9193,20 @@ class TypeParameterBoundsResolver {
91909193
for (TypeParameter typeParameter in typeParameters.typeParameters) {
91919194
TypeName bound = typeParameter.bound;
91929195
if (bound != null) {
9193-
libraryScope ??= new LibraryScope(library, errorListener);
9194-
typeParametersScope ??= createTypeParametersScope();
9195-
typeNameResolver ??= new TypeNameResolver(new TypeSystemImpl(),
9196-
typeProvider, library, source, errorListener);
9197-
typeNameResolver.nameScope = typeParametersScope;
9198-
_resolveTypeName(bound);
91999196
Element typeParameterElement = typeParameter.name.staticElement;
92009197
if (typeParameterElement is TypeParameterElementImpl) {
9201-
typeParameterElement.bound = bound.type;
9198+
if (LibraryElementImpl.hasResolutionCapability(
9199+
library, LibraryResolutionCapability.resolvedTypeNames)) {
9200+
bound.type = typeParameterElement.bound;
9201+
} else {
9202+
libraryScope ??= new LibraryScope(library, errorListener);
9203+
typeParametersScope ??= createTypeParametersScope();
9204+
typeNameResolver ??= new TypeNameResolver(new TypeSystemImpl(),
9205+
typeProvider, library, source, errorListener);
9206+
typeNameResolver.nameScope = typeParametersScope;
9207+
_resolveTypeName(bound);
9208+
typeParameterElement.bound = bound.type;
9209+
}
92029210
}
92039211
}
92049212
}

0 commit comments

Comments
 (0)