From cd260b604037b16c1d5574b3b5feb4308de20e84 Mon Sep 17 00:00:00 2001 From: chen ruixiang Date: Mon, 6 Mar 2023 15:46:19 +0800 Subject: [PATCH] Fix: remove excess optimization for sourcemap --- src/passes/Print.cpp | 10 +--------- src/wasm-binary.h | 2 -- src/wasm/wasm-binary.cpp | 9 --------- test/lit/source-map.wast | 14 ++++++++++++++ 4 files changed, 15 insertions(+), 20 deletions(-) diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp index 4a4fe60c76d..67a7d70b39a 100644 --- a/src/passes/Print.cpp +++ b/src/passes/Print.cpp @@ -2521,7 +2521,6 @@ struct PrintSExpression : public UnifiedExpressionVisitor { Module* currModule = nullptr; Function* currFunction = nullptr; - Function::DebugLocation lastPrintedLocation; bool debugInfo; // Used to print delegate's depth argument when it throws to the caller @@ -2535,10 +2534,6 @@ struct PrintSExpression : public UnifiedExpressionVisitor { } 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'; @@ -3100,7 +3095,6 @@ struct PrintSExpression : public UnifiedExpressionVisitor { void visitImportedFunction(Function* curr) { doIndent(o, indent); currFunction = curr; - lastPrintedLocation = {0, 0, 0}; o << '('; emitImportHeader(curr); handleSignature(curr->getSig(), curr->name); @@ -3110,7 +3104,6 @@ struct PrintSExpression : public UnifiedExpressionVisitor { void visitDefinedFunction(Function* curr) { doIndent(o, indent); currFunction = curr; - lastPrintedLocation = {0, 0, 0}; if (currFunction->prologLocation.size()) { printDebugLocation(*currFunction->prologLocation.begin()); } @@ -3168,8 +3161,7 @@ struct PrintSExpression : public UnifiedExpressionVisitor { // 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); diff --git a/src/wasm-binary.h b/src/wasm-binary.h index f09094c9df6..137c9be7be5 100644 --- a/src/wasm-binary.h +++ b/src/wasm-binary.h @@ -1341,7 +1341,6 @@ class WasmBinaryWriter { void writeDylinkSection(); void writeLegacyDylinkSection(); - void initializeDebugInfo(); void writeSourceMapProlog(); void writeSourceMapEpilog(); void writeDebugLocation(const Function::DebugLocation& loc); @@ -1402,7 +1401,6 @@ class WasmBinaryWriter { std::vector> sourceMapLocations; size_t sourceMapLocationsSizeAtSectionStart; - Function::DebugLocation lastDebugLocation; std::unique_ptr importInfo; diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index 72f99c033e9..14347fe9b6b 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -43,7 +43,6 @@ void WasmBinaryWriter::write() { writeDylinkSection(); - initializeDebugInfo(); if (sourceMap) { writeSourceMapProlog(); } @@ -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++) { @@ -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) { diff --git a/test/lit/source-map.wast b/test/lit/source-map.wast index fcb5e1dd3d2..ea0eeb9e830 100644 --- a/test/lit/source-map.wast +++ b/test/lit/source-map.wast @@ -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) + ) ) ) @@ -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: )