zig icon indicating copy to clipboard operation
zig copied to clipboard

Lower comptime field ptrs

Open Vexu opened this issue 1 year ago • 3 comments

Salvaging the useful parts of #19347

Closes #12963

Vexu avatar Mar 24 '24 07:03 Vexu

This contradicts #19414 - since comptime-vars are semantically mutable (albeit only with the ability to store the "correct" value), pointers to them are disallowed at runtime for all the same reasons as normal comptime vars.

mlugg avatar Mar 24 '24 14:03 mlugg

It shouldn't since these are pointers to comptime-fields not pointers to fields of comptime-var structs.

Vexu avatar Mar 24 '24 18:03 Vexu

Oops, sorry, typo in my earlier comment. That should say "comptime fields", not "comptime vars".

The problem, in short, is that comptime fields are weird -- pointers to them are considered mutable, it's just that Sema will emit a compile error if the stored value differs from the default. If we want to allow pointers to comptime fields to be emitted into runtime code, we will need to change the language to not consider comptime fields mutable, although probably special-case initialization expression to allow setting them (provided, of course, that the given value matches the default).

mlugg avatar Mar 24 '24 18:03 mlugg