diff --git a/.packages b/.packages index a034cb06f545..e2104d3aa014 100644 --- a/.packages +++ b/.packages @@ -53,7 +53,6 @@ json_rpc_2:third_party/pkg/json_rpc_2/lib kernel:pkg/kernel/lib linter:third_party/pkg/linter/lib logging:third_party/pkg/logging/lib -lookup_map:pkg/lookup_map/lib markdown:third_party/pkg/markdown/lib matcher:third_party/pkg/matcher/lib meta:pkg/meta/lib diff --git a/pkg/compiler/README.md b/pkg/compiler/README.md index e91c9399e3d9..746e47d83ec4 100644 --- a/pkg/compiler/README.md +++ b/pkg/compiler/README.md @@ -780,7 +780,6 @@ _TODO: complete the documentation for the following files_. `lib/src/js_backend/js_interop_analysis.dart` `lib/src/js_backend/backend_impact.dart` `lib/src/js_backend/constant_emitter.dart` -`lib/src/js_backend/lookup_map_analysis.dart` `lib/src/js_backend/namer_names.dart` `lib/src/js_backend/runtime_types.dart` `lib/src/js_backend/no_such_method_registry.dart` diff --git a/pkg/compiler/lib/src/diagnostics/messages.dart b/pkg/compiler/lib/src/diagnostics/messages.dart index 8ef340afb8c2..ac290bf68de7 100644 --- a/pkg/compiler/lib/src/diagnostics/messages.dart +++ b/pkg/compiler/lib/src/diagnostics/messages.dart @@ -400,7 +400,6 @@ enum MessageKind { UNIMPLEMENTED_SETTER, UNIMPLEMENTED_SETTER_ONE, UNMATCHED_TOKEN, - UNRECOGNIZED_VERSION_OF_LOOKUP_MAP, UNSUPPORTED_BANG_EQ_EQ, UNSUPPORTED_EQ_EQ_EQ, UNSUPPORTED_LITERAL_SYMBOL, @@ -3715,11 +3714,6 @@ $MIRRORS_NOT_SUPPORTED_BY_BACKEND_PADDING#{importChain}"""), "more code and prevents the compiler from doing some optimizations.", howToFix: "Consider removing this 'noSuchMethod' implementation."), - MessageKind.UNRECOGNIZED_VERSION_OF_LOOKUP_MAP: const MessageTemplate( - MessageKind.UNRECOGNIZED_VERSION_OF_LOOKUP_MAP, - "Unsupported version of package:lookup_map.", - howToFix: DONT_KNOW_HOW_TO_FIX), - MessageKind.DUPLICATE_SERIALIZED_LIBRARY: const MessageTemplate( MessageKind.DUPLICATE_SERIALIZED_LIBRARY, "Library '#{libraryUri}' found in both '#{sourceUri1}' and " diff --git a/pkg/compiler/lib/src/js_backend/backend.dart b/pkg/compiler/lib/src/js_backend/backend.dart index 086f8ad73499..0d3c246ea01c 100644 --- a/pkg/compiler/lib/src/js_backend/backend.dart +++ b/pkg/compiler/lib/src/js_backend/backend.dart @@ -64,8 +64,6 @@ import 'enqueuer.dart'; import 'impact_transformer.dart'; import 'interceptor_data.dart'; import 'js_interop_analysis.dart' show JsInteropAnalysis; -import 'lookup_map_analysis.dart' - show LookupMapResolutionAnalysis, LookupMapAnalysis; import 'mirrors_analysis.dart'; import 'mirrors_data.dart'; import 'namer.dart'; @@ -383,12 +381,6 @@ class JavaScriptBackend { /// constructors for custom elements. CustomElementsCodegenAnalysis _customElementsCodegenAnalysis; - /// Resolution support for tree-shaking entries of `LookupMap`. - LookupMapResolutionAnalysis lookupMapResolutionAnalysis; - - /// Codegen support for tree-shaking entries of `LookupMap`. - LookupMapAnalysis _lookupMapAnalysis; - /// Codegen support for typed JavaScript interop. JsInteropAnalysis jsInteropAnalysis; @@ -461,8 +453,6 @@ class JavaScriptBackend { jsInteropAnalysis = new JsInteropAnalysis(this); _mirrorsResolutionAnalysis = compiler.frontendStrategy.createMirrorsResolutionAnalysis(this); - lookupMapResolutionAnalysis = new LookupMapResolutionAnalysis( - reporter, compiler.frontendStrategy.elementEnvironment); noSuchMethodRegistry = new NoSuchMethodRegistry( commonElements, compiler.frontendStrategy.createNoSuchMethodResolver()); @@ -529,15 +519,6 @@ class JavaScriptBackend { return _mirrorsCodegenAnalysis; } - /// Codegen support for tree-shaking entries of `LookupMap`. - LookupMapAnalysis get lookupMapAnalysis { - assert( - _lookupMapAnalysis != null, - failedAt(NO_LOCATION_SPANNABLE, - "LookupMapAnalysis has not been created yet.")); - return _lookupMapAnalysis; - } - OneShotInterceptorData get oneShotInterceptorData { assert( _oneShotInterceptorData != null, @@ -771,7 +752,6 @@ class JavaScriptBackend { mirrorsDataBuilder, noSuchMethodRegistry, customElementsResolutionAnalysis, - lookupMapResolutionAnalysis, mirrorsResolutionAnalysis, typeVariableResolutionAnalysis, _nativeResolutionEnqueuer, @@ -798,13 +778,6 @@ class JavaScriptBackend { new BackendImpacts(compiler.options, commonElements); _typeVariableCodegenAnalysis = new TypeVariableCodegenAnalysis( closedWorld.elementEnvironment, this, commonElements, mirrorsData); - _lookupMapAnalysis = new LookupMapAnalysis( - reporter, - constantSystem, - constants, - elementEnvironment, - commonElements, - lookupMapResolutionAnalysis); _mirrorsCodegenAnalysis = mirrorsResolutionAnalysis.close(); _customElementsCodegenAnalysis = new CustomElementsCodegenAnalysis( constantSystem, @@ -834,7 +807,6 @@ class JavaScriptBackend { closedWorld.rtiNeed, customElementsCodegenAnalysis, typeVariableCodegenAnalysis, - lookupMapAnalysis, mirrorsCodegenAnalysis, nativeCodegenEnqueuer)); } @@ -964,8 +936,6 @@ class JavaScriptBackend { Uri uri = library.canonicalUri; if (uri == Uris.dart_html) { htmlLibraryIsLoaded = true; - } else if (uri == LookupMapResolutionAnalysis.PACKAGE_LOOKUP_MAP) { - lookupMapResolutionAnalysis.init(library); } } @@ -1015,7 +985,6 @@ class JavaScriptBackend { nativeCodegenEnqueuer, namer, oneShotInterceptorData, - lookupMapAnalysis, rtiChecksBuilder); return const WorldImpact(); } diff --git a/pkg/compiler/lib/src/js_backend/codegen_listener.dart b/pkg/compiler/lib/src/js_backend/codegen_listener.dart index 1f4e0248f5c1..a5a2ac369a60 100644 --- a/pkg/compiler/lib/src/js_backend/codegen_listener.dart +++ b/pkg/compiler/lib/src/js_backend/codegen_listener.dart @@ -18,7 +18,6 @@ import '../universe/world_impact.dart' import 'backend_impact.dart'; import 'backend_usage.dart'; import 'custom_elements_analysis.dart'; -import 'lookup_map_analysis.dart' show LookupMapAnalysis; import 'mirrors_analysis.dart'; import 'runtime_types.dart'; import 'type_variable_handler.dart'; @@ -33,7 +32,6 @@ class CodegenEnqueuerListener extends EnqueuerListener { final CustomElementsCodegenAnalysis _customElementsAnalysis; final TypeVariableCodegenAnalysis _typeVariableCodegenAnalysis; - final LookupMapAnalysis _lookupMapAnalysis; final MirrorsCodegenAnalysis _mirrorsAnalysis; final NativeCodegenEnqueuer _nativeEnqueuer; @@ -48,7 +46,6 @@ class CodegenEnqueuerListener extends EnqueuerListener { this._rtiNeed, this._customElementsAnalysis, this._typeVariableCodegenAnalysis, - this._lookupMapAnalysis, this._mirrorsAnalysis, this._nativeEnqueuer); @@ -79,7 +76,6 @@ class CodegenEnqueuerListener extends EnqueuerListener { if (nativeUsage) { _nativeEnqueuer.onInstantiatedType(type); } - _lookupMapAnalysis.registerInstantiatedType(type); } /// Called to enable support for isolates. Any backend specific [WorldImpact] @@ -142,7 +138,6 @@ class CodegenEnqueuerListener extends EnqueuerListener { // Return early if any elements are added to avoid counting the elements as // due to mirrors. enqueuer.applyImpact(_customElementsAnalysis.flush()); - enqueuer.applyImpact(_lookupMapAnalysis.flush()); enqueuer.applyImpact(_typeVariableCodegenAnalysis.flush()); if (_backendUsage.isNoSuchMethodUsed && !_isNoSuchMethodUsed) { @@ -158,21 +153,13 @@ class CodegenEnqueuerListener extends EnqueuerListener { } @override - void onQueueClosed() { - _lookupMapAnalysis.onQueueClosed(); - } + void onQueueClosed() {} /// Adds the impact of [constant] to [impactBuilder]. void _computeImpactForCompileTimeConstant( ConstantValue constant, WorldImpactBuilder impactBuilder) { _computeImpactForCompileTimeConstantInternal(constant, impactBuilder); - if (_lookupMapAnalysis.isLookupMap(constant)) { - // Note: internally, this registration will temporarily remove the - // constant dependencies and add them later on-demand. - _lookupMapAnalysis.registerLookupMapReference(constant); - } - for (ConstantValue dependency in constant.getDependencies()) { _computeImpactForCompileTimeConstant(dependency, impactBuilder); } @@ -202,10 +189,8 @@ class CodegenEnqueuerListener extends EnqueuerListener { if (type.representedType.isInterfaceType) { InterfaceType representedType = type.representedType; _customElementsAnalysis.registerTypeConstant(representedType.element); - _lookupMapAnalysis.registerTypeConstant(representedType.element); } } - _lookupMapAnalysis.registerConstantKey(constant); } void _computeImpactForInstantiatedConstantType( @@ -320,7 +305,6 @@ class CodegenEnqueuerListener extends EnqueuerListener { } _customElementsAnalysis.registerInstantiatedClass(cls); - _lookupMapAnalysis.registerInstantiatedClass(cls); return impactBuilder; } @@ -336,7 +320,6 @@ class CodegenEnqueuerListener extends EnqueuerListener { @override void logSummary(void log(String message)) { - _lookupMapAnalysis.logSummary(log); _nativeEnqueuer.logSummary(log); } } diff --git a/pkg/compiler/lib/src/js_backend/impact_transformer.dart b/pkg/compiler/lib/src/js_backend/impact_transformer.dart index d390090623f6..dff5872a4f7f 100644 --- a/pkg/compiler/lib/src/js_backend/impact_transformer.dart +++ b/pkg/compiler/lib/src/js_backend/impact_transformer.dart @@ -27,7 +27,6 @@ import 'backend_usage.dart'; import 'checked_mode_helpers.dart'; import 'custom_elements_analysis.dart'; import 'interceptor_data.dart'; -import 'lookup_map_analysis.dart'; import 'mirrors_data.dart'; import 'namer.dart'; import 'native_data.dart'; @@ -347,7 +346,6 @@ class CodegenImpactTransformer { final NativeCodegenEnqueuer _nativeCodegenEnqueuer; final Namer _namer; final OneShotInterceptorData _oneShotInterceptorData; - final LookupMapAnalysis _lookupMapAnalysis; final RuntimeTypesChecksBuilder _rtiChecksBuilder; CodegenImpactTransformer( @@ -362,7 +360,6 @@ class CodegenImpactTransformer { this._nativeCodegenEnqueuer, this._namer, this._oneShotInterceptorData, - this._lookupMapAnalysis, this._rtiChecksBuilder); void onIsCheckForCodegen(DartType type, TransformedWorldImpact transformed) { @@ -409,14 +406,8 @@ class CodegenImpactTransformer { for (TypeUse typeUse in impact.typeUses) { DartType type = typeUse.type; - switch (typeUse.kind) { - case TypeUseKind.INSTANTIATION: - _lookupMapAnalysis.registerInstantiatedType(type); - break; - case TypeUseKind.IS_CHECK: - onIsCheckForCodegen(type, transformed); - break; - default: + if (typeUse.kind == TypeUseKind.IS_CHECK) { + onIsCheckForCodegen(type, transformed); } } @@ -427,26 +418,19 @@ class CodegenImpactTransformer { } for (StaticUse staticUse in impact.staticUses) { - switch (staticUse.kind) { - case StaticUseKind.CALL_METHOD: - FunctionEntity callMethod = staticUse.element; - // TODO(johnniwinther): Remove [localFunctionNeedsRti] and use - // the call method instead. - if (_rtiNeed.methodNeedsRti(callMethod)) { + if (staticUse.kind == StaticUseKind.CALL_METHOD) { + FunctionEntity callMethod = staticUse.element; + // TODO(johnniwinther): Remove [localFunctionNeedsRti] and use + // the call method instead. + if (_rtiNeed.methodNeedsRti(callMethod)) { + _impacts.computeSignature + .registerImpact(transformed, _elementEnvironment); + } else if (callMethod is SynthesizedCallMethodElementX) { + if (_rtiNeed.localFunctionNeedsRti(callMethod.expression)) { _impacts.computeSignature .registerImpact(transformed, _elementEnvironment); - } else if (callMethod is SynthesizedCallMethodElementX) { - if (_rtiNeed.localFunctionNeedsRti(callMethod.expression)) { - _impacts.computeSignature - .registerImpact(transformed, _elementEnvironment); - } } - break; - case StaticUseKind.CONST_CONSTRUCTOR_INVOKE: - case StaticUseKind.CONSTRUCTOR_INVOKE: - _lookupMapAnalysis.registerInstantiatedType(staticUse.type); - break; - default: + } } } diff --git a/pkg/compiler/lib/src/js_backend/lookup_map_analysis.dart b/pkg/compiler/lib/src/js_backend/lookup_map_analysis.dart deleted file mode 100644 index 4fddd0cdad2c..000000000000 --- a/pkg/compiler/lib/src/js_backend/lookup_map_analysis.dart +++ /dev/null @@ -1,524 +0,0 @@ -// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -/// Analysis to determine how to generate code for `LookupMap`s. -library compiler.src.js_backend.lookup_map_analysis; - -import 'package:pub_semver/pub_semver.dart'; - -import '../common.dart'; -import '../common_elements.dart'; -import '../compile_time_constants.dart'; -import '../constants/constant_system.dart'; -import '../constants/values.dart' - show - ConstantValue, - ConstructedConstantValue, - ListConstantValue, - NullConstantValue, - StringConstantValue, - TypeConstantValue; -import '../elements/elements.dart' show FieldElement; -import '../elements/entities.dart'; -import '../elements/types.dart'; -import '../universe/use.dart' show ConstantUse, StaticUse; -import '../universe/world_impact.dart' - show WorldImpact, StagedWorldImpactBuilder; - -/// Lookup map handling for resolution. -/// -/// This analysis checks for the import of `package:lookup_map/lookup_map.dart`, -/// and if found, read the `_version` variable from it. -/// -/// In [LookupMapAnalysis] the value of `_version` is checked to ensure that it -/// is valid to perform the optimization of `LookupMap`. The actual optimization -/// is performed by [LookupMapAnalysis]. -class LookupMapResolutionAnalysis { - static final Uri PACKAGE_LOOKUP_MAP = - new Uri(scheme: 'package', path: 'lookup_map/lookup_map.dart'); - - /// Reference the diagnostic reporting system for logging and reporting issues - /// to the end-user. - final DiagnosticReporter _reporter; - - final ElementEnvironment _elementEnvironment; - - /// The resolved [FieldEntity] associated with the top-level `_version`. - FieldEntity lookupMapVersionVariable; - - /// The resolved [LibraryEntity] associated with - /// `package:lookup_map/lookup_map.dart`. - LibraryEntity lookupMapLibrary; - - final StagedWorldImpactBuilder _impactBuilder = - new StagedWorldImpactBuilder(); - - LookupMapResolutionAnalysis(this._reporter, this._elementEnvironment); - - /// Compute the [WorldImpact] for the constants registered since last flush. - WorldImpact flush() { - return _impactBuilder.flush(); - } - - /// Initializes this analysis by providing the resolved library. This is - /// invoked during resolution when the `lookup_map` library is discovered. - void init(LibraryEntity library) { - lookupMapLibrary = library; - // We will enable the lookupMapAnalysis as long as we get a known version of - // the lookup_map package. We otherwise produce a warning. - lookupMapVersionVariable = - _elementEnvironment.lookupLibraryMember(lookupMapLibrary, '_version'); - if (lookupMapVersionVariable == null) { - _reporter.reportHintMessage( - library, MessageKind.UNRECOGNIZED_VERSION_OF_LOOKUP_MAP); - } else { - _impactBuilder - .registerStaticUse(new StaticUse.staticGet(lookupMapVersionVariable)); - } - } -} - -/// An analysis and optimization to remove unused entries from a `LookupMap`. -/// -/// `LookupMaps` are defined in `package:lookup_map/lookup_map.dart`. They are -/// simple maps that contain constant expressions as keys, and that only support -/// the lookup operation. -/// -/// This analysis and optimization will tree-shake the contents of the maps by -/// looking at the program and finding which keys are clearly unused. Not all -/// constants can be approximated statically, so this optimization is limited to -/// the following keys: -/// -/// * Const expressions that can only be created via const constructors. This -/// excludes primitives, strings, and any const type that overrides the == -/// operator. -/// -/// * Type literals. -/// -/// Type literals are more complex than const expressions because they can be -/// created in multiple ways. We can approximate the possible set of keys if we -/// follow these rules: -/// -/// * Include all type-literals used explicitly in the code (excluding -/// obviously the uses that can be removed from LookupMaps) -/// -/// * Include every reflectable type-literal if a mirror API is used to create -/// types (e.g. ClassMirror.reflectedType). -/// -/// * Include all allocated types if the program contains `e.runtimeType` -/// expressions. -/// -/// * Include all generic-type arguments, if the program uses type -/// variables in expressions such as `class A { Type get extract => T }`. -/// -// TODO(sigmund): add support for const expressions, currently this -// implementation only supports Type literals. To support const expressions we -// need to change some of the invariants below (e.g. we can no longer use the -// ClassEntity of a type to refer to keys we need to discover). -// TODO(sigmund): detect uses of mirrors -class LookupMapAnalysis { - const LookupMapAnalysis._(); - - factory LookupMapAnalysis( - DiagnosticReporter reporter, - ConstantSystem constantSystem, - ConstantEnvironment constants, - ElementEnvironment elementEnvironment, - CommonElements commonElements, - LookupMapResolutionAnalysis analysis) { - /// Checks if the version of lookup_map is valid, and if so, enable this - /// analysis during codegen. - FieldElement lookupMapVersionVariable = analysis.lookupMapVersionVariable; - if (lookupMapVersionVariable == null) return const LookupMapAnalysis._(); - - // At this point, the lookupMapVersionVariable should be resolved and it's - // constant value should be available. - StringConstantValue value = - constants.getConstantValue(lookupMapVersionVariable.constant); - if (value == null) { - reporter.reportHintMessage(lookupMapVersionVariable, - MessageKind.UNRECOGNIZED_VERSION_OF_LOOKUP_MAP); - return const LookupMapAnalysis._(); - } - - // TODO(sigmund): add proper version resolution using the pub_semver package - // when we introduce the next version. - Version version; - try { - version = new Version.parse(value.primitiveValue); - } catch (e) {} - - if (version == null || !_validLookupMapVersionConstraint.allows(version)) { - reporter.reportHintMessage(lookupMapVersionVariable, - MessageKind.UNRECOGNIZED_VERSION_OF_LOOKUP_MAP); - return const LookupMapAnalysis._(); - } - - ClassEntity typeLookupMapClass = - elementEnvironment.lookupClass(analysis.lookupMapLibrary, 'LookupMap'); - FieldEntity entriesField = - elementEnvironment.lookupClassMember(typeLookupMapClass, '_entries'); - FieldEntity keyField = - elementEnvironment.lookupClassMember(typeLookupMapClass, '_key'); - FieldEntity valueField = - elementEnvironment.lookupClassMember(typeLookupMapClass, '_value'); - // TODO(sigmund): Maybe inline nested maps to make the output code smaller? - - return new _LookupMapAnalysis(constantSystem, elementEnvironment, - commonElements, entriesField, keyField, valueField, typeLookupMapClass); - } - - /// Compute the [WorldImpact] for the constants registered since last flush. - WorldImpact flush() => const WorldImpact(); - - /// Whether [constant] is an instance of a `LookupMap`. - bool isLookupMap(ConstantValue constant) => false; - - /// Registers an instance of a lookup-map with the analysis. - void registerLookupMapReference(ConstantValue lookupMap) {} - - /// Callback from the enqueuer, invoked when [element] is instantiated. - void registerInstantiatedClass(ClassEntity element) {} - - /// Callback from the enqueuer, invoked when [type] is instantiated. - void registerInstantiatedType(InterfaceType type) {} - - /// Callback from the codegen enqueuer, invoked when a constant (which is - /// possibly a const key or a type literal) is used in the program. - void registerTypeConstant(ClassEntity element) {} - - void registerConstantKey(ConstantValue constant) {} - - void logSummary(void log(String message)) {} - - void onQueueClosed() {} -} - -class _LookupMapAnalysis implements LookupMapAnalysis { - static final Uri PACKAGE_LOOKUP_MAP = - new Uri(scheme: 'package', path: 'lookup_map/lookup_map.dart'); - - final ConstantSystem _constantSystem; - - final ElementEnvironment _elementEnvironment; - - final CommonElements _commonElements; - - /// The resolved [ClassEntity] associated with `LookupMap`. - final ClassEntity _typeLookupMapClass; - - /// The resolved [FieldEntity] for `LookupMap._entries`. - final FieldEntity _entriesField; - - /// The resolved [FieldEntity] for `LookupMap._key`. - final FieldEntity _keyField; - - /// The resolved [FieldEntity] for `LookupMap._value`. - final FieldEntity _valueField; - - /// Constant instances of `LookupMap` and information about them tracked by - /// this analysis. - final Map _lookupMaps = {}; - - /// Keys that we have discovered to be in use in the program. - final Set _inUse = new Set(); - - /// Internal helper to memoize the mapping between class elements and their - /// corresponding type constants. - final Map _typeConstants = - {}; - - /// Internal helper to memoize which classes (ignoring Type) override equals. - /// - /// Const keys of these types will not be tree-shaken because we can't - /// statically guarantee that the program doesn't produce an equivalent key at - /// runtime. Technically if we limit lookup-maps to check for identical keys, - /// we could allow const instances of these types. However, we internally use - /// a hash map within lookup-maps today, so we need this restriction. - final Map _typesWithEquals = {}; - - /// Pending work to do if we discover that a new key is in use. For each key - /// that we haven't seen, we record the list of lookup-maps that contain an - /// entry with that key. - final _pending = >{}; - - final StagedWorldImpactBuilder _impactBuilder = - new StagedWorldImpactBuilder(); - - _LookupMapAnalysis( - this._constantSystem, - this._elementEnvironment, - this._commonElements, - this._entriesField, - this._keyField, - this._valueField, - this._typeLookupMapClass); - - /// Compute the [WorldImpact] for the constants registered since last flush. - WorldImpact flush() { - return _impactBuilder.flush(); - } - - /// Whether [constant] is an instance of a `LookupMap`. - bool isLookupMap(ConstantValue constant) { - if (constant is ConstructedConstantValue) { - InterfaceType type = constant.type; - ClassEntity superclass = type.element; - while (superclass != null) { - if (superclass == _typeLookupMapClass) return true; - superclass = _elementEnvironment.getSuperClass(superclass); - } - } - return false; - } - - /// Registers an instance of a lookup-map with the analysis. - void registerLookupMapReference(ConstantValue lookupMap) { - assert(isLookupMap(lookupMap)); - _lookupMaps.putIfAbsent( - lookupMap, () => new _LookupMapInfo(lookupMap, this).._updateUsed()); - } - - /// Whether [key] is a constant value whose type overrides equals. - bool _overridesEquals(ConstantValue key) { - if (key is ConstructedConstantValue) { - ClassEntity element = key.type.element; - return _typesWithEquals.putIfAbsent(element, () { - ClassEntity cls = element; - while (cls != _commonElements.objectClass) { - MemberEntity member = - _elementEnvironment.lookupClassMember(cls, '=='); - if (member != null) { - return true; - } - cls = _elementEnvironment.getSuperClass(cls); - } - return false; - }); - } - return false; - } - - /// Whether we need to preserve [key]. This is true for keys that are not - /// candidates for tree-shaking in the first place (primitives and non-type - /// const values overriding equals) and keys that we have seen in the program. - bool _shouldKeep(ConstantValue key) => - key.isPrimitive || _inUse.contains(key) || _overridesEquals(key); - - void _addClassUse(ClassEntity cls) { - TypeConstantValue f() => _constantSystem.createType( - _commonElements, _elementEnvironment.getRawType(cls)); - ConstantValue key = _typeConstants.putIfAbsent(cls, f); - _addUse(key); - } - - /// Record that [key] is used and update every lookup map that contains it. - void _addUse(ConstantValue key) { - if (_inUse.add(key)) { - _pending[key]?.forEach((info) => info._markUsed(key)); - _pending.remove(key); - } - } - - /// If [key] is a type, cache it in [_typeConstants]. - _registerTypeKey(ConstantValue key) { - if (key is TypeConstantValue && key.representedType is InterfaceType) { - InterfaceType type = key.representedType; - _typeConstants[type.element] = key; - } else { - // TODO(sigmund): report error? - } - } - - /// Callback from the enqueuer, invoked when [element] is instantiated. - void registerInstantiatedClass(ClassEntity element) { - // TODO(sigmund): only add if .runtimeType is ever used - _addClassUse(element); - } - - /// Callback from the enqueuer, invoked when [type] is instantiated. - void registerInstantiatedType(InterfaceType type) { - // TODO(sigmund): only add if .runtimeType is ever used - _addClassUse(type.element); - // TODO(sigmund): only do this when type-argument expressions are used? - _addGenerics(type); - } - - /// Records generic type arguments in [type], in case they are retrieved and - /// returned using a type-argument expression. - void _addGenerics(InterfaceType type) { - if (type.typeArguments.isEmpty) return; - for (DartType arg in type.typeArguments) { - if (arg is InterfaceType) { - _addClassUse(arg.element); - // Note: this call was needed to generate correct code for - // type_lookup_map/generic_type_test - // TODO(sigmund): can we get rid of this? - _impactBuilder.registerStaticUse(new StaticUse.staticInvoke( - // TODO(johnniwinther): Find the right [CallStructure]. - _commonElements.createRuntimeType, - null)); - _addGenerics(arg); - } - } - } - - /// Callback from the codegen enqueuer, invoked when a constant (which is - /// possibly a const key or a type literal) is used in the program. - void registerTypeConstant(ClassEntity element) { - _addClassUse(element); - } - - void registerConstantKey(ConstantValue constant) { - if (constant.isPrimitive || _overridesEquals(constant)) return; - _addUse(constant); - } - - void logSummary(void log(String message)) { - // When --verbose is passed, we show the total number and set of keys that - // were tree-shaken from lookup maps. - var sb = new StringBuffer(); - int count = 0; - for (var info in _lookupMaps.values) { - for (var key in info.unusedEntries.keys) { - if (count != 0) sb.write(','); - sb.write(key.toDartText()); - count++; - } - } - log(count == 0 - ? 'lookup-map: nothing was tree-shaken' - : 'lookup-map: found $count unused keys ($sb)'); - } - - /// Callback from the backend, invoked when reaching the end of the enqueuing - /// process, but before emitting the code. At this moment we have discovered - /// all types used in the program and we can tree-shake anything that is - /// unused. - void onQueueClosed() { - _lookupMaps.values.forEach((info) { - assert(!info.emitted); - info.emitted = true; - info._prepareForEmission(); - }); - - // Release resources. - _lookupMaps.clear(); - _pending.clear(); - _inUse.clear(); - } -} - -/// Internal information about the entries on a lookup-map. -class _LookupMapInfo { - /// The original reference to the constant value. - /// - /// This reference will be mutated in place to remove it's entries when the - /// map is first seen during codegen, and to restore them (or a subset of - /// them) when we have finished discovering which entries are used. This has - /// the side-effect that `orignal.getDependencies()` will be empty during - /// most of codegen until we are ready to emit the constants. However, - /// restoring the entries before emitting code lets us keep the emitter logic - /// agnostic of this optimization. - final ConstructedConstantValue original; - - /// Reference to the lookup map analysis to be able to refer to data shared - /// across infos. - final _LookupMapAnalysis analysis; - - /// Whether we have already emitted this constant. - bool emitted = false; - - /// Whether the `LookupMap` constant was built using the `LookupMap.pair` - /// constructor. - bool singlePair; - - /// Entries in the lookup map whose keys have not been seen in the rest of the - /// program. - Map unusedEntries = - {}; - - /// Entries that have been used, and thus will be part of the generated code. - Map usedEntries = - {}; - - /// Creates and initializes the information containing all keys of the - /// original map marked as unused. - _LookupMapInfo(this.original, this.analysis) { - ConstantValue key = original.fields[analysis._keyField]; - singlePair = !key.isNull; - - if (singlePair) { - unusedEntries[key] = original.fields[analysis._valueField]; - - // Note: we modify the constant in-place, see comment in [original]. - original.fields[analysis._keyField] = new NullConstantValue(); - original.fields[analysis._valueField] = new NullConstantValue(); - } else { - ListConstantValue list = original.fields[analysis._entriesField]; - List keyValuePairs = list.entries; - for (int i = 0; i < keyValuePairs.length; i += 2) { - ConstantValue key = keyValuePairs[i]; - unusedEntries[key] = keyValuePairs[i + 1]; - } - - // Note: we modify the constant in-place, see comment in [original]. - original.fields[analysis._entriesField] = - new ListConstantValue(list.type, []); - } - } - - /// Check every key in unusedEntries and mark it as used if the analysis has - /// already discovered them. This is meant to be called once to finalize - /// initialization after constructing an instance of this class. Afterwards, - /// we call [_markUsed] on each individual key as it gets discovered. - void _updateUsed() { - // Note: we call toList because `_markUsed` modifies the map. - for (ConstantValue key in unusedEntries.keys.toList()) { - analysis._registerTypeKey(key); - if (analysis._shouldKeep(key)) { - _markUsed(key); - } else { - analysis._pending.putIfAbsent(key, () => []).add(this); - } - } - } - - /// Marks that [key] has been seen, and thus, the corresponding entry in this - /// map should be considered reachable. - _markUsed(ConstantValue key) { - assert(!emitted); - assert(unusedEntries.containsKey(key)); - assert(!usedEntries.containsKey(key)); - ConstantValue constant = unusedEntries.remove(key); - usedEntries[key] = constant; - analysis._impactBuilder - .registerConstantUse(new ConstantUse.lookupMap(constant)); - } - - /// Restores [original] to contain all of the entries marked as possibly used. - void _prepareForEmission() { - ListConstantValue originalEntries = original.fields[analysis._entriesField]; - InterfaceType listType = originalEntries.type; - List keyValuePairs = []; - usedEntries.forEach((key, value) { - keyValuePairs.add(key); - keyValuePairs.add(value); - }); - - // Note: we are restoring the entries here, see comment in [original]. - if (singlePair) { - assert(keyValuePairs.length == 0 || keyValuePairs.length == 2); - if (keyValuePairs.length == 2) { - original.fields[analysis._keyField] = keyValuePairs[0]; - original.fields[analysis._valueField] = keyValuePairs[1]; - } - } else { - original.fields[analysis._entriesField] = - new ListConstantValue(listType, keyValuePairs); - } - } -} - -final _validLookupMapVersionConstraint = new VersionConstraint.parse('^0.0.1'); diff --git a/pkg/compiler/lib/src/js_backend/resolution_listener.dart b/pkg/compiler/lib/src/js_backend/resolution_listener.dart index 851295613dd5..2d8d21c47e7b 100644 --- a/pkg/compiler/lib/src/js_backend/resolution_listener.dart +++ b/pkg/compiler/lib/src/js_backend/resolution_listener.dart @@ -24,7 +24,6 @@ import 'backend_usage.dart'; import 'checked_mode_helpers.dart'; import 'custom_elements_analysis.dart'; import 'interceptor_data.dart'; -import 'lookup_map_analysis.dart' show LookupMapResolutionAnalysis; import 'mirrors_analysis.dart'; import 'mirrors_data.dart'; import 'native_data.dart' show NativeBasicData; @@ -50,7 +49,6 @@ class ResolutionEnqueuerListener extends EnqueuerListener { final NoSuchMethodRegistry _noSuchMethodRegistry; final CustomElementsResolutionAnalysis _customElementsAnalysis; - final LookupMapResolutionAnalysis _lookupMapResolutionAnalysis; final MirrorsResolutionAnalysis _mirrorsAnalysis; final TypeVariableResolutionAnalysis _typeVariableResolutionAnalysis; @@ -71,7 +69,6 @@ class ResolutionEnqueuerListener extends EnqueuerListener { this._mirrorsDataBuilder, this._noSuchMethodRegistry, this._customElementsAnalysis, - this._lookupMapResolutionAnalysis, this._mirrorsAnalysis, this._typeVariableResolutionAnalysis, this._nativeEnqueuer, @@ -204,8 +201,6 @@ class ResolutionEnqueuerListener extends EnqueuerListener { // due to mirrors. enqueuer.applyImpact(_customElementsAnalysis.flush(), impactSource: _customElementsAnalysis); - enqueuer.applyImpact(_lookupMapResolutionAnalysis.flush(), - impactSource: _lookupMapResolutionAnalysis); enqueuer.applyImpact(_typeVariableResolutionAnalysis.flush(), impactSource: _typeVariableResolutionAnalysis); diff --git a/pkg/compiler/lib/src/universe/use.dart b/pkg/compiler/lib/src/universe/use.dart index 4c82f6c71904..b1bb0d1b6bf4 100644 --- a/pkg/compiler/lib/src/universe/use.dart +++ b/pkg/compiler/lib/src/universe/use.dart @@ -512,10 +512,6 @@ class ConstantUse { ConstantUse.customElements(TypeConstantValue value) : this._(value, ConstantUseKind.DIRECT); - /// Constant used through a lookup map. - ConstantUse.lookupMap(ConstantValue value) - : this._(value, ConstantUseKind.INDIRECT); - /// Constant used through mirrors. // TODO(johnniwinther): Maybe if this is `DIRECT` and we can avoid the // extra calls to `addCompileTimeConstantForEmission`. diff --git a/pkg/compiler/pubspec.yaml b/pkg/compiler/pubspec.yaml index b3de8c378e40..3cf04df857ea 100644 --- a/pkg/compiler/pubspec.yaml +++ b/pkg/compiler/pubspec.yaml @@ -17,8 +17,6 @@ dependencies: path: ../../sdk/lib/_internal/sdk_library_metadata dart2js_info: path: ../../third_party/pkg/dart2js_info - lookup_map: - path: ../lookup_map front_end: path: ../front_end dependency_overrides: diff --git a/pkg/dev_compiler/tool/build_pkgs.dart b/pkg/dev_compiler/tool/build_pkgs.dart index 6cad23ee5bcf..d8e60c4b9e9d 100755 --- a/pkg/dev_compiler/tool/build_pkgs.dart +++ b/pkg/dev_compiler/tool/build_pkgs.dart @@ -37,7 +37,6 @@ void main(List arguments) { compileModule('js', libs: ['js_util']); compileModule('meta'); if (isTravis) { - compileModule('lookup_map'); compileModule('microlytics', libs: ['html_channels']); compileModule('typed_mock'); } diff --git a/pkg/lookup_map/AUTHORS b/pkg/lookup_map/AUTHORS deleted file mode 100644 index e8063a8cd6e5..000000000000 --- a/pkg/lookup_map/AUTHORS +++ /dev/null @@ -1,6 +0,0 @@ -# Below is a list of people and organizations that have contributed -# to the project. Names should be added to the list like so: -# -# Name/Organization - -Google Inc. diff --git a/pkg/lookup_map/CHANGELOG.md b/pkg/lookup_map/CHANGELOG.md deleted file mode 100644 index beb0eb05017a..000000000000 --- a/pkg/lookup_map/CHANGELOG.md +++ /dev/null @@ -1,7 +0,0 @@ -# Changelog - -## 0.0.1+1 -- Fix minor typo in readme. - -## 0.0.1 -- Initial version of `LookupMap` diff --git a/pkg/lookup_map/LICENSE b/pkg/lookup_map/LICENSE deleted file mode 100644 index de31e1a0a48a..000000000000 --- a/pkg/lookup_map/LICENSE +++ /dev/null @@ -1,26 +0,0 @@ -Copyright 2015, the Dart project authors. All rights reserved. -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above - copyright notice, this list of conditions and the following - disclaimer in the documentation and/or other materials provided - with the distribution. - * Neither the name of Google Inc. nor the names of its - contributors may be used to endorse or promote products derived - from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/pkg/lookup_map/README.md b/pkg/lookup_map/README.md deleted file mode 100644 index a3337912f142..000000000000 --- a/pkg/lookup_map/README.md +++ /dev/null @@ -1,31 +0,0 @@ -# Lookup maps - -This package contains the definition of `LookupMap`: a simple, but very -restricted map. The map can only hold constant keys and the only way to use the -map is to retrieve values with a key you already have. Except for lookup, any -other operation in `Map` (like forEach, keys, values, length, etc) is not -available. - -Constant `LookupMap`s are understood by dart2js and can be tree-shaken -internally: if a key is not used elsewhere in the program, its entry can be -deleted from the map during compilation without changing the program's behavior. -Currently dart2js supports tree-shaking keys that are Type literals, and any -const expression that can only be created with a const constructor. This means -that primitives, Strings, and constant objects that override the `==` operator -cannot be tree-shaken. - -**Note**: this feature is currently experimental in dart2js, we recommend trying -other alternatives before relying on this feature. - -## Examples - -`LookupMap` is unlikely going to be useful for individual developers writing -code by hand. It is mainly intended as a helper utility for frameworks that need -to autogenerate data and associate it with a type in the program. For example, -this can be used by a dependency injection system to record how to create -instances of a given type. A dependency injection framework can store in a -`LookupMap` all the information it needs for every injectable type in every -library and package. When compiling a specific application, dart2js can -tree-shake the data of types that are not used by the application. Similarly, -this can also be used by serialization/deserialization packages that can store -in a `LookupMap` the deserialization logic for a given type. diff --git a/pkg/lookup_map/lib/lookup_map.dart b/pkg/lookup_map/lib/lookup_map.dart deleted file mode 100644 index 2e501cd16e6e..000000000000 --- a/pkg/lookup_map/lib/lookup_map.dart +++ /dev/null @@ -1,106 +0,0 @@ -// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -/// Defines [LookupMap], a simple map that can be optimized by dart2js. -library lookup_map; - -/// [LookupMap] is a simple, but very restricted map. The map can only hold -/// constant keys and the only way to use the map is to retrieve values with a -/// key you already have. Except for lookup, any other operation in [Map] (like -/// forEach, keys, values, length, etc) is not available. -/// -/// Constant [LookupMap]s are understood by dart2js and can be tree-shaken -/// internally: if a key is not used elsewhere in the program, its entry can be -/// deleted from the map during compilation without changing the program's -/// behavior. Currently dart2js supports tree-shaking keys that are `Type` -/// literals, and any const expression that can only be created with a const -/// constructor. This means that primitives, Strings, and constant objects that -/// override the `==` operator cannot be tree-shaken. -/// -/// Note: [LookupMap] is unlikely going to be useful for individual developers -/// writing code by hand. It is mainly intended as a helper utility for -/// frameworks that need to autogenerate data and associate it with a type in -/// the program. For example, this can be used by a dependency injection system -/// to record how to create instances of a given type. A dependency injection -/// framework can store in a [LookupMap] all the information it needs for every -/// injectable type in every library and package. When compiling a specific -/// application, dart2js can tree-shake the data of types that are not used by -/// the application. Similarly, this can also be used by -/// serialization/deserialization packages that can store in a [LookupMap] the -/// deserialization logic for a given type. -class LookupMap { - /// The key for [LookupMap]s with a single key/value pair. - final K _key; - - /// The value for [LookupMap]s with a single key/value pair. - final V _value; - - /// List of alternating key-value pairs in the map. - final List _entries; - - /// Other maps to which this map delegates lookup operations if the key is not - /// found on [entries]. See [LookupMap]'s constructor for details. - final List> _nestedMaps; - - /// Creates a lookup-map given a list of key-value pair [entries], and - /// optionally additional entries from other [LookupMap]s. - /// - /// When doing a lookup, if the key is not found on [entries]. The lookup will - /// be performed in reverse order of the list of [nestedMaps], so a later - /// entry for a key shadows previous entries. For example, in: - /// - /// const map = const LookupMap(const [A, 1], - /// const [const LookupMap(const [A, 2, B, 4]), - /// const LookupMap(const [A, 3, B, 5])); - /// - /// `map[A]` returns `1` and `map[B]` returns `5`. - /// - /// Note: in the future we expect to change [entries] to be a const map - /// instead of a list of key-value pairs. - // TODO(sigmund): make entries a map once we fix TypeImpl.== (issue #17207). - const LookupMap(List entries, [List> nestedMaps = const []]) - : _key = null, - _value = null, - _entries = entries, - _nestedMaps = nestedMaps; - - /// Creates a lookup map with a single key-value pair. - const LookupMap.pair(K key, V value) - : _key = key, - _value = value, - _entries = const [], - _nestedMaps = const []; - - /// Return the data corresponding to [key]. - V operator [](K key) { - var map = _flatMap[this]; - if (map == null) { - map = {}; - _addEntriesTo(map); - _flatMap[this] = map; - } - return map[key]; - } - - /// Add to [map] entries from [nestedMaps] and from [entries] according to the - /// precedense order described in [nestedMaps]. - _addEntriesTo(Map map) { - _nestedMaps.forEach((m) => m._addEntriesTo(map)); - for (var i = 0; i < _entries.length; i += 2) { - map[_entries[i]] = _entries[i + 1]; - } - if (_key != null) map[_key] = _value; - } -} - -/// An expando that stores a flatten version of a [LookupMap], this is -/// computed and stored the first time the map is accessed. -final _flatMap = new Expando('_flat_map'); - -/// Internal constant that matches the version in the pubspec. This is used by -/// dart2js to ensure that optimizations are only enabled on known versions of -/// this code. -// Note: this needs to be kept in sync with the pubspec, otherwise -// test/version_check_test would fail. -final _version = '0.0.1+1'; diff --git a/pkg/lookup_map/pubspec.yaml b/pkg/lookup_map/pubspec.yaml deleted file mode 100644 index adaee09ecd8c..000000000000 --- a/pkg/lookup_map/pubspec.yaml +++ /dev/null @@ -1,10 +0,0 @@ -name: lookup_map -description: a lookup-only map that can be tree-shaken by dart2js -# Note: the version needs to be kept in sync with the string in -# lib/lookup_map.dart, otherwise test/version_check_test would fail. -version: 0.0.1+1 -author: "Dart Team " -homepage: https://github.com/dart-lang/sdk/blob/master/pkg/lookup_map/README.md -dev_dependencies: - test: ^0.12.3+8 - yaml: ^2.1.2 diff --git a/pkg/lookup_map/test/lookup_map_test.dart b/pkg/lookup_map/test/lookup_map_test.dart deleted file mode 100644 index d35e0beb98b0..000000000000 --- a/pkg/lookup_map/test/lookup_map_test.dart +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -import 'package:lookup_map/lookup_map.dart'; - -import 'package:test/test.dart'; - -class Key { - final int id; - const Key(this.id); -} - -class A {} - -const B = const Key(1); - -class C {} - -main() { - test('entries constructor', () { - var m = const LookupMap(const [ - A, - "the-text-for-A", - B, - "the-text-for-B", - 1.2, - "the-text-for-1.2" - ]); - expect(m[A], 'the-text-for-A'); - expect(m[B], 'the-text-for-B'); - expect(m[1.2], 'the-text-for-1.2'); - expect(m[C], null); - expect(m[1.3], null); - }); - - test('pair constructor', () { - var m = const LookupMap.pair(A, "the-text-for-A"); - expect(m[A], 'the-text-for-A'); - expect(m[B], null); - }); - - test('nested lookup', () { - var m = const LookupMap(const [], - const [const LookupMap.pair(A, "the-text-for-A")]); - expect(m[A], 'the-text-for-A'); - expect(m[B], null); - }); - - test('entry shadows nested maps', () { - var m = const LookupMap(const [ - A, - "the-text-for-A2", - ], const [ - const LookupMap.pair(A, "the-text-for-A1"), - ]); - expect(m[A], 'the-text-for-A2'); - }); - - test('nested maps shadow in order', () { - var m = const LookupMap(const [], const [ - const LookupMap.pair(A, "the-text-for-A1"), - const LookupMap.pair(B, "the-text-for-B2"), - const LookupMap.pair(A, "the-text-for-A2"), - const LookupMap.pair(B, "the-text-for-B1"), - ]); - expect(m[A], 'the-text-for-A2'); - expect(m[B], 'the-text-for-B1'); - }); - - // This test would fail if dart2js has a bug, but we keep it here for our - // sanity. - test('reachable lookups are not tree-shaken', () { - var m = const LookupMap(const [ - A, - B, - B, - C, - C, - 3.4, - ]); - expect(m[m[m[A]]], 3.4); - }); -} diff --git a/pkg/lookup_map/test/version_check_test.dart b/pkg/lookup_map/test/version_check_test.dart deleted file mode 100644 index 2bee1a612800..000000000000 --- a/pkg/lookup_map/test/version_check_test.dart +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -import 'dart:io'; -import 'dart:mirrors'; -import 'package:lookup_map/lookup_map.dart'; // accessed via mirrors; -import 'package:test/test.dart'; -import 'package:yaml/yaml.dart'; - -/// This dartdoc helps remove a warning for the unused import on [LookupMap]. -main() { - test('validate version number matches', () { - var pubspec = Platform.script.resolve('../pubspec.yaml'); - var yaml = loadYaml(new File.fromUri(pubspec).readAsStringSync()); - var version1 = yaml['version']; - var library = currentMirrorSystem().findLibrary(#lookup_map); - var version2 = library.getField(new Symbol('_version')).reflectee; - expect(version1, version2); - }); -} diff --git a/pkg/pkg.status b/pkg/pkg.status index 1fd913993c26..ddcf8f92e4d3 100644 --- a/pkg/pkg.status +++ b/pkg/pkg.status @@ -72,7 +72,6 @@ dev_compiler/test/codegen_test: MissingCompileTimeError # Issue 30245 [ $compiler == none && $runtime == drt ] mutation_observer: Skip # Issue 21149 unittest/*: Skip # Issue 21949 -lookup_map/*: SkipByDesign front_end/*: SkipByDesign [ $runtime == vm && $mode == debug ] @@ -125,7 +124,6 @@ collection/test/equality_test/05: Fail # Issue 1533 collection/test/equality_test/none: Pass, Fail # Issue 14348 compiler/tool/*: SkipByDesign # Only meant to run on vm front_end/tool/*: SkipByDesign # Only meant to run on vm -lookup_map/test/version_check_test: SkipByDesign # Only meant to run in vm. telemetry/test/*: SkipByDesign # Only meant to run on vm typed_data/test/typed_buffers_test/01: Fail # Not supporting Int64List, Uint64List. front_end/test/incremental_kernel_generator_test: SkipByDesign # Uses dart:io diff --git a/tests/compiler/dart2js/kernel/closed_world_test.dart b/tests/compiler/dart2js/kernel/closed_world_test.dart index 4cabddf874cc..2ac1de6a9900 100644 --- a/tests/compiler/dart2js/kernel/closed_world_test.dart +++ b/tests/compiler/dart2js/kernel/closed_world_test.dart @@ -151,7 +151,6 @@ List createResolutionEnqueuerListener(Compiler compiler) { backend.mirrorsDataBuilder, backend.noSuchMethodRegistry, backend.customElementsResolutionAnalysis, - backend.lookupMapResolutionAnalysis, backend.mirrorsResolutionAnalysis, new TypeVariableResolutionAnalysis( compiler.frontendStrategy.elementEnvironment, diff --git a/tests/compiler/dart2js/lookup_map_test.dart b/tests/compiler/dart2js/lookup_map_test.dart deleted file mode 100644 index 33a324f5b7e1..000000000000 --- a/tests/compiler/dart2js/lookup_map_test.dart +++ /dev/null @@ -1,392 +0,0 @@ -// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -library tests.dart2js.lookup_map_test; - -import 'package:test/test.dart'; -import 'compiler_helper.dart'; - -main() { - Map testDeclarations = { - 'types': r''' - import 'package:lookup_map/lookup_map.dart'; - class A {} - class B {} - class C {} - class D {} - class E {}''', - 'const keys': r''' - import 'package:lookup_map/lookup_map.dart'; - class Key { final name; const Key(this.name); } - const A = const Key("A"); - const B = const Key("B"); - const C = const Key("C"); - const D = const Key("D"); - const E = const Key("E");''', - 'mixed keys': r''' - import 'package:lookup_map/lookup_map.dart'; - class Key { final name; const Key(this.name); } - const A = const Key("A"); - class B {} - const C = const Key("C"); - class D {} - const E = const Key("E");''', - }; - - testDeclarations.forEach((name, declarations) { - group(name, () => _commonTests(declarations)); - }); - group('generic', _genericTests); - group('metadata', _metadataTests); - group('unsupported', _unsupportedKeysTests); - group('mirrors', _mirrorsTests); -} - -/// Common tests for both declarations that use Types or other const expressions -/// as keys. The argument [declaration] should contain a declaration for -/// constant keys named `A`, `B`, `C`, `D`, and `E`. -_commonTests(String declarations) { - test('live entries are kept', () async { - String generated = await compileAll(""" - $declarations - const map = const LookupMap(const [ - A, "the-text-for-A", - ]); - main() => print(map[A]); - """); - expect(generated, contains("the-text-for-A")); - }); - - test('live entries are kept - single-pair', () async { - String generated = await compileAll(""" - $declarations - const map = const LookupMap.pair(A, "the-text-for-A"); - main() => print(map[A]); - """); - expect(generated, contains("the-text-for-A")); - }); - - test('unused entries are removed', () async { - String generated = await compileAll(""" - $declarations - const map = const LookupMap(const [ - A, "the-text-for-A", - B, "the-text-for-B", - ]); - main() => print(map[A]); - """); - expect(generated, isNot(contains("the-text-for-B"))); - }); - - test('unused entries are removed - nested maps', () async { - String generated = await compileAll(""" - $declarations - const map = const LookupMap(const [], const [ - const LookupMap(const [ - A, "the-text-for-A", - B, "the-text-for-B", - ]), - ]); - main() => print(map[A]); - """); - expect(generated, isNot(contains("the-text-for-B"))); - }); - - test('unused entries are removed - single-pair', () async { - String generated = await compileAll(""" - $declarations - const map = const LookupMap.pair(A, "the-text-for-A"); - main() => print(map[A]); - """); - expect(generated, isNot(contains("the-text-for-B"))); - }); - - test('unused entries are removed - nested single-pair', () async { - String generated = await compileAll(""" - import 'package:lookup_map/lookup_map.dart'; - $declarations - const map = const LookupMap(const [], const [ - const LookupMap.pair(A, "the-text-for-A"), - const LookupMap.pair(B, "the-text-for-B"), - ]); - main() => print(map[A]); - """); - expect(generated, isNot(contains("the-text-for-B"))); - }); - - test('works if entries are declared separate from map', () async { - String generated = await compileAll(""" - $declarations - const entries = const [ - A, "the-text-for-A", - B, "the-text-for-B", - ]; - const map = const LookupMap(entries); - main() => print(map[A]); - """); - expect(generated, isNot(contains("the-text-for-B"))); - }); - - test('escaping entries disable tree-shaking', () async { - String generated = await compileAll(""" - $declarations - const entries = const [ - A, "the-text-for-A", - B, "the-text-for-B", - ]; - const map = const LookupMap(entries); - main() { - entries.forEach(print); - print(map[A]); - } - """); - expect(generated, contains("the-text-for-B")); - }); - - test('uses include recursively reachable data', () async { - String generated = await compileAll(""" - $declarations - const map = const LookupMap(const [ - A, const ["the-text-for-A", B], - B, const ["the-text-for-B", C], - C, const ["the-text-for-C"], - D, const ["the-text-for-D", E], - E, const ["the-text-for-E"], - ]); - main() => print(map[map[A][1]]); - """); - expect(generated, contains("the-text-for-A")); - expect(generated, contains("the-text-for-B")); - expect(generated, contains("the-text-for-C")); - expect(generated, isNot(contains("the-text-for-D"))); - expect(generated, isNot(contains("the-text-for-E"))); - }); - - test('uses are found through newly discovered code', () async { - String generated = await compileAll(""" - $declarations - f1() => map[B][1](); - f2() => E; - const map = const LookupMap(const [ - A, const ["the-text-for-A", f1], - B, const ["the-text-for-B", f2], - C, const ["the-text-for-C"], - D, const ["the-text-for-D"], - E, const ["the-text-for-E"], - ]); - main() => print(map[A][1]()); - """); - expect(generated, contains("the-text-for-A")); - expect(generated, contains("the-text-for-B")); - expect(generated, isNot(contains("the-text-for-C"))); - expect(generated, isNot(contains("the-text-for-C"))); - expect(generated, contains("the-text-for-E")); - }); - - test('support subclassing LookupMap', () async { - String generated = await compileAll(""" - $declarations - class S extends LookupMap { - const S(list) : super(list); - } - const map = const S(const [ - A, "the-text-for-A", - B, "the-text-for-B", - ]); - - main() => print(map[A]); - """); - expect(generated, contains("the-text-for-A")); - expect(generated, isNot(contains("the-text-for-B"))); - }); - - test('constants keys are processed recursively', () async { - String generated = await compileAll(""" - $declarations - - const nested = const [ B ]; - const map = const LookupMap(const [ - A, "the-text-for-A", - B, "the-text-for-B", - ]); - main() => print(map[nested]); - """); - expect(generated, isNot(contains("the-text-for-A"))); - expect(generated, contains("the-text-for-B")); - }); -} - -/// Tests specific to type keys, we ensure that generic type arguments are -/// considered. -_genericTests() { - test('generic type allocations are considered used', () async { - String generated = await compileAll(r""" - import 'package:lookup_map/lookup_map.dart'; - class A{} - class M{ get type => T; } - const map = const LookupMap(const [ - A, "the-text-for-A", - ]); - main() => print(map[new M().type]); - """); - expect(generated, contains("the-text-for-A")); - }); - - test('generics in type signatures are ignored', () async { - String generated = await compileAll(r""" - import 'package:lookup_map/lookup_map.dart'; - class A{} - class B{} - class M{ get type => T; } - _factory(M t) => t; - const map = const LookupMap(const [ - A, const ["the-text-for-A", _factory], - B, "the-text-for-B", - ]); - main() => print(map[A]); - """); - expect(generated, isNot(contains("the-text-for-B"))); - }); - - // regression test for a failure when looking up `dynamic` in a generic. - test('do not choke with dynamic type arguments', () async { - await compileAll(r""" - import 'package:lookup_map/lookup_map.dart'; - class A{} - class M{ get type => T; } - const map = const LookupMap(const [ - A, "the-text-for-A", - ]); - main() => print(map[new M().type]); - """); - }); -} - -/// Sanity checks about metadata: it is ignored for codegen even though it is -/// visited during resolution. -_metadataTests() { - test('metadata is ignored', () async { - String generated = await compileAll(r""" - import 'package:lookup_map/lookup_map.dart'; - class A{ const A(); } - - @A() - class M {} - const map = const LookupMap(const [ - A, "the-text-for-A", - ]); - main() => print(map[M]); - """); - expect(generated, isNot(contains("the-text-for-A"))); - }); - - test('shared constants used in metadata are ignored', () async { - String generated = await compileAll(r""" - import 'package:lookup_map/lookup_map.dart'; - const annot = const B(foo: A); - - @B(foo: annot) - class A{ const A(); } - class B{ final Type foo; const B({this.foo}); } - - class M {} - const map = const LookupMap(const [ - A, const ["the-text-for-A", annot] - ]); - main() => print(map[M]); - """); - expect(generated, isNot(contains("the-text-for-A"))); - }); -} - -_unsupportedKeysTests() { - test('primitive and string keys are always kept', () async { - String generated = await compileAll(""" - import 'package:lookup_map/lookup_map.dart'; - const A = "A"; - const B = "B"; - const map = const LookupMap(const [ - A, "the-text-for-A", - B, "the-text-for-B", - 3, "the-text-for-3", - 1.1, "the-text-for-1.1", - false, "the-text-for-false", - ]); - main() => print(map[A]); - """); - expect(generated, contains("the-text-for-A")); - expect(generated, contains("the-text-for-B")); - expect(generated, contains("the-text-for-3")); - expect(generated, contains("the-text-for-1.1")); - expect(generated, contains("the-text-for-false")); - }); - - test('non-type const keys implementing equals are not removed', () async { - String generated = await compileAll(""" - import 'package:lookup_map/lookup_map.dart'; - class Key { - final name; - const Key(this.name); - int get hashCode => name.hashCode * 13; - operator ==(other) => other is Key && name == other.name; - } - const A = const Key("A"); - const B = const Key("B"); - const map = const LookupMap(const [ - A, "the-text-for-A", - B, "the-text-for-B", - ]); - main() => print(map[A]); - """); - expect(generated, contains("the-text-for-B")); - }); -} - -_mirrorsTests() { - test('retain entries if mirrors keep the type', () async { - String generated = await compileAll(""" - import 'dart:mirrors'; - import 'package:lookup_map/lookup_map.dart'; - class A {} - class B {} - class C {} - const map = const LookupMap(const [ - A, "the-text-for-A", - B, "the-text-for-B", - C, "the-text-for-C", - ]); - main() { - reflectType(A); - print(map[A]); - } - """); - expect(generated, contains("the-text-for-A")); - expect(generated, contains("the-text-for-B")); - expect(generated, contains("the-text-for-C")); - }); - - test('exclude entries if MirrorsUsed also exclude the type', () async { - String generated = await compileAll(""" - library foo; - @MirrorsUsed(targets: const [B]) - import 'dart:mirrors'; - import 'package:lookup_map/lookup_map.dart'; - class A {} - class B {} - class C {} - const map = const LookupMap(const [ - A, "the-text-for-A", - B, "the-text-for-B", - C, "the-text-for-C", - ]); - main() { - reflectType(A); - print(map[A]); - } - """); - expect(generated, contains("the-text-for-A")); - expect(generated, contains("the-text-for-B")); - expect(generated, isNot(contains("the-text-for-C"))); - }); -} diff --git a/tests/compiler/dart2js/mock_compiler.dart b/tests/compiler/dart2js/mock_compiler.dart index 6c759d4461c6..43e390347db2 100644 --- a/tests/compiler/dart2js/mock_compiler.dart +++ b/tests/compiler/dart2js/mock_compiler.dart @@ -18,8 +18,6 @@ import 'package:compiler/src/diagnostics/spannable.dart'; import 'package:compiler/src/elements/elements.dart'; import 'package:compiler/src/elements/visitor.dart'; import 'package:compiler/src/library_loader.dart' show LoadedLibraries; -import 'package:compiler/src/js_backend/lookup_map_analysis.dart' - show LookupMapResolutionAnalysis; import 'package:compiler/src/io/source_file.dart'; import 'package:compiler/src/options.dart' show CompilerOptions; import 'package:compiler/src/resolution/members.dart'; @@ -131,8 +129,6 @@ class MockCompiler extends Compiler { asyncLibrarySource.addAll(ASYNC_AWAIT_LIBRARY); } registerSource(Uris.dart_async, buildLibrarySource(asyncLibrarySource)); - registerSource(LookupMapResolutionAnalysis.PACKAGE_LOOKUP_MAP, - buildLibrarySource(DEFAULT_LOOKUP_MAP_LIBRARY)); } /// Initialize the mock compiler with an empty main library. diff --git a/tests/compiler/dart2js/mock_libraries.dart b/tests/compiler/dart2js/mock_libraries.dart index ec8bee7fbc6d..3b5fc23b6d7b 100644 --- a/tests/compiler/dart2js/mock_libraries.dart +++ b/tests/compiler/dart2js/mock_libraries.dart @@ -473,21 +473,3 @@ preserveMetadata(){} preserveUris(){} preserveLibraryNames(){} '''; - -const Map DEFAULT_LOOKUP_MAP_LIBRARY = const { - 'LookupMap': r''' - class LookupMap { - final _key; - final _value; - final _entries; - final _nestedMaps; - - const LookupMap(this._entries, [this._nestedMaps = const []]) - : _key = null, _value = null; - - const LookupMap.pair(this._key, this._value) - : _entries = const [], _nestedMaps = const []; - V operator[](K k) => null; - }''', - '_version': 'const _version = "0.0.1+1";', -}; diff --git a/tests/compiler/dart2js_extra/dart2js_extra.status b/tests/compiler/dart2js_extra/dart2js_extra.status index bc84acac2698..e0394a6ffa93 100644 --- a/tests/compiler/dart2js_extra/dart2js_extra.status +++ b/tests/compiler/dart2js_extra/dart2js_extra.status @@ -48,9 +48,6 @@ deferred/deferred_mirrors2_test: Fail # mirrors not supported inference_nsm_mirrors_test: Fail # mirrors not supported invalid_annotation2_test/none: Fail # mirrors not supported invalid_annotation2_test/01: Pass # mirrors not supported, passes for the wrong reason -lookup_map/dead_entry_through_mirrors_test: Fail # mirrors not supported -lookup_map/live_entry_through_mirrors_test: Fail # mirrors not supported -lookup_map/live_entry_through_mirrors_used_test: Fail # mirrors not supported mirror_enqueuer_regression_test: Fail # mirrors not supported mirror_invalid_field_access2_test: Fail # mirrors not supported mirror_invalid_field_access3_test: Fail # mirrors not supported @@ -115,7 +112,6 @@ deferred_custom_loader_test: SkipByDesign # Issue 25683 [ $compiler == none && $runtime == vm ] invalid_annotation_test/01: MissingCompileTimeError, OK # vm is lazy -lookup_map/dead_entry_through_mirrors_test: SkipByDesign # Test for tree-shaking, vm never tree-shakes unconditional_dartio_import_test: SkipByDesign # dart2js only test new_from_env_test: SkipByDesign # dart2js only test @@ -146,9 +142,6 @@ inference_super_set_call_test: RuntimeError # Issue 27394 invalid_annotation2_test/01: Crash # Issue 27394 invalid_annotation2_test/none: Crash # Issue 27394 invalid_annotation_test/01: Crash # Issue 27394 -lookup_map/dead_entry_through_mirrors_test: Crash # Issue 27394 -lookup_map/live_entry_through_mirrors_test: Crash # Issue 27394 -lookup_map/live_entry_through_mirrors_used_test: Crash # Issue 27394 many_fields_test: Crash # Issue 27394 mirror_enqueuer_regression_test: Crash # Issue 27394 mirror_invalid_invoke2_test: Crash # Issue 27394 @@ -218,20 +211,6 @@ invalid_annotation2_test/none: Crash is_check_instanceof_test: Crash js_dispatch_property_test: RuntimeError label_test/06: Crash -lookup_map/dead_entry_single_nested_pairs_test: Crash -lookup_map/dead_entry_test: Crash -lookup_map/dead_entry_through_mirrors_test: Crash -lookup_map/discovered_code_test: Crash -lookup_map/entries_aside_test: Crash -lookup_map/escaping_entries_test: Crash -lookup_map/generic_type_test: Crash -lookup_map/live_entry_single_pair_test: Crash -lookup_map/live_entry_test: Crash -lookup_map/live_entry_through_mirrors_test: Crash -lookup_map/live_entry_through_mirrors_used_test: Crash -lookup_map/reachable_data2_test: Crash -lookup_map/reachable_data_test: Crash -lookup_map/subclass_lookup_map_test: Crash many_constants_test: RuntimeError mirror_invalid_field_access2_test: Crash mirror_invalid_field_access3_test: Crash @@ -327,20 +306,6 @@ invalid_annotation2_test/none: Crash # NoSuchMethodError: Class 'DynamicType' ha is_check_instanceof_test: Crash # NoSuchMethodError: The getter 'enclosingClass' was called on null. js_dispatch_property_test: RuntimeError label_test/06: Crash # RangeError (index): Invalid value: Valid value range is empty: 0 -lookup_map/dead_entry_single_nested_pairs_test: Crash # NoSuchMethodError: Class 'KField' has no instance getter 'constant'. -lookup_map/dead_entry_test: Crash # NoSuchMethodError: Class 'KField' has no instance getter 'constant'. -lookup_map/dead_entry_through_mirrors_test: Crash # NoSuchMethodError: Class 'KField' has no instance getter 'constant'. -lookup_map/discovered_code_test: Crash # NoSuchMethodError: Class 'KField' has no instance getter 'constant'. -lookup_map/entries_aside_test: Crash # NoSuchMethodError: Class 'KField' has no instance getter 'constant'. -lookup_map/escaping_entries_test: Crash # NoSuchMethodError: Class 'KField' has no instance getter 'constant'. -lookup_map/generic_type_test: Crash # NoSuchMethodError: Class 'KField' has no instance getter 'constant'. -lookup_map/live_entry_single_pair_test: Crash # NoSuchMethodError: Class 'KField' has no instance getter 'constant'. -lookup_map/live_entry_test: Crash # NoSuchMethodError: Class 'KField' has no instance getter 'constant'. -lookup_map/live_entry_through_mirrors_test: Crash # NoSuchMethodError: Class 'KField' has no instance getter 'constant'. -lookup_map/live_entry_through_mirrors_used_test: Crash # NoSuchMethodError: Class 'KField' has no instance getter 'constant'. -lookup_map/reachable_data2_test: Crash # NoSuchMethodError: Class 'KField' has no instance getter 'constant'. -lookup_map/reachable_data_test: Crash # NoSuchMethodError: Class 'KField' has no instance getter 'constant'. -lookup_map/subclass_lookup_map_test: Crash # NoSuchMethodError: Class 'KField' has no instance getter 'constant'. many_constants_test: RuntimeError mirror_invalid_field_access2_test: Crash # Assertion failure: Cannot find value local(main_closure.call#mirror) in (local(main#)) for j:closure_call(main_closure.call). mirror_invalid_field_access3_test: Crash # Assertion failure: Cannot find value local(main_closure.call#mirror) in (local(main#)) for j:closure_call(main_closure.call). diff --git a/tests/compiler/dart2js_extra/lookup_map/dead_entry_single_nested_pairs_test.dart b/tests/compiler/dart2js_extra/lookup_map/dead_entry_single_nested_pairs_test.dart deleted file mode 100644 index 1b9d21eec817..000000000000 --- a/tests/compiler/dart2js_extra/lookup_map/dead_entry_single_nested_pairs_test.dart +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -import 'package:lookup_map/lookup_map.dart'; -import 'package:expect/expect.dart'; - -class A {} - -class B {} - -const map = const LookupMap(const [], const [ - const LookupMap.pair(A, "the-text-for-A"), - const LookupMap.pair(B, "the-text-for-B"), -]); - -main() { - Expect.equals(map[A], "the-text-for-A"); -} diff --git a/tests/compiler/dart2js_extra/lookup_map/dead_entry_test.dart b/tests/compiler/dart2js_extra/lookup_map/dead_entry_test.dart deleted file mode 100644 index 347135109984..000000000000 --- a/tests/compiler/dart2js_extra/lookup_map/dead_entry_test.dart +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -import 'package:lookup_map/lookup_map.dart'; -import 'package:expect/expect.dart'; - -class A {} - -class B {} - -const map = const LookupMap(const [ - A, - "the-text-for-A", - B, - "the-text-for-B", -]); - -main() { - Expect.equals(map[A], "the-text-for-A"); -} diff --git a/tests/compiler/dart2js_extra/lookup_map/dead_entry_through_mirrors_test.dart b/tests/compiler/dart2js_extra/lookup_map/dead_entry_through_mirrors_test.dart deleted file mode 100644 index 2c1f3a2215a8..000000000000 --- a/tests/compiler/dart2js_extra/lookup_map/dead_entry_through_mirrors_test.dart +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -library dead_entry_through_mirrors_test; - -import 'package:lookup_map/lookup_map.dart'; -import 'package:expect/expect.dart'; - -@MirrorsUsed(targets: const [A]) -import 'dart:mirrors'; - -class A {} - -class B {} - -const map = const LookupMap(const [ - A, - "the-text-for-A", - B, - "the-text-for-B", -]); - -main() { - LibraryMirror lib = - currentMirrorSystem().findLibrary(#dead_entry_through_mirrors_test); - - // `A` is included by @MirrorsUsed, so its entry is retained too. - ClassMirror aClass = lib.declarations[#A]; - Expect.equals(map[aClass.reflectedType], "the-text-for-A"); - - // `B` is not included altogether. - Expect.equals(lib.declarations[#B], null); -} diff --git a/tests/compiler/dart2js_extra/lookup_map/discovered_code_test.dart b/tests/compiler/dart2js_extra/lookup_map/discovered_code_test.dart deleted file mode 100644 index 745b7e3e451d..000000000000 --- a/tests/compiler/dart2js_extra/lookup_map/discovered_code_test.dart +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -import 'package:lookup_map/lookup_map.dart'; -import 'package:expect/expect.dart'; - -class A { - A(B x); -} - -class B {} - -class C {} - -class D {} - -class E {} - -createA() => new A(map[B][1]()); -createB() => new B(); -const map = const LookupMap(const [ - A, - const ["the-text-for-A", createA], - B, - const ["the-text-for-B", createB], - C, - const ["the-text-for-C"], -]); - -main() { - Expect.isTrue(map[A][1]() is A); -} diff --git a/tests/compiler/dart2js_extra/lookup_map/entries_aside_test.dart b/tests/compiler/dart2js_extra/lookup_map/entries_aside_test.dart deleted file mode 100644 index e8caff346990..000000000000 --- a/tests/compiler/dart2js_extra/lookup_map/entries_aside_test.dart +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -import 'package:lookup_map/lookup_map.dart'; -import 'package:expect/expect.dart'; - -class A {} - -class B {} - -const entries = const [ - A, - "the-text-for-A", - B, - "the-text-for-B", -]; -const map = const LookupMap(entries); - -main() { - Expect.equals(map[A], 'the-text-for-A'); -} diff --git a/tests/compiler/dart2js_extra/lookup_map/escaping_entries_test.dart b/tests/compiler/dart2js_extra/lookup_map/escaping_entries_test.dart deleted file mode 100644 index 704f44845a84..000000000000 --- a/tests/compiler/dart2js_extra/lookup_map/escaping_entries_test.dart +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -import 'package:lookup_map/lookup_map.dart'; -import 'package:expect/expect.dart'; - -class A {} - -class B {} - -const entries = const [ - A, - "the-text-for-A", - B, - "the-text-for-B", -]; -const map = const LookupMap(entries); -main() { - entries.forEach(print); - Expect.equals(map[A], 'the-text-for-A'); -} diff --git a/tests/compiler/dart2js_extra/lookup_map/generic_type_test.dart b/tests/compiler/dart2js_extra/lookup_map/generic_type_test.dart deleted file mode 100644 index 2befb517eeaf..000000000000 --- a/tests/compiler/dart2js_extra/lookup_map/generic_type_test.dart +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -import 'package:lookup_map/lookup_map.dart'; -import 'package:expect/expect.dart'; - -class A {} - -class M { - get type => T; -} - -const map = const LookupMap(const [ - A, - 'the-text-for-A', -]); - -main() { - Expect.equals(map[new M().type], 'the-text-for-A'); -} diff --git a/tests/compiler/dart2js_extra/lookup_map/live_entry_single_pair_test.dart b/tests/compiler/dart2js_extra/lookup_map/live_entry_single_pair_test.dart deleted file mode 100644 index 4b7110aff771..000000000000 --- a/tests/compiler/dart2js_extra/lookup_map/live_entry_single_pair_test.dart +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -import 'package:lookup_map/lookup_map.dart'; -import 'package:expect/expect.dart'; - -class A {} - -const map = const LookupMap.pair(A, "the-text-for-A"); -main() { - Expect.equals(map[A], 'the-text-for-A'); -} diff --git a/tests/compiler/dart2js_extra/lookup_map/live_entry_test.dart b/tests/compiler/dart2js_extra/lookup_map/live_entry_test.dart deleted file mode 100644 index a1481479be4d..000000000000 --- a/tests/compiler/dart2js_extra/lookup_map/live_entry_test.dart +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -import 'package:lookup_map/lookup_map.dart'; -import 'package:expect/expect.dart'; - -class A {} - -const map = const LookupMap(const [ - A, - "the-text-for-A", -]); -main() { - Expect.equals(map[A], 'the-text-for-A'); -} diff --git a/tests/compiler/dart2js_extra/lookup_map/live_entry_through_mirrors_test.dart b/tests/compiler/dart2js_extra/lookup_map/live_entry_through_mirrors_test.dart deleted file mode 100644 index 7649246510f9..000000000000 --- a/tests/compiler/dart2js_extra/lookup_map/live_entry_through_mirrors_test.dart +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -library live_entry_through_mirrors_test; - -import 'package:lookup_map/lookup_map.dart'; -import 'package:expect/expect.dart'; -import 'dart:mirrors'; - -class A {} - -class B {} - -const map = const LookupMap(const [ - A, - "the-text-for-A", - B, - "the-text-for-B", -]); - -main() { - // `A` is referenced explicitly, so its entry should be retained regardless. - ClassMirror aClass = reflectClass(A); - Expect.equals(map[aClass.reflectedType], "the-text-for-A"); - - // `B` is used via mirrors. Because no @MirrorsUsed was found that's enough to - // retain the entry. - LibraryMirror lib = - currentMirrorSystem().findLibrary(#live_entry_through_mirrors_test); - ClassMirror bClass = lib.declarations[#B]; - Expect.equals(map[bClass.reflectedType], "the-text-for-B"); -} diff --git a/tests/compiler/dart2js_extra/lookup_map/live_entry_through_mirrors_used_test.dart b/tests/compiler/dart2js_extra/lookup_map/live_entry_through_mirrors_used_test.dart deleted file mode 100644 index 991934d67ac2..000000000000 --- a/tests/compiler/dart2js_extra/lookup_map/live_entry_through_mirrors_used_test.dart +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -// Subset of dead_entry_through_mirrors_test that is not affected by -// tree-shaking. This subset can be run in the VM. -library live_entry_through_mirrors_used_test; - -import 'package:lookup_map/lookup_map.dart'; -import 'package:expect/expect.dart'; - -@MirrorsUsed(targets: const [A]) -import 'dart:mirrors'; - -class A {} - -class B {} - -const map = const LookupMap(const [ - A, - "the-text-for-A", - B, - "the-text-for-B", -]); - -main() { - // `A` is included by @MirrorsUsed, so its entry is retained too. - LibraryMirror lib = - currentMirrorSystem().findLibrary(#live_entry_through_mirrors_used_test); - ClassMirror aClass = lib.declarations[#A]; - Expect.equals(map[aClass.reflectedType], "the-text-for-A"); -} diff --git a/tests/compiler/dart2js_extra/lookup_map/reachable_data2_test.dart b/tests/compiler/dart2js_extra/lookup_map/reachable_data2_test.dart deleted file mode 100644 index d73c468a5954..000000000000 --- a/tests/compiler/dart2js_extra/lookup_map/reachable_data2_test.dart +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -import 'package:lookup_map/lookup_map.dart'; -import 'package:expect/expect.dart'; - -class Key { - final x; - const Key(this.x); -} - -const A = const Key(1); -const B = const Key(2); -const C = const Key(3); -const D = const Key(4); -const E = const Key(5); -const map = const LookupMap(const [ - A, - const ["the-text-for-A", B], - B, - const ["the-text-for-B", C], - C, - const ["the-text-for-C"], - D, - const ["the-text-for-D", E], - E, - const ["the-text-for-E"], -]); -main() { - Expect.equals(map[map[A][1]][0], 'the-text-for-B'); -} diff --git a/tests/compiler/dart2js_extra/lookup_map/reachable_data_test.dart b/tests/compiler/dart2js_extra/lookup_map/reachable_data_test.dart deleted file mode 100644 index edbcd979abae..000000000000 --- a/tests/compiler/dart2js_extra/lookup_map/reachable_data_test.dart +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -import 'package:lookup_map/lookup_map.dart'; -import 'package:expect/expect.dart'; - -class A {} - -class B {} - -class C {} - -class D {} - -class E {} - -const map = const LookupMap(const [ - A, - const ["the-text-for-A", B], - B, - const ["the-text-for-B", C], - C, - const ["the-text-for-C"], - D, - const ["the-text-for-D", E], - E, - const ["the-text-for-E"], -]); -main() { - Expect.equals(map[map[A][1]][0], 'the-text-for-B'); -} diff --git a/tests/compiler/dart2js_extra/lookup_map/subclass_lookup_map_test.dart b/tests/compiler/dart2js_extra/lookup_map/subclass_lookup_map_test.dart deleted file mode 100644 index 09bc4acfb531..000000000000 --- a/tests/compiler/dart2js_extra/lookup_map/subclass_lookup_map_test.dart +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -import 'package:lookup_map/lookup_map.dart'; -import 'package:expect/expect.dart'; - -class A {} - -class B {} - -class S extends LookupMap { - const S(list) : super(list); -} - -const map = const S(const [ - A, - "the-text-for-A", - B, - "the-text-for-B", -]); - -main() { - Expect.equals(map[A], "the-text-for-A"); -}