Skip to content

Commit f52f491

Browse files
committed
EmbeddedSwiftDiagnostics: check apply diagnostics also for begin_apply and partial_apply
1 parent d9c7a68 commit f52f491

File tree

1 file changed

+40
-33
lines changed

1 file changed

+40
-33
lines changed

SwiftCompilerSources/Sources/Optimizer/ModulePasses/EmbeddedSwiftDiagnostics.swift

Lines changed: 40 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -131,20 +131,26 @@ private struct FunctionChecker {
131131
at: instruction.location)
132132
}
133133

134-
case is BeginApplyInst:
134+
case is ThunkInst:
135135
if context.options.noAllocations {
136-
throw Diagnostic(.embedded_swift_allocating_coroutine, at: instruction.location)
136+
throw Diagnostic(.embedded_swift_allocating, at: instruction.location)
137137
}
138138

139-
case is ThunkInst:
139+
case let ba as BeginApplyInst:
140140
if context.options.noAllocations {
141-
throw Diagnostic(.embedded_swift_allocating, at: instruction.location)
141+
throw Diagnostic(.embedded_swift_allocating_coroutine, at: instruction.location)
142142
}
143+
try checkApply(apply: ba)
143144

144145
case let pai as PartialApplyInst:
145146
if context.options.noAllocations && !pai.isOnStack {
146147
throw Diagnostic(.embedded_swift_allocating_closure, at: instruction.location)
147148
}
149+
try checkApply(apply: pai)
150+
151+
// Remaining apply instructions
152+
case let apply as ApplySite:
153+
try checkApply(apply: apply)
148154

149155
case let bi as BuiltinInst:
150156
switch bi.id {
@@ -162,39 +168,40 @@ private struct FunctionChecker {
162168
break
163169
}
164170

165-
case let apply as ApplySite:
166-
if context.options.noAllocations && apply.isAsync {
167-
throw Diagnostic(.embedded_swift_allocating_type, at: instruction.location)
168-
}
171+
default:
172+
break
173+
}
174+
}
169175

170-
if !apply.callee.type.hasValidSignatureForEmbedded,
171-
// Some runtime functions have generic parameters in SIL, which are not used in IRGen.
172-
// Therefore exclude runtime functions at all.
173-
!apply.callsEmbeddedRuntimeFunction
174-
{
175-
switch apply.callee {
176-
case let cmi as ClassMethodInst:
177-
throw Diagnostic(.embedded_cannot_specialize_class_method, cmi.member, at: instruction.location)
178-
case let wmi as WitnessMethodInst:
179-
throw Diagnostic(.embedded_cannot_specialize_witness_method, wmi.member, at: instruction.location)
180-
default:
181-
throw Diagnostic(.embedded_call_generic_function, at: instruction.location)
182-
}
183-
}
176+
mutating func checkApply(apply: ApplySite) throws {
177+
if context.options.noAllocations && apply.isAsync {
178+
throw Diagnostic(.embedded_swift_allocating_type, at: apply.location)
179+
}
184180

185-
// Although all (non-generic) functions are initially put into the worklist there are two reasons
186-
// to call `checkFunction` recursively:
187-
// * To get a better caller info in the diagnostics.
188-
// * When passing an opened existential to a generic function, it's valid in Embedded swift even if the
189-
// generic is not specialized. We need to check such generic functions, too.
190-
if let callee = apply.referencedFunction {
191-
callStack.push(CallSite(apply: apply, callee: callee))
192-
try checkFunction(callee)
193-
_ = callStack.pop()
181+
if !apply.callee.type.hasValidSignatureForEmbedded,
182+
// Some runtime functions have generic parameters in SIL, which are not used in IRGen.
183+
// Therefore exclude runtime functions at all.
184+
!apply.callsEmbeddedRuntimeFunction
185+
{
186+
switch apply.callee {
187+
case let cmi as ClassMethodInst:
188+
throw Diagnostic(.embedded_cannot_specialize_class_method, cmi.member, at: apply.location)
189+
case let wmi as WitnessMethodInst:
190+
throw Diagnostic(.embedded_cannot_specialize_witness_method, wmi.member, at: apply.location)
191+
default:
192+
throw Diagnostic(.embedded_call_generic_function, at: apply.location)
194193
}
194+
}
195195

196-
default:
197-
break
196+
// Although all (non-generic) functions are initially put into the worklist there are two reasons
197+
// to call `checkFunction` recursively:
198+
// * To get a better caller info in the diagnostics.
199+
// * When passing an opened existential to a generic function, it's valid in Embedded swift even if the
200+
// generic is not specialized. We need to check such generic functions, too.
201+
if let callee = apply.referencedFunction {
202+
callStack.push(CallSite(apply: apply, callee: callee))
203+
try checkFunction(callee)
204+
_ = callStack.pop()
198205
}
199206
}
200207

0 commit comments

Comments
 (0)