Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upChange default type parameters to match the behavior specified in the RFC #27761
Conversation
rust-highfive
assigned
nikomatsakis
Aug 12, 2015
nikomatsakis
reviewed
Aug 12, 2015
| .collect() | ||
| &TypeVariableValue::Bounded { .. } => Some(ty::TyVid { index: i as u32 }), | ||
| &TypeVariableValue::Known(v) => match v.sty { | ||
| ty::TyInfer(ty::FloatVar(_)) | ty::TyInfer(ty::IntVar(_)) => |
This comment has been minimized.
This comment has been minimized.
nikomatsakis
Aug 12, 2015
Contributor
Nit: the behavior of this fn merits a comment. Also, ty::TyInfer(_) seems more "forward compatible" to me (or else adding the other cases with a call to bug, since I think they are impossible)
nikomatsakis
reviewed
Aug 12, 2015
|
|
||
| // We now remove any numeric types that also have defaults, and instead insert | ||
| // the type variable with a defined fallback. | ||
| for ty in &unsolved_variables { | ||
| if let Some(_default) = default_map.get(ty) { |
This comment has been minimized.
This comment has been minimized.
nikomatsakis
Aug 12, 2015
Contributor
Nit: I personally prefer is_some() or perhaps Some(_) if your intention is just to check whether it is some.
nikomatsakis
reviewed
Aug 12, 2015
| // variables without defaults. | ||
| // Examine all unsolved variables, and narrow them to the set that have applicable | ||
| // defaults. We want to process any unsolved variables that have either an explicit | ||
| // user default, literal fallback, or are diverging. | ||
| for ty in &unsolved_variables { | ||
| let resolved = self.infcx().resolve_type_vars_if_possible(ty); |
This comment has been minimized.
This comment has been minimized.
nikomatsakis
Aug 12, 2015
Contributor
So, I think that resolved == ty must always hold at this point in the code. (I can't see why that would not be the case.) If so, we could simplify this code by removing this call, and removing the various matches below.
this is incorrect, because unsolved_variables returns, well, some variables that are in fact solved
nikomatsakis
reviewed
Aug 12, 2015
| unbound_tyvars.remove(resolved); | ||
| } | ||
| ty::TyInfer(_) => { | ||
| unbound_tyvars.insert(*ty); |
This comment has been minimized.
This comment has been minimized.
nikomatsakis
Aug 12, 2015
Contributor
This set unbound_tyvars probably needs a better name, like defaults_to_apply
This comment has been minimized.
This comment has been minimized.
|
After some discussion over IRC, @jroesch and I agreed current code isn't quite right -- in particular, the reason that user defaults wind up being preferred over integral defaults is because unsolved_variables just happens to return them in that order, which is quite non-obvious. My suggestion is to split the We must be sure to apply the user-defined defaults indiscriminantly (whether or not variable has since been bound) because otherwise conflicting defaults will go undetected. |
This comment has been minimized.
This comment has been minimized.
|
I also THINK that first loop could be simplified to something like this https://gist.github.com/nikomatsakis/a54823f42f8546436e7a, though naturally we'd want to use distinct sets as discussed in previous comment |
jroesch
force-pushed the
jroesch:default-typaram-user-defaults
branch
2 times, most recently
from
7cefd00
to
f9aff1e
Aug 19, 2015
This comment has been minimized.
This comment has been minimized.
|
Tidy is still unhappy. This looks good, modulo the question of what semantics we want. Can we rename things so that all the test cases have some common prefix, like "default-type-param-fallback"? |
jroesch
force-pushed the
jroesch:default-typaram-user-defaults
branch
from
0984c08
to
c9ecb8c
Sep 4, 2015
This comment has been minimized.
This comment has been minimized.
|
@bors r=nikomatsakis |
This comment has been minimized.
This comment has been minimized.
|
|
jroesch
force-pushed the
jroesch:default-typaram-user-defaults
branch
from
c9ecb8c
to
2f5df9e
Sep 4, 2015
This comment has been minimized.
This comment has been minimized.
|
@bors r=nikomatsakis |
This comment has been minimized.
This comment has been minimized.
|
|
bors
added a commit
that referenced
this pull request
Sep 4, 2015
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Some cfail issues: https://travis-ci.org/rust-lang/rust/builds/78808560#L6472 |
This comment has been minimized.
This comment has been minimized.
|
@sfackler thanks! looks like I broke the error message formatting on my last commit, will fix and try again |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
|
jroesch
added some commits
Aug 11, 2015
jroesch
force-pushed the
jroesch:default-typaram-user-defaults
branch
from
2f5df9e
to
bbcc665
Sep 16, 2015
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
Any updates on this PR? |
This comment has been minimized.
This comment has been minimized.
|
@steveklabnik this is my fault, things got a little busy with my move and starting my PhD, Niko was going to rebase this, but I assume he never found time. I'll get in contact with Niko and figure it out. |
This comment has been minimized.
This comment has been minimized.
|
Bah, I really ought to rebase this indeed. |
This comment has been minimized.
This comment has been minimized.
|
OK, so I pulled a copy of this branch locally and am going to close the PR. I'll follow up with @jroesch privately with a few questions. |
jroesch commentedAug 12, 2015
This addresses the issues raised by some members of the community about default priorities, and matches the behavior specified in the RFC.
You can also see the related internals discussion here
r? @nikomatsakis