Skip to content

Move collection of items accessible directly or through reexports from rustc_privacy to rustc_resolve #82064

Open

Description

Directly accessible item AccessLevel::Public is an item with a fully public path from a crate root making it nameable from other crates.
AccessLevel::Exported item is an item with a fully public chain of reexports or modules making it nameable from other crates.
All such items can be found either by visiting the crate repeatedly and marking new and new items as Public/Exported until no items can be marked anymore, or doing the same thing by maintaining an item queue and pushing/popping things to/from it for processing until the queue is empty.

Sets of directly accessible and reexported items are build in rustc_privacy (EmbargoVisitor).
The problem is that information about reexport chains is lost at that point, so the produced sets do not contain all the necessary items.
fn update_visibility_of_intermediate_use_statements hack tries to mitigate that issue a bit, but it doesn't work correctly in presence of glob imports (see PR #57922 for more details).

What we need to do is to move the logic for determining AccessLevel::{Public,Exported}s to rustc_resolve where all the information about reexport chains is still available.
That logic should run either as a part of fn finalize_imports or after it.
It should build a table NodeId -> AccessLevel in Resolver, and that table should later move to struct ResolverOutputs and then to GlobalCtxt like all other ResolverOutputs fields.

Later in rustc_privacy the resolver-based table should be used as a seed for EmbargoVisitor which will then assign type-based accessibility levels like AccessLevel::Reachable etc.
fn update_visibility_of_intermediate_use_statements will need to be removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

A-resolveArea: Name resolutionA-visibilityArea: Visibility / privacyT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions