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

Some more pattern cleanup and bugfixing #34365

Merged
merged 11 commits into from
Jul 10, 2016
Merged

Conversation

petrochenkov
Copy link
Contributor

@petrochenkov petrochenkov commented Jun 19, 2016

The next part of #34095

The most significant fixed mistake is definitions for partially resolved associated types not being updated after full resolution.

fn f<T: Fn()>(arg: T::Output) { .... } // <- the definition of T::Output was not updated in def_map

For this reason unstable associated types of stable traits, like FnOnce::Output, could be used in stable code when written in unqualified form. Now they are properly checked, this is a [breaking-change] (pretty minor one, but a crater run would be nice). The fix is not to use unstable library features in stable code, alternatively FnOnce::Output can be stabilized.

Besides that, paths in struct patterns and expressions S::A { .. } are now fully resolved as associated types. Such types cannot be identified as structs at the moment, i.e. the change doesn't make previously invalid code valid, but it improves error diagnostics.

Other changes: Def::Err is supported better (less chances for ICEs for erroneous code), some incorrect error messages are corrected, some duplicated error messages are not reported, ADT definitions are now available through constructor IDs, everything else is cleanup and code audit.

Fixes #34209
Closes #22933 (adds tests)

r? @eddyb

@eddyb eddyb added the S-waiting-on-crater Status: Waiting on a crater run to be completed. label Jun 19, 2016
@eddyb
Copy link
Member

eddyb commented Jun 19, 2016

cc @nrc @nikomatsakis

let adt = ccx.tcx.intern_adt_def(did, ty::AdtKind::Struct, variants);
if let Some(ctor_id) = ctor_id {
// Make adt definition available through constructor id as well.
ccx.tcx.insert_adt_def(ctor_id, adt);
Copy link
Member

Choose a reason for hiding this comment

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

Why was this done?

Copy link
Contributor Author

@petrochenkov petrochenkov Jun 19, 2016

Choose a reason for hiding this comment

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

So you can go directly from Def::Struct to ADT definition regardless of where this Def::Struct is used - in a pattern, expression or a type. Sometimes Def::Struct denotes a type and sometimes a constructor and previously lookup_adt_def worked only with Def::Structs in type context and panicked otherwise, so workarounds had to be used.

let ty_substituted = self.instantiate_type_scheme(path.span, substs, &type_scheme.ty);
self.write_ty(node_id, ty_substituted);
self.write_substs(node_id, ty::ItemSubsts {
substs: substs
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm, this is probably a mistake and regression. The substs written are substs before instantiate_type_scheme, not after.
I.e. for

type Alias<T> = S<T, u16>;
// Inside match
Alias::<u8> { .. }

only u8 is written, not [u8, u16].
However, instantiate_path does the same mistake(?) even without this PR.

jseyfried added a commit to jseyfried/rust that referenced this pull request Jun 25, 2016
@bors
Copy link
Contributor

bors commented Jun 28, 2016

☔ The latest upstream changes (presumably #34424) made this pull request unmergeable. Please resolve the merge conflicts.

@petrochenkov
Copy link
Contributor Author

Rebased.
Still waiting for crater run.

@eddyb
Copy link
Member

eddyb commented Jun 29, 2016

@petrochenkov Sorry about that, @nikomatsakis is on vacation.
But I have crater access now, so here's the crater report.
The two actual root regressions are in traverse and parsell, both using FnOnce::Output.

@eddyb eddyb added I-nominated T-lang Relevant to the language team, which will review and decide on the PR/issue. and removed S-waiting-on-crater Status: Waiting on a crater run to be completed. labels Jun 29, 2016
@nikomatsakis
Copy link
Contributor

So as I wrote on IRC, I don't think that F::Output (where F: FnOnce) has to be unstable -- and I'm not sure it was intended to be, though I'll have to check around. What we wanted to be careful about was something like F: FnOnce<()>, because this reveals the form of the "input types", and there was some concern that F: FnOnce<(A,B)> might change to F: FnOnce<A,B> or something, depending on what approach we wound up with for variadic generics. But I think we know that the return type will always be an associated type, and I see no reason we would ever change its name.

@bors
Copy link
Contributor

bors commented Jun 30, 2016

☔ The latest upstream changes (presumably #34552) made this pull request unmergeable. Please resolve the merge conflicts.

@aturon
Copy link
Member

aturon commented Jun 30, 2016

But I think we know that the return type will always be an associated type, and I see no reason we would ever change its name.

I agree on both counts. It seems OK for this name to be available on stable Rust.

@aturon
Copy link
Member

aturon commented Jul 7, 2016

Lang team meeting: we decided we should try this PR, but with marking the Output type as stable, and see whether that eliminates the regressions.

@eddyb
Copy link
Member

eddyb commented Jul 7, 2016

@petrochenkov Looks like FnOnce::Output is explicitly marked unstable so just flipping that should work. This is likely what @nikomatsakis had in mind.

Instead of Def::Err erroneous bindings can get usual definitions that doesn't require special cases later on and have less chances to generate ICE.
…k_pat_path

Update definitions in def_map for associated types written in unqualified form (like `Self::Output`)
Cleanup finish_resolving_def_to_ty/resolve_ty_and_def_ufcs
Make VariantDef's available through constructor IDs
@petrochenkov
Copy link
Contributor Author

Rebased, FnOnce::Output is stabilized.

@eddyb
Copy link
Member

eddyb commented Jul 9, 2016

Crater report only shows 4 regressions in code using the unstable librustc APIs.

@alexcrichton @aturon Can we merge this with the stabilization of FnOnce::Output directly?

@aturon
Copy link
Member

aturon commented Jul 9, 2016

@eddyb Yep, at this point everybody's signed off on that step.

@eddyb
Copy link
Member

eddyb commented Jul 9, 2016

@bors r+

@bors
Copy link
Contributor

bors commented Jul 9, 2016

📌 Commit d27e55c has been approved by eddyb

@bors
Copy link
Contributor

bors commented Jul 9, 2016

⌛ Testing commit d27e55c with merge f93aaf8...

bors added a commit that referenced this pull request Jul 9, 2016
Some more pattern cleanup and bugfixing

The next part of #34095

The most significant fixed mistake is definitions for partially resolved associated types not being updated after full resolution.
```
fn f<T: Fn()>(arg: T::Output) { .... } // <- the definition of T::Output was not updated in def_map
```
For this reason unstable associated types of stable traits, like `FnOnce::Output`, could be used in stable code when written in unqualified form. Now they are properly checked, this is a **[breaking-change]** (pretty minor one, but a crater run would be nice). The fix is not to use unstable library features in stable code, alternatively `FnOnce::Output` can be stabilized.

Besides that, paths in struct patterns and expressions `S::A { .. }` are now fully resolved as associated types. Such types cannot be identified as structs at the moment, i.e. the change doesn't make previously invalid code valid, but it improves error diagnostics.

Other changes: `Def::Err` is supported better (less chances for ICEs for erroneous code), some incorrect error messages are corrected, some duplicated error messages are not reported, ADT definitions are now available through constructor IDs, everything else is cleanup and code audit.

Fixes #34209
Closes #22933 (adds tests)

r? @eddyb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
6 participants