Skip to content

The crate store does not deduplicate used crates #3474

Closed

Description

@brson

If you have code that links the same crate multiple times, the metadata loader may record several copies of the same crate in its crate list, e.g.

extern mod std(vers = "0.4");
extern std;

This could have potentially bad effects. It has already resulted a mysterious situation that caused all the crate hashes to change because of a spurious 'use'. I can imagine it also could cause types to not resolve if referenced from different mount points.

I believe that the metadata loader does make some effort to do this but it isn't sufficient.

Activity

  1. pnkfelix commented on Jun 24, 2013

    @pnkfelix
    Contributor

    Bug triage 2013jun24. I tried to construct an example where linking to the same crate multiple times would cause the types to not resolve, but I did not encounter any examples of such. Still, it would be good to fix this bug.

  2. huonw commented on Dec 19, 2013

    @huonw
    Contributor

    Triage: I think this may be fixed.

    #[no_uv];
    
    #[cfg(extra_crate)]
    extern mod std;
    
    fn main() {}
    $ RUST_LOG=rustc::metadata::creader rustc --cfg extra_crate 3474.rs
    resolving extern mod stmt. ident: @"std" path_opt: None
    resolving deps of external crate
    resolved crates:
    cnum: 1u32
    span: syntax::codemap::Span{lo: syntax::codemap::BytePos(0u32), hi: syntax::codemap::BytePos(0u32), expn_info: None}
    hash: @"04ff901ef9eb93b7ed8d17b7ddf76fa8eb8b4c7295ad21af7133790d77381330"
    

    and the output is the same without --cfg extra_crate. The above is full dump of the crate_cache list, clearly std doesn't appear twice (Without the no_uv there are two, rustuv and std).

  3. added a commit that references this issue on May 11, 2024
  4. added a commit that references this issue on Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-linkageArea: linking into static, shared libraries and binariesA-metadataArea: Crate metadata

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions