[Proposal] Allow @export
to export any value, not just a declaration
#14911
Labels
Milestone
@export
to export any value, not just a declaration
#14911
Currently, the first argument to
@export
needs to be a name of some sort. Quoting from the documentation:Once #14796 lands, this restriction seems pretty needless.
@export(comptime get_my_u32(), .{ .name = "foo" })
has a clear meaning which is no harder to lower (you just need the behaviour implemented in that PR). The only necessary restriction on this builtin is that the first argument is:Put more simply, it's just any expression
x
where&x
is comptime-known.Exporting an arbitrary comptime-known expression is already possible by simply putting it in a
const
first (since that variable is comptime-known, it is then able to be exported). But making this change would simplify the language by removing a needless restriction.An alternative approach, which is arguably clearer, is to make
@export
actually take a pointer; so rather than@export(foo, ...)
, you have to do@export(&foo, ...)
. This makes@export
a nice parallel to@extern
, as well as making@export
even less of a special-case: it has no specific restrictions on its argument at all other than that it has to be a comptime-known pointer. I don't have strong feelings either way on this.The text was updated successfully, but these errors were encountered: