Skip to content

Commit 5701c4f

Browse files
creliercommit-bot@chromium.org
authored andcommitted
[VM/nnbd] Remove propagation of library mode to runtime after spec change.
On 1/27/20, the nnbd specification changed weak and strong mode instance checks to make them behave uniformly across legacy and opted-in libraries. Therefore, it is not necessary anymore to propagate the library mode in generated code to the runtime. Change-Id: I42d3ddc6e9a921899aeac21be6374c7893a6d27c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/138111 Reviewed-by: Alexander Markov <alexmarkov@google.com> Commit-Queue: Régis Crelier <regis@google.com>
1 parent 5cd6b30 commit 5701c4f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+372
-731
lines changed

pkg/vm/lib/bytecode/dbc.dart

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -674,8 +674,3 @@ const int argumentsLimit = 1 << 8;
674674
// Base class for exceptions thrown when certain limit of bytecode
675675
// format is exceeded.
676676
abstract class BytecodeLimitExceededException {}
677-
678-
// Constants specifying the NNBD mode of libraries.
679-
// Must be kept in sync with enum class NNBDMode in the VM.
680-
const int kLegacy = 0;
681-
const int kOptedIn = 1;

pkg/vm/lib/bytecode/gen_bytecode.dart

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,11 +1272,6 @@ class BytecodeGenerator extends RecursiveVisitor<Null> {
12721272
}
12731273
}
12741274

