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

check the recursion limit when finding a struct's tail #79445

Merged
merged 1 commit into from
Dec 5, 2020

Conversation

SNCPlay42
Copy link
Contributor

fixes #79437

This does a delay_span_bug (via ty_error_with_message) rather than emit a new error message, under the assumption that there will be an error elsewhere (even if the type isn't infinitely recursive, just deeper than the recursion limit, this appears to be the case).

@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 26, 2020
@jyn514 jyn514 added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Nov 26, 2020
@meithecatte
Copy link
Contributor

I don't know much about rustc internals, but nevertheless, I don't think this is the right approach. I would expect that making all code work with cyclic data structures, even when such cycles can only be present in ill-formed code, is not an attainable goal. As I've mentioned in #79437 (comment), I believe that when the error about recursive types is emitted in the first place, the offending field should be replaced with a TyKind::Error.

@oli-obk
Copy link
Contributor

oli-obk commented Dec 3, 2020

I believe that when the error about recursive types is emitted in the first place, the offending field should be replaced with a TyKind::Error.

that would be ideal, but I don't see how that can be done in the present setup. The typeck code that actually performs the check that detects the recursion happens without yielding any results but diagnostic messages:

check_representable(tcx, span, def_id);

It would require a nontrivial amount of refactoring to implement that, so I think we should first merge a fix, but keep open an issue about solving this properly and use that issue to plan how to actually do that.

@oli-obk
Copy link
Contributor

oli-obk commented Dec 3, 2020

r? @oli-obk

@rust-highfive rust-highfive assigned oli-obk and unassigned eddyb Dec 3, 2020
Copy link
Contributor

@oli-obk oli-obk left a comment

Choose a reason for hiding this comment

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

Instead of having an iteration limit, we could also fill in an FxHashSet<Ty<'tcx>> to see if we've encountered a type before. If we have, we can abort directly. If the set grows beyond the recursion limit, we abort due to the recursion limit.

We'll need to benchmark that change though

@SNCPlay42 SNCPlay42 force-pushed the struct-tail-recursion-limit branch from a648e6f to 98fc02d Compare December 4, 2020 16:45
@oli-obk
Copy link
Contributor

oli-obk commented Dec 4, 2020

Instead of having an iteration limit, we could also fill in an FxHashSet<Ty<'tcx>> to see if we've encountered a type before. If we have, we can abort directly. If the set grows beyond the recursion limit, we abort due to the recursion limit.

What do you think about this? Do prefer if we merge the PR as it is (it's totally fine as it is) and move this to an issue, or do you want to have a look at that in this PR?

@SNCPlay42 SNCPlay42 closed this Dec 4, 2020
@SNCPlay42 SNCPlay42 reopened this Dec 4, 2020
@SNCPlay42
Copy link
Contributor Author

Wouldn't that only improve performance in the case we're going to error? If we ever stop early because we found a type we'd seen before in the hash set, we've seen a recursive type and compilation will ultimately fail. It doesn't seem like it would be worth the performance cost of building the set in the happy path.

(oops, fumbled the close button)

@oli-obk
Copy link
Contributor

oli-obk commented Dec 4, 2020

It doesn't seem like it would be worth the performance cost of building the set in the happy path.

Yea, that's what I was worried about as well with my comment about benchmarking above

@bors r+

@bors
Copy link
Contributor

bors commented Dec 4, 2020

📌 Commit 98fc02d has been approved by oli-obk

@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 Dec 4, 2020
@bors
Copy link
Contributor

bors commented Dec 4, 2020

⌛ Testing commit 98fc02d with merge cc29f8ddc616e9245378d720729339a9f22df7b7...

@bors
Copy link
Contributor

bors commented Dec 4, 2020

💔 Test failed - checks-actions

@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 Dec 4, 2020
@jonas-schievink
Copy link
Contributor

@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 Dec 5, 2020
@bors
Copy link
Contributor

bors commented Dec 5, 2020

⌛ Testing commit 98fc02d with merge 5bb68c3...

@bors
Copy link
Contributor

bors commented Dec 5, 2020

☀️ Test successful - checks-actions
Approved by: oli-obk
Pushing 5bb68c3 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Dec 5, 2020
@bors bors merged commit 5bb68c3 into rust-lang:master Dec 5, 2020
@rustbot rustbot added this to the 1.50.0 milestone Dec 5, 2020
@SNCPlay42 SNCPlay42 deleted the struct-tail-recursion-limit branch April 18, 2021 01:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

struct Foo(Self) leads to infinite loop
9 participants