Skip to content

Commit

Permalink
Entity-fy the non-frequence minifier so it can be supported under the…
Browse files Browse the repository at this point in the history
… CFE.

This minifier is used only when passing --no-frequency-based-minification.

Closes #32600

Bug: #32600
Change-Id: I91ae293c78f4cfe3dd0421493162d9e5744a9217
Reviewed-on: https://dart-review.googlesource.com/47303
Reviewed-by: Emily Fortuna <efortuna@google.com>
Commit-Queue: Sigmund Cherem <sigmund@google.com>
  • Loading branch information
sigmundch authored and commit-bot@chromium.org committed Mar 20, 2018
1 parent 0e76439 commit 996277d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 32 deletions.
4 changes: 2 additions & 2 deletions pkg/compiler/lib/src/js_backend/field_naming_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,10 @@ class _MixinFieldNamingScope extends _FieldNamingScope {
@override
Map<Entity, jsAst.Name> get names => registry.globalNames;

_MixinFieldNamingScope.mixin(ClassElement cls, _FieldNamingRegistry registry)
_MixinFieldNamingScope.mixin(ClassEntity cls, _FieldNamingRegistry registry)
: super.rootScope(cls, registry);

_MixinFieldNamingScope.mixedIn(MixinApplicationElement container,
_MixinFieldNamingScope.mixedIn(ClassEntity container,
_FieldNamingScope superScope, _FieldNamingRegistry registry)
: super.inherit(container, superScope, registry);

Expand Down
50 changes: 31 additions & 19 deletions pkg/compiler/lib/src/js_backend/minify_namer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -316,37 +316,42 @@ class MinifyNamer extends Namer
/// constructors declared along the inheritance chain.
class _ConstructorBodyNamingScope {
final int _startIndex;
final List _constructors;

final List<ConstructorEntity> _constructors;
int get numberOfConstructors => _constructors.length;

_ConstructorBodyNamingScope.rootScope(ClassElement cls)
_ConstructorBodyNamingScope.rootScope(
ClassEntity cls, ElementEnvironment environment)
: _startIndex = 0,
_constructors = cls.constructors.toList(growable: false);
_constructors = _getConstructorList(cls, environment);

_ConstructorBodyNamingScope.forClass(
ClassElement cls, _ConstructorBodyNamingScope superScope)
_ConstructorBodyNamingScope.forClass(ClassEntity cls,
_ConstructorBodyNamingScope superScope, ElementEnvironment environment)
: _startIndex = superScope._startIndex + superScope.numberOfConstructors,
_constructors = cls.constructors.toList(growable: false);
_constructors = _getConstructorList(cls, environment);

// Mixin Applications have constructors but we never generate code for them,
// so they do not count in the inheritance chain.
_ConstructorBodyNamingScope.forMixinApplication(
ClassElement cls, _ConstructorBodyNamingScope superScope)
ClassEntity cls, _ConstructorBodyNamingScope superScope)
: _startIndex = superScope._startIndex + superScope.numberOfConstructors,
_constructors = const [];

factory _ConstructorBodyNamingScope(ClassElement cls,
Map<ClassElement, _ConstructorBodyNamingScope> registry) {
factory _ConstructorBodyNamingScope(
ClassEntity cls,
Map<ClassEntity, _ConstructorBodyNamingScope> registry,
ElementEnvironment environment) {
return registry.putIfAbsent(cls, () {
if (cls.superclass == null) {
return new _ConstructorBodyNamingScope.rootScope(cls);
} else if (cls.isMixinApplication) {
return new _ConstructorBodyNamingScope.forMixinApplication(
cls, new _ConstructorBodyNamingScope(cls.superclass, registry));
ClassEntity superclass = environment.getSuperClass(cls);
if (superclass == null) {
return new _ConstructorBodyNamingScope.rootScope(cls, environment);
} else if (environment.isMixinApplication(cls)) {
return new _ConstructorBodyNamingScope.forMixinApplication(cls,
new _ConstructorBodyNamingScope(superclass, registry, environment));
} else {
return new _ConstructorBodyNamingScope.forClass(
cls, new _ConstructorBodyNamingScope(cls.superclass, registry));
cls,
new _ConstructorBodyNamingScope(superclass, registry, environment),
environment);
}
});
}
Expand All @@ -356,16 +361,23 @@ class _ConstructorBodyNamingScope {
assert(position >= 0, failedAt(body, "constructor body missing"));
return "@constructorBody@${_startIndex + position}";
}

static List<ConstructorEntity> _getConstructorList(
ClassEntity cls, ElementEnvironment environment) {
var result = <ConstructorEntity>[];
environment.forEachConstructor(cls, result.add);
return result;
}
}

abstract class _MinifyConstructorBodyNamer implements Namer {
Map<ClassElement, _ConstructorBodyNamingScope> _constructorBodyScopes =
new Map<ClassElement, _ConstructorBodyNamingScope>();
Map<ClassEntity, _ConstructorBodyNamingScope> _constructorBodyScopes =
new Map<ClassEntity, _ConstructorBodyNamingScope>();

@override
jsAst.Name constructorBodyName(ConstructorBodyEntity method) {
_ConstructorBodyNamingScope scope = new _ConstructorBodyNamingScope(
method.enclosingClass, _constructorBodyScopes);
method.enclosingClass, _constructorBodyScopes, elementEnvironment);
String key = scope.constructorBodyKeyFor(method);
return _disambiguateMemberByKey(
key, () => _proposeNameForConstructorBody(method));
Expand Down
16 changes: 5 additions & 11 deletions pkg/compiler/lib/src/js_backend/namer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,7 @@ import '../common/names.dart' show Identifiers, Names, Selectors;
import '../constants/values.dart';
import '../common_elements.dart' show CommonElements, ElementEnvironment;
import '../diagnostics/invariant.dart' show DEBUG_MODE;
import '../elements/elements.dart'
show
ClassElement,
Element,
Elements,
MemberElement,
MixinApplicationElement;
import '../elements/elements.dart' show Element, Elements, MemberElement;
import '../elements/entities.dart';
import '../elements/entity_utils.dart' as utils;
import '../elements/jumps.dart';
Expand Down Expand Up @@ -578,7 +572,7 @@ class Namer {
_literalLazyGetterPrefix = new StringBackedName(lazyGetterPrefix);
}

ElementEnvironment get _elementEnvironment => _closedWorld.elementEnvironment;
ElementEnvironment get elementEnvironment => _closedWorld.elementEnvironment;

CommonElements get _commonElements => _closedWorld.commonElements;

Expand Down Expand Up @@ -983,10 +977,10 @@ class Namer {
bool isPrivate = Name.isPrivateName(fieldName);
LibraryEntity memberLibrary = element.library;
ClassEntity lookupClass =
_elementEnvironment.getSuperClass(element.enclosingClass);
elementEnvironment.getSuperClass(element.enclosingClass);
while (lookupClass != null) {
MemberEntity foundMember =
_elementEnvironment.lookupLocalClassMember(lookupClass, fieldName);
elementEnvironment.lookupLocalClassMember(lookupClass, fieldName);
if (foundMember != null) {
if (foundMember.isField) {
if (!isPrivate || memberLibrary == foundMember.library) {
Expand All @@ -996,7 +990,7 @@ class Namer {
}
}
}
lookupClass = _elementEnvironment.getSuperClass(lookupClass);
lookupClass = elementEnvironment.getSuperClass(lookupClass);
}
return false;
}
Expand Down

0 comments on commit 996277d

Please sign in to comment.