Skip to content

Commit b4779e8

Browse files
committed
Revert "[VM/nnbd] Make Nullability and NNBDMode class enums to avoid name conflicts."
This reverts commit d45c3d1. Reason for revert: Please see https://buganizer.corp.google.com/issues/144304690 (This CL is dependent on https://dart-review.googlesource.com/c/sdk/+/124480 which caused the regression). Original change's description: > [VM/nnbd] Make Nullability and NNBDMode class enums to avoid name conflicts. > > Change-Id: Ic78d3f48964bb61cbd1d90a69fcd68b4f29071e4 > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/124587 > Commit-Queue: Régis Crelier <regis@google.com> > Reviewed-by: Alexander Markov <alexmarkov@google.com> TBR=alexmarkov@google.com,regis@google.com # Not skipping CQ checks because original CL landed > 1 day ago. Change-Id: I24603236f04bd2ec1ad80789d78cca89e70fb1d1 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/125101 Reviewed-by: Siva Annamalai <asiva@google.com>
1 parent 82aa7e7 commit b4779e8

File tree

7 files changed

+50
-76
lines changed

7 files changed

+50
-76
lines changed

runtime/lib/mirrors.cc

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -633,17 +633,16 @@ static RawInstance* CreateTypeMirror(const AbstractType& type) {
633633
// TODO(regis): Until mirrors reflect nullability, force kLegacy, except for
634634
// Null type, which should remain nullable.
635635
if (!type.IsNullType()) {
636-
const Type& legacy_type = Type::Handle(
637-
Type::Cast(type).ToNullability(Nullability::kLegacy, Heap::kOld));
636+
const Type& legacy_type =
637+
Type::Handle(Type::Cast(type).ToNullability(kLegacy, Heap::kOld));
638638
return CreateClassMirror(cls, legacy_type, Bool::False(),
639639
Object::null_instance());
640640
}
641641
return CreateClassMirror(cls, type, Bool::False(), Object::null_instance());
642642
} else if (type.IsTypeParameter()) {
643643
// TODO(regis): Until mirrors reflect nullability, force kLegacy.
644-
const TypeParameter& legacy_type =
645-
TypeParameter::Handle(TypeParameter::Cast(type).ToNullability(
646-
Nullability::kLegacy, Heap::kOld));
644+
const TypeParameter& legacy_type = TypeParameter::Handle(
645+
TypeParameter::Cast(type).ToNullability(kLegacy, Heap::kOld));
647646
return CreateTypeVariableMirror(legacy_type, Object::null_instance());
648647
}
649648
UNREACHABLE();

runtime/vm/compiler/frontend/bytecode_reader.cc

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -502,12 +502,11 @@ void BytecodeReaderHelper::ReadClosureDeclaration(const Function& function,
502502
closures_->SetAt(closureIndex, closure);
503503

504504
Type& signature_type = Type::Handle(
505-
Z, ReadFunctionSignature(closure,
506-
(flags & kHasOptionalPositionalParamsFlag) != 0,
507-
(flags & kHasOptionalNamedParamsFlag) != 0,
508-
(flags & kHasTypeParamsFlag) != 0,
509-
/* has_positional_param_names = */ true,
510-
Nullability::kNonNullable));
505+
Z, ReadFunctionSignature(
506+
closure, (flags & kHasOptionalPositionalParamsFlag) != 0,
507+
(flags & kHasOptionalNamedParamsFlag) != 0,
508+
(flags & kHasTypeParamsFlag) != 0,
509+
/* has_positional_param_names = */ true, kNonNullable));
511510

512511
closure.SetSignatureType(signature_type);
513512

@@ -1509,7 +1508,7 @@ RawObject* BytecodeReaderHelper::ReadObjectContents(uint32_t header) {
15091508
const Nullability nullability =
15101509
bytecode_component_->GetVersion() >= 24
15111510
? static_cast<Nullability>((flags & kNullabilityMask) / kFlagBit4)
1512-
: Nullability::kLegacy;
1511+
: kLegacy;
15131512
return ReadType(tag, nullability);
15141513
}
15151514
default:

