Skip to content

Commit 4037e8a

Browse files
committed
fix windows segfault
1 parent 7e2cf43 commit 4037e8a

File tree

1 file changed

+8
-29
lines changed

1 file changed

+8
-29
lines changed

src/build/builtin_compiler/main.zig

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,12 @@ fn replaceStrIsEmptyWithLowLevel(env: *ModuleEnv) !std.ArrayList(CIR.Def.Idx) {
337337
}
338338

339339
// Iterate through all defs and replace matching anno-only defs with low-level implementations
340-
const all_defs = env.store.sliceDefs(env.all_defs);
341-
for (all_defs) |def_idx| {
340+
const all_defs_slice = env.store.sliceDefs(env.all_defs);
341+
var def_indices = std.ArrayList(CIR.Def.Idx).empty;
342+
defer def_indices.deinit(gpa);
343+
try def_indices.appendSlice(gpa, all_defs_slice);
344+
345+
for (def_indices.items) |def_idx| {
342346
const def = env.store.getDef(def_idx);
343347
const expr = env.store.getExpr(def.expr);
344348

@@ -371,7 +375,7 @@ fn replaceStrIsEmptyWithLowLevel(env: *ModuleEnv) !std.ArrayList(CIR.Def.Idx) {
371375
const arg_pattern_idx = try env.addPattern(.{ .assign = .{ .ident = arg_ident } }, base.Region.zero());
372376
try env.store.scratch.?.patterns.append(arg_pattern_idx);
373377
}
374-
const args_span = CIR.Pattern.Span{ .span = .{ .start = @intCast(patterns_start), .len = num_params } };
378+
const args_span = try env.store.patternSpanFrom(patterns_start);
375379

376380
// Create an e_runtime_error body that crashes when the function is called
377381
const error_msg_lit = try env.insertString("Low-level builtin not yet implemented in interpreter");
@@ -825,32 +829,7 @@ fn compileModule(
825829
defer new_def_indices.deinit(gpa);
826830

827831
if (new_def_indices.items.len > 0) {
828-
// Rebuild all_defs span to include both old and new defs
829-
// First, get the old def indices from extra_data
830-
const old_span = module_env.all_defs.span;
831-
const old_def_count = old_span.len;
832-
833-
// Allocate new space in extra_data for all defs (old + new)
834-
const new_span_start: u32 = @intCast(module_env.store.extra_data.len());
835-
836-
// Copy old def indices
837-
var i: u32 = 0;
838-
while (i < old_def_count) : (i += 1) {
839-
const idx = @as(collections.SafeList(u32).Idx, @enumFromInt(old_span.start + i));
840-
const old_def_idx = module_env.store.extra_data.get(idx).*;
841-
_ = try module_env.store.extra_data.append(gpa, old_def_idx);
842-
}
843-
844-
// Append new def indices
845-
for (new_def_indices.items) |new_def_idx| {
846-
_ = try module_env.store.extra_data.append(gpa, @intFromEnum(new_def_idx));
847-
}
848-
849-
// Update all_defs to point to the new span
850-
module_env.all_defs.span.start = new_span_start;
851-
module_env.all_defs.span.len = old_def_count + @as(u32, @intCast(new_def_indices.items.len));
852-
853-
// Rebuild the dependency graph and evaluation order to include new defs
832+
// Rebuild the dependency graph and evaluation order to include the updated defs
854833
const DependencyGraph = @import("can").DependencyGraph;
855834
var graph = try DependencyGraph.buildDependencyGraph(
856835
module_env,

0 commit comments

Comments
 (0)