From 30098ad3e00c9901e0f7ce463da2ccfacf130683 Mon Sep 17 00:00:00 2001 From: Nate Chandler Date: Thu, 18 Sep 2025 12:20:28 -0700 Subject: [PATCH] [AllocBoxToStack] Fix missing [nothrow] of apply. When specializing an apply which is annotated `[nothrow]`, the resulting function's apply must still be annotated `[nothrow]`. rdar://160742150 --- .../FunctionPasses/AllocBoxToStack.swift | 2 +- validation-test/SILOptimizer/gh84337.swift | 38 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 validation-test/SILOptimizer/gh84337.swift diff --git a/SwiftCompilerSources/Sources/Optimizer/FunctionPasses/AllocBoxToStack.swift b/SwiftCompilerSources/Sources/Optimizer/FunctionPasses/AllocBoxToStack.swift index 733c0c3348376..2c64e178cd691 100644 --- a/SwiftCompilerSources/Sources/Optimizer/FunctionPasses/AllocBoxToStack.swift +++ b/SwiftCompilerSources/Sources/Optimizer/FunctionPasses/AllocBoxToStack.swift @@ -261,7 +261,7 @@ private struct FunctionSpecializations { switch apply { case let applyInst as ApplyInst: - let newApply = builder.createApply(function: specializedCallee, applyInst.substitutionMap, arguments: newArgs) + let newApply = builder.createApply(function: specializedCallee, applyInst.substitutionMap, arguments: newArgs, isNonThrowing: applyInst.isNonThrowing) applyInst.replace(with: newApply, context) case let partialAp as PartialApplyInst: let newApply = builder.createPartialApply(function: specializedCallee, substitutionMap: diff --git a/validation-test/SILOptimizer/gh84337.swift b/validation-test/SILOptimizer/gh84337.swift new file mode 100644 index 0000000000000..ea29e12d41258 --- /dev/null +++ b/validation-test/SILOptimizer/gh84337.swift @@ -0,0 +1,38 @@ +// RUN: %target-build-swift -O %s + +@propertyWrapper +public struct Dependency2 { + public init( + _ keyPath: KeyPath + ) { + + } + public var wrappedValue: Value { + let any: Any = "somestring" + return any as! Value + } +} + +struct Client { + var get: (_ id: String) -> Bool +} + +public struct DependencyValues { + var client3: Client +} + +public protocol WindowData2 { + var id :String {get set} +} + +extension WindowData2 { + func didSetProfileForSpaceIDs( + spaceIDs: [String] + ) -> Void { + @Dependency2(\.client3) var client: Client + spaceIDs.forEach { _ in + spaceIDs + .map { _ in return client.get(id) } + } + } +}