[vm/kernel/bytecode] Fix generation of InstantiateTypeArgumentsTOS bytecode

Change-Id: I1c4f503cc664d678815e45628a8a14044b00f55f
Reviewed-on: https://dart-review.googlesource.com/61312
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: RĂ©gis Crelier <regis@google.com>
diff --git a/pkg/vm/lib/bytecode/gen_bytecode.dart b/pkg/vm/lib/bytecode/gen_bytecode.dart
index 7a9f65e..e77e28a 100644
--- a/pkg/vm/lib/bytecode/gen_bytecode.dart
+++ b/pkg/vm/lib/bytecode/gen_bytecode.dart
@@ -338,7 +338,14 @@
         _genPushInstantiatorTypeArguments();
       } else {
         _genPushInstantiatorAndFunctionTypeArguments(typeArgs);
-        asm.emitInstantiateTypeArgumentsTOS(1, typeArgsCPIndex());
+        // TODO(alexmarkov): Optimize type arguments instantiation
+        // by passing rA = 1 in InstantiateTypeArgumentsTOS.
+        // For this purpose, we need to detect if type arguments
+        // would be all-dynamic in case of all-dynamic instantiator and
+        // function type arguments.
+        // Corresponding check is implemented in VM in
+        // TypeArguments::IsRawWhenInstantiatedFromRaw.
+        asm.emitInstantiateTypeArgumentsTOS(0, typeArgsCPIndex());
       }
     }
   }
diff --git a/pkg/vm/testcases/bytecode/closures.dart.expect b/pkg/vm/testcases/bytecode/closures.dart.expect
index 733f8b1..c9f41f0 100644
--- a/pkg/vm/testcases/bytecode/closures.dart.expect
+++ b/pkg/vm/testcases/bytecode/closures.dart.expect
@@ -362,7 +362,7 @@
   LoadFieldTOS         CP#1
   LoadFieldTOS         CP#17
   Push                 r0
-  InstantiateTypeArgumentsTOS 1, CP#34
+  InstantiateTypeArgumentsTOS 0, CP#34
   PushConstant         CP#36
   IndirectStaticCall   1, CP#35
   Drop1
diff --git a/pkg/vm/testcases/bytecode/instance_creation.dart.expect b/pkg/vm/testcases/bytecode/instance_creation.dart.expect
index 40f0356..2fe3e73 100644
--- a/pkg/vm/testcases/bytecode/instance_creation.dart.expect
+++ b/pkg/vm/testcases/bytecode/instance_creation.dart.expect
@@ -294,7 +294,7 @@
   CheckStack
   Push                 FP[-5]
   PushConstant         CP#1
-  InstantiateTypeArgumentsTOS 1, CP#3
+  InstantiateTypeArgumentsTOS 0, CP#3
   PushConstant         CP#0
   AllocateT
   StoreLocal           r0
@@ -475,7 +475,7 @@
   CheckStack
   PushConstant         CP#1
   Push                 FP[-5]
-  InstantiateTypeArgumentsTOS 1, CP#3
+  InstantiateTypeArgumentsTOS 0, CP#3
   PushConstant         CP#0
   AllocateT
   StoreLocal           r0
diff --git a/pkg/vm/testcases/bytecode/literals.dart.expect b/pkg/vm/testcases/bytecode/literals.dart.expect
index 6fe7650..a3c9ec2 100644
--- a/pkg/vm/testcases/bytecode/literals.dart.expect
+++ b/pkg/vm/testcases/bytecode/literals.dart.expect
@@ -553,7 +553,7 @@
   Drop1
   PushConstant         CP#16
   Push                 FP[-8]
-  InstantiateTypeArgumentsTOS 1, CP#17
+  InstantiateTypeArgumentsTOS 0, CP#17
   PushConstant         CP#18
   PushConstant         CP#19
   IndirectStaticCall   2, CP#7
@@ -562,7 +562,7 @@
   Drop1
   PushConstant         CP#16
   Push                 FP[-8]
-  InstantiateTypeArgumentsTOS 1, CP#21
+  InstantiateTypeArgumentsTOS 0, CP#21
   PushConstant         CP#1
   PushConstant         CP#5
   CreateArrayTOS
diff --git a/pkg/vm/testcases/bytecode/type_ops.dart.expect b/pkg/vm/testcases/bytecode/type_ops.dart.expect
index eb5a775..cf66e57 100644
--- a/pkg/vm/testcases/bytecode/type_ops.dart.expect
+++ b/pkg/vm/testcases/bytecode/type_ops.dart.expect
@@ -253,7 +253,7 @@
   Push                 FP[-6]
   LoadFieldTOS         CP#0
   PushConstant         CP#1
-  InstantiateTypeArgumentsTOS 1, CP#2
+  InstantiateTypeArgumentsTOS 0, CP#2
   StoreLocal           r1
   Push                 r1
   PushConstant         CP#3