Skip to content

Commit 149331d

Browse files
committed
[SILGen]: SR-11803. Inject "willThrow" hooks after foreign error propagation.
1 parent 70031d3 commit 149331d

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

lib/SILGen/SILGenForeignError.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ void SILGenFunction::emitForeignErrorBlock(SILLocation loc,
279279

280280
// Propagate.
281281
FullExpr throwScope(Cleanups, CleanupLocation::get(loc));
282-
emitThrow(loc, error);
282+
emitThrow(loc, error, true);
283283
}
284284

285285
/// Perform a foreign error check by testing whether the call result is zero.

test/SILGen/foreign_errors.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ func test0() throws {
5151
// CHECK: [[T0:%.*]] = load [take] [[ERR_TEMP0]]
5252
// CHECK: [[T1:%.*]] = function_ref @$s10Foundation22_convertNSErrorToErrorys0E0_pSo0C0CSgF : $@convention(thin) (@guaranteed Optional<NSError>) -> @owned Error
5353
// CHECK: [[T2:%.*]] = apply [[T1]]([[T0]])
54+
// CHECK: "willThrow"([[T2]] : $Error)
5455
// CHECK: throw [[T2]] : $Error
5556
}
5657

@@ -161,6 +162,7 @@ let fn = ErrorProne.fail
161162
// CHECK: return
162163
// CHECK: [[T0:%.*]] = load [take] [[TEMP]]
163164
// CHECK: [[T1:%.*]] = apply {{%.*}}([[T0]])
165+
// CHECK: "willThrow"([[T1]] : $Error)
164166
// CHECK: throw [[T1]]
165167

166168
func testArgs() throws {

test/SILGen/objc_factory_init.swift

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,40 @@ extension Hive {
4242
convenience init(otherQueen other: Bee) {
4343
self.init(queen: other)
4444
}
45+
46+
// CHECK-LABEL: sil hidden [ossa] @$sSo4HiveC17objc_factory_initE15otherFlakyQueenABSo3BeeC_tKcfC
47+
// CHECK: bb0([[QUEEN:%.*]] : @owned $Bee, [[META:%.*]] : $@thick Hive.Type):
48+
// CHECK: [[SELF_BOX:%.*]] = alloc_box ${ var Hive }, let, name "self"
49+
// CHECK: [[MU:%.*]] = mark_uninitialized [delegatingself] [[SELF_BOX]]
50+
// CHECK: [[PB_BOX:%.*]] = project_box [[MU]] : ${ var Hive }, 0
51+
// CHECK: [[FOREIGN_ERROR_STACK:%.*]] = alloc_stack $Optional<NSError>
52+
// CHECK: [[OBJC_META:%[0-9]+]] = thick_to_objc_metatype [[META]] : $@thick Hive.Type to $@objc_metatype Hive.Type
53+
// CHECK: [[BORROWED_QUEEN:%.*]] = begin_borrow [[QUEEN]]
54+
// CHECK: [[COPIED_BORROWED_QUEEN:%.*]] = copy_value [[BORROWED_QUEEN]]
55+
// CHECK: [[OPT_COPIED_BORROWED_QUEEN:%.*]] = enum $Optional<Bee>, #Optional.some!enumelt.1, [[COPIED_BORROWED_QUEEN]]
56+
// CHECK: [[FACTORY:%[0-9]+]] = objc_method [[OBJC_META]] : $@objc_metatype Hive.Type, #Hive.init!allocator.1.foreign : (Hive.Type) -> (Bee?) throws -> Hive, $@convention(objc_method) (Optional<Bee>, Optional<AutoreleasingUnsafeMutablePointer<Optional<NSError>>>, @objc_metatype Hive.Type) -> @autoreleased Optional<Hive> // user: %25
57+
// CHECK: [[ERROR_PTR_STACK:%.*]] = alloc_stack $AutoreleasingUnsafeMutablePointer<Optional<NSError>>
58+
// CHECK: [[ERROR_PTR:%.*]] = load [trivial] [[ERROR_PTR_STACK]]
59+
// CHECK: [[OPT_ERROR_PTR:%.*]] = enum $Optional<AutoreleasingUnsafeMutablePointer<Optional<NSError>>>, #Optional.some!enumelt.1, [[ERROR_PTR]]
60+
// CHECK: [[OPT_NEW_HIVE:%.*]] = apply [[FACTORY]]([[OPT_COPIED_BORROWED_QUEEN]], [[OPT_ERROR_PTR]], [[OBJC_META]]) : $@convention(objc_method) (Optional<Bee>, Optional<AutoreleasingUnsafeMutablePointer<Optional<NSError>>>, @objc_metatype Hive.Type) -> @autoreleased Optional<Hive>
61+
// CHECK: switch_enum [[OPT_NEW_HIVE]] : $Optional<Hive>, case #Optional.some!enumelt.1: [[NORMAL_BB:bb[0-9]+]], case #Optional.none!enumelt: [[ERROR_BB:bb[0-9]+]] // id: %34
62+
//
63+
// CHECK: bb1([[HIVE:%.*]] : @owned $Hive):
64+
// CHECK: assign [[HIVE]] to [[PB_BOX]]
65+
// CHECK: dealloc_stack [[FOREIGN_ERROR_STACK]]
66+
// CHECK: [[HIVE_COPY:%.*]] = load [copy] [[PB_BOX]]
67+
// CHECK: return [[HIVE_COPY]]
68+
// CHECK: bb2:
69+
// CHECK: [[OPTIONAL_NSERROR:%.*]] = load [take] [[FOREIGN_ERROR_STACK]] : $*Optional<NSError>
70+
// CHECK: [[CONVERT_NSERROR_TO_ERROR_FUNC:%.*]] = function_ref @$s10Foundation22_convertNSErrorToErrorys0E0_pSo0C0CSgF : $@convention(thin) (@guaranteed Optional<NSError>) -> @owned Error
71+
// CHECK: [[ERROR:%.*]] = apply [[CONVERT_NSERROR_TO_ERROR_FUNC]]([[OPTIONAL_NSERROR]]) : $@convention(thin) (@guaranteed Optional<NSError>) -> @owned Error
72+
// CHECK: "willThrow"([[ERROR]] : $Error)
73+
// CHECK: dealloc_stack [[FOREIGN_ERROR_STACK]]
74+
// CHECK: throw [[ERROR]] : $Error
75+
// CHECK: } // end sil function '$sSo4HiveC17objc_factory_initE15otherFlakyQueenABSo3BeeC_tKcfC'
76+
convenience init(otherFlakyQueen other: Bee) throws {
77+
try self.init(flakyQueen: other)
78+
}
4579
}
4680

4781
extension SomeClass {

0 commit comments

Comments
 (0)