Skip to content

[Serialization] Lazily Resolve the Eraser Type of @ _typeEraser #30800

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
Apr 4, 2020

Conversation

CodaFi
Copy link
Contributor

@CodaFi CodaFi commented Apr 3, 2020

Type erasure requires a circular construction by its very nature:

@_typeEraser(AnyProto)
protocol Proto { /**/ }
public struct AnyProto : Proto {}

If we eagerly resolve AnyProto, the chain of resolution steps that
deserialization must make goes a little something like this:

Lookup(Proto)
    -> Deserialize(@_typeEraser(AnyProto))
    -> Lookup(AnyProto)
    -> DeserializeInheritedStuff(AnyProto)
    -> Lookup(Proto)

Now, this cycle could be broken if the order of incremental inputs was
such that we had already cached the lookup of Proto.

Resolve this cycle in any case by suspending the deserialization of the
type eraser until the point it's demanded by adding
ResolveTypeEraserTypeRequest.

rdar://61270195

@CodaFi CodaFi requested a review from hborla April 3, 2020 21:39
@CodaFi
Copy link
Contributor Author

CodaFi commented Apr 3, 2020

@swift-ci smoke test

Copy link
Member

@hborla hborla left a comment

Choose a reason for hiding this comment

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

LGTM, thank you!

CodaFi added 2 commits April 3, 2020 14:52
Type erasure requires a circular construction by its very nature:

@_typeEraser(AnyProto)
protocol Proto { /**/ }
public struct AnyProto : Proto {}

If we eagerly resolve AnyProto, the chain of resolution steps that
deserialization must make goes a little something like this:

Lookup(Proto)
    -> Deserialize(@_typeEraser(AnyProto))
    -> Lookup(AnyProto)
    -> DeserializeInheritedStuff(AnyProto)
    -> Lookup(Proto)

This cycle could be broken if the order of incremental inputs was
such that we had already cached the lookup of Proto.

Resolve this cycle in any case by suspending the deserialization of the
type eraser until the point it's demanded by adding
ResolveTypeEraserTypeRequest.

rdar://61270195
ModuleDecl is its own declaration context.
@CodaFi
Copy link
Contributor Author

CodaFi commented Apr 3, 2020

@swift-ci smoke test

Going through sil-opt is going to print the contents of the module
without forcing the attribute which renders the test toothless. Now that
we have the multifile test, we're testing it can be round-tripped
through serialization anyhow.
@CodaFi
Copy link
Contributor Author

CodaFi commented Apr 4, 2020

@swift-ci smoke test

@CodaFi CodaFi merged commit b78ed53 into swiftlang:master Apr 4, 2020
@CodaFi CodaFi deleted the erase-install branch April 9, 2020 17:51
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