Skip to content

Commit

Permalink
Fix: remove excess optimization for sourcemap
Browse files Browse the repository at this point in the history
  • Loading branch information
chen ruixiang committed Mar 6, 2023
1 parent 661fe5e commit cd260b6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 20 deletions.
10 changes: 1 addition & 9 deletions src/passes/Print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2521,7 +2521,6 @@ struct PrintSExpression : public UnifiedExpressionVisitor<PrintSExpression> {

Module* currModule = nullptr;
Function* currFunction = nullptr;
Function::DebugLocation lastPrintedLocation;
bool debugInfo;

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

void printDebugLocation(const Function::DebugLocation& location) {
if (lastPrintedLocation == location) {
return;
}
lastPrintedLocation = location;
auto fileName = currModule->debugInfoFileNames[location.fileIndex];
o << ";;@ " << fileName << ":" << location.lineNumber << ":"
<< location.columnNumber << '\n';
Expand Down Expand Up @@ -3100,7 +3095,6 @@ struct PrintSExpression : public UnifiedExpressionVisitor<PrintSExpression> {
void visitImportedFunction(Function* curr) {
doIndent(o, indent);
currFunction = curr;
lastPrintedLocation = {0, 0, 0};
o << '(';
emitImportHeader(curr);
handleSignature(curr->getSig(), curr->name);
Expand All @@ -3110,7 +3104,6 @@ struct PrintSExpression : public UnifiedExpressionVisitor<PrintSExpression> {
void visitDefinedFunction(Function* curr) {
doIndent(o, indent);
currFunction = curr;
lastPrintedLocation = {0, 0, 0};
if (currFunction->prologLocation.size()) {
printDebugLocation(*currFunction->prologLocation.begin());
}
Expand Down Expand Up @@ -3168,8 +3161,7 @@ struct PrintSExpression : public UnifiedExpressionVisitor<PrintSExpression> {
// Print the stack IR.
printStackIR(curr->stackIR.get(), o, curr);
}
if (currFunction->epilogLocation.size() &&
lastPrintedLocation != *currFunction->epilogLocation.begin()) {
if (currFunction->epilogLocation.size()) {
// Print last debug location: mix of decIndent and printDebugLocation
// logic.
doIndent(o, indent);
Expand Down
2 changes: 0 additions & 2 deletions src/wasm-binary.h
Original file line number Diff line number Diff line change
Expand Up @@ -1341,7 +1341,6 @@ class WasmBinaryWriter {
void writeDylinkSection();
void writeLegacyDylinkSection();

void initializeDebugInfo();
void writeSourceMapProlog();
void writeSourceMapEpilog();
void writeDebugLocation(const Function::DebugLocation& loc);
Expand Down Expand Up @@ -1402,7 +1401,6 @@ class WasmBinaryWriter {
std::vector<std::pair<size_t, const Function::DebugLocation*>>
sourceMapLocations;
size_t sourceMapLocationsSizeAtSectionStart;
Function::DebugLocation lastDebugLocation;

std::unique_ptr<ImportInfo> importInfo;

Expand Down
9 changes: 0 additions & 9 deletions src/wasm/wasm-binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ void WasmBinaryWriter::write() {

writeDylinkSection();

initializeDebugInfo();
if (sourceMap) {
writeSourceMapProlog();
}
Expand Down Expand Up @@ -1117,10 +1116,6 @@ void WasmBinaryWriter::writeSymbolMap() {
file.close();
}

void WasmBinaryWriter::initializeDebugInfo() {
lastDebugLocation = {0, /* lineNumber = */ 1, 0};
}

void WasmBinaryWriter::writeSourceMapProlog() {
*sourceMap << "{\"version\":3,\"sources\":[";
for (size_t i = 0; i < wasm->debugInfoFileNames.size(); i++) {
Expand Down Expand Up @@ -1301,12 +1296,8 @@ void WasmBinaryWriter::writeDylinkSection() {
}

void WasmBinaryWriter::writeDebugLocation(const Function::DebugLocation& loc) {
if (loc == lastDebugLocation) {
return;
}
auto offset = o.size();
sourceMapLocations.emplace_back(offset, &loc);
lastDebugLocation = loc;
}

void WasmBinaryWriter::writeDebugLocation(Expression* curr, Function* func) {
Expand Down
14 changes: 14 additions & 0 deletions test/lit/source-map.wast
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@
;;@ src.cpp:80:1
(local.get $y)
)
;;@ src.cpp:90:1
(call $foo
;;@ src.cpp:90:1
(local.get $x)
;;@ src.cpp:90:1
(local.get $y)
)
)
)

Expand All @@ -45,3 +52,10 @@
;; CHECK-NEXT: ;;@ src.cpp:80:1
;; CHECK-NEXT: (local.get $y)
;; CHECK-NEXT: )
;; CHECK-NEXT: ;;@ src.cpp:90:1
;; CHECK-NEXT: (call $foo
;; CHECK-NEXT: ;;@ src.cpp:90:1
;; CHECK-NEXT: (local.get $x)
;; CHECK-NEXT: ;;@ src.cpp:90:1
;; CHECK-NEXT: (local.get $y)
;; CHECK-NEXT: )

0 comments on commit cd260b6

Please sign in to comment.