Uh oh!
There was an error while loading. Please reload this page.
RFC 213: Implement Default Type Parameter Fallback - #26870
Conversation
aturon
commented
Jul 7, 2015
\o/ |
There was a problem hiding this comment.
I was working on improving it this afternoon/evening but got side tracked by trying to get type aliases to work correctly. Going to try to finish (and then add it here) it tomorrow morning PST.
bluss
commented
Jul 8, 2015
Is it a breaking change for code involving default type parameters in struct declarations? I guess not. Defaults in impl blocks? Defaults in methods and functions' type parameters? (Yes, I guess it must be). The rationale is that type parameter defaults never did anything really for methods and functions, so it's not breaking a previously working feature(?) |
bluss
commented
Jul 8, 2015
Default type parameters allow a form of static function parameters with defaults. Imagine |
Gankra
commented
Jul 8, 2015
Definitely would like a crater build of this change just to see what the impact would be. I don't expect much breakage in practice. |
There was a problem hiding this comment.
So, I'm concerned about this map.
For one thing, I'd want to "encapsulate it more":
a. make this private
b. key it by ty::TyVid
c. insert new data by adding an (optional) parameter to next_ty_var, rather than mutating the table after the fact
But a bigger issue is that it should be versioned for transactions. As it is, we are going to create fresh type variables with defaults then (potentially) roll them back, which might clear the default. I think my preference would be to remove the map, and instead store the Option<Ty<'tcx>> as part of the Bounded variant in type_variable::TypeVariableValue (after all, who cares what the default was once the type is Known?)
I'd probably change TypeVariableValue to something like:
enumTypeVariableValue<'tcx>{Known(Ty<'tcx>),Bounded{relations:Vec<Relation>,default:Option<Ty<'tcx>>}}(Also, if you do it this way, the transactional problem should just take care of itself.)
There was a problem hiding this comment.
Did this refactor, testing now.
nikomatsakis
commented
Jul 8, 2015
More tests that would be nice:
|
Gankra
commented
Jul 8, 2015
CC @apasel422 and @reem for crazy uses of defaults |
bors
commented
Jul 12, 2015
☔ The latest upstream changes (presumably #26895) made this pull request unmergeable. Please resolve the merge conflicts. |
d652a37 to
ea007bfCompareThere was a problem hiding this comment.
we still are not substituting here, right? I am guessing you'll have problems related to references to other variables, as well as maybe Self...?
1462a88 to
cae3f61Comparebrson
commented
Jul 20, 2015
Crater says: https://gist.github.com/brson/ce88d850e673ea2c2d05 Two stack overflows. |
cae3f61 to
d1545d3Compare2fd7d2b to
8ea9672Comparenikomatsakis
commented
Jul 26, 2015
@bors r+ |
bors
commented
Jul 26, 2015
📌 Commit 5ad36cb has been approved by |
This PR completes [RFC 213](https://github.com/rust-lang/rfcs/blob/master/text/0213-defaulted-type-params.md) by allowing default type parameters to influence inference. This is almost certainly a breaking change due to interactions between default type parameters and the old fallback algorithm used for integral and floating point literals. The error messages still require polish but I wanted to get early review and feedback from others on the the changes, error messages, and test cases. I also imagine we will want to run anywhere from 1-3 versions of this on crater and evaluate the impact, and it would be best to get that ball rolling. The only outstanding issue I'm aware of is that type alias defaults don't work. It seems this may require significant restructuring, since during inference type aliases have already been expanded. @nikomatsakis might be able to provide some clarity here. r? @nikomatsakis cc @eddyb@gankro@aturon@brson
bors
commented
Jul 26, 2015
bors
commented
Jul 26, 2015
petrochenkov
commented
Jul 26, 2015
Hm, after this change I still can't implement heterogeneous comparisons for Option without breakage. Reduced case: |
eddyb
commented
Jul 26, 2015
@petrochenkov Maybe the impl also needs the default? |
petrochenkov
commented
Jul 26, 2015
@eddyb |
Gankra
commented
Jul 26, 2015
💓 😻 😍 💖 ✨ |
jroesch
commented
Jul 26, 2015
This program works on the compiler built from my branch: // Almost PartialEqtraitPartialQe<Rhs = Self>{fnqe(&self,other:&Rhs){}}impl<A,B = A>PartialQe<Option<B>>forOption<A>{}fnmain(){PartialQe::qe(&Some("str"),&None);Some('a').qe(&None);} |
petrochenkov
commented
Jul 26, 2015
Now I see, it works only when the feature gate is enabled. So, it can't yet be used to generalize standard library facilities, like |
jroesch
commented
Jul 27, 2015
@petrochenkov we are going to let it bake for a cycle in order to give us time to tweak the algorithm, then it will be stabilized. |
This PR completes RFC 213 by allowing default type parameters to influence inference. This is almost certainly a breaking change due to interactions between default type parameters and the old fallback algorithm used for integral and floating point literals.
The error messages still require polish but I wanted to get early review and feedback from others on the the changes, error messages, and test cases. I also imagine we will want to run anywhere from 1-3 versions of this on crater and evaluate the impact, and it would be best to get that ball rolling.
The only outstanding issue I'm aware of is that type alias defaults don't work. It seems this may require significant restructuring, since during inference type aliases have already been expanded. @nikomatsakis might be able to provide some clarity here.
r? @nikomatsakis
cc @eddyb@gankro@aturon@brson