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
This commit is contained in:
Luuk de Gram 2022-03-06 22:38:10 +01:00 committed by Jakub Konka
parent 27c084065a
commit c7e4c711fc
2 changed files with 4 additions and 9 deletions

View File

@ -504,7 +504,7 @@ pub fn updateFunc(self: *Wasm, module: *Module, func: *Module.Fn, air: Air, live
const decl = func.owner_decl;
assert(decl.link.wasm.sym_index != 0); // Must call allocateDeclIndexes()
decl.link.wasm.clear(self.base.allocator);
decl.link.wasm.clear();
var code_writer = std.ArrayList(u8).init(self.base.allocator);
defer code_writer.deinit();
@ -542,7 +542,7 @@ pub fn updateDecl(self: *Wasm, module: *Module, decl: *Module.Decl) !void {
assert(decl.link.wasm.sym_index != 0); // Must call allocateDeclIndexes()
decl.link.wasm.clear(self.base.allocator);
decl.link.wasm.clear();
if (decl.isExtern()) {
return self.addOrUpdateImport(decl);
@ -827,7 +827,7 @@ pub fn freeDecl(self: *Wasm, decl: *Module.Decl) void {
assert(self.imports.remove(atom.symbolLoc()));
}
assert(self.resolved_symbols.swapRemove(atom.symbolLoc()));
assert(self.symbol_atom.remove(atom.symbolLoc()));
_ = self.symbol_atom.remove(atom.symbolLoc()); // not all decl's exist in symbol_atom
atom.deinit(self.base.allocator);
}

View File

@ -62,14 +62,9 @@ pub fn deinit(self: *Atom, gpa: Allocator) void {
/// Sets the length of relocations and code to '0',
/// effectively resetting them and allowing them to be re-populated.
pub fn clear(self: *Atom, gpa: Allocator) void {
pub fn clear(self: *Atom) void {
self.relocs.clearRetainingCapacity();
self.code.clearRetainingCapacity();
// locals will be re-generated
for (self.locals.items) |*local| {
local.deinit(gpa);
}
}
pub fn format(self: Atom, comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void {