Skip to content

[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

Merged
merged 3 commits into from
Nov 1, 2017

Conversation

huonw
Copy link
Contributor

@huonw huonw commented Oct 13, 2017

No description provided.

@huonw huonw requested a review from slavapestov October 13, 2017 22:30
getASTContext());
Optional<ProtocolConformanceRef> witnessMethodConformance;
if (auto conformance = origType->getWitnessMethodConformanceOrNone()) {
if (conformance->isAbstract()) {
Copy link
Contributor Author

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).

@huonw huonw force-pushed the silfunctiontype-conformance branch 2 times, most recently from b320b7c to d06e518 Compare October 15, 2017 03:56
@huonw
Copy link
Contributor Author

huonw commented Oct 15, 2017

@swift-ci please smoke test

2 similar comments
@huonw
Copy link
Contributor Author

huonw commented Oct 16, 2017

@swift-ci please smoke test

@huonw
Copy link
Contributor Author

huonw commented Oct 16, 2017

@swift-ci please smoke test

@huonw
Copy link
Contributor Author

huonw commented Oct 16, 2017

@swift-ci please smoke test.

@huonw huonw force-pushed the silfunctiontype-conformance branch from 7e47c4a to cefe828 Compare October 16, 2017 23:34
@huonw
Copy link
Contributor Author

huonw commented Oct 16, 2017

@swift-ci please smoke test.

1 similar comment
@huonw
Copy link
Contributor Author

huonw commented Oct 16, 2017

@swift-ci please smoke test.

@huonw huonw force-pushed the silfunctiontype-conformance branch from cefe828 to 9ee5a7a Compare October 17, 2017 20:19
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.
Copy link
Contributor Author

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
...

@huonw huonw force-pushed the silfunctiontype-conformance branch from 9ee5a7a to 40edeff Compare October 17, 2017 20:45
@huonw
Copy link
Contributor Author

huonw commented Oct 17, 2017

@swift-ci please smoke test and merge.

@huonw huonw force-pushed the silfunctiontype-conformance branch from 40edeff to 572b62f Compare October 17, 2017 22:14
@huonw
Copy link
Contributor Author

huonw commented Oct 17, 2017

@swift-ci please smoke test and merge.

@huonw huonw force-pushed the silfunctiontype-conformance branch from 572b62f to c64db77 Compare October 17, 2017 22:46
@huonw
Copy link
Contributor Author

huonw commented Oct 17, 2017

@swift-ci please smoke test and merge.

2 similar comments
@huonw
Copy link
Contributor Author

huonw commented Oct 17, 2017

@swift-ci please smoke test and merge.

@huonw
Copy link
Contributor Author

huonw commented Oct 18, 2017

@swift-ci please smoke test and merge.

@huonw huonw changed the title WIP. [SIL] Witness methods store the conformance from which they come. [SIL] Witness methods store the conformance from which they come. Oct 18, 2017
/// 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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this variant useful?

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, OK.

@huonw
Copy link
Contributor Author

huonw commented Oct 18, 2017

Serialization is in the first commit.

@slavapestov
Copy link
Contributor

@swift-ci Please smoke test

2 similar comments
@slavapestov
Copy link
Contributor

@swift-ci Please smoke test

@huonw
Copy link
Contributor Author

huonw commented Oct 20, 2017

@swift-ci Please smoke test

@huonw
Copy link
Contributor Author

huonw commented Oct 21, 2017

@swift-ci Please smoke test

@huonw
Copy link
Contributor Author

huonw commented Oct 26, 2017

@swift-ci Please smoke test.

@huonw huonw force-pushed the silfunctiontype-conformance branch from d592702 to 7b13891 Compare October 26, 2017 23:11
@huonw
Copy link
Contributor Author

huonw commented Oct 26, 2017

@swift-ci smoke test

1 similar comment
@huonw
Copy link
Contributor Author

huonw commented Oct 26, 2017

@swift-ci smoke test

@huonw
Copy link
Contributor Author

huonw commented Oct 26, 2017

@swift-ci smoke test.

Maybe this will work some day?!

@shahmishal
Copy link
Member

@swift-ci smoke test

@huonw
Copy link
Contributor Author

huonw commented Oct 28, 2017

@swift-ci smoke test.

@huonw
Copy link
Contributor Author

huonw commented Oct 30, 2017

@swift-ci smoke test

@huonw huonw force-pushed the silfunctiontype-conformance branch 2 times, most recently from 0a94918 to 7322cfa Compare October 31, 2017 01:00
@huonw
Copy link
Contributor Author

huonw commented Oct 31, 2017

@swift-ci smoke test

@huonw huonw force-pushed the silfunctiontype-conformance branch from 7322cfa to 504aa10 Compare October 31, 2017 20:44
@huonw
Copy link
Contributor Author

huonw commented Oct 31, 2017

@swift-ci smoke test

1 similar comment
@huonw
Copy link
Contributor Author

huonw commented Oct 31, 2017

@swift-ci smoke test

@huonw
Copy link
Contributor Author

huonw commented Oct 31, 2017

@swift-ci smoke test and merge

@rudkx
Copy link
Contributor

rudkx commented Oct 31, 2017

@swift-ci Please smoke test

@shahmishal
Copy link
Member

@swift-ci Please smoke test Linux

@huonw huonw force-pushed the silfunctiontype-conformance branch from 504aa10 to 9240404 Compare November 1, 2017 00:13
@huonw
Copy link
Contributor Author

huonw commented Nov 1, 2017

@swift-ci smoke test and merge

@huonw
Copy link
Contributor Author

huonw commented Nov 1, 2017

@swift-ci Please smoke test and merge

@huonw
Copy link
Contributor Author

huonw commented Nov 1, 2017

@swift-ci Please smoke test

huonw added 3 commits November 1, 2017 11:33
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.
@huonw huonw force-pushed the silfunctiontype-conformance branch from 23f93cc to b5eb418 Compare November 1, 2017 18:43
@huonw
Copy link
Contributor Author

huonw commented Nov 1, 2017

@swift-ci Please smoke test

1 similar comment
@huonw
Copy link
Contributor Author

huonw commented Nov 1, 2017

@swift-ci Please smoke test

@huonw huonw merged commit 161dd6a into swiftlang:master Nov 1, 2017
@huonw huonw deleted the silfunctiontype-conformance branch November 1, 2017 21:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants