@@ -944,13 +944,13 @@ void Object::Init(Isolate* isolate) {
944944 cls.set_is_type_finalized();
945945
946946 cls = dynamic_class_;
947- *dynamic_type_ = Type::NewNonParameterizedType(cls, kNullable );
947+ *dynamic_type_ = Type::NewNonParameterizedType(cls);
948948
949949 cls = void_class_;
950- *void_type_ = Type::NewNonParameterizedType(cls, kNullable );
950+ *void_type_ = Type::NewNonParameterizedType(cls);
951951
952952 cls = never_class_;
953- *never_type_ = Type::NewNonParameterizedType(cls, kNonNullable );
953+ *never_type_ = Type::NewNonParameterizedType(cls);
954954
955955 // Since TypeArguments objects are passed as function arguments, make them
956956 // behave as Dart instances, although they are just VM objects.
@@ -1567,7 +1567,7 @@ RawError* Object::Init(Isolate* isolate,
15671567 cls = object_store->array_class(); // Was allocated above.
15681568 RegisterPrivateClass(cls, Symbols::_List(), core_lib);
15691569 pending_classes.Add(cls);
1570- // We cannot use NewNonParameterizedType(), because Array is
1570+ // We cannot use NewNonParameterizedType(cls ), because Array is
15711571 // parameterized. Warning: class _List has not been patched yet. Its
15721572 // declared number of type parameters is still 0. It will become 1 after
15731573 // patching. The array type allocated below represents the raw type _List
@@ -1934,8 +1934,7 @@ RawError* Object::Init(Isolate* isolate,
19341934 // name is a built-in identifier (this is wrong). The corresponding types
19351935 // are stored in the object store.
19361936 cls = object_store->null_class();
1937- type = Type::NewNonParameterizedType(cls, kNullable);
1938- cls.set_declaration_type(type);
1937+ type = Type::NewNonParameterizedType(cls);
19391938 object_store->set_null_type(type);
19401939 ASSERT(type.IsNullable());
19411940
@@ -4336,23 +4335,18 @@ void Class::set_declaration_type(const Type& value) const {
43364335 // TODO(regis): Since declaration type is used as the runtime type of
43374336 // instances of a non-generic class, the nullability should be set to
43384337 // kNonNullable instead of kLegacy.
4339- // For now, we accept any except for Null (kNullable) .
4340- ASSERT(! value.IsNullType () || value.IsNullable());
4338+ // For now, we set the nullability to kLegacy, except for Null.
4339+ ASSERT(value.IsLegacy () || ( value.IsNullType() && value. IsNullable() ));
43414340 StorePointer(&raw_ptr()->declaration_type_, value.raw());
43424341}
43434342
4344- RawType* Class::DeclarationType(Nullability nullability ) const {
4343+ RawType* Class::DeclarationType() const {
43454344 ASSERT(is_declaration_loaded());
4346- if (IsNullClass()) {
4347- // Ignore requested nullability (e.g. by mirrors).
4348- nullability = kNullable;
4349- }
4350- Type& type = Type::Handle(declaration_type());
4351- if (!type.IsNull()) {
4352- return type.ToNullability(nullability, Heap::kOld);
4345+ if (declaration_type() != Type::null()) {
4346+ return declaration_type();
43534347 }
4354- type = Type::New(*this, TypeArguments:: Handle(type_parameters()), token_pos(),
4355- nullability );
4348+ Type& type = Type::Handle(
4349+ Type::New(*this, TypeArguments::Handle(type_parameters()), token_pos()) );
43564350 type ^= ClassFinalizer::FinalizeType(*this, type);
43574351 set_declaration_type(type);
43584352 return type.raw();
@@ -6324,8 +6318,8 @@ RawType* Function::SignatureType(Nullability nullability) const {
63246318 const TypeArguments& signature_type_arguments =
63256319 TypeArguments::Handle(scope_class.type_parameters());
63266320 // Return the still unfinalized signature type.
6327- type = Type::New(scope_class, signature_type_arguments, token_pos(),
6328- nullability);
6321+ type = Type::New(scope_class, signature_type_arguments, token_pos());
6322+ type.set_nullability( nullability);
63296323 type.set_signature(*this);
63306324 SetSignatureType(type);
63316325 }
@@ -16662,10 +16656,7 @@ RawAbstractType* Instance::GetType(Heap::Space space) const {
1666216656 if (cls.NumTypeArguments() > 0) {
1666316657 type_arguments = GetTypeArguments();
1666416658 }
16665- // TODO(regis): The runtime type of a non-null instance should be
16666- // non-nullable instead of legacy. Revisit.
16667- type = Type::New(cls, type_arguments, TokenPosition::kNoSource, kLegacy,
16668- space);
16659+ type = Type::New(cls, type_arguments, TokenPosition::kNoSource, space);
1666916660 type.SetIsFinalized();
1667016661 type ^= type.Canonicalize();
1667116662 }
@@ -17649,22 +17640,20 @@ RawType* Type::DartTypeType() {
1764917640 return Isolate::Current()->object_store()->type_type();
1765017641}
1765117642
17652- RawType* Type::NewNonParameterizedType(const Class& type_class,
17653- Nullability nullability) {
17643+ RawType* Type::NewNonParameterizedType(const Class& type_class) {
1765417644 ASSERT(type_class.NumTypeArguments() == 0);
1765517645 // It is too early to use the class finalizer, as type_class may not be named
1765617646 // yet, so do not call DeclarationType().
1765717647 Type& type = Type::Handle(type_class.declaration_type());
1765817648 if (type.IsNull()) {
1765917649 type = Type::New(Class::Handle(type_class.raw()),
17660- Object::null_type_arguments(), TokenPosition::kNoSource,
17661- nullability);
17650+ Object::null_type_arguments(), TokenPosition::kNoSource);
1766217651 type.SetIsFinalized();
1766317652 type ^= type.Canonicalize();
1766417653 type_class.set_declaration_type(type);
1766517654 }
1766617655 ASSERT(type.IsFinalized());
17667- return type.ToNullability(nullability, Heap::kOld );
17656+ return type.raw( );
1766817657}
1766917658
1767017659void Type::SetIsFinalized() const {
@@ -17800,8 +17789,8 @@ RawAbstractType* Type::InstantiateFrom(
1780017789 }
1780117790 // This uninstantiated type is not modified, as it can be instantiated
1780217791 // with different instantiators. Allocate a new instantiated version of it.
17803- const Type& instantiated_type = Type::Handle(
17804- zone, Type::New(cls, type_arguments, token_pos(), nullability (), space));
17792+ const Type& instantiated_type =
17793+ Type::Handle( zone, Type::New(cls, type_arguments, token_pos(), space));
1780517794 // For a function type, possibly instantiate and set its signature.
1780617795 if (!sig_fun.IsNull()) {
1780717796 // If we are finalizing a typedef, do not yet instantiate its signature,
@@ -18020,8 +18009,10 @@ RawAbstractType* Type::Canonicalize(TrailPtr trail) const {
1802018009 const Class& cls = Class::Handle(zone, type_class());
1802118010
1802218011 // Fast canonical lookup/registry for simple types.
18023- if (!cls.IsGeneric() && !cls.IsClosureClass() && !cls.IsTypedefClass()) {
18012+ if (IsNullType() || (IsLegacy() && !cls.IsGeneric() &&
18013+ !cls.IsClosureClass() && !cls.IsTypedefClass())) {
1802418014 ASSERT(!IsFunctionType());
18015+ ASSERT(!IsNullType() || IsNullable());
1802518016 Type& type = Type::Handle(zone, cls.declaration_type());
1802618017 if (type.IsNull()) {
1802718018 ASSERT(!cls.raw()->InVMIsolateHeap() || (isolate == Dart::vm_isolate()));
@@ -18054,12 +18045,10 @@ RawAbstractType* Type::Canonicalize(TrailPtr trail) const {
1805418045 }
1805518046 }
1805618047 }
18057- if (nullability() == type.nullability()) {
18058- ASSERT(this->Equals(type));
18059- ASSERT(type.IsCanonical());
18060- ASSERT(type.IsOld());
18061- return type.raw();
18062- }
18048+ ASSERT(this->Equals(type));
18049+ ASSERT(type.IsCanonical());
18050+ ASSERT(type.IsOld());
18051+ return type.raw();
1806318052 }
1806418053
1806518054 AbstractType& type = Type::Handle(zone);
@@ -18147,13 +18136,12 @@ bool Type::CheckIsCanonical(Thread* thread) const {
1814718136 const Class& cls = Class::Handle(zone, type_class());
1814818137
1814918138 // Fast canonical lookup/registry for simple types.
18150- if (!cls.IsGeneric() && !cls.IsClosureClass() && !cls.IsTypedefClass()) {
18139+ if (IsNullType() || (IsLegacy() && !cls.IsGeneric() &&
18140+ !cls.IsClosureClass() && !cls.IsTypedefClass())) {
1815118141 ASSERT(!IsFunctionType());
18142+ ASSERT(!IsNullType() || IsNullable());
1815218143 type = cls.declaration_type();
18153- ASSERT(type.IsCanonical());
18154- if (nullability() == type.nullability()) {
18155- return (raw() == type.raw());
18156- }
18144+ return (raw() == type.raw());
1815718145 }
1815818146
1815918147 ObjectStore* object_store = isolate->object_store();
@@ -18246,7 +18234,6 @@ RawType* Type::New(Heap::Space space) {
1824618234RawType* Type::New(const Class& clazz,
1824718235 const TypeArguments& arguments,
1824818236 TokenPosition token_pos,
18249- Nullability nullability,
1825018237 Heap::Space space) {
1825118238 Zone* Z = Thread::Current()->zone();
1825218239 const Type& result = Type::Handle(Z, Type::New(space));
@@ -18255,7 +18242,11 @@ RawType* Type::New(const Class& clazz,
1825518242 result.SetHash(0);
1825618243 result.set_token_pos(token_pos);
1825718244 result.StoreNonPointer(&result.raw_ptr()->type_state_, RawType::kAllocated);
18258- result.set_nullability(nullability);
18245+ if (clazz.id() == kNullCid) {
18246+ result.set_nullability(kNullable);
18247+ } else {
18248+ result.set_nullability(kLegacy);
18249+ }
1825918250
1826018251 result.SetTypeTestingStub(
1826118252 Code::Handle(Z, TypeTestingStubGenerator::DefaultCodeForType(result)));
0 commit comments