Skip to content

Commit 0ef8b89

Browse files
committed
reflect: remove comptime var pointer returns
Following ziglang/zig#19414 and https://ziggit.dev/t/comptime-mutable-memory-changes/3702 change in zig, we cannot return `comptime var` pointer anymore.
1 parent 6e8f6ff commit 0ef8b89

File tree

3 files changed

+23
-16
lines changed

3 files changed

+23
-16
lines changed

src/block.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ const Pull = struct {
9999
/// (See https://github.com/ziglang/zig/issues/8289)
100100
pub fn block(
101101
comptime T: type,
102-
items: []T,
102+
comptime items: []const T,
103103
context: anytype,
104104
comptime lessThan: fn (@TypeOf(context), lhs: T, rhs: T) bool,
105105
) void {

src/generate.zig

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@ const loadFn = @import("private_api.zig").loadFn;
2424
// reflect the user-defined types to obtain type information (T_refl)
2525
// This function must be called at comptime by the root file of the project
2626
// and stored in a constant named `Types`
27-
pub fn reflect(comptime types: anytype) []refl.Struct {
27+
pub fn reflect(comptime types: anytype) []const refl.Struct {
2828
std.debug.assert(@inComptime());
2929

3030
// call types reflection
31-
return refl.do(types) catch unreachable;
31+
@compileLog(refl.do(types));
32+
return refl.do(types) catch |e| @compileError(e);
3233
}
3334

3435
// Import user-defined types

src/reflect.zig

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ pub const Type = struct {
241241
}
242242

243243
// check that user-defined types have been provided as an API
244-
pub fn lookup(comptime self: *Type, comptime structs: []Struct) Error!void {
244+
pub fn lookup(comptime self: *Type, comptime structs: []const Struct) Error!void {
245245
std.debug.assert(@inComptime());
246246

247247
// lookup unecessary
@@ -462,7 +462,7 @@ pub const Func = struct {
462462

463463
setter_index: ?u8, // TODO: not ideal, is there a cleaner solution?
464464

465-
fn lookupTypes(comptime self: *Func, comptime structs: []Struct) Error!void {
465+
fn lookupTypes(comptime self: *const Func, comptime structs: []const Struct) Error!void {
466466
inline for (self.args) |*arg| {
467467
try arg.lookup(structs);
468468
}
@@ -738,12 +738,12 @@ pub const Struct = struct {
738738
has_constructor: bool,
739739
constructor: Func,
740740

741-
getters: []Func,
742-
setters: []Func,
743-
methods: []Func,
741+
getters: []const Func,
742+
setters: []const Func,
743+
methods: []const Func,
744744

745745
// nested types
746-
nested: []StructNested,
746+
nested: []const StructNested,
747747

748748
pub fn Self(comptime self: Struct) type {
749749
comptime {
@@ -784,7 +784,7 @@ pub const Struct = struct {
784784
return @sizeOf(self.Self()) == 0;
785785
}
786786

787-
fn lookupTypes(comptime self: *Struct, comptime structs: []Struct) Error!void {
787+
fn lookupTypes(comptime self: *Struct, comptime structs: []const Struct) Error!void {
788788
try self.value.lookup(structs);
789789
if (self.has_constructor) {
790790
try self.constructor.lookupTypes(structs);
@@ -1323,6 +1323,11 @@ pub const Struct = struct {
13231323
}
13241324
}
13251325

1326+
const final_getters = getters;
1327+
const final_setters = setters;
1328+
const final_methods = methods;
1329+
const final_nested = nested;
1330+
13261331
return Struct{
13271332
// struct info
13281333
.name = struct_name,
@@ -1343,12 +1348,12 @@ pub const Struct = struct {
13431348
// struct functions
13441349
.has_constructor = has_constructor,
13451350
.constructor = constructor,
1346-
.getters = getters[0..],
1347-
.setters = setters[0..],
1348-
.methods = methods[0..],
1351+
.getters = &final_getters,
1352+
.setters = &final_setters,
1353+
.methods = &final_methods,
13491354

13501355
// nested types
1351-
.nested = nested[0..],
1356+
.nested = &final_nested,
13521357
};
13531358
}
13541359
};
@@ -1432,7 +1437,7 @@ fn lookupException(comptime all: []Struct) Error!void {
14321437
}
14331438
}
14341439

1435-
pub fn do(comptime types: anytype) Error![]Struct {
1440+
pub fn do(comptime types: anytype) Error![]const Struct {
14361441
comptime {
14371442

14381443
// check types provided
@@ -1475,7 +1480,8 @@ pub fn do(comptime types: anytype) Error![]Struct {
14751480
try s.lookupTypes(&all);
14761481
}
14771482

1478-
return &all;
1483+
const final = all;
1484+
return &final;
14791485
}
14801486
}
14811487

0 commit comments

Comments
 (0)