Skip to content

Commit 3731cfd

Browse files
zichanggcommit-bot@chromium.org
authored andcommitted
[vm] source report marks all const field as executed
Since const evaluation has been done at the front end, skip evaluating all static const field in source report. Bug: #38284 Change-Id: I876a173b1643d3836277ebcfc1f8546a1f4c71ef Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/117166 Commit-Queue: Zichang Guo <[email protected]> Reviewed-by: Siva Annamalai <[email protected]> Reviewed-by: Régis Crelier <[email protected]>
1 parent a56b4ee commit 3731cfd

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'dart:developer';
6+
import 'package:observatory/service_io.dart';
7+
import 'package:unittest/unittest.dart';
8+
import 'service_test_common.dart';
9+
import 'test_helper.dart';
10+
11+
const int LINE = 14;
12+
13+
class Bar {
14+
static const String field = "field"; // LINE
15+
}
16+
17+
void testFunction() {
18+
debugger();
19+
}
20+
21+
var tests = <IsolateTest>[
22+
hasStoppedAtBreakpoint,
23+
(Isolate isolate) async {
24+
var stack = await isolate.getStack();
25+
26+
// Make sure we are in the right place.
27+
expect(stack.type, 'Stack');
28+
expect(stack['frames'].length, greaterThanOrEqualTo(1));
29+
expect(stack['frames'][0].function.name, 'testFunction');
30+
31+
var root = isolate.rootLibrary;
32+
await root.load();
33+
Script script = root.scripts.first;
34+
await script.load();
35+
36+
var params = {
37+
'reports': ['Coverage'],
38+
'scriptId': script.id,
39+
'forceCompile': true
40+
};
41+
var report = await isolate.invokeRpcNoUpgrade('getSourceReport', params);
42+
List<dynamic> ranges = report['ranges'];
43+
44+
int match = 0;
45+
for (var range in ranges) {
46+
for (int i in range["coverage"]["hits"]) {
47+
int line = script.tokenToLine(i);
48+
if (line == null) {
49+
throw FormatException('token ${i} was missing source location');
50+
}
51+
// Check LINE.
52+
if (line == LINE) {
53+
match = (match | 1);
54+
} else if (line == LINE - 3) {
55+
// static const field LINE is defined at LINE - 3.
56+
match = (match | 2);
57+
}
58+
}
59+
}
60+
// Neither LINE nor Bar.field should be added into coverage.
61+
expect(match, 0);
62+
},
63+
resumeIsolate
64+
];
65+
66+
main(args) => runIsolateTests(args, tests, testeeConcurrent: testFunction);

runtime/vm/source_report.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,13 @@ void SourceReport::VisitLibrary(JSONArray* jsarr, const Library& lib) {
585585
functions = cls.functions();
586586
for (int i = 0; i < functions.Length(); i++) {
587587
func ^= functions.At(i);
588+
// Skip getter functions of static const field.
589+
if (func.kind() == RawFunction::kImplicitStaticGetter) {
590+
field ^= func.accessor_field();
591+
if (field.is_const() && field.is_static()) {
592+
continue;
593+
}
594+
}
588595
VisitFunction(jsarr, func);
589596
}
590597

0 commit comments

Comments
 (0)