Skip to content

resolve: fix stack overflow on cyclic ambiguous glob reexports - #160983

Closed
calvinrp wants to merge 1 commit into
rust-lang:mainfrom
calvinrp:fix/effective-vis-glob-cycle
Closed

resolve: fix stack overflow on cyclic ambiguous glob reexports#160983
calvinrp wants to merge 1 commit into
rust-lang:mainfrom
calvinrp:fix/effective-vis-glob-cycle

Conversation

@calvinrp

@calvinrp calvinrp commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Fixes #160685 (1.98 beta regression from #159039, found by the crater run).

#159039 made update_decl_chain follow ambiguity_vis_max recursively, so the most visible declaration's whole reexport chain gets its effective visibility. But ambiguous glob imports can form cycles, in the minimized example two modules glob-import each other and the same item also arrives through a third, and on such a cycle the recursion never terminates, so rustc overflows its stack.

Fix, two parts that belong together:

  • Each chain walk now visits a declaration at most once (a visited set threaded through the recursion). This breaks the cycle.
  • Skipping a revisit can leave one update behind within that single walk, so the crate root's bindings now walk inside the changed fixpoint loop like every other module's bindings already do. Anything a walk skips is re-attempted until nothing changes, so the final table is unchanged for code that compiled before.

The minimized reproducer from the issue is added as a check-pass test. tests/ui/{imports,privacy,resolve} pass with the #159039 regression tests unmodified, and a crate depending on reflect_tools 0.4.0 (the crater trigger) compiles again.

Since the regression ships in 1.98 otherwise, nominating for beta backport.

@rustbot label +A-resolve +A-visibility +T-compiler +beta-nominated

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 12, 2026
@rustbot

rustbot commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator

r? @camelid

rustbot has assigned @camelid.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 75 candidates
  • Random selection from 19 candidates

@rustbot rustbot added A-resolve Area: Name/path resolution done by `rustc_resolve` specifically beta-nominated Nominated for backporting to the compiler in the beta channel. A-visibility Area: Visibility / privacy labels Aug 12, 2026
@rustbot

This comment has been minimized.

`update_decl_chain` follows `ambiguity_vis_max` recursively, and
ambiguous glob imports can form cyclic reexport chains, so the walk
never terminated. Visit each declaration at most once per walk, and
walk the crate root's bindings inside the `changed` fixpoint loop like
every other module's, so any update a skipped revisit leaves behind is
re-attempted until nothing changes.
@calvinrp
calvinrp force-pushed the fix/effective-vis-glob-cycle branch from e8a9bbb to bbccc30 Compare August 12, 2026 12:46
@apiraino

Copy link
Copy Markdown
Contributor

@calvinrp can you please share how you're using an LLM to author this patch? Thanks

@calvinrp

Copy link
Copy Markdown
Contributor Author

@apiraino I used Claude Fable to assist with investigating and testing the patch. I should have disclosed that upfront. I was trying to be helpful to resolve this regression quickly.

@calvinrp

Copy link
Copy Markdown
Contributor Author

I'm going to close this and revise.

@calvinrp calvinrp closed this Aug 12, 2026
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 12, 2026
@jieyouxu jieyouxu removed the beta-nominated Nominated for backporting to the compiler in the beta channel. label Aug 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-resolve Area: Name/path resolution done by `rustc_resolve` specifically A-visibility Area: Visibility / privacy 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.

1.98 beta regression: compiler stack overflow

5 participants