Skip to content

Commit

Permalink
Test ResolutionImpact equivalence.
Browse files Browse the repository at this point in the history
R=sigmund@google.com

Review URL: https://codereview.chromium.org/1856713002 .
  • Loading branch information
johnniwinther committed Apr 5, 2016
1 parent 9fc0e5e commit e914716
Show file tree
Hide file tree
Showing 15 changed files with 1,201 additions and 539 deletions.
4 changes: 4 additions & 0 deletions pkg/compiler/lib/src/closure.dart
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,10 @@ class SynthesizedCallMethodElementX extends BaseFunctionElementX
}

Element get analyzableElement => closureClass.methodElement.analyzableElement;

accept(ElementVisitor visitor, arg) {
return visitor.visitMethodElement(this, arg);
}
}

// The box-element for a scope, and the captured variables that need to be
Expand Down
13 changes: 13 additions & 0 deletions pkg/compiler/lib/src/common/resolution.dart
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ class MapLiteralUse {
isConstant == other.isConstant &&
isEmpty == other.isEmpty;
}

String toString() {
return 'MapLiteralUse($type,isConstant:$isConstant,isEmpty:$isEmpty)';
}
}

/// A use of a list literal seen during resolution.
Expand All @@ -170,6 +174,10 @@ class ListLiteralUse {
isConstant == other.isConstant &&
isEmpty == other.isEmpty;
}

String toString() {
return 'ListLiteralUse($type,isConstant:$isConstant,isEmpty:$isEmpty)';
}
}

