Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
symbol_names: treat ReifyShim like VtableShim.
  • Loading branch information
eddyb committed Mar 21, 2020
1 parent 98803c1 commit 14e0aad
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
4 changes: 0 additions & 4 deletions src/librustc/ty/instance.rs
Expand Up @@ -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(
Expand Down
9 changes: 7 additions & 2 deletions src/librustc_symbol_mangling/legacy.rs
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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);
});

Expand Down
13 changes: 11 additions & 2 deletions src/librustc_symbol_mangling/v0.rs
Expand Up @@ -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()
};
Expand Down

0 comments on commit 14e0aad

Please sign in to comment.