Rollup merge of #70003 - eddyb:symbol-mangling-reify-shims, r=nikomatsakis

symbol_names: treat ReifyShim like VtableShim.

Without this, the `#[track_caller]` tests don't pass with `-Zsymbol-mangling-version=v0`, because there is a symbol name collision between the `ReifyShim` and the original definition.

cc @anp
This commit is contained in:
Dylan DPC 2020-03-21 22:56:18 +01:00 committed by GitHub
commit 834ed36a53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 8 deletions

View File

@ -406,10 +406,6 @@ impl<'tcx> Instance<'tcx> {
| InstanceDef::VtableShim(..) => Some(self.substs),
}
}
pub fn is_vtable_shim(&self) -> bool {
if let InstanceDef::VtableShim(..) = self.def { true } else { false }
}
}
fn needs_fn_once_adapter_shim(

View File

@ -59,10 +59,14 @@ pub(super) fn mangle(
.print_def_path(def_id, &[])
.unwrap();
if instance.is_vtable_shim() {
if let ty::InstanceDef::VtableShim(..) = instance.def {
let _ = printer.write_str("{{vtable-shim}}");
}
if let ty::InstanceDef::ReifyShim(..) = instance.def {
let _ = printer.write_str("{{reify-shim}}");
}
printer.path.finish(hash)
}
@ -123,7 +127,8 @@ fn get_symbol_hash<'tcx>(
}
// We want to avoid accidental collision between different types of instances.
// Especially, VtableShim may overlap with its original instance without this.
// Especially, `VtableShim`s and `ReifyShim`s may overlap with their original
// instances without this.
discriminant(&instance.def).hash_stable(&mut hcx, &mut hasher);
});

View File

@ -34,8 +34,17 @@ pub(super) fn mangle(
binders: vec![],
out: String::from(prefix),
};
cx = if instance.is_vtable_shim() {
cx.path_append_ns(|cx| cx.print_def_path(def_id, substs), 'S', 0, "").unwrap()
// Append `::{shim:...#0}` to shims that can coexist with a non-shim instance.
let shim_kind = match instance.def {
ty::InstanceDef::VtableShim(_) => Some("vtable"),
ty::InstanceDef::ReifyShim(_) => Some("reify"),
_ => None,
};
cx = if let Some(shim_kind) = shim_kind {
cx.path_append_ns(|cx| cx.print_def_path(def_id, substs), 'S', 0, shim_kind).unwrap()
} else {
cx.print_def_path(def_id, substs).unwrap()
};