// TODO(johnniwinther): Rename to `Resolver` or `ResolverContext`.
Expand All @@ -178,6 +186,8 @@ abstract class Resolution {
DiagnosticReporter get reporter;
CoreTypes get coreTypes;

bool retainCaches;

void resolveTypedef(TypedefElement typdef);
void resolveClass(ClassElement cls);
void registerClass(ClassElement cls);
Expand All @@ -190,6 +200,9 @@ abstract class Resolution {
ResolutionWorkItem createWorkItem(
Element element, ItemCompilationContext compilationContext);

/// Returns `true` if the [ResolutionImpact] for [element] is cached.
bool hasResolutionImpact(Element element);

/// Returns the precomputed [ResolutionImpact] for [element].
ResolutionImpact getResolutionImpact(Element element);

Expand Down
10 changes: 9 additions & 1 deletion pkg/compiler/lib/src/compiler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1960,6 +1960,7 @@ class _CompilerResolution implements Resolution {
final Map<Element, ResolutionImpact> _resolutionImpactCache =
<Element, ResolutionImpact>{};
final Map<Element, WorldImpact> _worldImpactCache = <Element, WorldImpact>{};
bool retainCaches = false;

_CompilerResolution(this.compiler);

Expand Down Expand Up @@ -2002,6 +2003,11 @@ class _CompilerResolution implements Resolution {
return compiler.resolver.resolveTypeAnnotation(element, node);
}

@override
bool hasResolutionImpact(Element element) {
return _resolutionImpactCache.containsKey(element);
}

@override
ResolutionImpact getResolutionImpact(Element element) {
ResolutionImpact resolutionImpact = _resolutionImpactCache[element];
Expand All @@ -2026,7 +2032,7 @@ class _CompilerResolution implements Resolution {
assert(invariant(element, !element.isSynthesized || tree == null));
ResolutionImpact resolutionImpact =
compiler.resolver.resolve(element);
if (compiler.serialization.supportSerialization) {
if (compiler.serialization.supportSerialization || retainCaches) {
// [ResolutionImpact] is currently only used by serialization. The
// enqueuer uses the [WorldImpact] which is always cached.
// TODO(johnniwinther): Align these use cases better; maybe only
Expand All @@ -2049,6 +2055,7 @@ class _CompilerResolution implements Resolution {

@override
void uncacheWorldImpact(Element element) {
if (retainCaches) return;
if (compiler.serialization.isDeserialized(element)) return;
assert(invariant(element, _worldImpactCache[element] != null,
message: "WorldImpact not computed for $element."));
Expand All @@ -2058,6 +2065,7 @@ class _CompilerResolution implements Resolution {

@override
void emptyCache() {
if (retainCaches) return;
for (Element element in _worldImpactCache.keys) {
_worldImpactCache[element] = const WorldImpact();
}
Expand Down
20 changes: 16 additions & 4 deletions pkg/compiler/lib/src/elements/modelx.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2078,10 +2078,6 @@ abstract class BaseFunctionElementX

bool get isAbstract => false;

accept(ElementVisitor visitor, arg) {
return visitor.visitFunctionElement(this, arg);
}

// A function is defined by the implementation element.
AstElement get definingElement => implementation;
}
Expand Down Expand Up @@ -2132,6 +2128,10 @@ abstract class MethodElementX extends FunctionElementX {
bool get isAbstract {
return !modifiers.isExternal && !hasBody;
}

accept(ElementVisitor visitor, arg) {
return visitor.visitMethodElement(this, arg);
}
}

abstract class AccessorElementX extends MethodElementX
Expand All @@ -2154,6 +2154,10 @@ abstract class GetterElementX extends AccessorElementX
Element enclosing,
bool hasBody)
: super(name, ElementKind.GETTER, modifiers, enclosing, hasBody);

accept(ElementVisitor visitor, arg) {
return visitor.visitGetterElement(this, arg);
}
}

abstract class SetterElementX extends AccessorElementX
Expand All @@ -2164,6 +2168,10 @@ abstract class SetterElementX extends AccessorElementX
Element enclosing,
bool hasBody)
: super(name, ElementKind.SETTER, modifiers, enclosing, hasBody);

accept(ElementVisitor visitor, arg) {
return visitor.visitSetterElement(this, arg);
}
}

class LocalFunctionElementX extends BaseFunctionElementX
Expand Down Expand Up @@ -2195,6 +2203,10 @@ class LocalFunctionElementX extends BaseFunctionElementX
}

bool get isLocal => true;

accept(ElementVisitor visitor, arg) {
return visitor.visitLocalFunctionElement(this, arg);
}
}

abstract class ConstantConstructorMixin implements ConstructorElement {
Expand Down
26 changes: 24 additions & 2 deletions pkg/compiler/lib/src/elements/visitor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ abstract class ElementVisitor<R, A> {
R visitFieldElement(FieldElement e, A arg) => null;
R visitFieldParameterElement(InitializingFormalElement e, A arg) => null;
R visitAbstractFieldElement(AbstractFieldElement e, A arg) => null;
R visitFunctionElement(FunctionElement e, A arg) => null;
R visitMethodElement(FunctionElement e, A arg) => null;
R visitGetterElement(GetterElement e, A arg) => null;
R visitSetterElement(SetterElement e, A arg) => null;
R visitLocalFunctionElement(LocalFunctionElement e, A arg) => null;
R visitConstructorElement(ConstructorElement e, A arg) => null;
R visitConstructorBodyElement(ConstructorBodyElement e, A arg) => null;
R visitClassElement(ClassElement e, A arg) => null;
Expand Down Expand Up @@ -127,11 +130,30 @@ abstract class BaseElementVisitor<R, A> extends ElementVisitor<R, A> {
return visitElement(e, arg);
}

@override
R visitFunctionElement(FunctionElement e, A arg) {
return visitElement(e, arg);
}

@override
R visitMethodElement(MethodElement e, A arg) {
return visitFunctionElement(e, arg);
}

@override
R visitGetterElement(GetterElement e, A arg) {
return visitFunctionElement(e, arg);
}

@override
R visitSetterElement(SetterElement e, A arg) {
return visitFunctionElement(e, arg);
}

@override
R visitLocalFunctionElement(LocalFunctionElement e, A arg) {
return visitFunctionElement(e, arg);
}

@override
R visitConstructorElement(ConstructorElement e, A arg) {
return visitFunctionElement(e, arg);
Expand Down
Loading

0 comments on commit e914716

Please sign in to comment.