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
504504 const decl = func.owner_decl;
505505 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
509509 var code_writer = std.ArrayList(u8).init(self.base.allocator);
510510 defer code_writer.deinit();
......@@ -542,7 +542,7 @@ pub fn updateDecl(self: *Wasm, module: *Module, decl: *Module.Decl) !void {
542542
543543 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
547547 if (decl.isExtern()) {
548548 return self.addOrUpdateImport(decl);
......@@ -827,7 +827,7 @@ pub fn freeDecl(self: *Wasm, decl: *Module.Decl) void {
827827 assert(self.imports.remove(atom.symbolLoc()));
828828 }
829829 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
831831 atom.deinit(self.base.allocator);
832832}
833833
src/link/Wasm/Atom.zig+1-6
......@@ -62,14 +62,9 @@ pub fn deinit(self: *Atom, gpa: Allocator) void {
6262
6363/// Sets the length of relocations and code to '0',
6464/// effectively resetting them and allowing them to be re-populated.
65pub fn clear(self: *Atom, gpa: Allocator) void {
65pub fn clear(self: *Atom) void {
6666 self.relocs.clearRetainingCapacity();
6767 self.code.clearRetainingCapacity();
68
69 // locals will be re-generated
70 for (self.locals.items) |*local| {
71 local.deinit(gpa);
72 }
7368}
7469
7570pub fn format(self: Atom, comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void {