Skip to content

Commit c49823e

Browse files
authored
fix: Use unique debug info per concrete function (AssemblyScript#2729)
1 parent cb7c9de commit c49823e

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

src/compiler.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9870,8 +9870,10 @@ export class Compiler extends DiagnosticEmitter {
98709870
let targetFunction = this.currentFlow.targetFunction;
98719871
let source = range.source;
98729872
if (source.debugInfoIndex < 0) source.debugInfoIndex = this.module.addDebugInfoFile(source.normalizedPath);
9873-
range.debugInfoRef = expr;
9874-
targetFunction.debugLocations.push(range);
9873+
// It's possible that an `expr` is seen multiple times, for example when
9874+
// first adding debug information for an inner expression and later on for
9875+
// an expression supposedly wrapping it, where the wrapping became a noop.
9876+
targetFunction.debugLocations.set(expr, range);
98759877
}
98769878

98779879
/** Checks whether a particular function signature is supported. */

src/diagnostics.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ export const enum DiagnosticCategory {
4545
export class Range {
4646

4747
source!: Source;
48-
debugInfoRef: usize = 0;
4948

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

src/program.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ import {
116116

117117
import {
118118
Module,
119+
ExpressionRef,
119120
FunctionRef,
120121
MemorySegment,
121122
getFunctionName
@@ -3749,8 +3750,8 @@ export class Function extends TypedElement {
37493750
contextualTypeArguments: Map<string,Type> | null;
37503751
/** Default control flow. */
37513752
flow!: Flow;
3752-
/** Remembered debug locations. */
3753-
debugLocations: Range[] = [];
3753+
/** Ordered debug locations by Binaryen expression reference. */
3754+
debugLocations: Map<ExpressionRef, Range> = new Map();
37543755
/** Function reference, if compiled. */
37553756
ref: FunctionRef = 0;
37563757
/** Varargs stub for calling with omitted arguments. */
@@ -3918,12 +3919,13 @@ export class Function extends TypedElement {
39183919
addDebugInfo(module: Module, ref: FunctionRef): void {
39193920
if (this.program.options.sourceMap) {
39203921
let debugLocations = this.debugLocations;
3921-
for (let i = 0, k = debugLocations.length; i < k; ++i) {
3922-
let range = debugLocations[i];
3922+
for (let _keys = Map_keys(debugLocations), i = 0, k = _keys.length; i < k; ++i) {
3923+
let expressionRef = _keys[i];
3924+
let range = assert(debugLocations.get(expressionRef));
39233925
let source = range.source;
39243926
module.setDebugLocation(
39253927
ref,
3926-
range.debugInfoRef,
3928+
expressionRef,
39273929
source.debugInfoIndex,
39283930
source.lineAt(range.start),
39293931
source.columnAt() - 1 // source maps are 0-based

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy