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

Generic arg disambiguation #66104

Merged
merged 6 commits into from
Nov 20, 2019

Conversation

yodaldevoid
Copy link
Contributor

@yodaldevoid yodaldevoid commented Nov 5, 2019

Using the tactic suggested by @petrochenkov in #60804 (comment) and on zulip, this change checks type arguments to see if they are really incorrectly-parsed const arguments.

it should be noted that segments.len() == 1 && segments[0].arg.is_none() was reduced to segments.len() == 1 as suggested by @petrochenkov in zulip. This change allowed a few more existing tests to have their braces removed.

There are a couple of "problems" with these changes that I should note. First, there was a regression in the error messages found in "src/test/ui/privacy-ns1.rs" and "src/test/ui/privacy-ns1.rs". Second, some braces were unable to be removed from "src/test/ui/const-generics/fn-const-param-infer.rs". Those on line 24 caused the statement to stop equating when removed, and those on line 20 cause a statement that should not equate to produce no error when removed.

I have not looked further into any of these issues yet, though I would be willing to look into them before landing this. I simply wanted to get some other eyes on this before going further.

Fixes #60804

cc @varkor @jplatte

@rust-highfive
Copy link
Collaborator

r? @eddyb

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 5, 2019
@petrochenkov petrochenkov self-assigned this Nov 5, 2019
src/librustc/hir/lowering.rs Outdated Show resolved Hide resolved
src/librustc_resolve/late.rs Outdated Show resolved Hide resolved
@varkor varkor added the F-const_generics `#![feature(const_generics)]` label Nov 5, 2019
src/librustc/hir/lowering.rs Outdated Show resolved Hide resolved
Copy link
Member

@eddyb eddyb left a comment

Choose a reason for hiding this comment

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

Mostly LGTM, I'm only worried about the "value namespace" check, maybe @petrochenkov has some ideas there?

@petrochenkov
Copy link
Contributor

This will probably have to wait until the weekend.
r? @petrochenkov

src/librustc/hir/lowering.rs Outdated Show resolved Hide resolved
src/librustc/hir/def.rs Outdated Show resolved Hide resolved
src/librustc/hir/lowering.rs Outdated Show resolved Hide resolved
src/librustc_resolve/late.rs Outdated Show resolved Hide resolved
src/librustc_resolve/late.rs Outdated Show resolved Hide resolved
@@ -86,7 +64,19 @@ LL | use foo2::Bar;
LL | use foo3::Bar;
|

error: aborting due to 4 previous errors
error[E0107]: wrong number of const arguments: expected 0, found 1
Copy link
Member

Choose a reason for hiding this comment

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

This is interesting fallout. I imagine we should be able to special-case this sort of error to get back the old ones, though I'm not sure how much work that would be.

Copy link
Contributor

Choose a reason for hiding this comment

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

As far as I remember, the fix may be non-trivial and error-prone, so it's better to make an issue and fix it in a separate PR.

src/librustc/hir/def.rs Outdated Show resolved Hide resolved
src/librustc/hir/lowering.rs Outdated Show resolved Hide resolved
src/librustc/hir/lowering.rs Outdated Show resolved Hide resolved
DefPathData::AnonConst,
ExpnId::root(),
ty.span,
);
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, this distinction between types and consts (consts requiring an extra def path node) is something I didn't expect.
@eddyb, is it possible that creating this node during lowering is too late?

Copy link
Member

Choose a reason for hiding this comment

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

Maybe? But if you limit this to a really simple path with no generic args, there shouldn't be any children defs nested inside so making a leaf AnonConst should be fine.

Copy link
Contributor

Choose a reason for hiding this comment

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

