Skip to content

Commit 3efdd01

Browse files
committed
Switch some fallbacks to debug asserts
1 parent d89f5ee commit 3efdd01

File tree

3 files changed

+3
-23
lines changed

3 files changed

+3
-23
lines changed

src/canonicalize/NodeStore.zig

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2626,14 +2626,9 @@ pub fn clearScratchDefsFrom(store: *NodeStore, start: u32) void {
26262626
}
26272627

26282628
/// Creates a slice corresponding to a span.
2629-
/// Returns an empty slice if the span is out of bounds (can happen with corrupted malformed code).
26302629
pub fn sliceFromSpan(store: *const NodeStore, comptime T: type, span: base.DataSpan) []T {
26312630
const extra_data_len = store.extra_data.items.items.len;
2632-
// Bounds check: ensure the span doesn't exceed the extra_data length
2633-
if (span.start >= extra_data_len or span.start + span.len > extra_data_len) {
2634-
// Return empty slice for corrupted spans
2635-
return &[_]T{};
2636-
}
2631+
std.debug.assert(span.start + span.len <= extra_data_len);
26372632
return @ptrCast(store.extra_data.items.items[span.start..][0..span.len]);
26382633
}
26392634

src/check/Check.zig

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -524,15 +524,7 @@ fn instantiateVarHelp(
524524
env: *Env,
525525
region_behavior: InstantiateRegionBehavior,
526526
) std.mem.Allocator.Error!Var {
527-
// Guard against corrupted vars from malformed code (e.g., uninitialized memory)
528-
const var_idx: u64 = @intFromEnum(var_to_instantiate);
529-
const type_store_len = self.types.len();
530-
if (var_idx >= type_store_len) {
531-
// Return a fresh error var for corrupted input - this properly maintains sync
532-
const fresh_error_var = try self.types.freshFromContentWithRank(.err, env.rank());
533-
try self.fillInRegionsThrough(fresh_error_var);
534-
return fresh_error_var;
535-
}
527+
std.debug.assert(@intFromEnum(var_to_instantiate) < self.types.len());
536528

537529
// First, reset state
538530
instantiator.var_map.clearRetainingCapacity();

src/types/instantiate.zig

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,7 @@ pub const Instantiator = struct {
7373
self: *Self,
7474
initial_var: Var,
7575
) std.mem.Allocator.Error!Var {
76-
// Guard against corrupted vars from malformed code (e.g., uninitialized memory)
77-
// We return var 0 (which always exists) rather than creating a new var,
78-
// since we can't create new vars here without causing array sync issues
79-
const var_idx: u64 = @intFromEnum(initial_var);
80-
const store_len = self.store.len();
81-
if (var_idx >= store_len) {
82-
return @enumFromInt(0);
83-
}
76+
std.debug.assert(@intFromEnum(initial_var) < self.store.len());
8477

8578
const resolved = self.store.resolveVar(initial_var);
8679
const resolved_var = resolved.var_;

0 commit comments

Comments
 (0)