about summary refs log tree commit diff
path: root/src/librustc_codegen_llvm/debuginfo
diff options
context:
space:
mode:
authorbjorn3 <bjorn3@users.noreply.github.com>2019-03-30 15:45:09 +0100
committerbjorn3 <bjorn3@users.noreply.github.com>2019-04-20 13:21:40 +0200
commitd4e7b083ceae25f15f1639cb432d466656aecd77 (patch)
treeac5726d882b1196c7ea01d6eeca0331ca643844b /src/librustc_codegen_llvm/debuginfo
parentdd4566f5118c20889ca778565ba14a065a368dc6 (diff)
downloadrust-d4e7b083ceae25f15f1639cb432d466656aecd77.tar.gz
rust-d4e7b083ceae25f15f1639cb432d466656aecd77.zip
Move cg_llvm/debuginfo/type_names.rs to cg_ssa
Diffstat (limited to 'src/librustc_codegen_llvm/debuginfo')
-rw-r--r--src/librustc_codegen_llvm/debuginfo/metadata.rs16
-rw-r--r--src/librustc_codegen_llvm/debuginfo/mod.rs5
-rw-r--r--src/librustc_codegen_llvm/debuginfo/type_names.rs256
3 files changed, 10 insertions, 267 deletions
diff --git a/src/librustc_codegen_llvm/debuginfo/metadata.rs b/src/librustc_codegen_llvm/debuginfo/metadata.rs
index 6560ed0a8e6..31348b99c5a 100644
--- a/src/librustc_codegen_llvm/debuginfo/metadata.rs
+++ b/src/librustc_codegen_llvm/debuginfo/metadata.rs
@@ -376,7 +376,7 @@ fn vec_slice_metadata(
 
     return_if_metadata_created_in_meantime!(cx, unique_type_id);
 
-    let slice_type_name = compute_debuginfo_type_name(cx, slice_ptr_type, true);
+    let slice_type_name = compute_debuginfo_type_name(cx.tcx, slice_ptr_type, true);
 
     let (pointer_size, pointer_align) = cx.size_and_align_of(data_ptr_type);
     let (usize_size, usize_align) = cx.size_and_align_of(cx.tcx.types.usize);
@@ -479,7 +479,7 @@ fn trait_pointer_metadata(
 
     let trait_object_type = trait_object_type.unwrap_or(trait_type);
     let trait_type_name =
-        compute_debuginfo_type_name(cx, trait_object_type, false);
+        compute_debuginfo_type_name(cx.tcx, trait_object_type, false);
 
     let file_metadata = unknown_file_metadata(cx);
 
@@ -866,7 +866,7 @@ fn foreign_type_metadata(
 ) -> &'ll DIType {
     debug!("foreign_type_metadata: {:?}", t);
 
-    let name = compute_debuginfo_type_name(cx, t, false);
+    let name = compute_debuginfo_type_name(cx.tcx, t, false);
     create_struct_stub(cx, t, &name, unique_type_id, NO_SCOPE_METADATA)
 }
 
@@ -876,7 +876,7 @@ fn pointer_type_metadata(
     pointee_type_metadata: &'ll DIType,
 ) -> &'ll DIType {
     let (pointer_size, pointer_align) = cx.size_and_align_of(pointer_type);
-    let name = compute_debuginfo_type_name(cx, pointer_type, false);
+    let name = compute_debuginfo_type_name(cx.tcx, pointer_type, false);
     let name = SmallCStr::new(&name);
     unsafe {
         llvm::LLVMRustDIBuilderCreatePointerType(
@@ -1072,7 +1072,7 @@ fn prepare_struct_metadata(
     unique_type_id: UniqueTypeId,
     span: Span,
 ) -> RecursiveTypeDescription<'ll, 'tcx> {
-    let struct_name = compute_debuginfo_type_name(cx, struct_type, false);
+    let struct_name = compute_debuginfo_type_name(cx.tcx, struct_type, false);
 
     let (struct_def_id, variant) = match struct_type.sty {
         ty::Adt(def, _) => (def.did, def.non_enum_variant()),
@@ -1138,7 +1138,7 @@ fn prepare_tuple_metadata(
     unique_type_id: UniqueTypeId,
     span: Span,
 ) -> RecursiveTypeDescription<'ll, 'tcx> {
-    let tuple_name = compute_debuginfo_type_name(cx, tuple_type, false);
+    let tuple_name = compute_debuginfo_type_name(cx.tcx, tuple_type, false);
 
     let struct_stub = create_struct_stub(cx,
                                          tuple_type,
@@ -1194,7 +1194,7 @@ fn prepare_union_metadata(
     unique_type_id: UniqueTypeId,
     span: Span,
 ) -> RecursiveTypeDescription<'ll, 'tcx> {
-    let union_name = compute_debuginfo_type_name(cx, union_type, false);
+    let union_name = compute_debuginfo_type_name(cx.tcx, union_type, false);
 
     let (union_def_id, variant) = match union_type.sty {
         ty::Adt(def, _) => (def.did, def.non_enum_variant()),
@@ -1607,7 +1607,7 @@ fn prepare_enum_metadata(
     unique_type_id: UniqueTypeId,
     span: Span,
 ) -> RecursiveTypeDescription<'ll, 'tcx> {
-    let enum_name = compute_debuginfo_type_name(cx, enum_type, false);
+    let enum_name = compute_debuginfo_type_name(cx.tcx, enum_type, false);
 
     let containing_scope = get_namespace_for_item(cx, enum_def_id);
     // FIXME: This should emit actual file metadata for the enum, but we
diff --git a/src/librustc_codegen_llvm/debuginfo/mod.rs b/src/librustc_codegen_llvm/debuginfo/mod.rs
index 57e4ac07d5e..ae498673c1d 100644
--- a/src/librustc_codegen_llvm/debuginfo/mod.rs
+++ b/src/librustc_codegen_llvm/debuginfo/mod.rs
@@ -29,7 +29,7 @@ use rustc::util::nodemap::{DefIdMap, FxHashMap, FxHashSet};
 use rustc_data_structures::small_c_str::SmallCStr;
 use rustc_data_structures::indexed_vec::IndexVec;
 use rustc_codegen_ssa::debuginfo::{FunctionDebugContext, MirDebugScope, VariableAccess,
-    VariableKind, FunctionDebugContextData};
+    VariableKind, FunctionDebugContextData, type_names};
 
 use libc::c_uint;
 use std::cell::RefCell;
@@ -44,7 +44,6 @@ use rustc_codegen_ssa::traits::*;
 pub mod gdb;
 mod utils;
 mod namespace;
-mod type_names;
 pub mod metadata;
 mod create_scope_map;
 mod source_loc;
@@ -422,7 +421,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
                 let actual_type =
                     cx.tcx.normalize_erasing_regions(ParamEnv::reveal_all(), actual_type);
                 // Add actual type name to <...> clause of function name
-                let actual_type_name = compute_debuginfo_type_name(cx,
+                let actual_type_name = compute_debuginfo_type_name(cx.tcx(),
                                                                    actual_type,
                                                                    true);
                 name_to_append_suffix_to.push_str(&actual_type_name[..]);
diff --git a/src/librustc_codegen_llvm/debuginfo/type_names.rs b/src/librustc_codegen_llvm/debuginfo/type_names.rs
deleted file mode 100644
index eff7cd1bc8a..00000000000
--- a/src/librustc_codegen_llvm/debuginfo/type_names.rs
+++ /dev/null
@@ -1,256 +0,0 @@
-// Type Names for Debug Info.
-
-use crate::common::CodegenCx;
-use rustc::hir::def_id::DefId;
-use rustc::ty::subst::SubstsRef;
-use rustc::ty::{self, Ty};
-use rustc_codegen_ssa::traits::*;
-use rustc_data_structures::fx::FxHashSet;
-
-use rustc::hir;
-
-// Compute the name of the type as it should be stored in debuginfo. Does not do
-// any caching, i.e., calling the function twice with the same type will also do
-// the work twice. The `qualified` parameter only affects the first level of the
-// type name, further levels (i.e., type parameters) are always fully qualified.
-pub fn compute_debuginfo_type_name<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
-                                             t: Ty<'tcx>,
-                                             qualified: bool)
-                                             -> String {
-    let mut result = String::with_capacity(64);
-    let mut visited = FxHashSet::default();
-    push_debuginfo_type_name(cx, t, qualified, &mut result, &mut visited);
-    result
-}
-
-// Pushes the name of the type as it should be stored in debuginfo on the
-// `output` String. See also compute_debuginfo_type_name().
-pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
-                                          t: Ty<'tcx>,
-                                          qualified: bool,
-                                          output: &mut String,
-                                          visited: &mut FxHashSet<Ty<'tcx>>) {
-
-    // When targeting MSVC, emit C++ style type names for compatibility with
-    // .natvis visualizers (and perhaps other existing native debuggers?)
-    let cpp_like_names = cx.sess().target.target.options.is_like_msvc;
-
-    match t.sty {
-        ty::Bool => output.push_str("bool"),
-        ty::Char => output.push_str("char"),
-        ty::Str => output.push_str("str"),
-        ty::Never => output.push_str("!"),
-        ty::Int(int_ty) => output.push_str(int_ty.ty_to_string()),
-        ty::Uint(uint_ty) => output.push_str(uint_ty.ty_to_string()),
-        ty::Float(float_ty) => output.push_str(float_ty.ty_to_string()),
-        ty::Foreign(def_id) => push_item_name(cx, def_id, qualified, output),
-        ty::Adt(def, substs) => {
-            push_item_name(cx, def.did, qualified, output);
-            push_type_params(cx, substs, output, visited);
-        },
-        ty::Tuple(component_types) => {
-            output.push('(');
-            for &component_type in component_types {
-                push_debuginfo_type_name(cx, component_type, true, output, visited);
-                output.push_str(", ");
-            }
-            if !component_types.is_empty() {
-                output.pop();
-                output.pop();
-            }
-            output.push(')');
-        },
-        ty::RawPtr(ty::TypeAndMut { ty: inner_type, mutbl } ) => {
-            if !cpp_like_names {
-                output.push('*');
-            }
-            match mutbl {
-                hir::MutImmutable => output.push_str("const "),
-                hir::MutMutable => output.push_str("mut "),
-            }
-
-            push_debuginfo_type_name(cx, inner_type, true, output, visited);
-
-            if cpp_like_names {
-                output.push('*');
-            }
-        },
-        ty::Ref(_, inner_type, mutbl) => {
-            if !cpp_like_names {
-                output.push('&');
-            }
-            if mutbl == hir::MutMutable {
-                output.push_str("mut ");
-            }
-
-            push_debuginfo_type_name(cx, inner_type, true, output, visited);
-
-            if cpp_like_names {
-                output.push('*');
-            }
-        },
-        ty::Array(inner_type, len) => {
-            output.push('[');
-            push_debuginfo_type_name(cx, inner_type, true, output, visited);
-            output.push_str(&format!("; {}", len.unwrap_usize(cx.tcx)));
-            output.push(']');
-        },
-        ty::Slice(inner_type) => {
-            if cpp_like_names {
-                output.push_str("slice<");
-            } else {
-                output.push('[');
-            }
-
-            push_debuginfo_type_name(cx, inner_type, true, output, visited);
-
-            if cpp_like_names {
-                output.push('>');
-            } else {
-                output.push(']');
-            }
-        },
-        ty::Dynamic(ref trait_data, ..) => {
-            if let Some(principal) = trait_data.principal() {
-                let principal = cx.tcx.normalize_erasing_late_bound_regions(
-                    ty::ParamEnv::reveal_all(),
-                    &principal,
-                );
-                push_item_name(cx, principal.def_id, false, output);
-                push_type_params(cx, principal.substs, output, visited);
-            } else {
-                output.push_str("dyn '_");
-            }
-        },
-        ty::FnDef(..) | ty::FnPtr(_) => {
-            // We've encountered a weird 'recursive type'
-            // Currently, the only way to generate such a type
-            // is by using 'impl trait':
-            //
-            // fn foo() -> impl Copy { foo }
-            //
-            // There's not really a sensible name we can generate,
-            // since we don't include 'impl trait' types (e.g. ty::Opaque)
-            // in the output
-            //
-            // Since we need to generate *something*, we just
-            // use a dummy string that should make it clear
-            // that something unusual is going on
-            if !visited.insert(t) {
-                output.push_str("<recursive_type>");
-                return;
-            }
-
-
-            let sig = t.fn_sig(cx.tcx);
-            if sig.unsafety() == hir::Unsafety::Unsafe {
-                output.push_str("unsafe ");
-            }
-
-            let abi = sig.abi();
-            if abi != crate::abi::Abi::Rust {
-                output.push_str("extern \"");
-                output.push_str(abi.name());
-                output.push_str("\" ");
-            }
-
-            output.push_str("fn(");
-
-            let sig = cx.tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), &sig);
-            if !sig.inputs().is_empty() {
-                for &parameter_type in sig.inputs() {
-                    push_debuginfo_type_name(cx, parameter_type, true, output, visited);
-                    output.push_str(", ");
-                }
-                output.pop();
-                output.pop();
-            }
-
-            if sig.c_variadic {
-                if !sig.inputs().is_empty() {
-                    output.push_str(", ...");
-                } else {
-                    output.push_str("...");
-                }
-            }
-
-            output.push(')');
-
-            if !sig.output().is_unit() {
-                output.push_str(" -> ");
-                push_debuginfo_type_name(cx, sig.output(), true, output, visited);
-            }
-
-
-            // We only keep the type in 'visited'
-            // for the duration of the body of this method.
-            // It's fine for a particular function type
-            // to show up multiple times in one overall type
-            // (e.g. MyType<fn() -> u8, fn() -> u8>
-            //
-            // We only care about avoiding recursing
-            // directly back to the type we're currently
-            // processing
-            visited.remove(t);
-        },
-        ty::Closure(..) => {
-            output.push_str("closure");
-        }
-        ty::Generator(..) => {
-            output.push_str("generator");
-        }
-        ty::Error |
-        ty::Infer(_) |
-        ty::Placeholder(..) |
-        ty::UnnormalizedProjection(..) |
-        ty::Projection(..) |
-        ty::Bound(..) |
-        ty::Opaque(..) |
-        ty::GeneratorWitness(..) |
-        ty::Param(_) => {
-            bug!("debuginfo: Trying to create type name for \
-                  unexpected type: {:?}", t);
-        }
-    }
-
-    fn push_item_name(cx: &CodegenCx<'_, '_>,
-                      def_id: DefId,
-                      qualified: bool,
-                      output: &mut String) {
-        if qualified {
-            output.push_str(&cx.tcx.crate_name(def_id.krate).as_str());
-            for path_element in cx.tcx.def_path(def_id).data {
-                output.push_str("::");
-                output.push_str(&path_element.data.as_interned_str().as_str());
-            }
-        } else {
-            output.push_str(&cx.tcx.item_name(def_id).as_str());
-        }
-    }
-
-    // Pushes the type parameters in the given `InternalSubsts` to the output string.
-    // This ignores region parameters, since they can't reliably be
-    // reconstructed for items from non-local crates. For local crates, this
-    // would be possible but with inlining and LTO we have to use the least
-    // common denominator - otherwise we would run into conflicts.
-    fn push_type_params<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
-                                  substs: SubstsRef<'tcx>,
-                                  output: &mut String,
-                                  visited: &mut FxHashSet<Ty<'tcx>>) {
-        if substs.types().next().is_none() {
-            return;
-        }
-
-        output.push('<');
-
-        for type_parameter in substs.types() {
-            push_debuginfo_type_name(cx, type_parameter, true, output, visited);
-            output.push_str(", ");
-        }
-
-        output.pop();
-        output.pop();
-
-        output.push('>');
-    }
-}