mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 12:24:24 +00:00
Revert "[VM/nnbd] Make Nullability and NNBDMode class enums to avoid name conflicts."
This reverts commit d45c3d15cb
.
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>
This commit is contained in:
parent
82aa7e79af
commit
b4779e8f72
7 changed files with 50 additions and 76 deletions
|
@ -633,17 +633,16 @@ static RawInstance* CreateTypeMirror(const AbstractType& type) {
|
|||
// TODO(regis): Until mirrors reflect nullability, force kLegacy, except for
|
||||
// Null type, which should remain nullable.
|
||||
if (!type.IsNullType()) {
|
||||
const Type& legacy_type = Type::Handle(
|
||||
Type::Cast(type).ToNullability(Nullability::kLegacy, Heap::kOld));
|
||||
const Type& legacy_type =
|
||||
Type::Handle(Type::Cast(type).ToNullability(kLegacy, Heap::kOld));
|
||||
return CreateClassMirror(cls, legacy_type, Bool::False(),
|
||||
Object::null_instance());
|
||||
}
|
||||
return CreateClassMirror(cls, type, Bool::False(), Object::null_instance());
|
||||
} else if (type.IsTypeParameter()) {
|
||||
// TODO(regis): Until mirrors reflect nullability, force kLegacy.
|
||||
const TypeParameter& legacy_type =
|
||||
TypeParameter::Handle(TypeParameter::Cast(type).ToNullability(
|
||||
Nullability::kLegacy, Heap::kOld));
|
||||
const TypeParameter& legacy_type = TypeParameter::Handle(
|
||||
TypeParameter::Cast(type).ToNullability(kLegacy, Heap::kOld));
|
||||
return CreateTypeVariableMirror(legacy_type, Object::null_instance());
|
||||
}
|
||||
UNREACHABLE();
|
||||
|
|
|
@ -502,12 +502,11 @@ void BytecodeReaderHelper::ReadClosureDeclaration(const Function& function,
|
|||
closures_->SetAt(closureIndex, closure);
|
||||
|
||||
Type& signature_type = Type::Handle(
|
||||
Z, ReadFunctionSignature(closure,
|
||||
(flags & kHasOptionalPositionalParamsFlag) != 0,
|
||||
(flags & kHasOptionalNamedParamsFlag) != 0,
|
||||
(flags & kHasTypeParamsFlag) != 0,
|
||||
/* has_positional_param_names = */ true,
|
||||
Nullability::kNonNullable));
|
||||
Z, ReadFunctionSignature(
|
||||
closure, (flags & kHasOptionalPositionalParamsFlag) != 0,
|
||||
(flags & kHasOptionalNamedParamsFlag) != 0,
|
||||
(flags & kHasTypeParamsFlag) != 0,
|
||||
/* has_positional_param_names = */ true, kNonNullable));
|
||||
|
||||
closure.SetSignatureType(signature_type);
|
||||
|
||||
|
@ -1509,7 +1508,7 @@ RawObject* BytecodeReaderHelper::ReadObjectContents(uint32_t header) {
|
|||
const Nullability nullability =
|
||||
bytecode_component_->GetVersion() >= 24
|
||||
? static_cast<Nullability>((flags & kNullabilityMask) / kFlagBit4)
|
||||
: Nullability::kLegacy;
|
||||
: kLegacy;
|
||||
return ReadType(tag, nullability);
|
||||
}
|
||||
default:
|
||||
|
|
|
@ -246,7 +246,7 @@ void KernelFingerprintHelper::CalculateDartTypeFingerprint() {
|
|||
break;
|
||||
case kTypeParameterType: {
|
||||
Nullability nullability = ReadNullability();
|
||||
BuildHash(static_cast<uint32_t>(nullability));
|
||||
BuildHash(nullability);
|
||||
ReadUInt(); // read index for parameter.
|
||||
CalculateOptionalDartTypeFingerprint(); // read bound bound.
|
||||
break;
|
||||
|
@ -269,7 +269,7 @@ void KernelFingerprintHelper::CalculateOptionalDartTypeFingerprint() {
|
|||
|
||||
void KernelFingerprintHelper::CalculateInterfaceTypeFingerprint(bool simple) {
|
||||
Nullability nullability = ReadNullability();
|
||||
BuildHash(static_cast<uint32_t>(nullability));
|
||||
BuildHash(nullability);
|
||||
NameIndex kernel_class = ReadCanonicalNameReference();
|
||||
ASSERT(H.IsClass(kernel_class));
|
||||
const String& class_name = H.DartClassName(kernel_class);
|
||||
|
@ -285,7 +285,7 @@ void KernelFingerprintHelper::CalculateInterfaceTypeFingerprint(bool simple) {
|
|||
|
||||
void KernelFingerprintHelper::CalculateFunctionTypeFingerprint(bool simple) {
|
||||
Nullability nullability = ReadNullability();
|
||||
BuildHash(static_cast<uint32_t>(nullability));
|
||||
BuildHash(nullability);
|
||||
|
||||
if (!simple) {
|
||||
CalculateTypeParametersListFingerprint(); // read type_parameters.
|
||||
|
|
|
@ -2768,7 +2768,7 @@ void TypeTranslator::BuildTypeInternal() {
|
|||
break;
|
||||
case kBottomType:
|
||||
result_ = Class::Handle(Z, I->object_store()->null_class())
|
||||
.DeclarationType(Nullability::kNullable);
|
||||
.DeclarationType(kNullable);
|
||||
ASSERT(result_.IsNullable());
|
||||
break;
|
||||
case kNeverType:
|
||||
|
|
|
@ -944,13 +944,13 @@ void Object::Init(Isolate* isolate) {
|
|||
cls.set_is_type_finalized();
|
||||
|
||||
cls = dynamic_class_;
|
||||
*dynamic_type_ = Type::NewNonParameterizedType(cls, Nullability::kNullable);
|
||||
*dynamic_type_ = Type::NewNonParameterizedType(cls, kNullable);
|
||||
|
||||
cls = void_class_;
|
||||
*void_type_ = Type::NewNonParameterizedType(cls, Nullability::kNullable);
|
||||
*void_type_ = Type::NewNonParameterizedType(cls, kNullable);
|
||||
|
||||
cls = never_class_;
|
||||
*never_type_ = Type::NewNonParameterizedType(cls, Nullability::kNonNullable);
|
||||
*never_type_ = Type::NewNonParameterizedType(cls, kNonNullable);
|
||||
|
||||
// Since TypeArguments objects are passed as function arguments, make them
|
||||
// behave as Dart instances, although they are just VM objects.
|
||||
|
@ -1934,7 +1934,7 @@ RawError* Object::Init(Isolate* isolate,
|
|||
// name is a built-in identifier (this is wrong). The corresponding types
|
||||
// are stored in the object store.
|
||||
cls = object_store->null_class();
|
||||
type = Type::NewNonParameterizedType(cls, Nullability::kNullable);
|
||||
type = Type::NewNonParameterizedType(cls, kNullable);
|
||||
cls.set_declaration_type(type);
|
||||
object_store->set_null_type(type);
|
||||
ASSERT(type.IsNullable());
|
||||
|
@ -4345,7 +4345,7 @@ RawType* Class::DeclarationType(Nullability nullability) const {
|
|||
ASSERT(is_declaration_loaded());
|
||||
if (IsNullClass()) {
|
||||
// Ignore requested nullability (e.g. by mirrors).
|
||||
nullability = Nullability::kNullable;
|
||||
nullability = kNullable;
|
||||
}
|
||||
Type& type = Type::Handle(declaration_type());
|
||||
if (!type.IsNull()) {
|
||||
|
@ -16664,8 +16664,8 @@ RawAbstractType* Instance::GetType(Heap::Space space) const {
|
|||
}
|
||||
// TODO(regis): The runtime type of a non-null instance should be
|
||||
// non-nullable instead of legacy. Revisit.
|
||||
type = Type::New(cls, type_arguments, TokenPosition::kNoSource,
|
||||
Nullability::kLegacy, space);
|
||||
type = Type::New(cls, type_arguments, TokenPosition::kNoSource, kLegacy,
|
||||
space);
|
||||
type.SetIsFinalized();
|
||||
type ^= type.Canonicalize();
|
||||
}
|
||||
|
@ -17019,7 +17019,7 @@ TokenPosition AbstractType::token_pos() const {
|
|||
Nullability AbstractType::nullability() const {
|
||||
// AbstractType is an abstract class.
|
||||
UNREACHABLE();
|
||||
return Nullability::kNullable;
|
||||
return kNullable;
|
||||
}
|
||||
|
||||
bool AbstractType::IsInstantiated(Genericity genericity,
|
||||
|
@ -17201,21 +17201,8 @@ RawString* AbstractType::PrintURIs(URIs* uris) {
|
|||
return Symbols::FromConcatAll(thread, pieces);
|
||||
}
|
||||
|
||||
static const String& NullabilitySuffix(Nullability value) {
|
||||
// Keep in sync with Nullability enum in runtime/vm/object.h.
|
||||
switch (value) {
|
||||
case Nullability::kUndetermined:
|
||||
return Symbols::Percent();
|
||||
case Nullability::kNullable:
|
||||
return Symbols::QuestionMark();
|
||||
case Nullability::kNonNullable:
|
||||
return Symbols::Empty();
|
||||
case Nullability::kLegacy:
|
||||
return Symbols::Star();
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
// Keep in sync with Nullability enum in runtime/vm/object.h.
|
||||
static const char* nullability_suffix[4] = {"%", "?", "", "*"};
|
||||
|
||||
RawString* AbstractType::BuildName(NameVisibility name_visibility) const {
|
||||
ASSERT(name_visibility != kScrubbedName);
|
||||
|
@ -17225,7 +17212,7 @@ RawString* AbstractType::BuildName(NameVisibility name_visibility) const {
|
|||
if (FLAG_show_nullability) {
|
||||
return Symbols::FromConcat(
|
||||
thread, String::Handle(zone, TypeParameter::Cast(*this).name()),
|
||||
NullabilitySuffix(nullability()));
|
||||
String::Handle(zone, String::New(nullability_suffix[nullability()])));
|
||||
}
|
||||
return TypeParameter::Cast(*this).name();
|
||||
}
|
||||
|
@ -17243,7 +17230,8 @@ RawString* AbstractType::BuildName(NameVisibility name_visibility) const {
|
|||
return Symbols::FromConcat(
|
||||
thread,
|
||||
String::Handle(zone, signature_function.UserVisibleSignature()),
|
||||
NullabilitySuffix(nullability()));
|
||||
String::Handle(zone,
|
||||
String::New(nullability_suffix[nullability()])));
|
||||
}
|
||||
return signature_function.UserVisibleSignature();
|
||||
}
|
||||
|
@ -17253,9 +17241,10 @@ RawString* AbstractType::BuildName(NameVisibility name_visibility) const {
|
|||
if (!IsFinalized() || IsBeingFinalized()) {
|
||||
// TODO(regis): Check if this is dead code.
|
||||
if (FLAG_show_nullability) {
|
||||
return Symbols::FromConcat(thread,
|
||||
String::Handle(zone, class_name.raw()),
|
||||
NullabilitySuffix(nullability()));
|
||||
return Symbols::FromConcat(
|
||||
thread, String::Handle(zone, class_name.raw()),
|
||||
String::Handle(zone,
|
||||
String::New(nullability_suffix[nullability()])));
|
||||
}
|
||||
return class_name.raw();
|
||||
}
|
||||
|
@ -17298,7 +17287,8 @@ RawString* AbstractType::BuildName(NameVisibility name_visibility) const {
|
|||
pieces.Add(args_name);
|
||||
}
|
||||
if (FLAG_show_nullability) {
|
||||
pieces.Add(NullabilitySuffix(nullability()));
|
||||
pieces.Add(
|
||||
String::Handle(zone, String::New(nullability_suffix[nullability()])));
|
||||
}
|
||||
// The name is only used for type checking and debugging purposes.
|
||||
// Unless profiling data shows otherwise, it is not worth caching the name in
|
||||
|
@ -17337,7 +17327,7 @@ bool AbstractType::IsTopType(NNBDMode mode) const {
|
|||
return false;
|
||||
}
|
||||
if (cid == kDynamicCid || cid == kVoidCid ||
|
||||
(cid == kInstanceCid && (mode != NNBDMode::kStrong || IsNullable()))) {
|
||||
(cid == kInstanceCid && (mode != kStrong || IsNullable()))) {
|
||||
return true;
|
||||
}
|
||||
// FutureOr<T> where T is a top type behaves as a top type.
|
||||
|
@ -18473,7 +18463,7 @@ void TypeParameter::SetGenericCovariantImpl(bool value) const {
|
|||
}
|
||||
|
||||
void TypeParameter::set_nullability(Nullability value) const {
|
||||
StoreNonPointer(&raw_ptr()->nullability_, static_cast<int8_t>(value));
|
||||
StoreNonPointer(&raw_ptr()->nullability_, value);
|
||||
}
|
||||
|
||||
RawTypeParameter* TypeParameter::ToNullability(Nullability value,
|
||||
|
@ -18672,7 +18662,7 @@ RawTypeParameter* TypeParameter::New(const Class& parameterized_class,
|
|||
result.set_name(name);
|
||||
result.set_bound(bound);
|
||||
result.set_flags(0);
|
||||
result.set_nullability(Nullability::kLegacy);
|
||||
result.set_nullability(kLegacy);
|
||||
result.SetGenericCovariantImpl(is_generic_covariant_impl);
|
||||
result.SetHash(0);
|
||||
result.set_token_pos(token_pos);
|
||||
|
|
|
@ -838,7 +838,7 @@ typedef ZoneGrowableHandlePtrArray<const AbstractType>* TrailPtr;
|
|||
typedef ZoneGrowableHandlePtrArray<const String> URIs;
|
||||
|
||||
// Keep in sync with package:kernel/lib/ast.dart
|
||||
enum class Nullability {
|
||||
enum Nullability {
|
||||
kUndetermined = 0,
|
||||
kNullable = 1,
|
||||
kNonNullable = 2,
|
||||
|
@ -846,7 +846,7 @@ enum class Nullability {
|
|||
};
|
||||
|
||||
// Nullability aware subtype checking modes.
|
||||
enum class NNBDMode {
|
||||
enum NNBDMode {
|
||||
kUnaware,
|
||||
kWeak,
|
||||
kStrong,
|
||||
|
@ -954,8 +954,7 @@ class Class : public Object {
|
|||
// variant may be requested. The first requested type gets cached in the class
|
||||
// and subsequent nullability variants get cached in the object store.
|
||||
// TODO(regis): Is this caching still useful or should we eliminate it?
|
||||
RawType* DeclarationType(
|
||||
Nullability nullability = Nullability::kLegacy) const;
|
||||
RawType* DeclarationType(Nullability nullability = kLegacy) const;
|
||||
|
||||
static intptr_t declaration_type_offset() {
|
||||
return OFFSET_OF(RawClass, declaration_type_);
|
||||
|
@ -2190,8 +2189,7 @@ class Function : public Object {
|
|||
// function type with uninstantiated type arguments 'T' and 'R' as elements of
|
||||
// its type argument vector.
|
||||
// A function type is non-nullable by default.
|
||||
RawType* SignatureType(
|
||||
Nullability nullability = Nullability::kNonNullable) const;
|
||||
RawType* SignatureType(Nullability nullability = kNonNullable) const;
|
||||
RawType* ExistingSignatureType() const;
|
||||
|
||||
// Update the signature type (with a canonical version).
|
||||
|
@ -6821,18 +6819,10 @@ class AbstractType : public Instance {
|
|||
virtual void SetIsBeingFinalized() const;
|
||||
|
||||
virtual Nullability nullability() const;
|
||||
virtual bool IsUndetermined() const {
|
||||
return nullability() == Nullability::kUndetermined;
|
||||
}
|
||||
virtual bool IsNullable() const {
|
||||
return nullability() == Nullability::kNullable;
|
||||
}
|
||||
virtual bool IsNonNullable() const {
|
||||
return nullability() == Nullability::kNonNullable;
|
||||
}
|
||||
virtual bool IsLegacy() const {
|
||||
return nullability() == Nullability::kLegacy;
|
||||
}
|
||||
virtual bool IsUndetermined() const { return nullability() == kUndetermined; }
|
||||
virtual bool IsNullable() const { return nullability() == kNullable; }
|
||||
virtual bool IsNonNullable() const { return nullability() == kNonNullable; }
|
||||
virtual bool IsLegacy() const { return nullability() == kLegacy; }
|
||||
|
||||
virtual bool HasTypeClass() const { return type_class_id() != kIllegalCid; }
|
||||
virtual classid_t type_class_id() const;
|
||||
|
@ -6954,7 +6944,7 @@ class AbstractType : public Instance {
|
|||
|
||||
// Check if this type represents a top type.
|
||||
// TODO(regis): Remove default kUnaware mode as implementation progresses.
|
||||
bool IsTopType(NNBDMode mode = NNBDMode::kUnaware) const;
|
||||
bool IsTopType(NNBDMode mode = kUnaware) const;
|
||||
|
||||
// Check if this type represents the 'bool' type.
|
||||
bool IsBoolType() const;
|
||||
|
@ -7067,8 +7057,8 @@ class Type : public AbstractType {
|
|||
}
|
||||
void set_nullability(Nullability value) const {
|
||||
ASSERT(!IsCanonical());
|
||||
ASSERT(value != Nullability::kUndetermined);
|
||||
StoreNonPointer(&raw_ptr()->nullability_, static_cast<int8_t>(value));
|
||||
ASSERT(value != kUndetermined);
|
||||
StoreNonPointer(&raw_ptr()->nullability_, value);
|
||||
}
|
||||
RawType* ToNullability(Nullability value, Heap::Space space) const;
|
||||
virtual classid_t type_class_id() const;
|
||||
|
@ -7167,14 +7157,13 @@ class Type : public AbstractType {
|
|||
static RawType* DartTypeType();
|
||||
|
||||
// The finalized type of the given non-parameterized class.
|
||||
static RawType* NewNonParameterizedType(
|
||||
const Class& type_class,
|
||||
Nullability nullability = Nullability::kLegacy);
|
||||
static RawType* NewNonParameterizedType(const Class& type_class,
|
||||
Nullability nullability = kLegacy);
|
||||
|
||||
static RawType* New(const Class& clazz,
|
||||
const TypeArguments& arguments,
|
||||
TokenPosition token_pos,
|
||||
Nullability nullability = Nullability::kLegacy,
|
||||
Nullability nullability = kLegacy,
|
||||
Heap::Space space = Heap::kOld);
|
||||
|
||||
private:
|
||||
|
|
|
@ -580,9 +580,6 @@ class Symbols : public AllStatic {
|
|||
static const String& Percent() {
|
||||
return *(symbol_handles_[kNullCharId + '%']);
|
||||
}
|
||||
static const String& QuestionMark() {
|
||||
return *(symbol_handles_[kNullCharId + '?']);
|
||||
}
|
||||
static const String& Caret() { return *(symbol_handles_[kNullCharId + '^']); }
|
||||
static const String& Tilde() { return *(symbol_handles_[kNullCharId + '~']); }
|
||||
|
||||
|
|
Loading…
Reference in a new issue