#Is `null` passed to an optional argument considered comptime-known?

1 messages · Page 1 of 1 (latest)

naive crystal
#

I’m trying to understand whether passing null as a value to an optional argument of a function is considered comptime by the compiler, and if it can optimize away paths that follow in case of null. Here’s a trivial example:
https://godbolt.org/z/51zqf6Tso
I barely know assembly but I noticed that the loop in the example disappeared.

#

In my real code, I'd like to use null as a comptime mark to change/remove loop condition (in the same way it is shown at line 3).

still glade
#

arguments to (non-inline) fns, which aren't of comptime-only types, nor marked comptime, are considered runtime known.
LLVM is smart enough to do its own optimisations, but they're beyond Zig's semantics