Hey compiler team! I'm working on a builtin that emits a Builtin.RawPointer
. However, the emitted code is failable and I need to express that. Right now I'm checking if the bit pattern of the raw pointer equals 0
, but this seems like the wrong abstraction. Options I see are:
- Continue to check the bit pattern*,
- Return a
Builtin.Word
instead (and cast toUnsafeMutableRawPointer
after checking for0
*), or - Figure out how to return
Builtin.RawPointer?
i.e. an optional.
I'd prefer the third option, but I don't seem to be able to convince IRGenFunction
to accept a pointer value as such a thing. There aren't any other builtins that currently return optional values so I can't just crib from them. Any thoughts on the right way forward?
* Presumably there's no immediate plans to deploy Swift on a CPU architecture or operating system where a NULL
pointer's bit pattern is not all zeroes.