Skip to content

Long compile time due to privacy checking private alias of public type #50614

Closed
@iliekturtles

Description

@iliekturtles

Private type aliases of public types (e.g. type V = f32;) cause long compile times in the privacy checking phase. Making the type alias public resolves the issue. See iliekturtles/uom#52 where the issue was originally identified and the work-around was found. See privacy_checking.rs for a simple example to reproduce the problem.

The following command can be used to reproduce the problem with a private type alias.

time rustc +nightly --crate-type lib privacy_checking.rs -Ztime-passes --cfg 'feature="priv"' --cfg 'feature="T6"' --cfg 'feature="I5"'

Replacing the priv feature with pub shows that the issue is corrected when using a public type alias.

time rustc +nightly --crate-type lib privacy_checking.rs -Ztime-passes --cfg 'feature="pub"' --cfg 'feature="T6"' --cfg 'feature="I5"'

Varying the T_ (number of types) and I_ (number of trait impls) features shows how compile times change. See the below test data from my machine. It looks like privacy checking of a private type alias of a public type is exponential with the number of types and becomes linear with a very slight slope when checking public aliases.

image

Types Impls Ty x Impl Time Privacy checking Time (pub) Privacy checking (pub)
1 5 5 1.324 0.206 1.123 0.023
2 5 10 2.816 0.823 1.999 0.061
3 5 15 4.641 1.853 2.827 0.080
4 5 20 6.968 3.243 3.714 0.103
5 5 25 9.219 4.700 4.686 0.129
6 5 30 12.721 7.371 5.598 0.163

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-visibilityArea: Visibility / privacyC-bugCategory: This is a bug.I-compiletimeIssue: Problems and improvements with respect to compile times.T-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