authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-06-18 04:30:06+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-06-18 04:30:06+01:00
logedf14777bae56c3a6a155c59f793dc432656c1de
treec58ec953c2f038b9bf6c759ee9231162350c4e1f
parentf37d0725fa4c6a0b5e4e9ca4d25e2760dc06764d
signaturelock-open Commit is signed but in an unrecognized format.

link.Wasm: correctly fetch source location when decl is a type

The comment explains the situation here. This is a bit of a hack, and should be reworked when `Decl` is properly split up.

1 files changed, 11 insertions(+), 1 deletions(-)

src/link/Wasm/ZigObject.zig+11-1
......@@ -484,7 +484,17 @@ pub fn lowerUnnamedConst(zig_object: *ZigObject, wasm_file: *Wasm, val: Value, d
484484 });
485485 defer gpa.free(name);
486486
487 switch (try zig_object.lowerConst(wasm_file, name, val, decl.navSrcLoc(mod).upgrade(mod))) {
487 // We want to lower the source location of `decl`. However, when generating
488 // lazy functions (for e.g. `@tagName`), `decl` may correspond to a type
489 // rather than a `Nav`!
490 // The future split of `Decl` into `Nav` and `Cau` may require rethinking this
491 // logic. For now, just get the source location conditionally as needed.
492 const decl_src = if (decl.typeOf(mod).toIntern() == .type_type)
493 decl.val.toType().srcLoc(mod)
494 else
495 decl.navSrcLoc(mod);
496
497 switch (try zig_object.lowerConst(wasm_file, name, val, decl_src.upgrade(mod))) {
488498 .ok => |atom_index| {
489499 try wasm_file.getAtomPtr(parent_atom_index).locals.append(gpa, atom_index);
490500 return @intFromEnum(wasm_file.getAtom(atom_index).sym_index);