X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=compiler%2Frustc_codegen_ssa%2Fsrc%2Fdebuginfo%2Ftype_names.rs;h=b63851c195de6df091bed7ed0d4627ee3bb736ac;hb=26dd6ac8302ab7230cd2d78797910931e4b83015;hp=831c34d8f1f604fdd232d18c4605294088697146;hpb=4a3be6e6e296e3f58e8dfb493469d1cefdff3892;p=rust.git diff --git a/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs b/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs index 831c34d8f1f..b63851c195d 100644 --- a/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs +++ b/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs @@ -146,7 +146,7 @@ fn push_debuginfo_type_name<'tcx>( if cpp_like_debuginfo { output.push_str("array$<"); push_debuginfo_type_name(tcx, inner_type, true, output, visited); - match len.val { + match len.val() { ty::ConstKind::Param(param) => write!(output, ",{}>", param.name).unwrap(), _ => write!(output, ",{}>", len.eval_usize(tcx, ty::ParamEnv::reveal_all())) .unwrap(), @@ -154,7 +154,7 @@ fn push_debuginfo_type_name<'tcx>( } else { output.push('['); push_debuginfo_type_name(tcx, inner_type, true, output, visited); - match len.val { + match len.val() { ty::ConstKind::Param(param) => write!(output, "; {}]", param.name).unwrap(), _ => write!(output, "; {}]", len.eval_usize(tcx, ty::ParamEnv::reveal_all())) .unwrap(), @@ -343,7 +343,7 @@ fn push_debuginfo_type_name<'tcx>( // We only care about avoiding recursing // directly back to the type we're currently // processing - visited.remove(t); + visited.remove(&t); } ty::Closure(def_id, substs) | ty::Generator(def_id, substs, ..) => { // Name will be "{closure_env#0}", "{generator_env#0}", or @@ -469,7 +469,14 @@ fn pop_auto_trait_separator(output: &mut String) { } } -/// Computes a name for the global variable storing a vtable. +pub enum VTableNameKind { + // Is the name for the const/static holding the vtable? + GlobalVariable, + // Is the name for the type of the vtable? + Type, +} + +/// Computes a name for the global variable storing a vtable (or the type of that global variable). /// /// The name is of the form: /// @@ -478,10 +485,15 @@ fn pop_auto_trait_separator(output: &mut String) { /// or, when generating C++-like names: /// /// `impl$::vtable$` +/// +/// If `kind` is `VTableNameKind::Type` then the last component is `{vtable_ty}` instead of just +/// `{vtable}`, so that the type and the corresponding global variable get assigned different +/// names. pub fn compute_debuginfo_vtable_name<'tcx>( tcx: TyCtxt<'tcx>, t: Ty<'tcx>, trait_ref: Option>, + kind: VTableNameKind, ) -> String { let cpp_like_debuginfo = cpp_like_debuginfo(tcx); @@ -514,7 +526,12 @@ pub fn compute_debuginfo_vtable_name<'tcx>( push_close_angle_bracket(cpp_like_debuginfo, &mut vtable_name); - let suffix = if cpp_like_debuginfo { "::vtable$" } else { "::{vtable}" }; + let suffix = match (cpp_like_debuginfo, kind) { + (true, VTableNameKind::GlobalVariable) => "::vtable$", + (false, VTableNameKind::GlobalVariable) => "::{vtable}", + (true, VTableNameKind::Type) => "::vtable_type$", + (false, VTableNameKind::Type) => "::{vtable_type}", + }; vtable_name.reserve_exact(suffix.len()); vtable_name.push_str(suffix); @@ -628,19 +645,19 @@ fn push_generic_params_internal<'tcx>( true } -fn push_const_param<'tcx>(tcx: TyCtxt<'tcx>, ct: &'tcx ty::Const<'tcx>, output: &mut String) { - match ct.val { +fn push_const_param<'tcx>(tcx: TyCtxt<'tcx>, ct: ty::Const<'tcx>, output: &mut String) { + match ct.val() { ty::ConstKind::Param(param) => { write!(output, "{}", param.name) } - _ => match ct.ty.kind() { + _ => match ct.ty().kind() { ty::Int(ity) => { - let bits = ct.eval_bits(tcx, ty::ParamEnv::reveal_all(), ct.ty); + let bits = ct.eval_bits(tcx, ty::ParamEnv::reveal_all(), ct.ty()); let val = Integer::from_int_ty(&tcx, *ity).size().sign_extend(bits) as i128; write!(output, "{}", val) } ty::Uint(_) => { - let val = ct.eval_bits(tcx, ty::ParamEnv::reveal_all(), ct.ty); + let val = ct.eval_bits(tcx, ty::ParamEnv::reveal_all(), ct.ty()); write!(output, "{}", val) } ty::Bool => { @@ -655,7 +672,7 @@ fn push_const_param<'tcx>(tcx: TyCtxt<'tcx>, ct: &'tcx ty::Const<'tcx>, output: let mut hasher = StableHasher::new(); hcx.while_hashing_spans(false, |hcx| { hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| { - ct.val.hash_stable(hcx, &mut hasher); + ct.val().hash_stable(hcx, &mut hasher); }); }); // Let's only emit 64 bits of the hash value. That should be plenty for