Skip to content

[ClangImporter] Make conformance loading lazier. #10707

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 2 commits into from
Jun 30, 2017

Conversation

jrose-apple
Copy link
Contributor

Previously, the importer queued up conformances to complete once it was done importing the current batch of declarations. However, if there was a serialized Swift module that extended an imported type to add a conformance in exactly the wrong way, the importer could end up asking for that conformance later—even before the reference to the imported type was resolved. This led to a crash in the deserializer "while reading conformance for type X".

Instead of this "pending actions" queue, we can just use the mechanisms already in place for lazily loading conformances. That way they'll get filled out on demand, which is better all around anyway. This does mean putting the requirement signature into the "lazy" part of the conformance, though.

This does as a side effect mean that all of the witnesses for the imported conformance may be opaque—that is, they will never be devirtualized to a particular implementation. However, they previously would have referred to methods implemented in Objective-C anyway, which are always dispatched with objc_msgSend. So this should have no practical effect.

There's also a second commit that makes deserialization of Swift conformances a little lazier as well, now that we have that ability. This isn't critical to this fix and we could easily leave it for later.

rdar://problem/32346184

@jrose-apple jrose-apple requested a review from DougGregor June 29, 2017 20:27
@jrose-apple
Copy link
Contributor Author

@swift-ci Please test

@jrose-apple
Copy link
Contributor Author

@DougGregor: after discussing this with @ematejska we decided the story with a flag didn't make enough sense—either we're comfortable with this for 4.0 or we're not. I'm personally a lot happier than I thought I would be because the lazy mechanism is already there; if I had had to add that for the first time I'd be a lot more apprehensive.

Copy link
Member

@DougGregor DougGregor left a comment

Choose a reason for hiding this comment

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

This was smaller than I expected, which is great. Thank you, LGTM.

@jrose-apple
Copy link
Contributor Author

Failing a number of internal tests. Stay tuned.

Previously, the importer queued up conformances to complete once it
was done importing the current batch of declarations. However, if
there was a serialized Swift module that extended an imported type to
add a conformance in exactly the wrong way, the importer could end up
asking for that conformance later---even before the reference to the
imported type was resolved. This led to a crash in the deserializer
"while reading conformance for type X".

Instead of this "pending actions" queue, we can just use the
mechanisms already in place for lazily loading conformances. That way
they'll get filled out on demand, which is better all around anyway.
This does mean putting the requirement signature into the "lazy" part
of the conformance, though.

This does as a side effect mean that /all/ of the witnesses for the
imported conformance may be opaque---that is, they will never be
devirtualized to a particular implementation. However, they previously
would have referred to methods implemented in Objective-C anyway,
which are always dispatched with objc_msgSend. So this should have no
practical effect.

rdar://problem/32346184
@jrose-apple jrose-apple force-pushed the conformance-procrastination branch from 3cd0f13 to 4c18bda Compare June 29, 2017 22:54
@jrose-apple
Copy link
Contributor Author

It looks like those are configuration issues on our end, not related to this pull request. Previous full-testing passed.

@swift-ci Please smoke test

The previous commit needed this for the importer, so we might as well
take advantage of it in deserialization as well. No expected change in
behavior.
@jrose-apple jrose-apple force-pushed the conformance-procrastination branch from 4c18bda to 897effe Compare June 29, 2017 22:56
@jrose-apple
Copy link
Contributor Author

*sigh* Left in some conflict markers.

@swift-ci Please smoke test

@jrose-apple jrose-apple merged commit f9e2beb into swiftlang:master Jun 30, 2017
@jrose-apple jrose-apple deleted the conformance-procrastination branch June 30, 2017 01:03
@jrose-apple
Copy link
Contributor Author

@DougGregor, do you think we should take the serialization change for 4.0 as well, or just the importer work?

Copy link
Member

@DougGregor DougGregor left a comment

Choose a reason for hiding this comment

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

Thank you!

@jrose-apple
Copy link
Contributor Author

…wrong PR?

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.

2 participants