Skip to content

Use unique debug info per concrete function #2729

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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