Skip to content
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

Improve inferrability of stream IO #36323

Merged
merged 3 commits into from
Jun 23, 2020
Merged

Improve inferrability of stream IO #36323

merged 3 commits into from
Jun 23, 2020

Conversation

timholy
Copy link
Sponsor Member

@timholy timholy commented Jun 17, 2020

A lot of IO subtypes wrap other IO objects, and the field type declaration is typically abstract (e.g., ::IO or ::LibuvStream). This leads to widespread inference problems, because it's not possible for inference to know what io.io.status will return, even if it knows that io.io::LibuvStream.

To fix this, this PR defines a formal interface for three abstract types (LibuvStream, LibuvServer, and AbstractPipe) by specializing getproperty for them and adding name-specific type assertions. Since these types are unexported, it should not be considered a breaking change to specify that certain fields must have certain types.

This change makes most functions in base/stream.jl pretty well-inferred, which is a substantial change from where we are now.

Most concrete IO types declare that a subset of their fields
are other abstract IO types. As a result, if `obj1::IO`, and
`obj2 = obj1.fieldwithabstracttype`, then inference has no way of
knowing what type `obj2.status` returns. When `obj2.status` is used as
an argument for `Base.somefunction`, this leaves such code vulnerable
to invalidation via package specializations of `Base.somefunction`
even when in practice there is no risk that any IO code will call
the new package-supplied method.

This provides a more formal interface for three non-exported
abstract types: `LibuvStream`, `LibuvServer`, and `AbstractPipe`.
@timholy timholy added the compiler:latency Compiler latency label Jun 17, 2020
@timholy
Copy link
Sponsor Member Author

timholy commented Jun 22, 2020

If there are no objections, I might merge this soon. Among my invalidation PRs, this isn't one of the most consequential in terms of latency, but I think it has a certain elegance: it provides an example of how one might non-obtrusively define interfaces for abstract types. xref #4935

@timholy timholy merged commit be72a57 into master Jun 23, 2020
@timholy timholy deleted the teh/io_field_spec branch June 23, 2020 01:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:latency Compiler latency
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants