[−][src]Crate rustc_symbol_mangling

The Rust Linkage Model and Symbol Names

The semantic model of Rust linkage is, broadly, that "there's no global namespace" between crates. Our aim is to preserve the illusion of this model despite the fact that it's not quite possible to implement on modern linkers. We initially didn't use system linkers at all, but have been convinced of their utility.

There are a few issues to handle:

In order to fulfill the above requirements the following scheme is used by the compiler:

The main tool for avoiding naming conflicts is the incorporation of a 64-bit hash value into every exported symbol name. Anything that makes a difference to the symbol being named, but does not show up in the regular path needs to be fed into this hash:

The two measures described above suffice to avoid intra-crate conflicts. In order to also avoid inter-crate conflicts two more measures are taken:

A note on symbol name stability

Previous versions of the compiler resorted to feeding NodeIds into the symbol hash in order to disambiguate between items with the same path. The current version of the name generation algorithm takes great care not to do that, since NodeIds are notoriously unstable: A small change to the code base will offset all NodeIds after the change and thus, much as using the SVH in the hash, invalidate an unbounded number of symbol names. This makes re-using previously compiled code for incremental compilation virtually impossible. Thus, symbol hash generation exclusively relies on DefPaths which are much more robust in the face of changes to the code base.

Modules

legacy
test

Walks the crate looking for items/impl-items/trait-items that have either a rustc_symbol_name or rustc_def_path attribute and generates an error giving, respectively, the symbol name or def-path. This is used for unit testing the code that generates paths etc in all kinds of annoying scenarios.

v0

Functions

compute_symbol_name

Computes the symbol name for the given instance. This function will call compute_instantiating_crate if it needs to factor the instantiating crate into the symbol name.

is_generic
provide
symbol_name_for_instance_in_crate

This function computes the symbol name for the given instance and the given instantiating crate. That is, if you know that instance X is instantiated in crate Y, this is the symbol name this instance would have.

symbol_name_provider