From 996277d42725031824be1c9533ca2aaf23caa964 Mon Sep 17 00:00:00 2001 From: Sigmund Cherem Date: Tue, 20 Mar 2018 20:28:53 +0000 Subject: [PATCH] Entity-fy the non-frequence minifier so it can be supported under the CFE. This minifier is used only when passing --no-frequency-based-minification. Closes #32600 Bug: https://github.com/dart-lang/sdk/issues/32600 Change-Id: I91ae293c78f4cfe3dd0421493162d9e5744a9217 Reviewed-on: https://dart-review.googlesource.com/47303 Reviewed-by: Emily Fortuna Commit-Queue: Sigmund Cherem --- .../src/js_backend/field_naming_mixin.dart | 4 +- .../lib/src/js_backend/minify_namer.dart | 50 ++++++++++++------- pkg/compiler/lib/src/js_backend/namer.dart | 16 ++---- 3 files changed, 38 insertions(+), 32 deletions(-) diff --git a/pkg/compiler/lib/src/js_backend/field_naming_mixin.dart b/pkg/compiler/lib/src/js_backend/field_naming_mixin.dart index 667024965657..e2d67eacf08e 100644 --- a/pkg/compiler/lib/src/js_backend/field_naming_mixin.dart +++ b/pkg/compiler/lib/src/js_backend/field_naming_mixin.dart @@ -207,10 +207,10 @@ class _MixinFieldNamingScope extends _FieldNamingScope { @override Map 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); diff --git a/pkg/compiler/lib/src/js_backend/minify_namer.dart b/pkg/compiler/lib/src/js_backend/minify_namer.dart index 055492323181..723bca7f516f 100644 --- a/pkg/compiler/lib/src/js_backend/minify_namer.dart +++ b/pkg/compiler/lib/src/js_backend/minify_namer.dart @@ -316,37 +316,42 @@ class MinifyNamer extends Namer /// constructors declared along the inheritance chain. class _ConstructorBodyNamingScope { final int _startIndex; - final List _constructors; - + final List _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 registry) { + factory _ConstructorBodyNamingScope( + ClassEntity cls, + Map 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); } }); } @@ -356,16 +361,23 @@ class _ConstructorBodyNamingScope { assert(position >= 0, failedAt(body, "constructor body missing")); return "@constructorBody@${_startIndex + position}"; } + + static List _getConstructorList( + ClassEntity cls, ElementEnvironment environment) { + var result = []; + environment.forEachConstructor(cls, result.add); + return result; + } } abstract class _MinifyConstructorBodyNamer implements Namer { - Map _constructorBodyScopes = - new Map(); + Map _constructorBodyScopes = + new Map(); @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)); diff --git a/pkg/compiler/lib/src/js_backend/namer.dart b/pkg/compiler/lib/src/js_backend/namer.dart index 0dab60aff458..3a02f42c1e3d 100644 --- a/pkg/compiler/lib/src/js_backend/namer.dart +++ b/pkg/compiler/lib/src/js_backend/namer.dart @@ -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'; @@ -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; @@ -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) { @@ -996,7 +990,7 @@ class Namer { } } } - lookupClass = _elementEnvironment.getSuperClass(lookupClass); + lookupClass = elementEnvironment.getSuperClass(lookupClass); } return false; }