fixing recurrent panic
All checks were successful
Build / build (push) Successful in 2m14s
Test / build (push) Successful in 7m13s

This commit is contained in:
2026-01-27 22:55:02 +01:00
parent 1ad7b644c4
commit 57de432d0b
7 changed files with 639 additions and 304 deletions

View File

@@ -99,7 +99,7 @@ pub fn init(allocator: std.mem.Allocator, source: []const SpvWord, options: Modu
.output_locations = std.ArrayList(SpvWord).empty,
.bindings = std.AutoHashMap(SpvBinding, Value).init(allocator),
});
errdefer self.deinit(allocator);
errdefer allocator.free(self.code);
op.initRuntimeDispatcher();
@@ -123,9 +123,16 @@ pub fn init(allocator: std.mem.Allocator, source: []const SpvWord, options: Modu
self.bound = self.it.next() catch return ModuleError.InvalidSpirV;
self.results = allocator.alloc(Result, self.bound) catch return ModuleError.OutOfMemory;
errdefer allocator.free(self.results);
for (self.results) |*result| {
result.* = Result.init();
}
errdefer {
for (self.results) |*result| {
result.deinit(allocator);
}
}
_ = self.it.skip(); // Skip schema

View File

@@ -176,6 +176,7 @@ pub const Value = union(Type) {
}
break :blk self;
},
.RuntimeArray => .{ .RuntimeArray = .{} },
else => unreachable,
},
else => unreachable,
@@ -322,9 +323,7 @@ pub const VariantData = union(Variant) {
const Self = @This();
name: ?[]const u8,
decorations: std.ArrayList(Decoration),
variant: ?VariantData,
pub fn init() Self {

View File

@@ -158,6 +158,7 @@ pub const SetupDispatcher = block: {
.TypeInt = opTypeInt,
.TypeMatrix = opTypeMatrix,
.TypePointer = opTypePointer,
.TypeRuntimeArray = opTypeRuntimeArray,
.TypeStruct = opTypeStruct,
.TypeVector = opTypeVector,
.TypeVoid = opTypeVoid,
@@ -1248,6 +1249,7 @@ fn opFunction(allocator: std.mem.Allocator, _: SpvWord, rt: *Runtime) RuntimeErr
rt.mod.results[function_type_id].variant.?.Type.Function.source_location = source_location;
rt.current_function = &rt.mod.results[id];
rt.current_parameter_index = 0;
}
fn opFunctionCall(allocator: std.mem.Allocator, _: SpvWord, rt: *Runtime) RuntimeError!void {
@@ -1519,6 +1521,15 @@ fn opTypePointer(_: std.mem.Allocator, _: SpvWord, rt: *Runtime) RuntimeError!vo
};
}
fn opTypeRuntimeArray(_: std.mem.Allocator, _: SpvWord, rt: *Runtime) RuntimeError!void {
const id = try rt.it.next();
rt.mod.results[id].variant = .{
.Type = .{
.RuntimeArray = .{},
},
};
}
fn opTypeStruct(allocator: std.mem.Allocator, word_count: SpvWord, rt: *Runtime) RuntimeError!void {
const id = try rt.it.next();
const members_type_word = blk: {