Skip to content

Commit 239807f

Browse files
committed
[irgen] Convert emitIRGenBuiltin to use a covered switch.
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.
1 parent 5e64ea6 commit 239807f

File tree

3 files changed

+149
-118
lines changed

3 files changed

+149
-118
lines changed

include/swift/AST/Builtins.def

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,11 @@ BUILTIN_BINARY_PREDICATE(FCMP_ULE, "fcmp_ule", "n", FloatOrVector)
209209
BUILTIN_BINARY_PREDICATE(FCMP_UNE, "fcmp_une", "n", FloatOrVector)
210210
BUILTIN_BINARY_PREDICATE(FCMP_UNO, "fcmp_uno", "n", FloatOrVector)
211211

212-
// BUILTIN_SIL_OPERATION - Operations that can be lowered to SIL instructions.
213-
// These have various types.
214-
// Since these operations will be lowered to SIL Instructions, we do not
215-
// assign any attributes on them.
212+
// BUILTIN_SIL_OPERATION - Operations that can be lowered to SIL
213+
// instructions. They can never be invoked via a BuiltinInst and are instead
214+
// expected to just be used by SILGen to emit sequences of non-BuiltinInst
215+
// instructions. These have various types. Since these operations will be
216+
// lowered to SIL Instructions, we do not assign any attributes on them.
216217
#ifndef BUILTIN_SIL_OPERATION
217218
#define BUILTIN_SIL_OPERATION(Id, Name, Overload) BUILTIN(Id, Name, "")
218219
#endif
@@ -558,8 +559,9 @@ BUILTIN_RUNTIME_CALL(ErrorInMain, "errorInMain", "")
558559
/// nominal type is Optional.
559560
BUILTIN_RUNTIME_CALL(IsOptionalType, "isOptional", "")
560561

561-
// BUILTIN_MISC_OPERATION - Miscellaneous operations without a unifying class.
562-
// These have various types.
562+
/// BUILTIN_MISC_OPERATION - Miscellaneous operations without a unifying class.
563+
/// These have various types. They are emitted as BuiltinInst in a standard way
564+
/// by SILGen.
563565
#ifndef BUILTIN_MISC_OPERATION
564566
#define BUILTIN_MISC_OPERATION(Id, Name, Attrs, Overload) \
565567
BUILTIN(Id, Name, Attrs)

0 commit comments

Comments
 (0)