Skip to content
This repository has been archived by the owner on Feb 25, 2025. It is now read-only.

Commit

Permalink
[vm/kernel/bytecode] Minor fixes in bytecode generator
Browse files Browse the repository at this point in the history
This CL contains 2 fixes:

* Instantiator type arguments for factory constructors are calculated
  using factory's type parameters and not class type parameters
  (as factory's body uses factory's type parameters in kernel AST)
  This improves reuse of instantiator type arguments in factory
  constructors (optimization).

* Result of _AssertionError::_throwNew call is dropped off the stack.
  Although control never returns from _throwNew, this fix is needed
  to maintain correct stack balance while compiling bytecode.

Change-Id: Ib781b0d790a89576ef62b768513663e7e509749c
Reviewed-on: https://dart-review.googlesource.com/69384
Reviewed-by: Zach Anderson <zra@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
  • Loading branch information
alexmarkov authored and commit-bot@chromium.org committed Aug 10, 2018
1 parent fe0640e commit 98d07dd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
12 changes: 7 additions & 5 deletions pkg/vm/lib/bytecode/gen_bytecode.dart
Original file line number Diff line number Diff line change
Expand Up @@ -586,20 +586,21 @@ class BytecodeGenerator extends RecursiveVisitor<Null> {
enclosingFunction = node.function;
parentFunction = null;
hasErrors = false;
if (node.isInstanceMember ||
node is Constructor ||
(node is Procedure && node.isFactory)) {
final isFactory = node is Procedure && node.isFactory;
if (node.isInstanceMember || node is Constructor || isFactory) {
if (enclosingClass.typeParameters.isNotEmpty) {
classTypeParameters =
new Set<TypeParameter>.from(enclosingClass.typeParameters);
// Treat type arguments of factory constructors as class
// type parameters.
if (node is Procedure && node.isFactory) {
if (isFactory) {
classTypeParameters.addAll(node.function.typeParameters);
}
}
if (hasInstantiatorTypeArguments(enclosingClass)) {
final typeParameters = enclosingClass.typeParameters
final typeParameters = (isFactory
? node.function.typeParameters
: enclosingClass.typeParameters)
.map((p) => new TypeParameterType(p))
.toList();
instantiatorTypeArguments =
Expand Down Expand Up @@ -1797,6 +1798,7 @@ class BytecodeGenerator extends RecursiveVisitor<Null> {
}

_genStaticCall(throwNewAssertionError, new ConstantArgDesc(3), 3);
asm.emitDrop1();

asm.bind(done);
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/vm/testcases/bytecode/asserts.dart.expect
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Bytecode {
PushConstant CP#2
PushConstant CP#4
IndirectStaticCall 3, CP#3
Drop1
L1:
PushConstant CP#2
ReturnTOS
Expand Down Expand Up @@ -48,6 +49,7 @@ Bytecode {
InstanceCall1 1, CP#4
PushConstant CP#6
IndirectStaticCall 3, CP#5
Drop1
L1:
PushConstant CP#7
ReturnTOS
Expand Down
1 change: 1 addition & 0 deletions pkg/vm/testcases/bytecode/async.dart.expect
Original file line number Diff line number Diff line change
Expand Up @@ -2498,6 +2498,7 @@ L3:
PushConstant CP#3
PushConstant CP#16
IndirectStaticCall 3, CP#15
Drop1
L2:
Push r4
PushConstant CP#17
Expand Down

0 comments on commit 98d07dd

Please sign in to comment.