@@ -73,9 +73,8 @@ DEFINE_FLAG(
73
73
show_internal_names,
74
74
false,
75
75
"Show names of internal classes (e.g. \"OneByteString\") in error messages "
76
- "instead of showing the corresponding interface names (e.g. \"String\")");
77
- // TODO(regis): Remove this temporary flag used to debug nullability.
78
- DEFINE_FLAG(bool, show_nullability, false, "Show nullability in type names");
76
+ "instead of showing the corresponding interface names (e.g. \"String\"). "
77
+ "Also show legacy nullability in type names.");
79
78
DEFINE_FLAG(bool, use_lib_cache, false, "Use library name cache");
80
79
DEFINE_FLAG(bool, use_exp_cache, false, "Use library exported name cache");
81
80
@@ -5664,7 +5663,11 @@ void TypeArguments::PrintSubvectorName(intptr_t from_index,
5664
5663
for (intptr_t i = 0; i < len; i++) {
5665
5664
if (from_index + i < Length()) {
5666
5665
type = TypeAt(from_index + i);
5667
- type.PrintName(name_visibility, printer);
5666
+ if (type.IsNull()) {
5667
+ printer->AddString("null"); // Unfinalized vector.
5668
+ } else {
5669
+ type.PrintName(name_visibility, printer);
5670
+ }
5668
5671
} else {
5669
5672
printer->AddString("dynamic");
5670
5673
}
@@ -18084,17 +18087,26 @@ RawString* AbstractType::PrintURIs(URIs* uris) {
18084
18087
return Symbols::FromConcatAll(thread, pieces);
18085
18088
}
18086
18089
18087
- static const char* NullabilitySuffix(Nullability value) {
18090
+ const char* AbstractType::NullabilitySuffix(
18091
+ NameVisibility name_visibility) const {
18092
+ if (IsDynamicType() || IsVoidType() || IsNullType()) {
18093
+ // Hide nullable suffix.
18094
+ return "";
18095
+ }
18088
18096
// Keep in sync with Nullability enum in runtime/vm/object.h.
18089
- switch (value ) {
18097
+ switch (nullability() ) {
18090
18098
case Nullability::kUndetermined:
18091
- return "%";
18099
+ return (FLAG_show_internal_names || name_visibility == kInternalName)
18100
+ ? "%"
18101
+ : "";
18092
18102
case Nullability::kNullable:
18093
18103
return "?";
18094
18104
case Nullability::kNonNullable:
18095
18105
return "";
18096
18106
case Nullability::kLegacy:
18097
- return "*";
18107
+ return (FLAG_show_internal_names || name_visibility == kInternalName)
18108
+ ? "*"
18109
+ : "";
18098
18110
default:
18099
18111
UNREACHABLE();
18100
18112
}
@@ -18121,9 +18133,7 @@ void AbstractType::PrintName(NameVisibility name_visibility,
18121
18133
Zone* zone = thread->zone();
18122
18134
if (IsTypeParameter()) {
18123
18135
printer->AddString(String::Handle(zone, TypeParameter::Cast(*this).name()));
18124
- if (FLAG_show_nullability) {
18125
- printer->AddString(NullabilitySuffix(nullability()));
18126
- }
18136
+ printer->AddString(NullabilitySuffix(name_visibility));
18127
18137
return;
18128
18138
}
18129
18139
const TypeArguments& args = TypeArguments::Handle(zone, arguments());
@@ -18136,9 +18146,14 @@ void AbstractType::PrintName(NameVisibility name_visibility,
18136
18146
const Function& signature_function =
18137
18147
Function::Handle(zone, Type::Cast(*this).signature());
18138
18148
if (!cls.IsTypedefClass()) {
18139
- signature_function.PrintSignature(kUserVisibleName, printer);
18140
- if (FLAG_show_nullability) {
18141
- printer->AddString(NullabilitySuffix(nullability()));
18149
+ const char* suffix = NullabilitySuffix(name_visibility);
18150
+ if (suffix[0] != '\0') {
18151
+ printer->AddString("(");
18152
+ }
18153
+ signature_function.PrintSignature(name_visibility, printer);
18154
+ if (suffix[0] != '\0') {
18155
+ printer->AddString(")");
18156
+ printer->AddString(suffix);
18142
18157
}
18143
18158
return;
18144
18159
}
@@ -18148,9 +18163,7 @@ void AbstractType::PrintName(NameVisibility name_visibility,
18148
18163
if (!IsFinalized() || IsBeingFinalized()) {
18149
18164
// TODO(regis): Check if this is dead code.
18150
18165
printer->AddString(class_name);
18151
- if (FLAG_show_nullability) {
18152
- printer->AddString(NullabilitySuffix(nullability()));
18153
- }
18166
+ printer->AddString(NullabilitySuffix(name_visibility));
18154
18167
return;
18155
18168
}
18156
18169
// Print the name of a typedef as a regular, possibly parameterized, class.
@@ -18188,9 +18201,7 @@ void AbstractType::PrintName(NameVisibility name_visibility,
18188
18201
args.PrintSubvectorName(first_type_param_index, num_type_params,
18189
18202
name_visibility, printer);
18190
18203
}
18191
- if (FLAG_show_nullability) {
18192
- printer->AddString(NullabilitySuffix(nullability()));
18193
- }
18204
+ printer->AddString(NullabilitySuffix(name_visibility));
18194
18205
// The name is only used for type checking and debugging purposes.
18195
18206
// Unless profiling data shows otherwise, it is not worth caching the name in
18196
18207
// the type.
@@ -19251,32 +19262,42 @@ const char* Type::ToCString() const {
19251
19262
return "Type: null";
19252
19263
}
19253
19264
Zone* zone = Thread::Current()->zone();
19265
+ ZoneTextBuffer args(zone);
19254
19266
const TypeArguments& type_args = TypeArguments::Handle(zone, arguments());
19255
- const char* args_cstr = type_args.IsNull() ? "null" : type_args.ToCString();
19267
+ const char* args_cstr = "";
19268
+ if (!type_args.IsNull()) {
19269
+ type_args.PrintSubvectorName(0, type_args.Length(), kInternalName, &args);
19270
+ args_cstr = args.buffer();
19271
+ }
19256
19272
const Class& cls = Class::Handle(zone, type_class());
19257
19273
const char* class_name;
19258
19274
const String& name = String::Handle(zone, cls.Name());
19259
19275
class_name = name.IsNull() ? "<null>" : name.ToCString();
19276
+ const char* suffix = NullabilitySuffix(kInternalName);
19260
19277
if (IsFunctionType()) {
19261
19278
const Function& sig_fun = Function::Handle(zone, signature());
19262
19279
ZoneTextBuffer sig(zone);
19280
+ if (suffix[0] != '\0') {
19281
+ sig.AddString("(");
19282
+ }
19263
19283
sig_fun.PrintSignature(kInternalName, &sig);
19284
+ if (suffix[0] != '\0') {
19285
+ sig.AddString(")");
19286
+ sig.AddString(suffix);
19287
+ }
19264
19288
if (cls.IsClosureClass()) {
19265
19289
ASSERT(type_args.IsNull());
19266
19290
return OS::SCreate(zone, "Function Type: %s", sig.buffer());
19267
19291
}
19268
- return OS::SCreate(zone, "Function Type: %s (class: %s, args: %s)" ,
19269
- sig.buffer(), class_name, args_cstr);
19292
+ return OS::SCreate(zone, "Function Type: %s (%s%s%s)", sig.buffer() ,
19293
+ class_name, args_cstr, suffix );
19270
19294
}
19271
- if (type_args.IsNull()) {
19272
- return OS::SCreate(zone, "Type: class '%s'", class_name);
19273
- } else if (IsFinalized() && IsRecursive()) {
19295
+ if (IsFinalized() && IsRecursive()) {
19274
19296
const intptr_t hash = Hash();
19275
- return OS::SCreate(zone, "Type: (H%" Px ") class '%s', args:[%s] ", hash,
19276
- class_name, args_cstr );
19297
+ return OS::SCreate(zone, "Type: (H%" Px ") %s%s%s ", hash, class_name ,
19298
+ args_cstr, suffix );
19277
19299
} else {
19278
- return OS::SCreate(zone, "Type: class '%s', args:[%s]", class_name,
19279
- args_cstr);
19300
+ return OS::SCreate(zone, "Type: %s%s%s", class_name, args_cstr, suffix);
19280
19301
}
19281
19302
}
19282
19303
@@ -19713,7 +19734,8 @@ const char* TypeParameter::ToCString() const {
19713
19734
Thread* thread = Thread::Current();
19714
19735
ZoneTextBuffer printer(thread->zone());
19715
19736
printer.Printf("TypeParameter: name ");
19716
- printer.AddString(String::Handle(Name()));
19737
+ printer.AddString(String::Handle(name()));
19738
+ printer.AddString(NullabilitySuffix(kInternalName));
19717
19739
printer.Printf("; index: %" Pd ";", index());
19718
19740
if (IsFunctionTypeParameter()) {
19719
19741
const Function& function = Function::Handle(parameterized_function());
0 commit comments