-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[SIL] Witness methods store the conformance from which they come. #12430
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
Conversation
lib/SIL/SILFunctionType.cpp
Outdated
getASTContext()); | ||
Optional<ProtocolConformanceRef> witnessMethodConformance; | ||
if (auto conformance = origType->getWitnessMethodConformanceOrNone()) { | ||
if (conformance->isAbstract()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@slavapestov I don't understand what substitution I'm meant to being here to convert the abstract conformance into a concrete one (and even for the concrete case, I'm just guessing).
b320b7c
to
d06e518
Compare
@swift-ci please smoke test |
@swift-ci please smoke test. |
7e47c4a
to
cefe828
Compare
@swift-ci please smoke test. |
1 similar comment
@swift-ci please smoke test. |
cefe828
to
9ee5a7a
Compare
if (auto conformance = origType->getWitnessMethodConformanceOrNone()) { | ||
assert(origType->getExtInfo().hasSelfParam()); | ||
auto selfType = origType->getSelfParameter().getType(); | ||
// The Self type can be nested in a few layers of metatypes (etc.), e.g. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Example:
protocol Foo {
static var x: Int { get set }
}
func mutate(_: inout Int) {}
func foo<T: Foo>(ty: T.Type) {
mutate(&T.x)
}
The SIL for the setter callback call after calling materializeForSet looks like:
...
bb2(%16 : $Builtin.RawPointer): // Preds: bb0
%17 = pointer_to_thin_function %16 : $Builtin.RawPointer to $@convention(witness_method: Foo) <τ_0_0 where τ_0_0 : Foo> (Builtin.RawPointer, @inout Builtin.UnsafeValueBuffer, @inout @thick τ_0_0.Type, @thick τ_0_0.Type.Type) -> () // user: %22
...
9ee5a7a
to
40edeff
Compare
@swift-ci please smoke test and merge. |
40edeff
to
572b62f
Compare
@swift-ci please smoke test and merge. |
572b62f
to
c64db77
Compare
@swift-ci please smoke test and merge. |
/// If this is a @convention(witness_method) function, return the conformance | ||
/// for which the method is a witness, if it isn't that convention, return | ||
/// None. | ||
Optional<ProtocolConformanceRef> getWitnessMethodConformanceOrNone() const { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this variant useful?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's the one I call most often: it avoids having do a fnTy->getRepresentation() == SILFunctionRepresentation::WitnessMethod ? fnTy.getWitnessMethodConformance() : None
dance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, OK.
Serialization is in the first commit. |
@swift-ci Please smoke test |
@swift-ci Please smoke test |
@swift-ci Please smoke test. |
d592702
to
7b13891
Compare
@swift-ci smoke test |
1 similar comment
@swift-ci smoke test |
@swift-ci smoke test. Maybe this will work some day?! |
@swift-ci smoke test |
@swift-ci smoke test. |
@swift-ci smoke test |
0a94918
to
7322cfa
Compare
@swift-ci smoke test |
7322cfa
to
504aa10
Compare
@swift-ci smoke test |
1 similar comment
@swift-ci smoke test |
@swift-ci smoke test and merge |
@swift-ci Please smoke test |
@swift-ci Please smoke test Linux |
504aa10
to
9240404
Compare
@swift-ci smoke test and merge |
@swift-ci Please smoke test and merge |
@swift-ci Please smoke test |
Previously ProtocolConformance::subst would crash because it was receiving things with an unexpected relationship between the conformance's type and the substituted self type. The compiler doesn't quite properly model "abstract" inherited conformances, so we end up using normal conformances instead, and we need to work around this in some cases.
23f93cc
to
b5eb418
Compare
@swift-ci Please smoke test |
1 similar comment
@swift-ci Please smoke test |
No description provided.