Skip to content

Commit

Permalink
fix: Use unique debug info per concrete function (#2729)
Browse files Browse the repository at this point in the history
  • Loading branch information
dcodeIO authored Jul 31, 2023
1 parent cb7c9de commit c49823e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
6 changes: 4 additions & 2 deletions src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9870,8 +9870,10 @@ export class Compiler extends DiagnosticEmitter {
let targetFunction = this.currentFlow.targetFunction;
let source = range.source;
if (source.debugInfoIndex < 0) source.debugInfoIndex = this.module.addDebugInfoFile(source.normalizedPath);
range.debugInfoRef = expr;
targetFunction.debugLocations.push(range);
// It's possible that an `expr` is seen multiple times, for example when
// first adding debug information for an inner expression and later on for
// an expression supposedly wrapping it, where the wrapping became a noop.
targetFunction.debugLocations.set(expr, range);
}

/** Checks whether a particular function signature is supported. */
Expand Down
1 change: 0 additions & 1 deletion src/diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ export const enum DiagnosticCategory {
export class Range {

source!: Source;
debugInfoRef: usize = 0;

constructor(public start: i32, public end: i32) {}

Expand Down
12 changes: 7 additions & 5 deletions src/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ import {

import {
Module,
ExpressionRef,
FunctionRef,
MemorySegment,
getFunctionName
Expand Down Expand Up @@ -3749,8 +3750,8 @@ export class Function extends TypedElement {
contextualTypeArguments: Map<string,Type> | null;
/** Default control flow. */
flow!: Flow;
/** Remembered debug locations. */
debugLocations: Range[] = [];
/** Ordered debug locations by Binaryen expression reference. */
debugLocations: Map<ExpressionRef, Range> = new Map();
/** Function reference, if compiled. */
ref: FunctionRef = 0;
/** Varargs stub for calling with omitted arguments. */
Expand Down Expand Up @@ -3918,12 +3919,13 @@ export class Function extends TypedElement {
addDebugInfo(module: Module, ref: FunctionRef): void {
if (this.program.options.sourceMap) {
let debugLocations = this.debugLocations;
for (let i = 0, k = debugLocations.length; i < k; ++i) {
let range = debugLocations[i];
for (let _keys = Map_keys(debugLocations), i = 0, k = _keys.length; i < k; ++i) {
let expressionRef = _keys[i];
let range = assert(debugLocations.get(expressionRef));
let source = range.source;
module.setDebugLocation(
ref,
range.debugInfoRef,
expressionRef,
source.debugInfoIndex,
source.lineAt(range.start),
source.columnAt() - 1 // source maps are 0-based
Expand Down

0 comments on commit c49823e

Please sign in to comment.