From 69df740ea96a3d686ec11671354b9beccc5422eb Mon Sep 17 00:00:00 2001 From: Mayank Patke Date: Wed, 21 Feb 2024 00:02:13 +0000 Subject: [PATCH] [dart2js] Assorted TODO cleanup, bump pubspecs to 3.3.0 Change-Id: I621ac252c5d6f3b157a2f194b7f0b7ad85874e4c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/352990 Reviewed-by: Nate Biggs Commit-Queue: Mayank Patke --- .../lib/src/constants/constant_system.dart | 2 - pkg/compiler/lib/src/elements/entities.dart | 29 +++-------- pkg/compiler/lib/src/elements/types.dart | 4 +- .../src/inferrer/abstract_value_domain.dart | 8 +-- pkg/compiler/lib/src/inferrer/builder.dart | 3 +- pkg/compiler/lib/src/inferrer/computable.dart | 5 -- pkg/compiler/lib/src/inferrer/engine.dart | 2 - .../lib/src/inferrer/powersets/powersets.dart | 7 --- pkg/compiler/lib/src/inferrer/trivial.dart | 4 -- .../lib/src/inferrer/type_system.dart | 2 +- .../lib/src/inferrer/typemasks/masks.dart | 5 -- pkg/compiler/lib/src/inferrer/wrapped.dart | 5 -- .../js_backend/custom_elements_analysis.dart | 2 +- pkg/compiler/lib/src/js_backend/namer.dart | 4 -- .../js_backend/no_such_method_registry.dart | 50 +++++-------------- .../startup_emitter/model_emitter.dart | 3 +- pkg/compiler/lib/src/js_model/closure.dart | 2 +- .../lib/src/js_model/element_map_impl.dart | 2 - .../lib/src/js_model/type_recipe.dart | 6 +-- .../lib/src/kernel/element_map_impl.dart | 8 ++- .../lib/src/serialization/binary_sink.dart | 3 +- .../lib/src/serialization/binary_source.dart | 4 +- .../lib/src/serialization/object_sink.dart | 2 +- .../lib/src/serialization/object_source.dart | 2 +- pkg/compiler/lib/src/serialization/sink.dart | 8 +-- .../lib/src/serialization/source.dart | 4 +- pkg/compiler/lib/src/ssa/optimize.dart | 4 +- pkg/compiler/lib/src/universe/selector.dart | 32 ++++-------- pkg/compiler/pubspec.yaml | 2 +- .../test/analyses/analysis_helper.dart | 4 +- .../test/codegen/number_output_test.dart | 8 ++- pkg/compiler/test/codesize/swarm/Views.dart | 15 +++--- .../test/inference/data/deferred_load.dart | 2 +- pkg/compiler/test/model/subtypeset_test.dart | 8 ++- .../serialization/data/constructor_name.dart | 12 ++--- pkg/dart2js_info/lib/src/binary/sink.dart | 12 ++--- pkg/js_ast/lib/src/nodes.dart | 39 ++++++--------- pkg/js_ast/pubspec.yaml | 2 +- 38 files changed, 98 insertions(+), 218 deletions(-) diff --git a/pkg/compiler/lib/src/constants/constant_system.dart b/pkg/compiler/lib/src/constants/constant_system.dart index 8a9346c9a7d..7da74dede93 100644 --- a/pkg/compiler/lib/src/constants/constant_system.dart +++ b/pkg/compiler/lib/src/constants/constant_system.dart @@ -229,8 +229,6 @@ ConstructedConstantValue createSymbol( InterfaceType type = commonElements.symbolImplementationType; FieldEntity field = commonElements.symbolField; ConstantValue argument = createString(text); - // TODO(johnniwinther): Use type arguments when all uses no longer expect - // a [FieldElement]. var fields = {field: argument}; return ConstructedConstantValue(type, fields); } diff --git a/pkg/compiler/lib/src/elements/entities.dart b/pkg/compiler/lib/src/elements/entities.dart index 50a70836881..c32b8482247 100644 --- a/pkg/compiler/lib/src/elements/entities.dart +++ b/pkg/compiler/lib/src/elements/entities.dart @@ -174,21 +174,19 @@ abstract class FunctionEntity extends MemberEntity { } /// Enum for the synchronous/asynchronous function body modifiers. -class AsyncMarker { +enum AsyncMarker { /// The default function body marker. - static const AsyncMarker SYNC = AsyncMarker._(AsyncModifier.Sync); + SYNC._(AsyncModifier.Sync), /// The `sync*` function body marker. - static const AsyncMarker SYNC_STAR = - AsyncMarker._(AsyncModifier.SyncStar, isYielding: true); + SYNC_STAR._(AsyncModifier.SyncStar, isYielding: true), /// The `async` function body marker. - static const AsyncMarker ASYNC = - AsyncMarker._(AsyncModifier.Async, isAsync: true); + ASYNC._(AsyncModifier.Async, isAsync: true), /// The `async*` function body marker. - static const AsyncMarker ASYNC_STAR = - AsyncMarker._(AsyncModifier.AsyncStar, isAsync: true, isYielding: true); + ASYNC_STAR._(AsyncModifier.AsyncStar, isAsync: true, isYielding: true), + ; /// Is `true` if this marker defines the function body to have an /// asynchronous result, that is, either a [Future] or a [Stream]. @@ -207,21 +205,6 @@ class AsyncMarker { String toString() { return '${isAsync ? 'async' : 'sync'}${isYielding ? '*' : ''}'; } - - /// Canonical list of marker values. - /// - /// Added to make [AsyncMarker] enum-like. - static const List values = [ - SYNC, - SYNC_STAR, - ASYNC, - ASYNC_STAR - ]; - - /// Index to this marker within [values]. - /// - /// Added to make [AsyncMarker] enum-like. - int get index => values.indexOf(this); } /// Stripped down super interface for constructor like entities. diff --git a/pkg/compiler/lib/src/elements/types.dart b/pkg/compiler/lib/src/elements/types.dart index 8fb7a5c3b55..b53a63c8c66 100644 --- a/pkg/compiler/lib/src/elements/types.dart +++ b/pkg/compiler/lib/src/elements/types.dart @@ -1624,7 +1624,7 @@ class _DartTypeToStringVisitor extends DartTypeVisitor { // internal notion. The language specification does not define a '*' token // in the type language, and no such token should be surfaced to users. // For debugging, pass `--debug-print-legacy-stars` to emit the '*'. - if (_options == null || _options!.printLegacyStars) { + if (_options == null || _options.printLegacyStars) { _token('*'); } } @@ -1712,7 +1712,7 @@ class _DartTypeToStringVisitor extends DartTypeVisitor { needsComma = _comma(needsComma); _visit(typeVariable); DartType bound = typeVariable.bound; - if (_dartTypes == null || !_dartTypes!.isTopType(bound)) { + if (_dartTypes == null || !_dartTypes.isTopType(bound)) { _token(' extends '); _visit(bound); } diff --git a/pkg/compiler/lib/src/inferrer/abstract_value_domain.dart b/pkg/compiler/lib/src/inferrer/abstract_value_domain.dart index d31b6b7a13d..eb74feb66e4 100644 --- a/pkg/compiler/lib/src/inferrer/abstract_value_domain.dart +++ b/pkg/compiler/lib/src/inferrer/abstract_value_domain.dart @@ -73,7 +73,7 @@ class AbstractBool { @override String toString() => - 'AbstractBool.${_value == null ? 'Maybe' : (_value! ? 'True' : 'False')}'; + 'AbstractBool.${_value == null ? 'Maybe' : (_value ? 'True' : 'False')}'; } /// A value in an abstraction of runtime values. @@ -296,12 +296,6 @@ mixin AbstractValueDomain { /// subtypes of [cls] or `null` at runtime. AbstractBool containsOnlyType(covariant AbstractValue value, ClassEntity cls); - /// Returns an [AbstractBool] that describes whether [value] is an instance of - /// [cls] or `null` at runtime. - // TODO(johnniwinther): Merge this with [isInstanceOf]. - AbstractBool isInstanceOfOrNull( - covariant AbstractValue value, ClassEntity cls); - /// Returns an [AbstractBool] that describes whether [value] is known to be an /// instance of [cls] at runtime. AbstractBool isInstanceOf(AbstractValue value, ClassEntity cls); diff --git a/pkg/compiler/lib/src/inferrer/builder.dart b/pkg/compiler/lib/src/inferrer/builder.dart index af1f2526edc..ddf9ec2189a 100644 --- a/pkg/compiler/lib/src/inferrer/builder.dart +++ b/pkg/compiler/lib/src/inferrer/builder.dart @@ -1598,8 +1598,7 @@ class KernelTypeGraphBuilder extends ir.VisitorDefault @override TypeInformation visitLoadLibrary(ir.LoadLibrary node) { - // TODO(johnniwinther): Improve this by returning a Future type instead. - return _types.dynamicType; + return _types.asyncFutureType; } @override diff --git a/pkg/compiler/lib/src/inferrer/computable.dart b/pkg/compiler/lib/src/inferrer/computable.dart index 6ea2a69bae4..3bbf5215181 100644 --- a/pkg/compiler/lib/src/inferrer/computable.dart +++ b/pkg/compiler/lib/src/inferrer/computable.dart @@ -238,11 +238,6 @@ class ComputableAbstractValueDomain with AbstractValueDomain { covariant ComputableAbstractValue value, ClassEntity cls) => _wrappedDomain.containsOnlyType(_unwrap(value), cls); - @override - AbstractBool isInstanceOfOrNull( - covariant ComputableAbstractValue value, ClassEntity cls) => - _wrappedDomain.isInstanceOfOrNull(_unwrap(value), cls); - @override AbstractBool isInstanceOf( covariant ComputableAbstractValue value, ClassEntity cls) => diff --git a/pkg/compiler/lib/src/inferrer/engine.dart b/pkg/compiler/lib/src/inferrer/engine.dart index 603438674f0..99ad7670f46 100644 --- a/pkg/compiler/lib/src/inferrer/engine.dart +++ b/pkg/compiler/lib/src/inferrer/engine.dart @@ -114,8 +114,6 @@ class InferrerEngine { closedWorld.abstractValueDomain; CommonElements get commonElements => closedWorld.commonElements; - // TODO(johnniwinther): This should be part of [ClosedWorld] or - // [ClosureWorldRefiner]. NoSuchMethodData get noSuchMethodData => closedWorld.noSuchMethodData; final MemberHierarchyBuilder memberHierarchyBuilder; diff --git a/pkg/compiler/lib/src/inferrer/powersets/powersets.dart b/pkg/compiler/lib/src/inferrer/powersets/powersets.dart index 40765f91012..9e665b66576 100644 --- a/pkg/compiler/lib/src/inferrer/powersets/powersets.dart +++ b/pkg/compiler/lib/src/inferrer/powersets/powersets.dart @@ -606,13 +606,6 @@ class PowersetDomain with AbstractValueDomain { _powersetBitsDomain.isInstanceOf(value._powersetBits, cls), _abstractValueDomain.isInstanceOf(value._abstractValue, cls)); - @override - AbstractBool isInstanceOfOrNull( - covariant PowersetValue value, ClassEntity cls) => - AbstractBool.strengthen( - _powersetBitsDomain.isInstanceOfOrNull(value._powersetBits, cls), - _abstractValueDomain.isInstanceOfOrNull(value._abstractValue, cls)); - @override AbstractBool containsOnlyType( covariant PowersetValue value, ClassEntity cls) => diff --git a/pkg/compiler/lib/src/inferrer/trivial.dart b/pkg/compiler/lib/src/inferrer/trivial.dart index c2e65525eca..6ab037a02e0 100644 --- a/pkg/compiler/lib/src/inferrer/trivial.dart +++ b/pkg/compiler/lib/src/inferrer/trivial.dart @@ -323,10 +323,6 @@ class TrivialAbstractValueDomain with AbstractValueDomain { AbstractBool isInstanceOf(AbstractValue value, ClassEntity cls) => AbstractBool.Maybe; - @override - AbstractBool isInstanceOfOrNull(AbstractValue value, ClassEntity cls) => - AbstractBool.Maybe; - @override AbstractBool containsOnlyType(AbstractValue value, ClassEntity cls) => AbstractBool.Maybe; diff --git a/pkg/compiler/lib/src/inferrer/type_system.dart b/pkg/compiler/lib/src/inferrer/type_system.dart index 96c8efa2c80..ca3f1b7285e 100644 --- a/pkg/compiler/lib/src/inferrer/type_system.dart +++ b/pkg/compiler/lib/src/inferrer/type_system.dart @@ -413,7 +413,7 @@ class TypeSystem { bool isTypedArray = _closedWorld.classHierarchy.isInstantiated(typedDataClass) && _abstractValueDomain - .isInstanceOfOrNull(type.type, typedDataClass) + .isInstanceOf(type.type, typedDataClass) .isDefinitelyTrue; bool isConst = (type.type == _abstractValueDomain.constListType); bool isFixed = (type.type == _abstractValueDomain.fixedListType) || diff --git a/pkg/compiler/lib/src/inferrer/typemasks/masks.dart b/pkg/compiler/lib/src/inferrer/typemasks/masks.dart index aa18556699b..fa67e7f4224 100644 --- a/pkg/compiler/lib/src/inferrer/typemasks/masks.dart +++ b/pkg/compiler/lib/src/inferrer/typemasks/masks.dart @@ -176,7 +176,6 @@ class CommonMasks with AbstractValueDomain { late final TypeMask asyncStarStreamType = TypeMask.nonNullExact(commonElements.controllerStream, _closedWorld); - // TODO(johnniwinther): Assert that the null type has been resolved. @override late final TypeMask nullType = TypeMask.empty(); @@ -409,10 +408,6 @@ class CommonMasks with AbstractValueDomain { typeMask.containsOnly(cls); } - @override - AbstractBool isInstanceOfOrNull(TypeMask typeMask, ClassEntity cls) => - AbstractBool.trueOrMaybe(_isInstanceOfOrNull(typeMask, cls)); - bool _isInstanceOfOrNull(TypeMask typeMask, ClassEntity cls) { return _closedWorld.isImplemented(cls) && typeMask.satisfies(cls, _closedWorld); diff --git a/pkg/compiler/lib/src/inferrer/wrapped.dart b/pkg/compiler/lib/src/inferrer/wrapped.dart index 48489f25b48..ac8cfcbe876 100644 --- a/pkg/compiler/lib/src/inferrer/wrapped.dart +++ b/pkg/compiler/lib/src/inferrer/wrapped.dart @@ -450,11 +450,6 @@ class WrappedAbstractValueDomain with AbstractValueDomain { covariant WrappedAbstractValue value, ClassEntity cls) => _abstractValueDomain.isInstanceOf(value._abstractValue, cls); - @override - AbstractBool isInstanceOfOrNull( - covariant WrappedAbstractValue value, ClassEntity cls) => - _abstractValueDomain.isInstanceOfOrNull(value._abstractValue, cls); - @override AbstractBool containsOnlyType( covariant WrappedAbstractValue value, ClassEntity cls) => diff --git a/pkg/compiler/lib/src/js_backend/custom_elements_analysis.dart b/pkg/compiler/lib/src/js_backend/custom_elements_analysis.dart index f945a6a8675..d740d932201 100644 --- a/pkg/compiler/lib/src/js_backend/custom_elements_analysis.dart +++ b/pkg/compiler/lib/src/js_backend/custom_elements_analysis.dart @@ -191,7 +191,7 @@ class CustomElementsAnalysisJoin { } if (_backendUsageBuilder != null) { escapingConstructors - .forEach(_backendUsageBuilder!.registerGlobalFunctionDependency); + .forEach(_backendUsageBuilder.registerGlobalFunctionDependency); } // Force the generation of the type constant that is the key to an entry // in the generated table. diff --git a/pkg/compiler/lib/src/js_backend/namer.dart b/pkg/compiler/lib/src/js_backend/namer.dart index ad0c9d4bce0..34dd323a8fc 100644 --- a/pkg/compiler/lib/src/js_backend/namer.dart +++ b/pkg/compiler/lib/src/js_backend/namer.dart @@ -425,10 +425,6 @@ class Namer extends ModularNamer { case SelectorKind.SPECIAL: return specialSelectorName(selector); - - default: - throw failedAt(CURRENT_ELEMENT_SPANNABLE, - 'Unexpected selector kind: ${selector.kind}'); } } diff --git a/pkg/compiler/lib/src/js_backend/no_such_method_registry.dart b/pkg/compiler/lib/src/js_backend/no_such_method_registry.dart index 5e1f896d5af..35354a8d890 100644 --- a/pkg/compiler/lib/src/js_backend/no_such_method_registry.dart +++ b/pkg/compiler/lib/src/js_backend/no_such_method_registry.dart @@ -4,7 +4,7 @@ import '../common.dart'; import '../common/elements.dart' show CommonElements; -import '../common/names.dart' show Identifiers, Selectors; +import '../common/names.dart' show Identifiers; import '../elements/entities.dart'; import '../inferrer/types.dart' show GlobalTypeInferenceResults; import '../js_model/elements.dart' show JFunction; @@ -30,12 +30,7 @@ import '../serialization/serialization.dart'; /// /// noSuchMethod(x) => throw 'not implemented' /// -/// Implementations in category C are not applicable, for example: -/// -/// noSuchMethod() { /* missing parameter */ } -/// noSuchMethod(a, b) { /* too many parameters */ } -/// -/// Implementations that do not fall into category A, B or C are in category D. +/// Implementations that do not fall into category A or B are in category C. /// They are the only category of implementation that are considered during type /// inference. /// @@ -49,7 +44,7 @@ import '../serialization/serialization.dart'; /// implementations to avoid warnings. /// Registry for collecting `noSuchMethod` implementations and categorizing them -/// into categories `A`, `B`, `C`, `D`. +/// into categories `A`, `B`, `C`. class NoSuchMethodRegistry { /// The implementations that fall into category A, described above. final Set _defaultImpls = {}; @@ -58,11 +53,6 @@ class NoSuchMethodRegistry { final Set _throwingImpls = {}; /// The implementations that fall into category C, described above. - // TODO(johnniwinther): Remove this category when Dart 1 is no longer - // supported. - final Set _notApplicableImpls = {}; - - /// The implementations that fall into category D, described above. final Set _otherImpls = {}; /// The implementations that have not yet been categorized. @@ -82,7 +72,7 @@ class NoSuchMethodRegistry { /// `true` if a category `B` method has been seen so far. bool get hasThrowingNoSuchMethod => _throwingImpls.isNotEmpty; - /// `true` if a category `D` method has been seen so far. + /// `true` if a category `C` method has been seen so far. bool get hasComplexNoSuchMethod => _otherImpls.isNotEmpty; Iterable get defaultImpls => _defaultImpls; @@ -114,13 +104,6 @@ class NoSuchMethodRegistry { if (_otherImpls.contains(element)) { return NsmCategory.OTHER; } - if (_notApplicableImpls.contains(element)) { - return NsmCategory.NOT_APPLICABLE; - } - if (!Selectors.noSuchMethod_.signatureApplies(element)) { - _notApplicableImpls.add(element); - return NsmCategory.NOT_APPLICABLE; - } if (_commonElements.isDefaultNoSuchMethodImplementation(element)) { _defaultImpls.add(element); return NsmCategory.DEFAULT; @@ -140,12 +123,6 @@ class NoSuchMethodRegistry { case NsmCategory.OTHER: _otherImpls.add(element); break; - case NsmCategory.NOT_APPLICABLE: - // If the super method is not applicable, the call is redirected to - // `Object.noSuchMethod`. - _defaultImpls.add(element); - category = NsmCategory.DEFAULT; - break; } return category; } else if (_resolver.hasThrowingSyntax(element)) { @@ -166,8 +143,8 @@ class NoSuchMethodRegistry { /// Data object used during type inference. /// -/// Post inference collected category `D` methods are into subcategories `D1` -/// and `D2`. +/// Post inference collected category `C` methods are into subcategories `C1` +/// and `C2`. class NoSuchMethodData { /// Tag used for identifying serialized [NoSuchMethodData] objects in a /// debugging data stream. @@ -176,13 +153,13 @@ class NoSuchMethodData { /// The implementations that fall into category B, described above. final Set _throwingImpls; - /// The implementations that fall into category D, described above. + /// The implementations that fall into category C, described above. final Set _otherImpls; - /// The implementations that fall into category D1 + /// The implementations that fall into category C1 final Set _complexNoReturnImpls = {}; - /// The implementations that fall into category D2 + /// The implementations that fall into category C2 final Set _complexReturningImpls = {}; final Set _forwardingSyntaxImpls; @@ -230,8 +207,8 @@ class NoSuchMethodData { Iterable get complexReturningImpls => _complexReturningImpls; - /// Now that type inference is complete, split category D into two - /// subcategories: D1, those that have no return type, and D2, those + /// Now that type inference is complete, split category C into two + /// subcategories: C1, those that have no return type, and C2, those /// that have a return type. void categorizeComplexImplementations(GlobalTypeInferenceResults results) { _otherImpls.forEach((FunctionEntity element) { @@ -243,7 +220,7 @@ class NoSuchMethodData { }); } - /// Emits a diagnostic about methods in categories `B`, `D1` and `D2`. + /// Emits a diagnostic about methods in categories `B`, `C1` and `C2`. void emitDiagnostic(DiagnosticReporter reporter) { _throwingImpls.forEach((e) { if (!_forwardingSyntaxImpls.contains(e)) { @@ -264,7 +241,7 @@ class NoSuchMethodData { /// Returns [true] if the given element is a complex [noSuchMethod] /// implementation. An implementation is complex if it falls into - /// category D, as described above. + /// category C, as described above. bool isComplex(FunctionEntity element) { assert(element.name == Identifiers.noSuchMethod_); return _otherImpls.contains(element); @@ -274,6 +251,5 @@ class NoSuchMethodData { enum NsmCategory { DEFAULT, THROWING, - NOT_APPLICABLE, OTHER, } diff --git a/pkg/compiler/lib/src/js_emitter/startup_emitter/model_emitter.dart b/pkg/compiler/lib/src/js_emitter/startup_emitter/model_emitter.dart index c4862a2444a..7870c0d83cd 100644 --- a/pkg/compiler/lib/src/js_emitter/startup_emitter/model_emitter.dart +++ b/pkg/compiler/lib/src/js_emitter/startup_emitter/model_emitter.dart @@ -618,8 +618,7 @@ var ${startupMetricsGlobal} = }); output.add('\n'); output.add(js - .createCodeBuffer(epilogue, _options, - _sourceInformationStrategy as JavaScriptSourceInformationStrategy) + .createCodeBuffer(epilogue, _options, _sourceInformationStrategy) .getText()); // Add semi-colon to separate from other fragments in the same part. output.add(';'); diff --git a/pkg/compiler/lib/src/js_model/closure.dart b/pkg/compiler/lib/src/js_model/closure.dart index 3e059a65935..97c2eada9a0 100644 --- a/pkg/compiler/lib/src/js_model/closure.dart +++ b/pkg/compiler/lib/src/js_model/closure.dart @@ -881,7 +881,7 @@ class JsClosureClassInfo extends JsScopeInfo @override Local? getClosureEntity(KernelToLocalsMap localsMap) { return _closureEntityVariable != null - ? localsMap.getLocalVariable(_closureEntityVariable!) + ? localsMap.getLocalVariable(_closureEntityVariable) : _closureEntity; } } diff --git a/pkg/compiler/lib/src/js_model/element_map_impl.dart b/pkg/compiler/lib/src/js_model/element_map_impl.dart index 12e659438d0..1848245381b 100644 --- a/pkg/compiler/lib/src/js_model/element_map_impl.dart +++ b/pkg/compiler/lib/src/js_model/element_map_impl.dart @@ -2201,8 +2201,6 @@ class JsElementEnvironment extends ElementEnvironment return elementMap.getDartType( getFunctionNode(elementMap, function)!.emittedValueType!); } - throw failedAt( - CURRENT_ELEMENT_SPANNABLE, 'Unexpected marker ${asyncMarker}'); } @override diff --git a/pkg/compiler/lib/src/js_model/type_recipe.dart b/pkg/compiler/lib/src/js_model/type_recipe.dart index 0bc5f994fe0..318f498958e 100644 --- a/pkg/compiler/lib/src/js_model/type_recipe.dart +++ b/pkg/compiler/lib/src/js_model/type_recipe.dart @@ -533,13 +533,13 @@ class _Substitution extends DartTypeSubstitutionVisitor { // Returns `null` if not bound. DartType? _lookupTypeVariableType(TypeVariableType type) { if (_variables != null) { - int index = _variables!.indexOf(type); + int index = _variables.indexOf(type); if (index >= 0) return _replacements![index]; } if (_classEnvironment == null) return null; - if (_classEnvironment!.element == _classValue?.element) { - int index = _classEnvironment!.typeArguments.indexOf(type); + if (_classEnvironment.element == _classValue?.element) { + int index = _classEnvironment.typeArguments.indexOf(type); if (index >= 0) return _classValue!.typeArguments[index]; return null; } diff --git a/pkg/compiler/lib/src/kernel/element_map_impl.dart b/pkg/compiler/lib/src/kernel/element_map_impl.dart index 5a3cb6694b6..7e55ccb709a 100644 --- a/pkg/compiler/lib/src/kernel/element_map_impl.dart +++ b/pkg/compiler/lib/src/kernel/element_map_impl.dart @@ -1283,8 +1283,7 @@ class KernelToElementMap implements IrToElementMap { Name name = getName(node.name); bool isStatic = node.isStatic; bool isExternal = node.isExternal; - // TODO(johnniwinther): Remove `&& !node.isExternal` when #31233 is fixed. - bool isAbstract = node.isAbstract && !node.isExternal; + bool isAbstract = node.isAbstract; AsyncMarker asyncMarker = getAsyncMarker(node.function); switch (node.kind) { case ir.ProcedureKind.Factory: @@ -1901,9 +1900,8 @@ class KernelNativeMemberResolver { NativeBehavior fieldStoreBehavior = _computeNativeFieldStoreBehavior(field); _nativeDataBuilder! - .setNativeFieldLoadBehavior(field, fieldLoadBehavior); - _nativeDataBuilder! - .setNativeFieldStoreBehavior(field, fieldStoreBehavior); + ..setNativeFieldLoadBehavior(field, fieldLoadBehavior) + ..setNativeFieldStoreBehavior(field, fieldStoreBehavior); } } } diff --git a/pkg/compiler/lib/src/serialization/binary_sink.dart b/pkg/compiler/lib/src/serialization/binary_sink.dart index 2c45822447d..aa21f8ec35b 100644 --- a/pkg/compiler/lib/src/serialization/binary_sink.dart +++ b/pkg/compiler/lib/src/serialization/binary_sink.dart @@ -71,8 +71,7 @@ class BinaryDataSink implements DataSink { } @override - void writeEnum(dynamic value) { - // ignore: avoid_dynamic_calls + void writeEnum(E value) { writeInt(value.index); } diff --git a/pkg/compiler/lib/src/serialization/binary_source.dart b/pkg/compiler/lib/src/serialization/binary_source.dart index 7d50dc71034..c36c5c5c2fd 100644 --- a/pkg/compiler/lib/src/serialization/binary_source.dart +++ b/pkg/compiler/lib/src/serialization/binary_source.dart @@ -46,7 +46,7 @@ class BinaryDataSource implements DataSource { _byteOffset += bytes.length; String string = utf8.decode(bytes); if (_stringInterner == null) return string; - return _stringInterner!.internString(string); + return _stringInterner.internString(string); } @override @@ -68,7 +68,7 @@ class BinaryDataSource implements DataSource { } @override - E readEnum(List values) { + E readEnum(List values) { int index = readInt(); assert( 0 <= index && index < values.length, diff --git a/pkg/compiler/lib/src/serialization/object_sink.dart b/pkg/compiler/lib/src/serialization/object_sink.dart index a87ca083e2d..d6df3172a91 100644 --- a/pkg/compiler/lib/src/serialization/object_sink.dart +++ b/pkg/compiler/lib/src/serialization/object_sink.dart @@ -26,7 +26,7 @@ class ObjectDataSink implements DataSink { } @override - void writeEnum(dynamic value) { + void writeEnum(E value) { _data!.add(value); } diff --git a/pkg/compiler/lib/src/serialization/object_source.dart b/pkg/compiler/lib/src/serialization/object_source.dart index 6f1171a820d..696e83003cc 100644 --- a/pkg/compiler/lib/src/serialization/object_source.dart +++ b/pkg/compiler/lib/src/serialization/object_source.dart @@ -45,7 +45,7 @@ class ObjectDataSource implements DataSource { String readString() => _read(); @override - E readEnum(List values) => _read(); + E readEnum(List values) => _read(); @override int readInt() => _read(); diff --git a/pkg/compiler/lib/src/serialization/sink.dart b/pkg/compiler/lib/src/serialization/sink.dart index 5c46815dc2f..5682f04e8f8 100644 --- a/pkg/compiler/lib/src/serialization/sink.dart +++ b/pkg/compiler/lib/src/serialization/sink.dart @@ -15,7 +15,7 @@ abstract class DataSink { void writeInt(int value); /// Serialization of an enum value. - void writeEnum(dynamic value); + void writeEnum(E value); /// Serialization of a String value. void writeString(String value); @@ -287,11 +287,7 @@ class DataSinkWriter { } /// Writes the enum value [value] to this data sink. - // TODO(johnniwinther): Change the signature to - // `void writeEnum>(E value);` when an interface for enums - // is added to the language. - - void writeEnum(dynamic value) { + void writeEnum(E value) { _writeDataKind(DataKind.enumValue); _sinkWriter.writeEnum(value); } diff --git a/pkg/compiler/lib/src/serialization/source.dart b/pkg/compiler/lib/src/serialization/source.dart index bc9fec01cb2..814101646a3 100644 --- a/pkg/compiler/lib/src/serialization/source.dart +++ b/pkg/compiler/lib/src/serialization/source.dart @@ -22,7 +22,7 @@ abstract class DataSource { int readInt(); /// Deserialization of an enum value in [values]. - E readEnum(List values); + E readEnum(List values); /// Returns the offset for a deferred entity and skips it in the read queue. /// The offset can later be passed to [readAtOffset] to get the value. @@ -390,7 +390,7 @@ class DataSourceReader { /// ... /// Foo foo = source.readEnum(Foo.values); /// - E readEnum(List values) { + E readEnum(List values) { _checkDataKind(DataKind.enumValue); return _sourceReader.readEnum(values); } diff --git a/pkg/compiler/lib/src/ssa/optimize.dart b/pkg/compiler/lib/src/ssa/optimize.dart index 2240e843c78..8be10dcb3eb 100644 --- a/pkg/compiler/lib/src/ssa/optimize.dart +++ b/pkg/compiler/lib/src/ssa/optimize.dart @@ -674,11 +674,11 @@ class SsaInstructionSimplifier extends HBaseVisitor AbstractValue resultType = _abstractValueDomain.positiveIntType; // If we already have computed a more specific type, keep that type. if (_abstractValueDomain - .isInstanceOfOrNull(actualType, commonElements.jsUInt31Class) + .isInstanceOf(actualType, commonElements.jsUInt31Class) .isDefinitelyTrue) { resultType = _abstractValueDomain.uint31Type; } else if (_abstractValueDomain - .isInstanceOfOrNull(actualType, commonElements.jsUInt32Class) + .isInstanceOf(actualType, commonElements.jsUInt32Class) .isDefinitelyTrue) { resultType = _abstractValueDomain.uint32Type; } diff --git a/pkg/compiler/lib/src/universe/selector.dart b/pkg/compiler/lib/src/universe/selector.dart index 7e386e66b18..c8af97bdcdd 100644 --- a/pkg/compiler/lib/src/universe/selector.dart +++ b/pkg/compiler/lib/src/universe/selector.dart @@ -15,32 +15,20 @@ import '../serialization/serialization.dart'; import '../util/util.dart' show Hashing; import 'call_structure.dart' show CallStructure; -class SelectorKind { +enum SelectorKind { + GETTER('getter'), + SETTER('setter'), + CALL('call'), + OPERATOR('operator'), + INDEX('index'), + SPECIAL('special'), + ; + final String name; - final int index; - const SelectorKind(this.name, this.index); - - static const SelectorKind GETTER = SelectorKind('getter', 0); - static const SelectorKind SETTER = SelectorKind('setter', 1); - static const SelectorKind CALL = SelectorKind('call', 2); - static const SelectorKind OPERATOR = SelectorKind('operator', 3); - static const SelectorKind INDEX = SelectorKind('index', 4); - static const SelectorKind SPECIAL = SelectorKind('special', 5); - - @override - int get hashCode => index; + const SelectorKind(this.name); @override String toString() => name; - - static const List values = [ - GETTER, - SETTER, - CALL, - OPERATOR, - INDEX, - SPECIAL - ]; } class Selector { diff --git a/pkg/compiler/pubspec.yaml b/pkg/compiler/pubspec.yaml index 90d03475a56..78f7d1806c7 100644 --- a/pkg/compiler/pubspec.yaml +++ b/pkg/compiler/pubspec.yaml @@ -4,7 +4,7 @@ name: compiler # This package is not intended for consumption on pub.dev. DO NOT publish. publish_to: none environment: - sdk: '>=3.0.0 <4.0.0' + sdk: '>=3.3.0 <4.0.0' # Use 'any' constraints here; we get our versions from the DEPS file. dependencies: diff --git a/pkg/compiler/test/analyses/analysis_helper.dart b/pkg/compiler/test/analyses/analysis_helper.dart index bfda869aa08..f9f6eb34b6b 100644 --- a/pkg/compiler/test/analyses/analysis_helper.dart +++ b/pkg/compiler/test/analyses/analysis_helper.dart @@ -89,7 +89,7 @@ class DynamicVisitor extends ir.RecursiveVisitor { void run({bool verbose = false, bool generate = false}) { if (!generate && _allowedListPath != null) { - File file = File(_allowedListPath!); + File file = File(_allowedListPath); if (file.existsSync()) { try { _expectedJson = json.jsonDecode(file.readAsStringSync()); @@ -111,7 +111,7 @@ class DynamicVisitor extends ir.RecursiveVisitor { actualJson[uri] = map; }); - File(_allowedListPath!).writeAsStringSync( + File(_allowedListPath).writeAsStringSync( json.JsonEncoder.withIndent(' ').convert(actualJson)); return; } diff --git a/pkg/compiler/test/codegen/number_output_test.dart b/pkg/compiler/test/codegen/number_output_test.dart index 1988738e8c8..2114ea06dc4 100644 --- a/pkg/compiler/test/codegen/number_output_test.dart +++ b/pkg/compiler/test/codegen/number_output_test.dart @@ -13,8 +13,7 @@ const MEMORY_SOURCE_FILES = const { 'main.dart': ''' main() { print(12300000); - // TODO(efortuna): Uncomment below when issue 33160 is fixed. - // print(0xffffffff00000000); + print(0xffffffff00000000); print(double.maxFinite); print(-22230000); }''' @@ -44,9 +43,8 @@ Future test({required bool minify}) async { Expect.isTrue(jsOutput.contains('12300000')); Expect.isTrue(jsOutput.contains('-22230000')); } - // TODO(efortuna): Uncomment when issue 33160 is fixed. - //Expect.isTrue(jsOutput.contains('18446744069414584e3')); - //Expect.isFalse(jsOutput.contains('-4294967296')); + Expect.isTrue(jsOutput.contains('18446744069414584e3')); + Expect.isFalse(jsOutput.contains('-4294967296')); Expect.isTrue(jsOutput.contains('17976931348623157e292')); Expect.isFalse(jsOutput.contains('1234567890123456789012345')); // The decimal expansion of double.maxFinite has 308 digits. We only check diff --git a/pkg/compiler/test/codesize/swarm/Views.dart b/pkg/compiler/test/codesize/swarm/Views.dart index 0c8cac397a0..856d47b7dbc 100644 --- a/pkg/compiler/test/codesize/swarm/Views.dart +++ b/pkg/compiler/test/codesize/swarm/Views.dart @@ -158,7 +158,7 @@ class GenericListView extends View { // rather than tracking it ourselves. _select(findIndex(_lastSelectedItem), false); _select(findIndex(_selectedItem!.value), true); - _lastSelectedItem = _selectedItem!.value; + _lastSelectedItem = _selectedItem.value; } @override @@ -221,7 +221,7 @@ class GenericListView extends View { : 1); scroller!.onContentMoved.listen((e) => renderVisibleItems(false)); if (_pages != null) { - watch(_pages!.target, (s) => _onPageSelected()); + watch(_pages.target, (s) => _onPageSelected()); } if (_snapToItems) { @@ -258,7 +258,7 @@ class GenericListView extends View { } if (_selectedItem != null) { - watch(_selectedItem!, (EventSummary summary) => onSelectedItemChange()); + watch(_selectedItem, (EventSummary summary) => onSelectedItemChange()); } } @@ -348,7 +348,7 @@ class GenericListView extends View { } else { // Update the target page only after we are all done animating. if (_pages != null) { - _pages!.target.value = _layout.getPage(targetIndex, _viewLength); + _pages.target.value = _layout.getPage(targetIndex, _viewLength); } } } @@ -368,7 +368,7 @@ class GenericListView extends View { void _onPageSelected() { if (_pages!.target != _layout.getPage(_activeInterval.start, _viewLength)) { _throwTo(_layout.getOffset( - _layout.getPageStartIndex(_pages!.target.value, _viewLength))); + _layout.getPageStartIndex(_pages.target.value, _viewLength))); } } @@ -393,11 +393,10 @@ class GenericListView extends View { } if (_pages != null) { - _pages!.current.value = - _layout.getPage(targetInterval.start, _viewLength); + _pages.current.value = _layout.getPage(targetInterval.start, _viewLength); } if (_pages != null) { - _pages!.length.value = _data.isNotEmpty + _pages.length.value = _data.isNotEmpty ? _layout.getPage(_data.length - 1, _viewLength) + 1 : 0; } diff --git a/pkg/compiler/test/inference/data/deferred_load.dart b/pkg/compiler/test/inference/data/deferred_load.dart index 41ee085ad94..e6c371e8cb0 100644 --- a/pkg/compiler/test/inference/data/deferred_load.dart +++ b/pkg/compiler/test/inference/data/deferred_load.dart @@ -9,5 +9,5 @@ main() { callLoadLibrary(); } -/*member: callLoadLibrary:[null|subclass=Object]*/ +/*member: callLoadLibrary:[exact=_Future]*/ callLoadLibrary() => expect.loadLibrary(); diff --git a/pkg/compiler/test/model/subtypeset_test.dart b/pkg/compiler/test/model/subtypeset_test.dart index 14218c8a191..edac524da8c 100644 --- a/pkg/compiler/test/model/subtypeset_test.dart +++ b/pkg/compiler/test/model/subtypeset_test.dart @@ -15,12 +15,11 @@ import '../helpers/type_test_helper.dart'; void main() { asyncTest(() async { - // TODO(johnniwinther): Remove code for Dart 1 tests. - await runTests(strongMode: true); + await runTests(); }); } -runTests({bool strongMode = false}) async { +runTests() async { var env = await TypeEnvironment.create(r""" /// A /// / \ @@ -93,6 +92,5 @@ runTests({bool strongMode = false}) async { checkClass(G, [G]); checkClass(H, [H, I]); checkClass(I, [I]); - checkClass(Function_, strongMode ? [] : [A, B, C, D, E, F, G], - checkSubset: true); + checkClass(Function_, [], checkSubset: true); } diff --git a/pkg/compiler/test/serialization/data/constructor_name.dart b/pkg/compiler/test/serialization/data/constructor_name.dart index 55d0a861235..abb60a662eb 100644 --- a/pkg/compiler/test/serialization/data/constructor_name.dart +++ b/pkg/compiler/test/serialization/data/constructor_name.dart @@ -7,13 +7,13 @@ class Class1 { Class1.foo(); } -// TODO(johnniwinther): Uncomment this when #34965 is fixed: -//class Class2 { -// var bar; -// factory Class2.bar() => null; -//} +class Class2 { + var bar; + factory Class2.bar() => Class2._(); + Class2._(); +} main() { Class1.foo().foo; - //new Class2.bar().bar; + Class2.bar().bar; } diff --git a/pkg/dart2js_info/lib/src/binary/sink.dart b/pkg/dart2js_info/lib/src/binary/sink.dart index b3671795bf2..a4f627885ac 100644 --- a/pkg/dart2js_info/lib/src/binary/sink.dart +++ b/pkg/dart2js_info/lib/src/binary/sink.dart @@ -75,10 +75,7 @@ abstract class DataSink { {bool allowNull = false}); /// Writes the enum value [value] to this data sink. - // TODO(johnniwinther): Change the signature to - // `void writeEnum>(E value);` when an interface for enums - // is added to the language. - void writeEnum(dynamic value); + void writeEnum(E value); /// Writes the URI [value] to this data sink. void writeUri(Uri value); @@ -194,7 +191,7 @@ abstract class AbstractDataSink extends DataSinkMixin implements DataSink { } @override - void writeEnum(dynamic value) { + void writeEnum(E value) { _writeEnumInternal(value); } @@ -238,7 +235,7 @@ abstract class AbstractDataSink extends DataSinkMixin implements DataSink { void _writeIntInternal(int value); /// Actual serialization of an enum value, implemented by subclasses. - void _writeEnumInternal(dynamic value); + void _writeEnumInternal(E value); } /// [DataSink] that writes data as a sequence of bytes. @@ -282,8 +279,7 @@ class BinarySink extends AbstractDataSink { } @override - void _writeEnumInternal(dynamic value) { - // ignore: avoid_dynamic_calls + void _writeEnumInternal(E value) { _writeIntInternal(value.index); } diff --git a/pkg/js_ast/lib/src/nodes.dart b/pkg/js_ast/lib/src/nodes.dart index 77b01f3c603..595781db269 100644 --- a/pkg/js_ast/lib/src/nodes.dart +++ b/pkg/js_ast/lib/src/nodes.dart @@ -990,9 +990,8 @@ class While extends Loop { class Do extends Loop { final Expression condition; - Do(Statement body, this.condition, - {JavaScriptNodeSourceInformation? sourceInformation}) - : super(body) { + Do(super.body, this.condition, + {JavaScriptNodeSourceInformation? sourceInformation}) { _sourceInformation = sourceInformation; } @@ -1249,7 +1248,7 @@ class Case extends SwitchClause { } class Default extends SwitchClause { - Default(Block body) : super(body); + Default(super.body); @override T accept(NodeVisitor visitor) => visitor.visitDefault(this); @@ -1728,7 +1727,7 @@ class Call extends Expression { } class New extends Call { - New(Expression cls, List arguments) : super(cls, arguments); + New(super.cls, super.arguments); @override T accept(NodeVisitor visitor) => visitor.visitNew(this); @@ -1906,7 +1905,7 @@ abstract class VariableReference extends Expression { } class VariableUse extends VariableReference { - VariableUse(String name) : super(name); + VariableUse(super.name); @override T accept(NodeVisitor visitor) => visitor.visitVariableUse(this); @@ -1925,7 +1924,7 @@ class VariableUse extends VariableReference { class VariableDeclaration extends VariableReference implements Declaration { final bool allowRename; - VariableDeclaration(String name, {this.allowRename = true}) : super(name); + VariableDeclaration(super.name, {this.allowRename = true}); @override T accept(NodeVisitor visitor) => visitor.visitVariableDeclaration(this); @@ -1939,7 +1938,7 @@ class VariableDeclaration extends VariableReference implements Declaration { } class Parameter extends VariableDeclaration { - Parameter(String name) : super(name); + Parameter(super.name); @override T accept(NodeVisitor visitor) => visitor.visitParameter(this); @@ -2086,26 +2085,20 @@ class ArrowFunction extends FunctionExpression { int get precedenceLevel => ASSIGNMENT; } -class AsyncModifier { - final int index; +enum AsyncModifier { + sync('sync', isAsync: false, isYielding: false), + async('async', isAsync: true, isYielding: false), + asyncStar('async*', isAsync: true, isYielding: true), + syncStar('sync*', isAsync: false, isYielding: true), + ; + final bool isAsync; final bool isYielding; final String description; - const AsyncModifier(this.index, this.description, + const AsyncModifier(this.description, {required this.isAsync, required this.isYielding}); - static const AsyncModifier sync = - AsyncModifier(0, 'sync', isAsync: false, isYielding: false); - static const AsyncModifier async = - AsyncModifier(1, 'async', isAsync: true, isYielding: false); - static const AsyncModifier asyncStar = - AsyncModifier(2, 'async*', isAsync: true, isYielding: true); - static const AsyncModifier syncStar = - AsyncModifier(3, 'sync*', isAsync: false, isYielding: true); - - static const List values = [sync, async, asyncStar, syncStar]; - @override String toString() => description; } @@ -2510,7 +2503,7 @@ class MethodDefinition extends Node implements Property { } /// Tag class for all interpolated positions. -abstract class InterpolatedNode implements Node { +mixin InterpolatedNode implements Node { dynamic get nameOrPosition; bool get isNamed => nameOrPosition is String; diff --git a/pkg/js_ast/pubspec.yaml b/pkg/js_ast/pubspec.yaml index c407bea2afb..b75dbf0822b 100644 --- a/pkg/js_ast/pubspec.yaml +++ b/pkg/js_ast/pubspec.yaml @@ -3,7 +3,7 @@ name: js_ast publish_to: none environment: - sdk: '>=2.16.0 <3.0.0' + sdk: '>=3.3.0 <4.0.0' # Use 'any' constraints here; we get our versions from the DEPS file. dev_dependencies: