Skip to content

Commit e32c2ac

Browse files
alexmarkovCommit Queue
authored andcommitted
[vm,dyn_modules] Remove enclosing function type parameters from instantiated types
VM treats instantiated function types with NumParentTypeArguments() != 0 as non-instantiated (as they potentially depend on the numbering of enclosing type parameters) and would explicitly instantiate such types. So bytecode generator needs to make sure that instantiated types, instantiated type arguments and types used in constants always have NumParentTypeArguments() == 0, so they would not need unnecessary instantiation. TEST=ci Change-Id: I3ea54a0b535655611893d28edb54ffd50dcda1f0 Cq-Include-Trybots: luci.dart.try:vm-aot-dyn-linux-debug-x64-try,vm-aot-dyn-linux-product-x64-try,vm-dyn-linux-debug-x64-try Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/443630 Reviewed-by: Tess Strickland <[email protected]> Reviewed-by: Slava Egorov <[email protected]> Commit-Queue: Alexander Markov <[email protected]>
1 parent f46670e commit e32c2ac

File tree

6 files changed

+51
-28
lines changed

6 files changed

+51
-28
lines changed

pkg/dart2bytecode/lib/bytecode_generator.dart

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,7 +1298,11 @@ class BytecodeGenerator extends RecursiveVisitor {
12981298
}
12991299

13001300
if (typeArgs.isEmpty || !hasFreeTypeParameters(typeArgs)) {
1301-
asm.emitPushConstant(typeArgsCPIndex());
1301+
// Instantiated type arguments should not depend on
1302+
// the type parameters of the enclosing function.
1303+
objectTable.withoutEnclosingFunctionTypeParameters(() {
1304+
asm.emitPushConstant(typeArgsCPIndex());
1305+
});
13021306
} else {
13031307
final flattenedTypeArgs = (instantiatingClass != null &&
13041308
(instantiatorTypeArguments != null ||
@@ -1581,11 +1585,16 @@ class BytecodeGenerator extends RecursiveVisitor {
15811585

15821586
if (hasFreeTypeParameters([type])) {
15831587
_genPushInstantiatorAndFunctionTypeArguments([type]);
1588+
asm.emitPushConstant(cp.addType(type));
15841589
} else {
15851590
asm.emitPushNull(); // Instantiator type arguments.
15861591
asm.emitPushNull(); // Function type arguments.
1592+
// Instantiated type should not depend on
1593+
// the type parameters of the enclosing function.
1594+
objectTable.withoutEnclosingFunctionTypeParameters(() {
1595+
asm.emitPushConstant(cp.addType(type));
1596+
});
15871597
}
1588-
asm.emitPushConstant(cp.addType(type));
15891598
final argDesc = objectTable.getArgDescHandle(4);
15901599
final cpIndex =
15911600
cp.addInterfaceCall(InvocationKind.method, objectInstanceOf, argDesc);
@@ -3568,12 +3577,15 @@ class BytecodeGenerator extends RecursiveVisitor {
35683577
@override
35693578
void visitTypeLiteral(TypeLiteral node) {
35703579
final DartType type = node.type;
3571-
final int typeCPIndex = cp.addType(type);
35723580
if (!hasFreeTypeParameters([type])) {
3573-
asm.emitPushConstant(typeCPIndex);
3581+
// Instantiated type should not depend on
3582+
// the type parameters of the enclosing function.
3583+
objectTable.withoutEnclosingFunctionTypeParameters(() {
3584+
asm.emitPushConstant(cp.addType(type));
3585+
});
35743586
} else {
35753587
_genPushInstantiatorAndFunctionTypeArguments([type]);
3576-
asm.emitInstantiateType(typeCPIndex);
3588+
asm.emitInstantiateType(cp.addType(type));
35773589
}
35783590
}
35793591

pkg/dart2bytecode/lib/constant_pool.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -635,8 +635,12 @@ class ConstantPool {
635635

636636
int addEmptyTypeArguments() => _add(const ConstantEmptyTypeArguments());
637637

638-
int addObjectRef(Node? node) =>
639-
_add(new ConstantObjectRef(objectTable.getHandle(node)));
638+
int addObjectRef(Node? node) {
639+
// Constant objects should not depend on the type parameters of
640+
// the enclosing function.
641+
return objectTable.withoutEnclosingFunctionTypeParameters(
642+
() => _add(new ConstantObjectRef(objectTable.getHandle(node))));
643+
}
640644

641645
int addSelectorName(Name name, InvocationKind invocationKind) =>
642646
_add(new ConstantObjectRef(objectTable.getSelectorNameHandle(name,

pkg/dart2bytecode/lib/object_table.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1707,6 +1707,16 @@ class ObjectTable implements ObjectWriter, ObjectReader {
17071707
_nodeVisitor = _NodeVisitor(this, coreTypes);
17081708
}
17091709

1710+
// Can be used to add instantiated types and constants which
1711+
// should not depend on type parameters of the enclosing function.
1712+
T withoutEnclosingFunctionTypeParameters<T>(T Function() action) {
1713+
final saved = numEnclosingFunctionTypeParameters;
1714+
numEnclosingFunctionTypeParameters = 0;
1715+
final result = action();
1716+
numEnclosingFunctionTypeParameters = saved;
1717+
return result;
1718+
}
1719+
17101720
ObjectHandle? getHandle(Node? node) {
17111721
if (node == null) {
17121722
return null;

pkg/dart2bytecode/testcases/closures.dart.expect

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ Bytecode {
514514
PushConstant CP#0
515515
Push r1
516516
Push FP[-5]
517-
LoadTypeArgumentsField CP#14
517+
LoadTypeArgumentsField CP#13
518518
AllocateClosure
519519
StoreLocal r4
520520
Push r4
@@ -551,8 +551,8 @@ ConstantPool {
551551
[10] = ClosureFunction 1
552552
[11] = ClosureFunction 2
553553
[12] = ObjectRef < dart:core::Type >
554-
[13] = Type DART_SDK/pkg/dart2bytecode/testcases/closures.dart::A::TypeParam/0
555-
[14] = TypeArgumentsField DART_SDK/pkg/dart2bytecode/testcases/closures.dart::A
554+
[13] = TypeArgumentsField DART_SDK/pkg/dart2bytecode/testcases/closures.dart::A
555+
[14] = Type DART_SDK/pkg/dart2bytecode/testcases/closures.dart::A::TypeParam/0
556556
[15] = Type DART_SDK/pkg/dart2bytecode/testcases/closures.dart::A::TypeParam/1
557557
[16] = Type DART_SDK/pkg/dart2bytecode/testcases/closures.dart::A::foo::TypeParam/0
558558
[17] = Type DART_SDK/pkg/dart2bytecode/testcases/closures.dart::A::foo::TypeParam/1
@@ -605,7 +605,7 @@ L2:
605605
Push r1
606606
Push r1
607607
LoadContextVar 0, 0
608-
LoadTypeArgumentsField CP#14
608+
LoadTypeArgumentsField CP#13
609609
AllocateClosure
610610
StoreLocal r4
611611
Push r4
@@ -657,7 +657,7 @@ L2:
657657
Push r1
658658
Push r1
659659
LoadContextVar 0, 0
660-
LoadTypeArgumentsField CP#14
660+
LoadTypeArgumentsField CP#13
661661
AllocateClosure
662662
StoreLocal r4
663663
Push r4
@@ -686,12 +686,12 @@ ClosureCode {
686686
PushConstant CP#12
687687
Push r1
688688
LoadContextVar 0, 0
689-
LoadTypeArgumentsField CP#14
689+
LoadTypeArgumentsField CP#13
690690
PushNull
691-
InstantiateType CP#13
691+
InstantiateType CP#14
692692
Push r1
693693
LoadContextVar 0, 0
694-
LoadTypeArgumentsField CP#14
694+
LoadTypeArgumentsField CP#13
695695
PushNull
696696
InstantiateType CP#15
697697
PushNull
@@ -717,7 +717,7 @@ ClosureCode {
717717
Drop1
718718
Push r1
719719
LoadContextVar 0, 0
720-
LoadTypeArgumentsField CP#14
720+
LoadTypeArgumentsField CP#13
721721
Push r0
722722
InstantiateTypeArgumentsTOS 0, CP#26
723723
DirectCall CP#27, 1

pkg/dart2bytecode/testcases/instance_creation.dart.expect

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,9 @@ Bytecode {
241241
Push r0
242242
PushInt 1
243243
Push FP[-5]
244-
LoadTypeArgumentsField CP#4
244+
LoadTypeArgumentsField CP#3
245245
PushNull
246-
InstantiateType CP#3
246+
InstantiateType CP#4
247247
StoreIndexedTOS
248248
Push r0
249249
PushInt 2
@@ -252,7 +252,7 @@ Bytecode {
252252
Push r0
253253
PushInt 3
254254
Push FP[-5]
255-
LoadTypeArgumentsField CP#4
255+
LoadTypeArgumentsField CP#3
256256
PushNull
257257
InstantiateType CP#6
258258
StoreIndexedTOS
@@ -267,8 +267,8 @@ ConstantPool {
267267
[0] = DirectCall 'dart:core::Object:: (constructor)', ArgDesc num-args 1, num-type-args 0, names []
268268
[1] = Reserved
269269
[2] = ObjectRef 'Base: '
270-
[3] = Type DART_SDK/pkg/dart2bytecode/testcases/instance_creation.dart::Base::TypeParam/0
271-
[4] = TypeArgumentsField DART_SDK/pkg/dart2bytecode/testcases/instance_creation.dart::Base
270+
[3] = TypeArgumentsField DART_SDK/pkg/dart2bytecode/testcases/instance_creation.dart::Base
271+
[4] = Type DART_SDK/pkg/dart2bytecode/testcases/instance_creation.dart::Base::TypeParam/0
272272
[5] = ObjectRef ', '
273273
[6] = Type DART_SDK/pkg/dart2bytecode/testcases/instance_creation.dart::Base::TypeParam/1
274274
[7] = DirectCall 'dart:core::_StringBase::_interpolate', ArgDesc num-args 1, num-type-args 0, names []
@@ -325,9 +325,9 @@ Bytecode {
325325
Push r0
326326
PushInt 1
327327
Push FP[-5]
328-
LoadTypeArgumentsField CP#4
328+
LoadTypeArgumentsField CP#3
329329
PushNull
330-
InstantiateType CP#3
330+
InstantiateType CP#4
331331
StoreIndexedTOS
332332
DirectCall CP#5, 1
333333
DirectCall CP#7, 1
@@ -339,8 +339,8 @@ ConstantPool {
339339
[0] = DirectCall 'DART_SDK/pkg/dart2bytecode/testcases/instance_creation.dart::Base:: (constructor)', ArgDesc num-args 1, num-type-args 0, names []
340340
[1] = Reserved
341341
[2] = ObjectRef 'B: '
342-
[3] = Type DART_SDK/pkg/dart2bytecode/testcases/instance_creation.dart::B::TypeParam/0
343-
[4] = TypeArgumentsField DART_SDK/pkg/dart2bytecode/testcases/instance_creation.dart::B
342+
[3] = TypeArgumentsField DART_SDK/pkg/dart2bytecode/testcases/instance_creation.dart::B
343+
[4] = Type DART_SDK/pkg/dart2bytecode/testcases/instance_creation.dart::B::TypeParam/0
344344
[5] = DirectCall 'dart:core::_StringBase::_interpolate', ArgDesc num-args 1, num-type-args 0, names []
345345
[6] = Reserved
346346
[7] = DirectCall 'dart:core::print', ArgDesc num-args 1, num-type-args 0, names []

tests/language/language.status

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ unsorted/invocation_mirror_test: SkipByDesign # Relies on symbol names
2424
vm/type_cast_vm_test: SkipByDesign # Relies on symbol names
2525

2626
[ $compiler == dart2bytecode ]
27-
class_modifiers/trans_legacy/legacy_superdeclaration_test: Crash
28-
const/inference_test: Crash
29-
regress/regress45763_test: Crash
3027
vm/reflect_core_vm_test: Crash
3128

3229
[ $compiler != fasta ]

0 commit comments

Comments
 (0)