Skip to content

Commit 8fb77ec

Browse files
alexmarkovcommit-bot@chromium.org
authored andcommitted
[vm/bytecode] Preliminary support for new language features in bytecode
Issue: #36214 Issue: #36218 Change-Id: I39149b82cb93c1cb87c64cf9c41c56b753bba13a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/98400 Reviewed-by: Aart Bik <[email protected]> Commit-Queue: Alexander Markov <[email protected]> Auto-Submit: Alexander Markov <[email protected]>
1 parent 8aabbf3 commit 8fb77ec

File tree

4 files changed

+42
-25
lines changed

4 files changed

+42
-25
lines changed

pkg/vm/lib/bytecode/gen_bytecode.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2701,6 +2701,14 @@ class BytecodeGenerator extends RecursiveVisitor<Null> {
27012701
asm.bind(done);
27022702
}
27032703

2704+
@override
2705+
visitBlockExpression(BlockExpression node) {
2706+
_enterScope(node);
2707+
_generateNodeList(node.body.statements);
2708+
_generateNode(node.value);
2709+
_leaveScope();
2710+
}
2711+
27042712
@override
27052713
visitBreakStatement(BreakStatement node) {
27062714
final targetLabel = labeledStatements[node.target] ??

pkg/vm/lib/bytecode/local_vars.dart

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,16 @@ class _ScopeBuilder extends RecursiveVisitor<Null> {
597597
_visitWithScope(node);
598598
}
599599

600+
@override
601+
visitBlockExpression(BlockExpression node) {
602+
// Not using _visitWithScope as Block inside BlockExpression does not have
603+
// a scope.
604+
_enterScope(node);
605+
visitList(node.body.statements, this);
606+
node.value.accept(this);
607+
_leaveScope();
608+
}
609+
600610
@override
601611
visitAssertBlock(AssertBlock node) {
602612
_visitWithScope(node);
@@ -1036,6 +1046,15 @@ class _Allocator extends RecursiveVisitor<Null> {
10361046
_visit(node, scope: true);
10371047
}
10381048

1049+
@override
1050+
visitBlockExpression(BlockExpression node) {
1051+
// Not using _visit as Block inside BlockExpression does not have a scope.
1052+
_enterScope(node);
1053+
visitList(node.body.statements, this);
1054+
node.value.accept(this);
1055+
_leaveScope();
1056+
}
1057+
10391058
@override
10401059
visitAssertBlock(AssertBlock node) {
10411060
_visit(node, scope: true);

runtime/vm/compiler/frontend/bytecode_flow_graph_builder.cc

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -327,12 +327,6 @@ void BytecodeFlowGraphBuilder::PropagateStackState(intptr_t target_pc) {
327327
return;
328328
}
329329

330-
// Stack state propagation is supported for forward branches only.
331-
// Bytecode generation guarantees that expression stack is empty between
332-
// statements and backward jumps are only used to transfer control between
333-
// statements (e.g. in loop and continue statements).
334-
RELEASE_ASSERT(target_pc > pc_);
335-
336330
Value* current_stack = B->stack_;
337331
Value* target_stack = stack_states_.Lookup(target_pc);
338332

@@ -341,6 +335,8 @@ void BytecodeFlowGraphBuilder::PropagateStackState(intptr_t target_pc) {
341335
// all incoming branches.
342336
RELEASE_ASSERT(target_stack == current_stack);
343337
} else {
338+
// Stack state propagation is supported for forward branches only.
339+
RELEASE_ASSERT(target_pc > pc_);
344340
stack_states_.Insert(target_pc, current_stack);
345341
}
346342
}
@@ -666,11 +662,15 @@ void BytecodeFlowGraphBuilder::BuildCheckStack() {
666662
}
667663
const intptr_t loop_depth = DecodeOperandA().value();
668664
if (loop_depth == 0) {
665+
ASSERT(IsStackEmpty());
669666
code_ += B->CheckStackOverflowInPrologue(position_);
670667
} else {
671-
code_ += B->CheckStackOverflow(position_, loop_depth);
668+
// Avoid OSR points inside block-expressions.
669+
// TODO(ajcbik): make sure OSR works inside BE too.
670+
if (!IsStackEmpty()) {
671+
code_ += B->CheckStackOverflow(position_, loop_depth);
672+
}
672673
}
673-
ASSERT(IsStackEmpty());
674674
}
675675

676676
void BytecodeFlowGraphBuilder::BuildPushConstant() {
@@ -1824,7 +1824,10 @@ FlowGraph* BytecodeFlowGraphBuilder::BuildGraph() {
18241824
if (join != nullptr) {
18251825
Value* stack_state = stack_states_.Lookup(pc_);
18261826
if (code_.is_open()) {
1827-
ASSERT((stack_state == nullptr) || (stack_state == B->stack_));
1827+
if (stack_state != B->stack_) {
1828+
ASSERT(stack_state == nullptr);
1829+
stack_states_.Insert(pc_, B->stack_);
1830+
}
18281831
code_ += B->Goto(join);
18291832
} else {
18301833
ASSERT(IsStackEmpty());

tests/language_2/language_2_kernel.status

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ const_map4_test: RuntimeError
3737
const_nested_test: RuntimeError
3838
const_string_test: RuntimeError
3939
constructor12_test: RuntimeError
40-
control_flow_collections/*: Skip
4140
covariant_subtyping_test: RuntimeError
4241
ct_const_test: RuntimeError
4342
cyclic_type2_test: CompileTimeError
@@ -146,11 +145,7 @@ web_int_literals_test/*: SkipByDesign # Test applies only to JavaScript targets
146145
mixin_method_override_test/G5: Skip # Issue 34354
147146
private_method_tearoff_test: RuntimeError
148147

149-
[ $compiler == dartk ]
150-
control_flow_collections/*: Skip
151-
152148
[ $compiler == dartkp ]
153-
control_flow_collections/*: Skip
154149
covariant_subtyping_test: RuntimeError
155150
generic_no_such_method_dispatcher_test: RuntimeError # Issue 31424
156151
spread_collections/await_test: CompileTimeError
@@ -561,19 +556,8 @@ async_star_test/04: Pass, RuntimeError # Please triage
561556
compile_time_constant_o_test/01: Pass
562557
compile_time_constant_o_test/02: Pass
563558
const_dynamic_type_literal_test/02: Pass
564-
control_flow_collections/*: Skip
565559
map_literal3_test/01: Pass
566560
map_literal3_test/02: Pass
567-
spread_collections/await_test: CompileTimeError
568-
spread_collections/const_test: CompileTimeError
569-
spread_collections/inference_test: CompileTimeError
570-
spread_collections/map_set_ambiguity_test: CompileTimeError
571-
spread_collections/spread_test: CompileTimeError
572-
spread_collections/syntax_test: CompileTimeError
573-
spread_collections/type_error_test/00: DartkCrash
574-
spread_collections/type_error_test/02: DartkCrash
575-
spread_collections/type_error_test/03: DartkCrash
576-
spread_collections/type_error_test/05: DartkCrash
577561
vm/bool_check_stack_traces_test/02: Pass
578562
vm/causal_async_exception_stack2_test: RuntimeError # Please triage
579563
vm/causal_async_exception_stack_test: RuntimeError # Please triage
@@ -2181,6 +2165,9 @@ async_star_test/05: Skip # Timeout
21812165
async_star_test/none: Skip # Timeout
21822166
type_constants_test/none: Skip # Deferred libraries and hot reload.
21832167

2168+
[ $compiler == app_jitk || $compiler == dartk || $compiler == dartkb || $compiler == dartkp ]
2169+
control_flow_collections/*: Skip
2170+
21842171
[ $compiler == dartk || $compiler == dartkb || $compiler == dartkp ]
21852172
generic_function_bounds_test: RuntimeError # Issue 32076
21862173

0 commit comments

Comments
 (0)