authorgravatar for luuk@degram.devLuuk de Gram <luuk@degram.dev> 2022-03-06 22:38:10+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-03-06 23:33:50+01:00
logc7e4c711fc5795e66f974316611922a0b962eb99
tree71ea7a30dc840d640b55d632294603c0bc920df1
parent27c084065abcc404b7f58562f802999ae3ebce10

wasm: Fix incremental compilation

- atoms may have relocations, so freeing them when we update the parent atom will cause segfaults. - Not all declarations will live in symbol_atom

2 files changed, 4 insertions(+), 9 deletions(-)

src/link/Wasm.zig+3-3
...@@ -504,7 +504,7 @@ pub fn updateFunc(self: *Wasm, module: *Module, func: *Module.Fn, air: Air, live...@@ -504,7 +504,7 @@ pub fn updateFunc(self: *Wasm, module: *Module, func: *Module.Fn, air: Air, live
504 const decl = func.owner_decl;504 const decl = func.owner_decl;
505 assert(decl.link.wasm.sym_index != 0); // Must call allocateDeclIndexes()505 assert(decl.link.wasm.sym_index != 0); // Must call allocateDeclIndexes()
506506
507 decl.link.wasm.clear(self.base.allocator);507 decl.link.wasm.clear();
508508
509 var code_writer = std.ArrayList(u8).init(self.base.allocator);509 var code_writer = std.ArrayList(u8).init(self.base.allocator);
510 defer code_writer.deinit();510 defer code_writer.deinit();
...@@ -542,7 +542,7 @@ pub fn updateDecl(self: *Wasm, module: *Module, decl: *Module.Decl) !void {...@@ -542,7 +542,7 @@ pub fn updateDecl(self: *Wasm, module: *Module, decl: *Module.Decl) !void {
542542
543 assert(decl.link.wasm.sym_index != 0); // Must call allocateDeclIndexes()543 assert(decl.link.wasm.sym_index != 0); // Must call allocateDeclIndexes()
544544
545 decl.link.wasm.clear(self.base.allocator);545 decl.link.wasm.clear();
546546
547 if (decl.isExtern()) {547 if (decl.isExtern()) {
548 return self.addOrUpdateImport(decl);548 return self.addOrUpdateImport(decl);
...@@ -827,7 +827,7 @@ pub fn freeDecl(self: *Wasm, decl: *Module.Decl) void {...@@ -827,7 +827,7 @@ pub fn freeDecl(self: *Wasm, decl: *Module.Decl) void {
827 assert(self.imports.remove(atom.symbolLoc()));827 assert(self.imports.remove(atom.symbolLoc()));
828 }828 }
829 assert(self.resolved_symbols.swapRemove(atom.symbolLoc()));829 assert(self.resolved_symbols.swapRemove(atom.symbolLoc()));
830 assert(self.symbol_atom.remove(atom.symbolLoc()));830 _ = self.symbol_atom.remove(atom.symbolLoc()); // not all decl's exist in symbol_atom
831 atom.deinit(self.base.allocator);831 atom.deinit(self.base.allocator);
832}832}
833833
src/link/Wasm/Atom.zig+1-6
...@@ -62,14 +62,9 @@ pub fn deinit(self: *Atom, gpa: Allocator) void {...@@ -62,14 +62,9 @@ pub fn deinit(self: *Atom, gpa: Allocator) void {
6262
63/// Sets the length of relocations and code to '0',63/// Sets the length of relocations and code to '0',
64/// effectively resetting them and allowing them to be re-populated.64/// effectively resetting them and allowing them to be re-populated.
65pub fn clear(self: *Atom, gpa: Allocator) void {65pub fn clear(self: *Atom) void {
66 self.relocs.clearRetainingCapacity();66 self.relocs.clearRetainingCapacity();
67 self.code.clearRetainingCapacity();67 self.code.clearRetainingCapacity();
68
69 // locals will be re-generated
70 for (self.locals.items) |*local| {
71 local.deinit(gpa);
72 }
73}68}
7469
75pub fn format(self: Atom, comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void {70pub fn format(self: Atom, comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void {