-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
infer or permit declarations of variance for type parameters #3598
Comments
Do not forget: current region parameterization inference codes does not consider supertrait inheritance. |
Can you be a little more concrete about use cases and current failure modes? I'm having a hard time picturing the implications of this. |
Doesn't look like 0.6 |
Nominating for milestone 3, feature-complete |
@graydon, I ran into this today. I had something like:
...and I needed to update such a struct that I already had with a new value for As a workaround, I wrote a hand-monomorphized enum that's the same as option but didn't have a type parameter. (I can imagine that would be impossible for someone implementing a generic data structure, though.) |
punting to later triage mtg with niko present. |
Related to #5781 |
accepted for feature-complete milestone |
@pcwalton thinks this isn't necessary for 1.0. I'm not sure I agree, |
As part of the code for #4846 I implemented a general variance inference algorithm, but I do not yet apply it to type parameters. |
… old region-parameterization/variance inference. We now compute variance for type parameters but do not make use of it (most of the way towards rust-lang#3598).
nominating for discussion during triage when @nikomatsakis is present |
Marking as E-mentor -- this is almost entirely done. The variance inference is written. The declarations are written (in the form of marker types). The only thing missing is to update the type inferencer to consider the results of variance inference rather than treating all type parameters as invariant, and to update the vtable matching code in a similar way. Not exactly easy changes but not terribly hard with some pointers. |
Assigning P-backcompat-lang, 1.0 blocker. (The current default of invariant is backwards compatible, but niko says there's some other interaction with trait-matching that niko says makes this more important to the point of being P-backcompat-lang.) |
cc me |
@edwardw I guess I don't know what problem you're encountering precisely. I know you sent me some gists but I never head time to read into them. Perhaps you can repost them here. It's hard to say what the options are without knowing what the problem is, it seems to me it's likely just a bug somewhere. |
@nikomatsakis, I'd like to draw your attention to this line of the PR: combine.rs. Without it, the patched rustc won't be able to compile #[lang="covariant_type"]
#[deriving(Eq,Clone)] // error: cannot determine a type for this expression: unconstrained type
pub struct CovariantType<T>; Same error if manually implementing the |
@nikomatsakis @nick29581 I think I figured out what are those mysterious bivariant. They come from nullary generic type. With that handled we are one step closer to fix this bug. Since this is going to be a change with potentially big impact, do you have some specific tests in mind for it? Or some formerly ignored tests should be turned on as part of the fix? |
Nominating for removal from 1.0 milestone because the remaining soundness issue is covered by #5781 which is already milestoned. |
P-high, not 1.0. |
This issue has been moved to the RFCs repo: rust-lang/rfcs#281 |
…or when reorder_imports is disabled (rust-lang#3598)
alloc: update comments around malloc() alignment Also separate the C heap shims form the Windows heap shims; their guarantees aren't quite the same.
UPDATE
Variance inference is complete.
What is still missing is:
ORIGINAL
Today, we treat all type parameters as invariant, but infer variance for region parameters. We can use that same code which infers the variance for region parameters to infer the suitable variance for type parameters if we like.
Alternatively, if we decide that inference here is too magical, we could require explicit declaration of variance. In that case, i'd favor covariance as the default, and the possibility to write
struct Foo<mut T>
to indicate an invariant type parameterT
(which can appear in mutable locations). This seems more intuitive than the usual+
and-
. We probably don't need a notation for contravariance, but in that case perhapsfn T
(to indicate a type parameter that appears only in function arguments, far and away the most common place to have a contravariant type parameter).Still, I think I favor inference. It's inline with what we do for regions and I think it will basically match up with user expectations.
The text was updated successfully, but these errors were encountered: