@@ -73,9 +73,8 @@ DEFINE_FLAG(
7373 show_internal_names,
7474 false,
7575 "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.");
7978DEFINE_FLAG(bool, use_lib_cache, false, "Use library name cache");
8079DEFINE_FLAG(bool, use_exp_cache, false, "Use library exported name cache");
8180
@@ -5664,7 +5663,11 @@ void TypeArguments::PrintSubvectorName(intptr_t from_index,
56645663 for (intptr_t i = 0; i < len; i++) {
56655664 if (from_index + i < Length()) {
56665665 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+ }
56685671 } else {
56695672 printer->AddString("dynamic");
56705673 }
@@ -18084,17 +18087,26 @@ RawString* AbstractType::PrintURIs(URIs* uris) {
1808418087 return Symbols::FromConcatAll(thread, pieces);
1808518088}
1808618089
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+ }
1808818096 // Keep in sync with Nullability enum in runtime/vm/object.h.
18089- switch (value ) {
18097+ switch (nullability() ) {
1809018098 case Nullability::kUndetermined:
18091- return "%";
18099+ return (FLAG_show_internal_names || name_visibility == kInternalName)
18100+ ? "%"
18101+ : "";
1809218102 case Nullability::kNullable:
1809318103 return "?";
1809418104 case Nullability::kNonNullable:
1809518105 return "";
1809618106 case Nullability::kLegacy:
18097- return "*";
18107+ return (FLAG_show_internal_names || name_visibility == kInternalName)
18108+ ? "*"
18109+ : "";
1809818110 default:
1809918111 UNREACHABLE();
1810018112 }
@@ -18121,9 +18133,7 @@ void AbstractType::PrintName(NameVisibility name_visibility,
1812118133 Zone* zone = thread->zone();
1812218134 if (IsTypeParameter()) {
1812318135 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));
1812718137 return;
1812818138 }
1812918139 const TypeArguments& args = TypeArguments::Handle(zone, arguments());
@@ -18136,9 +18146,14 @@ void AbstractType::PrintName(NameVisibility name_visibility,
1813618146 const Function& signature_function =
1813718147 Function::Handle(zone, Type::Cast(*this).signature());
1813818148 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);
1814218157 }
1814318158 return;
1814418159 }
@@ -18148,9 +18163,7 @@ void AbstractType::PrintName(NameVisibility name_visibility,
1814818163 if (!IsFinalized() || IsBeingFinalized()) {
1814918164 // TODO(regis): Check if this is dead code.
1815018165 printer->AddString(class_name);
18151- if (FLAG_show_nullability) {
18152- printer->AddString(NullabilitySuffix(nullability()));
18153- }
18166+ printer->AddString(NullabilitySuffix(name_visibility));
1815418167 return;
1815518168 }
1815618169 // Print the name of a typedef as a regular, possibly parameterized, class.
@@ -18188,9 +18201,7 @@ void AbstractType::PrintName(NameVisibility name_visibility,
1818818201 args.PrintSubvectorName(first_type_param_index, num_type_params,
1818918202 name_visibility, printer);
1819018203 }
18191- if (FLAG_show_nullability) {
18192- printer->AddString(NullabilitySuffix(nullability()));
18193- }
18204+ printer->AddString(NullabilitySuffix(name_visibility));
1819418205 // The name is only used for type checking and debugging purposes.
1819518206 // Unless profiling data shows otherwise, it is not worth caching the name in
1819618207 // the type.
@@ -19251,32 +19262,42 @@ const char* Type::ToCString() const {
1925119262 return "Type: null";
1925219263 }
1925319264 Zone* zone = Thread::Current()->zone();
19265+ ZoneTextBuffer args(zone);
1925419266 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+ }
1925619272 const Class& cls = Class::Handle(zone, type_class());
1925719273 const char* class_name;
1925819274 const String& name = String::Handle(zone, cls.Name());
1925919275 class_name = name.IsNull() ? "<null>" : name.ToCString();
19276+ const char* suffix = NullabilitySuffix(kInternalName);
1926019277 if (IsFunctionType()) {
1926119278 const Function& sig_fun = Function::Handle(zone, signature());
1926219279 ZoneTextBuffer sig(zone);
19280+ if (suffix[0] != '\0') {
19281+ sig.AddString("(");
19282+ }
1926319283 sig_fun.PrintSignature(kInternalName, &sig);
19284+ if (suffix[0] != '\0') {
19285+ sig.AddString(")");
19286+ sig.AddString(suffix);
19287+ }
1926419288 if (cls.IsClosureClass()) {
1926519289 ASSERT(type_args.IsNull());
1926619290 return OS::SCreate(zone, "Function Type: %s", sig.buffer());
1926719291 }
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 );
1927019294 }
19271- if (type_args.IsNull()) {
19272- return OS::SCreate(zone, "Type: class '%s'", class_name);
19273- } else if (IsFinalized() && IsRecursive()) {
19295+ if (IsFinalized() && IsRecursive()) {
1927419296 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 );
1927719299 } 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);
1928019301 }
1928119302}
1928219303
@@ -19713,7 +19734,8 @@ const char* TypeParameter::ToCString() const {
1971319734 Thread* thread = Thread::Current();
1971419735 ZoneTextBuffer printer(thread->zone());
1971519736 printer.Printf("TypeParameter: name ");
19716- printer.AddString(String::Handle(Name()));
19737+ printer.AddString(String::Handle(name()));
19738+ printer.AddString(NullabilitySuffix(kInternalName));
1971719739 printer.Printf("; index: %" Pd ";", index());
1971819740 if (IsFunctionTypeParameter()) {
1971919741 const Function& function = Function::Handle(parameterized_function());
0 commit comments