@yodaldevoid
Could you bring back the "no generic args" restriction then?
(It should rarely be relevant in practice.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is done.

It should be noted that this does mean that we cannot remove all of the braces from the const-generics tests, specifically in "fn-const-param-infer.rs" which uses type params all over the place. How hard/wise would it be to iterate through the children of the new def to create defs for them if needed?

Copy link
Contributor

Choose a reason for hiding this comment

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

How hard/wise would it be to iterate through the children of the new def to create defs for them if needed?

I'm not sure.
First, we need to at least construct a test where things would break due to def paths not being constructed properly.
This is a material for another PR, IMO.
We get, like, 90% of benefits from disambiguating simple identifiers, so it would be nice to land this PR sooner.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we already have such a test in "fn-const-param-infer.rs", but I agree that is something for a future PR.

src/librustc/hir/lowering.rs Outdated Show resolved Hide resolved
src/librustc_resolve/late.rs Outdated Show resolved Hide resolved
src/librustc_resolve/late.rs Outdated Show resolved Hide resolved
src/librustc_resolve/late.rs Outdated Show resolved Hide resolved
@@ -86,7 +64,19 @@ LL | use foo2::Bar;
LL | use foo3::Bar;
|

error: aborting due to 4 previous errors
error[E0107]: wrong number of const arguments: expected 0, found 1
Copy link
Contributor

Choose a reason for hiding this comment

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

As far as I remember, the fix may be non-trivial and error-prone, so it's better to make an issue and fix it in a separate PR.

@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 9, 2019
@yodaldevoid
Copy link
Contributor Author

I believe I have addressed all comments given so far. There is one comment that I would like to have resolved before we move forward with these changes.

@petrochenkov petrochenkov added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 10, 2019
@petrochenkov
Copy link
Contributor

petrochenkov commented Nov 10, 2019

@yodaldevoid

What exactly is the reasoning behind only allowing single segment consts here? I'm not sure I've ever seen the reason spelled out.

We need to disambiguate in favor of types, but for multi-segment paths we cannot do that until type checking in general case (due to associated types).
https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/generic.20argument.20disambiguation/near/177847619

We can do some "figure disambiguation" for multi-segment paths to accept some cases, but that complicates the rules, and other alternatives like delaying the disambiguation until the generic argument substitution is really required (in type checking) may be preferable.

src/librustc/hir/lowering.rs Outdated Show resolved Hide resolved
src/librustc_resolve/late.rs Outdated Show resolved Hide resolved
src/librustc_resolve/late.rs Outdated Show resolved Hide resolved
@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 10, 2019
@yodaldevoid yodaldevoid force-pushed the generic-arg-disambiguation branch from b030eff to 512f344 Compare November 12, 2019 02:16
Gabriel Smith added 2 commits November 18, 2019 17:23
Braces were left in cases where generic args were in the generic const
paths.
The error messages of the two tests effected degraded in quality. The
errors no longer suggest types in other modules as they now assume that
the arguments are const args, not type args.
@yodaldevoid yodaldevoid force-pushed the generic-arg-disambiguation branch from ae90ff5 to 0207a15 Compare November 18, 2019 22:30
@petrochenkov petrochenkov added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 19, 2019
@petrochenkov
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Nov 19, 2019

📌 Commit 0207a15 has been approved by petrochenkov

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 19, 2019
@bors
Copy link
Contributor

bors commented Nov 19, 2019

⌛ Testing commit 0207a15 with merge 0a431b8e96bfc211dd2247e3cd56105e589b13a2...

@rust-highfive
Copy link
Collaborator

Your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
2019-11-19T18:41:44.6383257Z Attempting with retry: docker build --rm -t rust-ci -f /home/vsts/work/1/s/src/ci/docker/dist-x86_64-netbsd/Dockerfile /home/vsts/work/1/s/src/ci/docker
2019-11-19T18:41:44.8247314Z Sending build context to Docker daemon  528.4kB
2019-11-19T18:41:44.8247599Z 
2019-11-19T18:41:44.8847651Z Step 1/12 : FROM ubuntu:16.04
2019-11-19T18:41:45.5615847Z Get https://registry-1.docker.io/v2/library/ubuntu/manifests/16.04: received unexpected HTTP status: 500 Internal Server Error
2019-11-19T18:41:46.7933149Z Sending build context to Docker daemon  528.4kB
2019-11-19T18:41:46.7933379Z 
2019-11-19T18:41:46.8166438Z Step 1/12 : FROM ubuntu:16.04
2019-11-19T18:41:46.8166438Z Step 1/12 : FROM ubuntu:16.04
2019-11-19T18:41:47.3936219Z Get https://registry-1.docker.io/v2/library/ubuntu/manifests/16.04: received unexpected HTTP status: 500 Internal Server Error
2019-11-19T18:41:49.5810512Z Sending build context to Docker daemon  528.4kB
2019-11-19T18:41:49.5810778Z 
2019-11-19T18:41:49.6004519Z Step 1/12 : FROM ubuntu:16.04
2019-11-19T18:41:49.6004519Z Step 1/12 : FROM ubuntu:16.04
2019-11-19T18:41:50.0978698Z Get https://registry-1.docker.io/v2/library/ubuntu/manifests/16.04: received unexpected HTTP status: 500 Internal Server Error
2019-11-19T18:41:53.2482214Z Sending build context to Docker daemon  528.4kB
2019-11-19T18:41:53.2487663Z 
2019-11-19T18:41:53.2766217Z Step 1/12 : FROM ubuntu:16.04
2019-11-19T18:41:53.2766217Z Step 1/12 : FROM ubuntu:16.04
2019-11-19T18:41:53.7856733Z Get https://registry-1.docker.io/v2/library/ubuntu/manifests/16.04: received unexpected HTTP status: 500 Internal Server Error
2019-11-19T18:41:57.9035917Z Sending build context to Docker daemon  528.4kB
2019-11-19T18:41:57.9036879Z 
2019-11-19T18:41:57.9245669Z Step 1/12 : FROM ubuntu:16.04
2019-11-19T18:41:57.9245669Z Step 1/12 : FROM ubuntu:16.04
2019-11-19T18:41:58.4398790Z Get https://registry-1.docker.io/v2/library/ubuntu/manifests/16.04: received unexpected HTTP status: 500 Internal Server Error
2019-11-19T18:41:58.4470573Z 
2019-11-19T18:41:58.4470573Z 
2019-11-19T18:41:58.4581131Z ##[error]Bash exited with code '1'.
2019-11-19T18:41:58.4614098Z ##[section]Starting: Checkout
2019-11-19T18:41:58.4616398Z ==============================================================================
2019-11-19T18:41:58.4616517Z Task         : Get sources
2019-11-19T18:41:58.4616601Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@bors
Copy link
Contributor

bors commented Nov 19, 2019

💔 Test failed - checks-azure

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Nov 19, 2019
@varkor
Copy link
Member

varkor commented Nov 19, 2019

@bors retry

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 19, 2019
@bors
Copy link
Contributor

bors commented Nov 20, 2019

⌛ Testing commit 0207a15 with merge f50d6ea...

bors added a commit that referenced this pull request Nov 20, 2019
…ochenkov

Generic arg disambiguation

Using the tactic suggested by @petrochenkov in #60804 (comment) and on [zulip](https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/generic.20argument.20disambiguation), this change checks type arguments to see if they are really incorrectly-parsed const arguments.

it should be noted that `segments.len() == 1 && segments[0].arg.is_none()` was reduced to `segments.len() == 1` as suggested by @petrochenkov in [zulip](https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/generic.20argument.20disambiguation/near/177848002). This change allowed a few more existing tests to have their braces removed.

There are a couple of "problems" with these changes that I should note. First, there was a regression in the error messages found in "src/test/ui/privacy-ns1.rs" and "src/test/ui/privacy-ns1.rs". Second, some braces were unable to be removed from "src/test/ui/const-generics/fn-const-param-infer.rs". Those on line 24 caused the statement to stop equating when removed, and those on line 20 cause a statement that should not equate to produce no error when removed.

I have not looked further into any of these issues yet, though I would be willing to look into them before landing this. I simply wanted to get some other eyes on this before going further.

Fixes #60804

cc @varkor @jplatte
@bors
Copy link
Contributor

bors commented Nov 20, 2019

☀️ Test successful - checks-azure
Approved by: petrochenkov
Pushing f50d6ea to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Nov 20, 2019
@bors bors merged commit 0207a15 into rust-lang:master Nov 20, 2019
@rust-highfive
Copy link
Collaborator

📣 Toolstate changed by #66104!

Tested on commit f50d6ea.
Direct link to PR: #66104

🎉 rustc-guide on linux: test-fail → test-pass (cc @JohnTitor @amanjeev @spastorino @mark-i-m, @rust-lang/infra).

rust-highfive added a commit to rust-lang-nursery/rust-toolstate that referenced this pull request Nov 20, 2019
Tested on commit rust-lang/rust@f50d6ea.
Direct link to PR: <rust-lang/rust#66104>

🎉 rustc-guide on linux: test-fail → test-pass (cc @JohnTitor @amanjeev @spastorino @mark-i-m, @rust-lang/infra).
@yodaldevoid yodaldevoid deleted the generic-arg-disambiguation branch December 1, 2019 17:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-const_generics `#![feature(const_generics)]` merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Const generic arguments should be disambiguated from type arguments
7 participants