1275-
void _genPushNnbdMode() {
1276-
asm.emitPushInt(
1277-
staticTypeContext.isNonNullableByDefault ? kOptedIn : kLegacy);
1278-
}
1279-
12801275
Constant _getConstant(Expression expr) {
12811276
if (expr is ConstantExpression) {
12821277
return expr.constant;
@@ -1688,11 +1683,10 @@ class BytecodeGenerator extends RecursiveVisitor<Null> {
16881683
asm.emitPushNull(); // Function type arguments.
16891684
}
16901685
asm.emitPushConstant(cp.addType(type));
1691-
_genPushNnbdMode();
1692-
final argDesc = objectTable.getArgDescHandle(5);
1686+
final argDesc = objectTable.getArgDescHandle(4);
16931687
final cpIndex =
16941688
cp.addInterfaceCall(InvocationKind.method, objectInstanceOf, argDesc);
1695-
asm.emitInterfaceCall(cpIndex, 5);
1689+
asm.emitInterfaceCall(cpIndex, 4);
16961690
}
16971691

16981692
void start(Member node, bool hasCode) {
@@ -2449,7 +2443,6 @@ class BytecodeGenerator extends RecursiveVisitor<Null> {
24492443
final DartType bound = (forwardingTypeParameterBounds != null)
24502444
? forwardingTypeParameterBounds[typeParam]
24512445
: typeParam.bound;
2452-
// TODO(regis): Revisit and take nnbdMode into consideration.
24532446
final DartType type = new TypeParameterType(typeParam, Nullability.legacy);
24542447
_genPushInstantiatorAndFunctionTypeArguments([type, bound]);
24552448
asm.emitPushConstant(cp.addType(type));
@@ -2478,7 +2471,6 @@ class BytecodeGenerator extends RecursiveVisitor<Null> {
24782471
_genPushInstantiatorAndFunctionTypeArguments([type]);
24792472
asm.emitPushConstant(
24802473
name != null ? cp.addName(name) : cp.addString(message));
2481-
// TODO(regis): Revisit and take nnbd mode into consideration.
24822474
bool isIntOk = typeEnvironment.isSubtypeOf(
24832475
typeEnvironment.coreTypes.intLegacyRawType,
24842476
type,

pkg/vm/lib/bytecode/object_table.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ class _NeverTypeHandle extends _TypeHandle {
763763
other is _NeverTypeHandle && this.nullability == other.nullability;
764764

765765
@override
766-
// TODO(regis): Print nullability, only if nnbd experiment is enabled?
766+
// TODO(regis): Print nullability.
767767
String toString() => 'Never';
768768
}
769769

@@ -803,7 +803,7 @@ class _SimpleTypeHandle extends _TypeHandle {
803803
this.nullability == other.nullability;
804804

805805
@override
806-
// TODO(regis): Print nullability, only if nnbd experiment is enabled?
806+
// TODO(regis): Print nullability.
807807
String toString() => '$class_';
808808
}
809809

@@ -857,7 +857,7 @@ class _TypeParameterHandle extends _TypeHandle {
857857
this.nullability == other.nullability;
858858

859859
@override
860-
// TODO(regis): Print nullability, only if nnbd experiment is enabled?
860+
// TODO(regis): Print nullability.
861861
String toString() => '$parent::TypeParam/$indexInParent';
862862
}
863863

@@ -903,7 +903,7 @@ class _GenericTypeHandle extends _TypeHandle {
903903
this.nullability == other.nullability;
904904

905905
@override
906-
// TODO(regis): Print nullability, only if nnbd experiment is enabled?
906+
// TODO(regis): Print nullability.
907907
String toString() => '$class_ $typeArgs';
908908
}
909909

@@ -956,7 +956,7 @@ class _RecursiveGenericTypeHandle extends _TypeHandle {
956956
this.nullability == other.nullability;
957957

958958
@override
959-
// TODO(regis): Print nullability, only if nnbd experiment is enabled?
959+
// TODO(regis): Print nullability.
960960
String toString() => '(recursive #$id) $class_ $typeArgs';
961961
}
962962

@@ -1009,7 +1009,7 @@ class NameAndType {
10091009
this.type == other.type;
10101010

10111011
@override
1012-
// TODO(regis): Print nullability, always or only if nnbd experiment is enabled?
1012+
// TODO(regis): Print nullability.
10131013
String toString() => '$type ${name.name}';
10141014
}
10151015

@@ -1152,7 +1152,7 @@ class _FunctionTypeHandle extends _TypeHandle {
11521152
this.returnType == other.returnType;
11531153

11541154
@override
1155-
// TODO(regis): Print nullability, only if nnbd experiment is enabled?
1155+
// TODO(regis): Print nullability.
11561156
String toString() {
11571157
StringBuffer sb = new StringBuffer();
11581158
sb.write('FunctionType');

pkg/vm/testcases/bytecode/type_ops.dart.expect

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ L1:
3131
PushNull
3232
PushNull
3333
PushConstant CP#6
34-
PushInt 0
35-
InterfaceCall CP#7, 5
34+
InterfaceCall CP#7, 4
3635
JumpIfFalse L2
3736
PushConstant CP#9
3837
DirectCall CP#4, 1
@@ -54,7 +53,7 @@ ConstantPool {
5453
[4] = DirectCall 'dart:core::print', ArgDesc num-args 1, num-type-args 0, names []
5554
[5] = Reserved
5655
[6] = Type #lib::C < dart:core::String, dart:core::int, dart:core::Object, dynamic >
57-
[7] = InterfaceCall 'dart:core::Object::_instanceOf', ArgDesc num-args 5, num-type-args 0, names []
56+
[7] = InterfaceCall 'dart:core::Object::_instanceOf', ArgDesc num-args 4, num-type-args 0, names []
5857
[8] = Reserved
5958
[9] = ObjectRef '12'
6059
[10] = Type #lib::A < dart:core::int >
@@ -222,8 +221,7 @@ Bytecode {
222221
LoadTypeArgumentsField CP#0
223222
PushNull
224223
PushConstant CP#1
225-
PushInt 0
226-
InterfaceCall CP#2, 5
224+
InterfaceCall CP#2, 4
227225
JumpIfFalse L1
228226
PushConstant CP#4
229227
DirectCall CP#5, 1
@@ -234,8 +232,7 @@ L1:
234232
LoadTypeArgumentsField CP#0
235233
PushNull
236234
PushConstant CP#7
237-
PushInt 0
238-
InterfaceCall CP#2, 5
235+
InterfaceCall CP#2, 4
239236
JumpIfFalse L2
240237
PushConstant CP#8
241238
DirectCall CP#5, 1
@@ -257,7 +254,7 @@ L2:
257254
ConstantPool {
258255
[0] = TypeArgumentsField #lib::D
259256
[1] = Type #lib::A < #lib::D::TypeParam/0 >
260-
[2] = InterfaceCall 'dart:core::Object::_instanceOf', ArgDesc num-args 5, num-type-args 0, names []
257+
[2] = InterfaceCall 'dart:core::Object::_instanceOf', ArgDesc num-args 4, num-type-args 0, names []
261258
[3] = Reserved
262259
[4] = ObjectRef '21'
263260
[5] = DirectCall 'dart:core::print', ArgDesc num-args 1, num-type-args 0, names []
@@ -285,8 +282,7 @@ Bytecode {
285282
PushNull
286283
Push r0
287284
PushConstant CP#0
288-
PushInt 0
289-
InterfaceCall CP#1, 5
285+
InterfaceCall CP#1, 4
290286
JumpIfFalse L1
291287
PushConstant CP#3
292288
DirectCall CP#4, 1
@@ -297,8 +293,7 @@ L1:
297293
LoadTypeArgumentsField CP#6
298294
Push r0
299295
PushConstant CP#7
300-
PushInt 0
301-
InterfaceCall CP#1, 5
296+
InterfaceCall CP#1, 4
302297
JumpIfFalse L2
303298
PushConstant CP#8
304299
DirectCall CP#4, 1
@@ -316,7 +311,7 @@ L2:
316311
}
317312
ConstantPool {
318313
[0] = Type #lib::A < #lib::D::foo3::TypeParam/0 >
319-
[1] = InterfaceCall 'dart:core::Object::_instanceOf', ArgDesc num-args 5, num-type-args 0, names []
314+
[1] = InterfaceCall 'dart:core::Object::_instanceOf', ArgDesc num-args 4, num-type-args 0, names []
320315
[2] = Reserved
321316
[3] = ObjectRef '31'
322317
[4] = DirectCall 'dart:core::print', ArgDesc num-args 1, num-type-args 0, names []

runtime/bin/entrypoints_verification_test_extension.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ void FailClosurizeConstructor(const char* name, Dart_Handle result) {
6161
}
6262

6363
void TestFields(Dart_Handle target) {
64-
// TODO(regis): Fix these tests, as a function type is not nullable.
6564
FAIL("fld0", Dart_GetField(target, Dart_NewStringFromCString("fld0")));
6665
FAIL("fld0",
6766
Dart_SetField(target, Dart_NewStringFromCString("fld0"), Dart_Null()));

runtime/lib/ffi.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,7 @@ DEFINE_NATIVE_ENTRY(Ffi_storePointer, 0, 3) {
278278

279279
auto& new_value_type =
280280
AbstractType::Handle(zone, new_value.GetType(Heap::kNew));
281-
if (!new_value_type.IsSubtypeOf(NNBDMode::kLegacyLib, pointer_type_arg,
282-
Heap::kNew)) {
281+
if (!new_value_type.IsSubtypeOf(pointer_type_arg, Heap::kNew)) {
283282
const String& error = String::Handle(String::NewFormatted(
284283
"New value (%s) is not a subtype of '%s'.",
285284
String::Handle(new_value_type.UserVisibleName()).ToCString(),

runtime/lib/mirrors.cc

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -713,8 +713,8 @@ static RawAbstractType* InstantiateType(const AbstractType& type,
713713
instantiator_type_args = instantiator.arguments();
714714
}
715715
AbstractType& result = AbstractType::Handle(type.InstantiateFrom(
716-
NNBDMode::kLegacyLib, instantiator_type_args,
717-
Object::null_type_arguments(), kAllFree, NULL, Heap::kOld));
716+
instantiator_type_args, Object::null_type_arguments(), kAllFree, NULL,
717+
Heap::kOld));
718718
ASSERT(result.IsFinalized());
719719
return result.Canonicalize();
720720
}
@@ -1483,8 +1483,8 @@ DEFINE_NATIVE_ENTRY(ClassMirror_invokeConstructor, 0, 5) {
14831483
// type arguments of the type reflected by the class mirror.
14841484
ASSERT(redirect_type.IsInstantiated(kFunctions));
14851485
redirect_type ^= redirect_type.InstantiateFrom(
1486-
NNBDMode::kLegacyLib, type_arguments, Object::null_type_arguments(),
1487-
kNoneFree, NULL, Heap::kOld);
1486+
type_arguments, Object::null_type_arguments(), kNoneFree, NULL,
1487+
Heap::kOld);
14881488
redirect_type ^= redirect_type.Canonicalize();
14891489
}
14901490

@@ -1513,8 +1513,7 @@ DEFINE_NATIVE_ENTRY(ClassMirror_invokeConstructor, 0, 5) {
15131513
ArgumentsDescriptor::New(kTypeArgsLen, args.Length(), arg_names));
15141514

15151515
ArgumentsDescriptor args_descriptor(args_descriptor_array);
1516-
if (!redirected_constructor.AreValidArguments(NNBDMode::kLegacyLib,
1517-
args_descriptor, NULL)) {
1516+
if (!redirected_constructor.AreValidArguments(args_descriptor, NULL)) {
15181517
external_constructor_name = redirected_constructor.name();
15191518
ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()),
15201519
external_constructor_name, explicit_args, arg_names,
@@ -1524,7 +1523,7 @@ DEFINE_NATIVE_ENTRY(ClassMirror_invokeConstructor, 0, 5) {
15241523
}
15251524
const Object& type_error =
15261525
Object::Handle(redirected_constructor.DoArgumentTypesMatch(
1527-
NNBDMode::kLegacyLib, args, args_descriptor, type_arguments));
1526+
args, args_descriptor, type_arguments));
15281527
if (!type_error.IsNull()) {
15291528
Exceptions::PropagateError(Error::Cast(type_error));
15301529
UNREACHABLE();
@@ -1764,7 +1763,7 @@ DEFINE_NATIVE_ENTRY(VariableMirror_type, 0, 2) {
17641763
DEFINE_NATIVE_ENTRY(TypeMirror_subtypeTest, 0, 2) {
17651764
GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, a, arguments->NativeArgAt(0));
17661765
GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, b, arguments->NativeArgAt(1));
1767-
return Bool::Get(a.IsSubtypeOf(NNBDMode::kLegacyLib, b, Heap::kNew)).raw();
1766+
return Bool::Get(a.IsSubtypeOf(b, Heap::kNew)).raw();
17681767
}
17691768

17701769
#endif // !DART_PRECOMPILED_RUNTIME

runtime/lib/object.cc

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ DEFINE_NATIVE_ENTRY(Object_haveSameRuntimeType, 0, 2) {
133133
.raw();
134134
}
135135

136-
DEFINE_NATIVE_ENTRY(Object_instanceOf, 0, 5) {
136+
DEFINE_NATIVE_ENTRY(Object_instanceOf, 0, 4) {
137137
const Instance& instance =
138138
Instance::CheckedHandle(zone, arguments->NativeArgAt(0));
139139
const TypeArguments& instantiator_type_arguments =
@@ -142,11 +142,9 @@ DEFINE_NATIVE_ENTRY(Object_instanceOf, 0, 5) {
142142
TypeArguments::CheckedHandle(zone, arguments->NativeArgAt(2));
143143
const AbstractType& type =
144144
AbstractType::CheckedHandle(zone, arguments->NativeArgAt(3));
145-
const NNBDMode nnbd_mode = static_cast<NNBDMode>(
146-
Smi::CheckedHandle(zone, arguments->NativeArgAt(4)).Value());
147145
ASSERT(type.IsFinalized());
148146
const bool is_instance_of = instance.IsInstanceOf(
149-
nnbd_mode, type, instantiator_type_arguments, function_type_arguments);
147+
type, instantiator_type_arguments, function_type_arguments);
150148
if (FLAG_trace_type_checks) {
151149
const char* result_str = is_instance_of ? "true" : "false";
152150
OS::PrintErr("Native Object.instanceOf: result %s\n", result_str);
@@ -169,18 +167,8 @@ DEFINE_NATIVE_ENTRY(Object_simpleInstanceOf, 0, 2) {
169167
AbstractType::CheckedHandle(zone, arguments->NativeArgAt(1));
170168
ASSERT(type.IsFinalized());
171169
ASSERT(type.IsInstantiated());
172-
// If the instance is not null, the result of _simpleInstanceOf does not
173-
// depend on the nnbd mode, because we only check against a rare type,
174-
// i.e. a class. However, we need to determine the correct nnbd mode when
175-
// the instance is null.
176-
// Since type literals are not imported, a legacy type indicates that the
177-
// call originated in a legacy library. Note that the type test against a
178-
// non-legacy type (even in a legacy library) such as dynamic, void, or Null
179-
// yield the same result independently of the mode used.
180-
NNBDMode mode =
181-
type.IsLegacy() ? NNBDMode::kLegacyLib : NNBDMode::kOptedInLib;
182170
const bool is_instance_of = instance.IsInstanceOf(
183-
mode, type, Object::null_type_arguments(), Object::null_type_arguments());
171+
type, Object::null_type_arguments(), Object::null_type_arguments());
184172
return Bool::Get(is_instance_of).raw();
185173
}
186174

@@ -247,8 +235,8 @@ static bool ExtractInterfaceTypeArgs(Zone* zone,
247235
if (!cur_interface_type_args.IsNull() &&
248236
!cur_interface_type_args.IsInstantiated()) {
249237
cur_interface_type_args = cur_interface_type_args.InstantiateFrom(
250-
cur_cls.nnbd_mode(), instance_type_args,
251-
Object::null_type_arguments(), kNoneFree, NULL, Heap::kNew);
238+
instance_type_args, Object::null_type_arguments(), kNoneFree, NULL,
239+
Heap::kNew);
252240
}
253241
if (ExtractInterfaceTypeArgs(zone, cur_interface_cls,
254242
cur_interface_type_args, interface_cls,
@@ -401,10 +389,8 @@ DEFINE_NATIVE_ENTRY(Internal_boundsCheckForPartialInstantiation, 0, 2) {
401389
ASSERT(!supertype.IsNull());
402390

403391
// The supertype may not be instantiated.
404-
// TODO(regis): What is the correct nnbd mode to use here?
405392
if (!AbstractType::InstantiateAndTestSubtype(
406-
NNBDMode::kLegacyLib, &subtype, &supertype, instantiator_type_args,
407-
function_type_args)) {
393+
&subtype, &supertype, instantiator_type_args, function_type_args)) {
408394
// Throw a dynamic type error.
409395
TokenPosition location;
410396
{

runtime/vm/bootstrap_natives.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace dart {
2222
V(Object_toString, 1) \
2323
V(Object_runtimeType, 1) \
2424
V(Object_haveSameRuntimeType, 2) \
25-
V(Object_instanceOf, 5) \
25+
V(Object_instanceOf, 4) \
2626
V(Object_simpleInstanceOf, 2) \
2727
V(Function_apply, 2) \
2828
V(Closure_equals, 2) \

runtime/vm/class_finalizer.cc

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -390,16 +390,14 @@ void ClassFinalizer::CheckRecursiveType(const Class& cls,
390390
!pending_arguments.IsSubvectorInstantiated(first_type_param,
391391
num_type_params)) {
392392
const TypeArguments& instantiated_arguments = TypeArguments::Handle(
393-
zone, arguments.InstantiateFrom(NNBDMode::kLegacyLib,
394-
Object::null_type_arguments(),
393+
zone, arguments.InstantiateFrom(Object::null_type_arguments(),
395394
Object::null_type_arguments(),
396395
kNoneFree, NULL, Heap::kNew));
397396
const TypeArguments& instantiated_pending_arguments =
398-
TypeArguments::Handle(
399-
zone, pending_arguments.InstantiateFrom(
400-
NNBDMode::kLegacyLib, Object::null_type_arguments(),
401-
Object::null_type_arguments(), kNoneFree, NULL,
402-
Heap::kNew));
397+
TypeArguments::Handle(zone, pending_arguments.InstantiateFrom(
398+
Object::null_type_arguments(),
399+
Object::null_type_arguments(),
400+
kNoneFree, NULL, Heap::kNew));
403401
// By using TypeEquality::kInSubtypeTest, we throw a wider net than
404402
// using canonical or syntactical equality and may reject more
405403
// problematic declarations.
@@ -625,8 +623,8 @@ void ClassFinalizer::FinalizeTypeArguments(const Class& cls,
625623
continue;
626624
}
627625
super_type_arg = super_type_arg.InstantiateFrom(
628-
cls.nnbd_mode(), arguments, Object::null_type_arguments(),
629-
kNoneFree, instantiation_trail, Heap::kOld);
626+
arguments, Object::null_type_arguments(), kNoneFree,
627+
instantiation_trail, Heap::kOld);
630628
if (super_type_arg.IsBeingFinalized()) {
631629
// The super_type_arg was instantiated from a type being finalized.
632630
// We need to finish finalizing its type arguments.
@@ -783,8 +781,8 @@ RawAbstractType* ClassFinalizer::FinalizeType(const Class& cls,
783781
const TypeArguments& instantiator_type_arguments =
784782
TypeArguments::Handle(zone, fun_type.arguments());
785783
signature = signature.InstantiateSignatureFrom(
786-
scope_class.nnbd_mode(), instantiator_type_arguments,
787-
Object::null_type_arguments(), kNoneFree, Heap::kOld);
784+
instantiator_type_arguments, Object::null_type_arguments(),
785+
kNoneFree, Heap::kOld);
788786
// Note that if instantiator_type_arguments contains type parameters,
789787
// as in F<K>, the signature is still uninstantiated (the typedef type
790788
// parameters were substituted in the signature with typedef type

0 commit comments

Comments
 (0)