Skip to content

Small cleanups to type(of: self) handling in DI #19302

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/SILOptimizer/Mandatory/DefiniteInitialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -857,8 +857,7 @@ void LifetimeChecker::handleLoadForTypeOfSelfUse(const DIMemoryUse &Use) {
break;
}
assert(valueMetatype);
auto metatypeArgument = load->getFunction()->getEntryBlock()->getArguments()
.back();
auto metatypeArgument = load->getFunction()->getSelfMetadataArgument();
replaceAllSimplifiedUsesAndErase(valueMetatype, metatypeArgument,
[](SILInstruction*) { });
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// RUN: %target-swift-emit-sil -verify %s

// Integration test to ensure that `type(of: self)` keeps working in
// class convenience initializers, even though they are now implemented as
// allocating entry points.

class C {
init() { }
init(throwingDesignated: ()) throws {}

convenience init(normal: ()) {
_ = (type(of: self), type(of: self))
self.init()
_ = (type(of: self), type(of: self))
}

convenience init(throwing: ()) throws {
do {
_ = (type(of: self), type(of: self))
try self.init(throwingDesignated: ())
_ = (type(of: self), type(of: self))
} catch {
_ = (type(of: self), type(of: self))
throw error
}
_ = (type(of: self), type(of: self))
}

convenience init?(optional: Bool) {
_ = (type(of: self), type(of: self))
if optional {
_ = (type(of: self), type(of: self))
self.init()
} else {
_ = (type(of: self), type(of: self))
return nil
}
_ = (type(of: self), type(of: self))
}
}