Skip to content

Conversation

@gottesmm
Copy link
Contributor

This should make it easier to add new builtins by "following the warnings" and
prevent us from not handling a builtin in IRGen.

When I did this, I discovered that if I did this naively, we would have
AddressOf show up twice in the switch. This turned out to be because:

  1. AddressOf is a SIL builtin that semantically is expected to only result in
    SIL being emitted instead of having a builtin "addressof" be emitted.

  2. For what ever reason, we actually had code in IRGen to emit an AddressOf
    BuiltinInst if we saw it (which we never should have)... but also later code
    asserted that we would never see it b/c it is a "SIL only builtin".

  3. When I converted the if statements to be case statements, helpfully the
    compiler told me I had a duplicate case. After investigation, I found the above
    meaning that I was able to just delete the IRGen handling.

So now we properly handle AddressOf by asserting. As an additional tactic to
make "SIL only builtins" even more explicit, I added code to the SIL verifier
that validates we never see a builtin inst that is a "SIL only builtin" and
added some comments to Builtins.def that elaborate on this.

This simplifies the function and will make it easier for me to convert the
function into an exhaustive switch with an NFC commit.
This should make it easier to add new builtins by "following the warnings" and
prevent us from not handling a builtin in IRGen.

When I did this, I discovered that if I did this naively, we would have
AddressOf show up twice in the switch. This turned out to be because:

1. AddressOf is a SIL builtin that semantically is expected to only result in
SIL being emitted instead of having a builtin "addressof" be emitted.

2. For what ever reason, we actually had code in IRGen to emit an AddressOf
BuiltinInst if we saw it (which we never should have)... but also later code
asserted that we would never see it b/c it is a "SIL only builtin".

3. When I converted the if statements to be case statements, helpfully the
compiler told me I had a duplicate case. After investigation, I found the above
meaning that I was able to just delete the IRGen handling.

So now we properly handle AddressOf by asserting. As an additional tactic to
make "SIL only builtins" even more explicit, I added code to the SIL verifier
that validates we never see a builtin inst that is a "SIL only builtin" and
added some comments to Builtins.def that elaborate on this.
@gottesmm
Copy link
Contributor Author

@swift-ci smoke test

@gottesmm gottesmm enabled auto-merge October 24, 2025 19:13
@gottesmm
Copy link
Contributor Author

@swift-ci test windows platform

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant