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

Improvements to pattern resolution + some refactoring #34095

Merged
merged 6 commits into from
Jun 10, 2016

Conversation

petrochenkov
Copy link
Contributor

@petrochenkov petrochenkov commented Jun 5, 2016

Continuation of #33929
First commit is a careful rewrite of resolve_pattern, pattern path resolution and new binding creation logic is factored out in separate functions, some minor bugs are fixed. Also, resolve_possibly_assoc_item doesn't swallow modules now.
Later commits are refactorings, see the comment descriptions.

I intend to continue this work later with better support for Def::Err in patterns in post-resolve stages and cleanup of pattern resolution code in type checker.

Fixes #32086
Fixes #34047 ([breaking-change])
Fixes #34074

cc @jseyfried
r? @eddyb

@@ -1196,12 +1195,11 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {

(*op)(self, cmt.clone(), pat);

// This function can be used during region checking when not all paths are fully
// resolved. Partially resolved paths in patterns can only legally refer to
// associated constants which don't require categorization.
Copy link
Member

Choose a reason for hiding this comment

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

Region-checking runs after all paths have been resolved though, doesn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, I made this comment after encountering an ICE. But maybe it was "no resolution at all" for a non-path pattern rather than a partial resolution. I'll investigate.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's called during closure kind inference.

@eddyb
Copy link
Member

eddyb commented Jun 5, 2016

LGTM, modulo the questions I've raised, although I'd like a second look. cc @nrc

@arielb1
Copy link
Contributor

arielb1 commented Jun 5, 2016

I feel that it would be better to make all same-named idents in a match arm resolve to the same pattern, as I did in arielb1@0dbd027 - this makes for much cleaner code, and removes the need for hygiene after lowering.

path_names_to_string(path, 0), ty.id, def);
self.record_def(ty.id, def);
match def.base_def {
Def::Mod(..) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe have some real marker instead of Def::Mod?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This particular Def::Mod is not a marker, but a real module encountered in type position.
As for Def::Mod used in fake resolutions for <T>::A, it's a status quo, I'd like to come up with some better solution, then used now, but not in this PR. Just using a separate marker for it doesn't make much difference, I did some quick experiments.

@petrochenkov
Copy link
Contributor Author

petrochenkov commented Jun 5, 2016

@arielb1

it would be better to make all same-named idents in a match arm resolve to the same pattern

That would be great, I wanted to do this someday, but not as a part of this PR. If you already have the implementation, can I just apply it on top of this PR?

pat_id: NodeId,
outer_pat_id: NodeId,
pat_src: PatternSource,
bindings_list: &mut HashMap<Name, NodeId>)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I think bindings or bindings_map would make more sense

@jseyfried
Copy link
Contributor

@petrochenkov Excellent!
Reviewed, LGTM modulo the region checking comment, the error codes, and my (optional) nits.

@eddyb feel free to r=me if you're on the fence.

@arielb1
Copy link
Contributor

arielb1 commented Jun 6, 2016

@petrochenkov

Sure. If you won't add it to this PR I will land it myself.

@petrochenkov
Copy link
Contributor Author

Updated.

@bors
Copy link
Contributor

bors commented Jun 9, 2016

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

@petrochenkov
Copy link
Contributor Author

Rebased.
ping @eddyb

@eddyb
Copy link
Member

eddyb commented Jun 9, 2016

@bors r=jseyfried

@bors
Copy link
Contributor

bors commented Jun 9, 2016

📌 Commit 7b048c3 has been approved by jseyfried

@petrochenkov
Copy link
Contributor Author

Oops, just fixed one more typo.

@eddyb
Copy link
Member

eddyb commented Jun 9, 2016

@bors r=jseyfried

@bors
Copy link
Contributor

bors commented Jun 9, 2016

📌 Commit d407da6 has been approved by jseyfried

@bors
Copy link
Contributor

bors commented Jun 9, 2016

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

@petrochenkov
Copy link
Contributor Author

Rebased again.

@eddyb
Copy link
Member

eddyb commented Jun 9, 2016

@bors r=jseyfried

@bors
Copy link
Contributor

bors commented Jun 9, 2016

📌 Commit 6d7b35b has been approved by jseyfried

@bors
Copy link
Contributor

bors commented Jun 9, 2016

⌛ Testing commit 6d7b35b with merge 7d2f75a...

bors added a commit that referenced this pull request Jun 9, 2016
Improvements to pattern resolution + some refactoring

Continuation of #33929
First commit is a careful rewrite of `resolve_pattern`, pattern path resolution and new binding creation logic is factored out in separate functions, some minor bugs are fixed. Also, `resolve_possibly_assoc_item` doesn't swallow modules now.
Later commits are refactorings, see the comment descriptions.

I intend to continue this work later with better support for `Def::Err` in patterns in post-resolve stages and cleanup of pattern resolution code in type checker.

Fixes #32086
Fixes #34047 ([breaking-change])
Fixes #34074

cc @jseyfried
r? @eddyb
@bors bors merged commit 6d7b35b into rust-lang:master Jun 10, 2016
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
@petrochenkov petrochenkov deleted the pathir2 branch September 21, 2016 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants