Skip to content

Commit

Permalink
[VM/Compiler] Mark instructions related to late initialization error …
Browse files Browse the repository at this point in the history
…checks as synthetic

TEST=pkg/vm_service/test/breakpoints_ignore_late_initialization_error_instructions_test.dart

Fixes: #53376
Change-Id: Iab7d2489f29bfc4a586b9de6e3caa0a7c1a35454
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/355000
Reviewed-by: Ben Konyi <bkonyi@google.com>
Commit-Queue: Derek Xu <derekx@google.com>
  • Loading branch information
derekxu16 authored and Commit Queue committed Feb 28, 2024
1 parent df72011 commit 098d2f3
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// Regression test for https://dartbug.com/53376.

import 'common/service_test_common.dart';
import 'common/test_helper.dart';

const String shortFile =
'breakpoints_ignore_late_initialization_error_instructions_test.dart';

// AUTOGENERATED START
//
// Update these constants by running:
//
// dart pkg/vm_service/test/update_line_numbers.dart <test.dart>
//
const LINE_A = 33;
const LINE_B = 42;
const LINE_C = 51;
// AUTOGENERATED END

int getThree() => 3;

void testeeMain() {
// ignore: prefer_final_locals
late int x = 1;
// When a late variable is read, the VM performs checks to ensure that the
// variable has been initialized. When a breakpoint is set on the following
// line, it should resolve to the [toDouble] call instruction, not to an
// instruction part of the late variable initialization checks.
final double xd = x.toDouble(); // LINE_A
print(xd);

late final int y = 2;
// When a late final variable is read, the VM performs checks to ensure that
// the variable has been assigned a value exactly once. When a breakpoint is
// set on the following line, it should resolve to the [toDouble] call
// instruction, not to an instruction part of the late variable assignment
// checks.
final double yd = y.toDouble(); // LINE_B
print(yd);

late final int z;
// When a late final variable is assigned a value, the VM performs checks to
// ensure that the variable has not already been initialized. When a
// breakpoint is set on the following line, it should resolve to the
// [getThree] call instruction, not to an instruction part of the late
// variable initialization checks.
z = getThree(); // LINE_C
print(z);
}

List<String> stops = [];

const List<String> expected = [
'$shortFile:$LINE_A:23', // on 'toDouble'
'$shortFile:$LINE_B:23', // on 'toDouble'
'$shortFile:$LINE_C:7', // on 'getThree'
];

final tests = <IsolateTest>[
hasPausedAtStart,
setBreakpointAtLine(LINE_A),
setBreakpointAtLine(LINE_B),
setBreakpointAtLine(LINE_C),
resumeProgramRecordingStops(stops, false),
checkRecordedStops(stops, expected),
];

Future<void> main([args = const <String>[]]) => runIsolateTests(
args,
tests,
shortFile,
testeeConcurrent: testeeMain,
pauseOnStart: true,
pauseOnExit: true,
);
5 changes: 3 additions & 2 deletions runtime/vm/compiler/frontend/kernel_to_il.cc
Original file line number Diff line number Diff line change
Expand Up @@ -511,8 +511,9 @@ Fragment FlowGraphBuilder::ThrowLateInitializationError(

// Call LateError._throwFoo.
instructions += Constant(name);
instructions += StaticCall(position, throw_new,
/* argument_count = */ 1, ICData::kStatic);
instructions +=
StaticCall(TokenPosition::Synthetic(position.Pos()), throw_new,
/* argument_count = */ 1, ICData::kStatic);
instructions += Drop();

return instructions;
Expand Down

0 comments on commit 098d2f3

Please sign in to comment.