Skip to content

Commit cd260b6

Browse files
author
chen ruixiang
committed
Fix: remove excess optimization for sourcemap
1 parent 661fe5e commit cd260b6

File tree

4 files changed

+15
-20
lines changed

4 files changed

+15
-20
lines changed

src/passes/Print.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2521,7 +2521,6 @@ struct PrintSExpression : public UnifiedExpressionVisitor<PrintSExpression> {
25212521

25222522
Module* currModule = nullptr;
25232523
Function* currFunction = nullptr;
2524-
Function::DebugLocation lastPrintedLocation;
25252524
bool debugInfo;
25262525

25272526
// Used to print delegate's depth argument when it throws to the caller
@@ -2535,10 +2534,6 @@ struct PrintSExpression : public UnifiedExpressionVisitor<PrintSExpression> {
25352534
}
25362535

25372536
void printDebugLocation(const Function::DebugLocation& location) {
2538-
if (lastPrintedLocation == location) {
2539-
return;
2540-
}
2541-
lastPrintedLocation = location;
25422537
auto fileName = currModule->debugInfoFileNames[location.fileIndex];
25432538
o << ";;@ " << fileName << ":" << location.lineNumber << ":"
25442539
<< location.columnNumber << '\n';
@@ -3100,7 +3095,6 @@ struct PrintSExpression : public UnifiedExpressionVisitor<PrintSExpression> {
31003095
void visitImportedFunction(Function* curr) {
31013096
doIndent(o, indent);
31023097
currFunction = curr;
3103-
lastPrintedLocation = {0, 0, 0};
31043098
o << '(';
31053099
emitImportHeader(curr);
31063100
handleSignature(curr->getSig(), curr->name);
@@ -3110,7 +3104,6 @@ struct PrintSExpression : public UnifiedExpressionVisitor<PrintSExpression> {
31103104
void visitDefinedFunction(Function* curr) {
31113105
doIndent(o, indent);
31123106
currFunction = curr;
3113-
lastPrintedLocation = {0, 0, 0};
31143107
if (currFunction->prologLocation.size()) {
31153108
printDebugLocation(*currFunction->prologLocation.begin());
31163109
}
@@ -3168,8 +3161,7 @@ struct PrintSExpression : public UnifiedExpressionVisitor<PrintSExpression> {
31683161
// Print the stack IR.
31693162
printStackIR(curr->stackIR.get(), o, curr);
31703163
}
3171-
if (currFunction->epilogLocation.size() &&
3172-
lastPrintedLocation != *currFunction->epilogLocation.begin()) {
3164+
if (currFunction->epilogLocation.size()) {
31733165
// Print last debug location: mix of decIndent and printDebugLocation
31743166
// logic.
31753167
doIndent(o, indent);

src/wasm-binary.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,7 +1341,6 @@ class WasmBinaryWriter {
13411341
void writeDylinkSection();
13421342
void writeLegacyDylinkSection();
13431343

1344-
void initializeDebugInfo();
13451344
void writeSourceMapProlog();
13461345
void writeSourceMapEpilog();
13471346
void writeDebugLocation(const Function::DebugLocation& loc);
@@ -1402,7 +1401,6 @@ class WasmBinaryWriter {
14021401
std::vector<std::pair<size_t, const Function::DebugLocation*>>
14031402
sourceMapLocations;
14041403
size_t sourceMapLocationsSizeAtSectionStart;
1405-
Function::DebugLocation lastDebugLocation;
14061404

14071405
std::unique_ptr<ImportInfo> importInfo;
14081406

src/wasm/wasm-binary.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ void WasmBinaryWriter::write() {
4343

4444
writeDylinkSection();
4545

46-
initializeDebugInfo();
4746
if (sourceMap) {
4847
writeSourceMapProlog();
4948
}
@@ -1117,10 +1116,6 @@ void WasmBinaryWriter::writeSymbolMap() {
11171116
file.close();
11181117
}
11191118

1120-
void WasmBinaryWriter::initializeDebugInfo() {
1121-
lastDebugLocation = {0, /* lineNumber = */ 1, 0};
1122-
}
1123-
11241119
void WasmBinaryWriter::writeSourceMapProlog() {
11251120
*sourceMap << "{\"version\":3,\"sources\":[";
11261121
for (size_t i = 0; i < wasm->debugInfoFileNames.size(); i++) {
@@ -1301,12 +1296,8 @@ void WasmBinaryWriter::writeDylinkSection() {
13011296
}
13021297

13031298
void WasmBinaryWriter::writeDebugLocation(const Function::DebugLocation& loc) {
1304-
if (loc == lastDebugLocation) {
1305-
return;
1306-
}
13071299
auto offset = o.size();
13081300
sourceMapLocations.emplace_back(offset, &loc);
1309-
lastDebugLocation = loc;
13101301
}
13111302

13121303
void WasmBinaryWriter::writeDebugLocation(Expression* curr, Function* func) {

test/lit/source-map.wast

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@
2222
;;@ src.cpp:80:1
2323
(local.get $y)
2424
)
25+
;;@ src.cpp:90:1
26+
(call $foo
27+
;;@ src.cpp:90:1
28+
(local.get $x)
29+
;;@ src.cpp:90:1
30+
(local.get $y)
31+
)
2532
)
2633
)
2734

@@ -45,3 +52,10 @@
4552
;; CHECK-NEXT: ;;@ src.cpp:80:1
4653
;; CHECK-NEXT: (local.get $y)
4754
;; CHECK-NEXT: )
55+
;; CHECK-NEXT: ;;@ src.cpp:90:1
56+
;; CHECK-NEXT: (call $foo
57+
;; CHECK-NEXT: ;;@ src.cpp:90:1
58+
;; CHECK-NEXT: (local.get $x)
59+
;; CHECK-NEXT: ;;@ src.cpp:90:1
60+
;; CHECK-NEXT: (local.get $y)
61+
;; CHECK-NEXT: )

0 commit comments

Comments
 (0)