Odin
Odin copied to clipboard
Add `@(default_context)` and `intrinsics.__default_context`
The __default_context intrinsic calls the procedure marked with@(default_context) if it exists and returns true. If it does not exist, it returns false.
The @(default_context) is a file-scope procedure attribute that designates a procedure fitting the signature of proc "contextless" (^runtime.Context) as the procedure which will initialize all default contexts used throughout the entire program, including @(init) initializers, global variables, shared library initializers and shared global variables.
This change gives the programmer full control over the Odin context, and hence allocation, throughout all initialization that happens before main is reached.
Currently, @(default_context) is only supported in full executable builds, including -build-mode:test.
Fixes #5136
Presently, the test suite I added for this is failing only on Windows. ~~I am unable to debug it for lack of the platform, so~~ any help is appreciated.
Given that only the shared global and shared @(init) are failing, I suspect there are linkage particulars involved here, possibly order-related. I had to set __init_context to be linkage "weak" by default and "strong" for the executable build in order to link correctly on Linux with a single module build in -o:speed mode. I tried setting it to "internal" and "link_once" for Windows only instead of "weak" to exhaust the other linkage options, but neither proved to work on my testing commits against the CI; ~~someone on Windows will have to investigate this, unfortunately.~~
Pinging @karl-zylinski to see if this works for the original problem and @laytan as I've iterated on his original idea.