Skip to content

Commit

Permalink
[dart2wasm] Add function names to source maps
Browse files Browse the repository at this point in the history
Annotate code with the enclosing Dart function names.

Fixes #56718.

Change-Id: I1d53fc3752580514aa92b3d62ec717c93ad58d66
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/386780
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
  • Loading branch information
osa1 authored and Commit Queue committed Oct 18, 2024
1 parent 574a6b3 commit 9046485
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 18 deletions.
3 changes: 2 additions & 1 deletion pkg/dart2wasm/lib/code_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ abstract class AstCodeGenerator
final location = source.getLocation(fileUri, fileOffset);
final old = _sourceMapFileOffset;
_sourceMapFileOffset = fileOffset;
b.startSourceMapping(fileUri, location.line - 1, location.column - 1, null);
b.startSourceMapping(fileUri, location.line - 1, location.column - 1,
enclosingMember.name.text);
return old;
}

Expand Down
15 changes: 9 additions & 6 deletions tests/web/wasm/source_map_simple_lib.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ void g() {

runtimeFalse() => int.parse('1') == 0;

// `expectedFrames` is (String, line, column) of the frames we check.
// `expectedFrames` is (file, line, column, name) of the frames we check.
//
// Information we don't check are "null": we don't want to check line/column
// of standard library functions to avoid breaking the test with unrelated
// changes to the standard library.
void testMain(String testName, List<(String?, int?, int?)?> expectedFrames) {
void testMain(
String testName, List<(String?, int?, int?, String?)?> expectedFrames) {
// Use `f` and `g` in a few places to make sure wasm-opt won't inline them
// in the test.
final fTearOff = f;
Expand Down Expand Up @@ -69,7 +70,8 @@ void testMain(String testName, List<(String?, int?, int?)?> expectedFrames) {
}
if ((expected.$1 != null && actual.$1 != expected.$1) ||
(expected.$2 != null && actual.$2 != expected.$2) ||
(expected.$3 != null && actual.$3 != expected.$3)) {
(expected.$3 != null && actual.$3 != expected.$3) ||
(expected.$4 != null && actual.$4 != expected.$4)) {
throw 'Mismatch:\n Expected: $expected\n Actual: $actual';
}
}
Expand Down Expand Up @@ -112,9 +114,9 @@ Mapping getSourceMapping(String testName) {
return allMappings;
}

List<(String?, int?, int?)?> parseStack(
List<(String?, int?, int?, String?)?> parseStack(
String testName, Mapping mapping, String stackTraceString) {
final parsed = <(String?, int?, int?)?>[];
final parsed = <(String?, int?, int?, String?)?>[];
for (final line in stackTraceString.split('\n')) {
if (line.contains('.mjs') || line.contains('.js')) {
parsed.add(null);
Expand Down Expand Up @@ -145,7 +147,8 @@ List<(String?, int?, int?)?> parseStack(
final filename = span.sourceUrl!.pathSegments.last;
final lineNumber = span.start.line;
final columnNumber = span.start.column;
parsed.add((filename, 1 + lineNumber, 1 + columnNumber));
final symbolName = span.text;
parsed.add((filename, 1 + lineNumber, 1 + columnNumber, symbolName));
}
return parsed;
}
Expand Down
10 changes: 5 additions & 5 deletions tests/web/wasm/source_map_simple_optimized_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ void main() {
Lib.testMain('source_map_simple_optimized', frameDetails);
}

const List<(String?, int?, int?)?> frameDetails = [
('errors_patch.dart', null, null), // _throwWithCurrentStackTrace
('source_map_simple_lib.dart', 16, 3), // g
('source_map_simple_lib.dart', 12, 3), // f
('source_map_simple_lib.dart', 38, 5), // testMain, inlined in main
const List<(String?, int?, int?, String?)?> frameDetails = [
('errors_patch.dart', null, null, '_throwWithCurrentStackTrace'),
('source_map_simple_lib.dart', 16, 3, 'g'),
('source_map_simple_lib.dart', 12, 3, 'f'),
('source_map_simple_lib.dart', 39, 5, 'testMain'),
];

/*
Expand Down
12 changes: 6 additions & 6 deletions tests/web/wasm/source_map_simple_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ void main() {
Lib.testMain('source_map_simple', frameDetails);
}

const List<(String?, int?, int?)?> frameDetails = [
('errors_patch.dart', null, null), // _throwWithCurrentStackTrace
('source_map_simple_lib.dart', 16, 3), // g
('source_map_simple_lib.dart', 12, 3), // f
('source_map_simple_lib.dart', 38, 5), // testMain
('source_map_simple_test.dart', 10, 7), // main
const List<(String?, int?, int?, String?)?> frameDetails = [
('errors_patch.dart', null, null, '_throwWithCurrentStackTrace'),
('source_map_simple_lib.dart', 16, 3, 'g'),
('source_map_simple_lib.dart', 12, 3, 'f'),
('source_map_simple_lib.dart', 39, 5, 'testMain'),
('source_map_simple_test.dart', 10, 7, 'main'),
null, // main tear-off, compiler generated, not mapped
// The rest of the stack is dependent on the compiler mode.
];
Expand Down

0 comments on commit 9046485

Please sign in to comment.