|
8 | 8 | // option. This file may not be copied, modified, or distributed |
9 | 9 | // except according to those terms. |
10 | 10 |
|
11 | | -use hir::def_id::{DefId, CrateNum}; |
| 11 | +use hir::def_id::{DefId, CrateNum, LOCAL_CRATE}; |
12 | 12 | use syntax::ast::NodeId; |
13 | 13 | use syntax::symbol::{Symbol, InternedString}; |
14 | 14 | use ty::{Instance, TyCtxt}; |
@@ -266,7 +266,8 @@ impl<'a, 'gcx: 'tcx, 'tcx: 'a> CodegenUnitNameBuilder<'a, 'gcx, 'tcx> { |
266 | 266 | /// This function will build CGU names of the form: |
267 | 267 | /// |
268 | 268 | /// ``` |
269 | | - /// <crate-name>.<crate-disambiguator>(-<component>)*[.<special-suffix>] |
| 269 | + /// <crate-name>.<crate-disambiguator>[-in-<local-crate-id>](-<component>)*[.<special-suffix>] |
| 270 | + /// <local-crate-id> = <local-crate-name>.<local-crate-disambiguator> |
270 | 271 | /// ``` |
271 | 272 | /// |
272 | 273 | /// The '.' before `<special-suffix>` makes sure that names with a special |
@@ -311,9 +312,25 @@ impl<'a, 'gcx: 'tcx, 'tcx: 'a> CodegenUnitNameBuilder<'a, 'gcx, 'tcx> { |
311 | 312 | // Start out with the crate name and disambiguator |
312 | 313 | let tcx = self.tcx; |
313 | 314 | let crate_prefix = self.cache.entry(cnum).or_insert_with(|| { |
| 315 | + // Whenever the cnum is not LOCAL_CRATE we also mix in the |
| 316 | + // local crate's ID. Otherwise there can be collisions between CGUs |
| 317 | + // instantiating stuff for upstream crates. |
| 318 | + let local_crate_id = if cnum != LOCAL_CRATE { |
| 319 | + let local_crate_disambiguator = |
| 320 | + format!("{}", tcx.crate_disambiguator(LOCAL_CRATE)); |
| 321 | + format!("-in-{}.{}", |
| 322 | + tcx.crate_name(LOCAL_CRATE), |
| 323 | + &local_crate_disambiguator[0 .. 8]) |
| 324 | + } else { |
| 325 | + String::new() |
| 326 | + }; |
| 327 | + |
314 | 328 | let crate_disambiguator = format!("{}", tcx.crate_disambiguator(cnum)); |
315 | 329 | // Using a shortened disambiguator of about 40 bits |
316 | | - format!("{}.{}", tcx.crate_name(cnum), &crate_disambiguator[0 .. 8]) |
| 330 | + format!("{}.{}{}", |
| 331 | + tcx.crate_name(cnum), |
| 332 | + &crate_disambiguator[0 .. 8], |
| 333 | + local_crate_id) |
317 | 334 | }); |
318 | 335 |
|
319 | 336 | write!(cgu_name, "{}", crate_prefix).unwrap(); |
|
0 commit comments