Skip to content

Commit 5a55b4f

Browse files
committed
Small cleanups to type(of: self) handling in DI
Should be NFC
1 parent 91bf80f commit 5a55b4f

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

lib/SILOptimizer/Mandatory/DefiniteInitialization.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -857,8 +857,7 @@ void LifetimeChecker::handleLoadForTypeOfSelfUse(const DIMemoryUse &Use) {
857857
break;
858858
}
859859
assert(valueMetatype);
860-
auto metatypeArgument = load->getFunction()->getEntryBlock()->getArguments()
861-
.back();
860+
auto metatypeArgument = load->getFunction()->getSelfMetadataArgument();
862861
replaceAllSimplifiedUsesAndErase(valueMetatype, metatypeArgument,
863862
[](SILInstruction*) { });
864863
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// RUN: %target-swift-emit-sil -verify %s
2+
3+
// Integration test to ensure that `type(of: self)` keeps working in
4+
// class convenience initializers, even though they are now implemented as
5+
// allocating entry points.
6+
7+
class C {
8+
init() { }
9+
init(throwingDesignated: ()) throws {}
10+
11+
convenience init(normal: ()) {
12+
_ = (type(of: self), type(of: self))
13+
self.init()
14+
_ = (type(of: self), type(of: self))
15+
}
16+
17+
convenience init(throwing: ()) throws {
18+
do {
19+
_ = (type(of: self), type(of: self))
20+
try self.init(throwingDesignated: ())
21+
_ = (type(of: self), type(of: self))
22+
} catch {
23+
_ = (type(of: self), type(of: self))
24+
throw error
25+
}
26+
_ = (type(of: self), type(of: self))
27+
}
28+
29+
convenience init?(optional: Bool) {
30+
_ = (type(of: self), type(of: self))
31+
if optional {
32+
_ = (type(of: self), type(of: self))
33+
self.init()
34+
} else {
35+
_ = (type(of: self), type(of: self))
36+
return nil
37+
}
38+
_ = (type(of: self), type(of: self))
39+
}
40+
}

0 commit comments

Comments
 (0)