Open ghost opened 3 years ago
I just had a thought: once #1717 comes through, extern const foo = fn ...
will be distinct from const foo = extern fn ...
, so manually specifying callconv(.abi)
won't be necessary. Specifying .any
and .coroutine
are already unnecessary, since the compiler will automatically detect and apply these anyway, so that leaves .naked
as the only cross-target callconv
argument. Come to think of it, allowing extern
on the value side (which we can do without ambiguity, as fn
, union
, struct
, enum
are all keywords), we don't need a callconv
keyword at all, if we can handle that pesky .naked
.
Perhaps a better solution would be to provide a keyword for naked functions, like the nakedcc
of old, infer any other compiler-fungible convention, and specify well-defined conventions with arguments to extern
. That's a separate proposal though.
The separate proposal is #7365.
As noted in Discord, what about architectures that do not have registers? Does anyone care?
While the example given in Discord was old (PDP-8) there are current systems that use such processors such as older versions of ARM GPUs and many TTAs. Others include the CPU in the TI-99 (TI-9900?) which sort of had registers, but they were just references to memory.
These systems are NOT common and it may be perfectly reasonable to not support them!
The current
std.builtin.CallingConvention
is very monolithic and x86-specific. If we want to support all the myriad calling conventions of all our supported architectures, this will get messy quickly. We should have a more modular structure.This could be as simple as
pub const CallingConvention = switch (arch) // etc.
, but we'll probably want a solution that's more consolidated with other architecture-specific details once we consolidate architecture-specific details. We may even consider redefiningCallingConvention
like so:This might also make it easier to implement custom backends without making invasive changes to the compiler.