runtime/vm/compiler/frontend/kernel_fingerprints.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ void KernelFingerprintHelper::CalculateDartTypeFingerprint() {
246246
break;
247247
case kTypeParameterType: {
248248
Nullability nullability = ReadNullability();
249-
BuildHash(static_cast<uint32_t>(nullability));
249+
BuildHash(nullability);
250250
ReadUInt(); // read index for parameter.
251251
CalculateOptionalDartTypeFingerprint(); // read bound bound.
252252
break;
@@ -269,7 +269,7 @@ void KernelFingerprintHelper::CalculateOptionalDartTypeFingerprint() {
269269

270270
void KernelFingerprintHelper::CalculateInterfaceTypeFingerprint(bool simple) {
271271
Nullability nullability = ReadNullability();
272-
BuildHash(static_cast<uint32_t>(nullability));
272+
BuildHash(nullability);
273273
NameIndex kernel_class = ReadCanonicalNameReference();
274274
ASSERT(H.IsClass(kernel_class));
275275
const String& class_name = H.DartClassName(kernel_class);
@@ -285,7 +285,7 @@ void KernelFingerprintHelper::CalculateInterfaceTypeFingerprint(bool simple) {
285285

286286
void KernelFingerprintHelper::CalculateFunctionTypeFingerprint(bool simple) {
287287
Nullability nullability = ReadNullability();
288-
BuildHash(static_cast<uint32_t>(nullability));
288+
BuildHash(nullability);
289289

290290
if (!simple) {
291291
CalculateTypeParametersListFingerprint(); // read type_parameters.

runtime/vm/compiler/frontend/kernel_translation_helper.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2768,7 +2768,7 @@ void TypeTranslator::BuildTypeInternal() {
27682768
break;
27692769
case kBottomType:
27702770
result_ = Class::Handle(Z, I->object_store()->null_class())
2771-
.DeclarationType(Nullability::kNullable);
2771+
.DeclarationType(kNullable);
27722772
ASSERT(result_.IsNullable());
27732773
break;
27742774
case kNeverType:

runtime/vm/object.cc

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -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, Nullability::kNullable);
947+
*dynamic_type_ = Type::NewNonParameterizedType(cls, kNullable);
948948

949949
cls = void_class_;
950-
*void_type_ = Type::NewNonParameterizedType(cls, Nullability::kNullable);
950+
*void_type_ = Type::NewNonParameterizedType(cls, kNullable);
951951

952952
cls = never_class_;
953-
*never_type_ = Type::NewNonParameterizedType(cls, Nullability::kNonNullable);
953+
*never_type_ = Type::NewNonParameterizedType(cls, kNonNullable);
954954

955955
// Since TypeArguments objects are passed as function arguments, make them
956956
// behave as Dart instances, although they are just VM objects.
@@ -1934,7 +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, Nullability::kNullable);
1937+
type = Type::NewNonParameterizedType(cls, kNullable);
19381938
cls.set_declaration_type(type);
19391939
object_store->set_null_type(type);
19401940
ASSERT(type.IsNullable());
@@ -4345,7 +4345,7 @@ RawType* Class::DeclarationType(Nullability nullability) const {
43454345
ASSERT(is_declaration_loaded());
43464346
if (IsNullClass()) {
43474347
// Ignore requested nullability (e.g. by mirrors).
4348-
nullability = Nullability::kNullable;
4348+
nullability = kNullable;
43494349
}
43504350
Type& type = Type::Handle(declaration_type());
43514351
if (!type.IsNull()) {
@@ -16664,8 +16664,8 @@ RawAbstractType* Instance::GetType(Heap::Space space) const {
1666416664
}
1666516665
// TODO(regis): The runtime type of a non-null instance should be
1666616666
// non-nullable instead of legacy. Revisit.
16667-
type = Type::New(cls, type_arguments, TokenPosition::kNoSource,
16668-
Nullability::kLegacy, space);
16667+
type = Type::New(cls, type_arguments, TokenPosition::kNoSource, kLegacy,
16668+
space);
1666916669
type.SetIsFinalized();
1667016670
type ^= type.Canonicalize();
1667116671
}
@@ -17019,7 +17019,7 @@ TokenPosition AbstractType::token_pos() const {
1701917019
Nullability AbstractType::nullability() const {
1702017020
// AbstractType is an abstract class.
1702117021
UNREACHABLE();
17022-
return Nullability::kNullable;
17022+
return kNullable;
1702317023
}
1702417024

1702517025
bool AbstractType::IsInstantiated(Genericity genericity,
@@ -17201,21 +17201,8 @@ RawString* AbstractType::PrintURIs(URIs* uris) {
1720117201
return Symbols::FromConcatAll(thread, pieces);
1720217202
}
1720317203

17204-
static const String& NullabilitySuffix(Nullability value) {
17205-
// Keep in sync with Nullability enum in runtime/vm/object.h.
17206-
switch (value) {
17207-
case Nullability::kUndetermined:
17208-
return Symbols::Percent();
17209-
case Nullability::kNullable:
17210-
return Symbols::QuestionMark();
17211-
case Nullability::kNonNullable:
17212-
return Symbols::Empty();
17213-
case Nullability::kLegacy:
17214-
return Symbols::Star();
17215-
default:
17216-
UNREACHABLE();
17217-
}
17218-
}
17204+
// Keep in sync with Nullability enum in runtime/vm/object.h.
17205+
static const char* nullability_suffix[4] = {"%", "?", "", "*"};
1721917206

1722017207
RawString* AbstractType::BuildName(NameVisibility name_visibility) const {
1722117208
ASSERT(name_visibility != kScrubbedName);
@@ -17225,7 +17212,7 @@ RawString* AbstractType::BuildName(NameVisibility name_visibility) const {
1722517212
if (FLAG_show_nullability) {
1722617213
return Symbols::FromConcat(
1722717214
thread, String::Handle(zone, TypeParameter::Cast(*this).name()),
17228-
NullabilitySuffix(nullability()));
17215+
String::Handle(zone, String::New(nullability_suffix[nullability()])));
1722917216
}
1723017217
return TypeParameter::Cast(*this).name();
1723117218
}
@@ -17243,7 +17230,8 @@ RawString* AbstractType::BuildName(NameVisibility name_visibility) const {
1724317230
return Symbols::FromConcat(
1724417231
thread,
1724517232
String::Handle(zone, signature_function.UserVisibleSignature()),
17246-
NullabilitySuffix(nullability()));
17233+
String::Handle(zone,
17234+
String::New(nullability_suffix[nullability()])));
1724717235
}
1724817236
return signature_function.UserVisibleSignature();
1724917237
}
@@ -17253,9 +17241,10 @@ RawString* AbstractType::BuildName(NameVisibility name_visibility) const {
1725317241
if (!IsFinalized() || IsBeingFinalized()) {
1725417242
// TODO(regis): Check if this is dead code.
1725517243
if (FLAG_show_nullability) {
17256-
return Symbols::FromConcat(thread,
17257-
String::Handle(zone, class_name.raw()),
17258-
NullabilitySuffix(nullability()));
17244+
return Symbols::FromConcat(
17245+
thread, String::Handle(zone, class_name.raw()),
17246+
String::Handle(zone,
17247+
String::New(nullability_suffix[nullability()])));
1725917248
}
1726017249
return class_name.raw();
1726117250
}
@@ -17298,7 +17287,8 @@ RawString* AbstractType::BuildName(NameVisibility name_visibility) const {
1729817287
pieces.Add(args_name);
1729917288
}
1730017289
if (FLAG_show_nullability) {
17301-
pieces.Add(NullabilitySuffix(nullability()));
17290+
pieces.Add(
17291+
String::Handle(zone, String::New(nullability_suffix[nullability()])));
1730217292
}
1730317293
// The name is only used for type checking and debugging purposes.
1730417294
// Unless profiling data shows otherwise, it is not worth caching the name in
@@ -17337,7 +17327,7 @@ bool AbstractType::IsTopType(NNBDMode mode) const {
1733717327
return false;
1733817328
}
1733917329
if (cid == kDynamicCid || cid == kVoidCid ||
17340-
(cid == kInstanceCid && (mode != NNBDMode::kStrong || IsNullable()))) {
17330+
(cid == kInstanceCid && (mode != kStrong || IsNullable()))) {
1734117331
return true;
1734217332
}
1734317333
// FutureOr<T> where T is a top type behaves as a top type.
@@ -18473,7 +18463,7 @@ void TypeParameter::SetGenericCovariantImpl(bool value) const {
1847318463
}
1847418464

1847518465
void TypeParameter::set_nullability(Nullability value) const {
18476-
StoreNonPointer(&raw_ptr()->nullability_, static_cast<int8_t>(value));
18466+
StoreNonPointer(&raw_ptr()->nullability_, value);
1847718467
}
1847818468

1847918469
RawTypeParameter* TypeParameter::ToNullability(Nullability value,
@@ -18672,7 +18662,7 @@ RawTypeParameter* TypeParameter::New(const Class& parameterized_class,
1867218662
result.set_name(name);
1867318663
result.set_bound(bound);
1867418664
result.set_flags(0);
18675-
result.set_nullability(Nullability::kLegacy);
18665+
result.set_nullability(kLegacy);
1867618666
result.SetGenericCovariantImpl(is_generic_covariant_impl);
1867718667
result.SetHash(0);
1867818668
result.set_token_pos(token_pos);

runtime/vm/object.h

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -838,15 +838,15 @@ typedef ZoneGrowableHandlePtrArray<const AbstractType>* TrailPtr;
838838
typedef ZoneGrowableHandlePtrArray<const String> URIs;
839839

840840
// Keep in sync with package:kernel/lib/ast.dart
841-
enum class Nullability {
841+
enum Nullability {
842842
kUndetermined = 0,
843843
kNullable = 1,
844844
kNonNullable = 2,
845845
kLegacy = 3,
846846
};
847847

848848
// Nullability aware subtype checking modes.
849-
enum class NNBDMode {
849+
enum NNBDMode {
850850
kUnaware,
851851
kWeak,
852852
kStrong,
@@ -954,8 +954,7 @@ class Class : public Object {
954954
// variant may be requested. The first requested type gets cached in the class
955955
// and subsequent nullability variants get cached in the object store.
956956
// TODO(regis): Is this caching still useful or should we eliminate it?
957-
RawType* DeclarationType(
958-
Nullability nullability = Nullability::kLegacy) const;
957+
RawType* DeclarationType(Nullability nullability = kLegacy) const;
959958

960959
static intptr_t declaration_type_offset() {
961960
return OFFSET_OF(RawClass, declaration_type_);
@@ -2190,8 +2189,7 @@ class Function : public Object {
21902189
// function type with uninstantiated type arguments 'T' and 'R' as elements of
21912190
// its type argument vector.
21922191
// A function type is non-nullable by default.
2193-
RawType* SignatureType(
2194-
Nullability nullability = Nullability::kNonNullable) const;
2192+
RawType* SignatureType(Nullability nullability = kNonNullable) const;
21952193
RawType* ExistingSignatureType() const;
21962194

21972195
// Update the signature type (with a canonical version).
@@ -6821,18 +6819,10 @@ class AbstractType : public Instance {
68216819
virtual void SetIsBeingFinalized() const;
68226820

68236821
virtual Nullability nullability() const;
6824-
virtual bool IsUndetermined() const {
6825-
return nullability() == Nullability::kUndetermined;
6826-
}
6827-
virtual bool IsNullable() const {
6828-
return nullability() == Nullability::kNullable;
6829-
}
6830-
virtual bool IsNonNullable() const {
6831-
return nullability() == Nullability::kNonNullable;
6832-
}
6833-
virtual bool IsLegacy() const {
6834-
return nullability() == Nullability::kLegacy;
6835-
}
6822+
virtual bool IsUndetermined() const { return nullability() == kUndetermined; }
6823+
virtual bool IsNullable() const { return nullability() == kNullable; }
6824+
virtual bool IsNonNullable() const { return nullability() == kNonNullable; }
6825+
virtual bool IsLegacy() const { return nullability() == kLegacy; }
68366826

68376827
virtual bool HasTypeClass() const { return type_class_id() != kIllegalCid; }
68386828
virtual classid_t type_class_id() const;
@@ -6954,7 +6944,7 @@ class AbstractType : public Instance {
69546944

69556945
// Check if this type represents a top type.
69566946
// TODO(regis): Remove default kUnaware mode as implementation progresses.
6957-
bool IsTopType(NNBDMode mode = NNBDMode::kUnaware) const;
6947+
bool IsTopType(NNBDMode mode = kUnaware) const;
69586948

69596949
// Check if this type represents the 'bool' type.
69606950
bool IsBoolType() const;
@@ -7067,8 +7057,8 @@ class Type : public AbstractType {
70677057
}
70687058
void set_nullability(Nullability value) const {
70697059
ASSERT(!IsCanonical());
7070-
ASSERT(value != Nullability::kUndetermined);
7071-
StoreNonPointer(&raw_ptr()->nullability_, static_cast<int8_t>(value));
7060+
ASSERT(value != kUndetermined);
7061+
StoreNonPointer(&raw_ptr()->nullability_, value);
70727062
}
70737063
RawType* ToNullability(Nullability value, Heap::Space space) const;
70747064
virtual classid_t type_class_id() const;
@@ -7167,14 +7157,13 @@ class Type : public AbstractType {
71677157
static RawType* DartTypeType();
71687158

71697159
// The finalized type of the given non-parameterized class.
7170-
static RawType* NewNonParameterizedType(
7171-
const Class& type_class,
7172-
Nullability nullability = Nullability::kLegacy);
7160+
static RawType* NewNonParameterizedType(const Class& type_class,
7161+
Nullability nullability = kLegacy);
71737162

71747163
static RawType* New(const Class& clazz,
71757164
const TypeArguments& arguments,
71767165
TokenPosition token_pos,
7177-
Nullability nullability = Nullability::kLegacy,
7166+
Nullability nullability = kLegacy,
71787167
Heap::Space space = Heap::kOld);
71797168

71807169
private:

runtime/vm/symbols.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -580,9 +580,6 @@ class Symbols : public AllStatic {
580580
static const String& Percent() {
581581
return *(symbol_handles_[kNullCharId + '%']);
582582
}
583-
static const String& QuestionMark() {
584-
return *(symbol_handles_[kNullCharId + '?']);
585-
}
586583
static const String& Caret() { return *(symbol_handles_[kNullCharId + '^']); }
587584
static const String& Tilde() { return *(symbol_handles_[kNullCharId + '~']); }
588585

0 commit comments

Comments
 (0)