Skip to content

Commit 9814dc8

Browse files
committed
Move cg_llvm/debuginfo/type_names.rs to cg_ssa
1 parent ba48f6c commit 9814dc8

File tree

4 files changed

+41
-45
lines changed

4 files changed

+41
-45
lines changed

src/librustc_codegen_llvm/debuginfo/metadata.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ fn vec_slice_metadata(
375375

376376
return_if_metadata_created_in_meantime!(cx, unique_type_id);
377377

378-
let slice_type_name = compute_debuginfo_type_name(cx, slice_ptr_type, true);
378+
let slice_type_name = compute_debuginfo_type_name(cx.tcx, slice_ptr_type, true);
379379

380380
let (pointer_size, pointer_align) = cx.size_and_align_of(data_ptr_type);
381381
let (usize_size, usize_align) = cx.size_and_align_of(cx.tcx.types.usize);
@@ -478,7 +478,7 @@ fn trait_pointer_metadata(
478478

479479
let trait_object_type = trait_object_type.unwrap_or(trait_type);
480480
let trait_type_name =
481-
compute_debuginfo_type_name(cx, trait_object_type, false);
481+
compute_debuginfo_type_name(cx.tcx, trait_object_type, false);
482482

483483
let file_metadata = unknown_file_metadata(cx);
484484

@@ -865,7 +865,7 @@ fn foreign_type_metadata(
865865
) -> &'ll DIType {
866866
debug!("foreign_type_metadata: {:?}", t);
867867

868-
let name = compute_debuginfo_type_name(cx, t, false);
868+
let name = compute_debuginfo_type_name(cx.tcx, t, false);
869869
create_struct_stub(cx, t, &name, unique_type_id, NO_SCOPE_METADATA)
870870
}
871871

@@ -875,7 +875,7 @@ fn pointer_type_metadata(
875875
pointee_type_metadata: &'ll DIType,
876876
) -> &'ll DIType {
877877
let (pointer_size, pointer_align) = cx.size_and_align_of(pointer_type);
878-
let name = compute_debuginfo_type_name(cx, pointer_type, false);
878+
let name = compute_debuginfo_type_name(cx.tcx, pointer_type, false);
879879
let name = SmallCStr::new(&name);
880880
unsafe {
881881
llvm::LLVMRustDIBuilderCreatePointerType(
@@ -1071,7 +1071,7 @@ fn prepare_struct_metadata(
10711071
unique_type_id: UniqueTypeId,
10721072
span: Span,
10731073
) -> RecursiveTypeDescription<'ll, 'tcx> {
1074-
let struct_name = compute_debuginfo_type_name(cx, struct_type, false);
1074+
let struct_name = compute_debuginfo_type_name(cx.tcx, struct_type, false);
10751075

10761076
let (struct_def_id, variant) = match struct_type.sty {
10771077
ty::Adt(def, _) => (def.did, def.non_enum_variant()),
@@ -1137,7 +1137,7 @@ fn prepare_tuple_metadata(
11371137
unique_type_id: UniqueTypeId,
11381138
span: Span,
11391139
) -> RecursiveTypeDescription<'ll, 'tcx> {
1140-
let tuple_name = compute_debuginfo_type_name(cx, tuple_type, false);
1140+
let tuple_name = compute_debuginfo_type_name(cx.tcx, tuple_type, false);
11411141

11421142
let struct_stub = create_struct_stub(cx,
11431143
tuple_type,
@@ -1193,7 +1193,7 @@ fn prepare_union_metadata(
11931193
unique_type_id: UniqueTypeId,
11941194
span: Span,
11951195
) -> RecursiveTypeDescription<'ll, 'tcx> {
1196-
let union_name = compute_debuginfo_type_name(cx, union_type, false);
1196+
let union_name = compute_debuginfo_type_name(cx.tcx, union_type, false);
11971197

11981198
let (union_def_id, variant) = match union_type.sty {
11991199
ty::Adt(def, _) => (def.did, def.non_enum_variant()),
@@ -1599,7 +1599,7 @@ fn prepare_enum_metadata(
15991599
unique_type_id: UniqueTypeId,
16001600
span: Span,
16011601
) -> RecursiveTypeDescription<'ll, 'tcx> {
1602-
let enum_name = compute_debuginfo_type_name(cx, enum_type, false);
1602+
let enum_name = compute_debuginfo_type_name(cx.tcx, enum_type, false);
16031603

16041604
let containing_scope = get_namespace_for_item(cx, enum_def_id);
16051605
// FIXME: This should emit actual file metadata for the enum, but we

src/librustc_codegen_llvm/debuginfo/mod.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use rustc::util::nodemap::{DefIdMap, FxHashMap, FxHashSet};
2929
use rustc_data_structures::small_c_str::SmallCStr;
3030
use rustc_data_structures::indexed_vec::IndexVec;
3131
use rustc_codegen_ssa::debuginfo::{FunctionDebugContext, MirDebugScope, VariableAccess,
32-
VariableKind, FunctionDebugContextData};
32+
VariableKind, FunctionDebugContextData, type_names};
3333

3434
use libc::c_uint;
3535
use std::cell::RefCell;
@@ -44,7 +44,6 @@ use rustc_codegen_ssa::traits::*;
4444
pub mod gdb;
4545
mod utils;
4646
mod namespace;
47-
mod type_names;
4847
pub mod metadata;
4948
mod create_scope_map;
5049
mod source_loc;
@@ -423,7 +422,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
423422
let actual_type =
424423
cx.tcx.normalize_erasing_regions(ParamEnv::reveal_all(), actual_type);
425424
// Add actual type name to <...> clause of function name
426-
let actual_type_name = compute_debuginfo_type_name(cx,
425+
let actual_type_name = compute_debuginfo_type_name(cx.tcx(),
427426
actual_type,
428427
true);
429428
name_to_append_suffix_to.push_str(&actual_type_name[..]);

src/librustc_codegen_ssa/debuginfo.rs renamed to src/librustc_codegen_ssa/debuginfo/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use syntax_pos::{BytePos, Span};
22
use rustc::hir::def_id::CrateNum;
33

4+
pub mod type_names;
5+
46
pub enum FunctionDebugContext<D> {
57
RegularContext(FunctionDebugContextData<D>),
68
DebugInfoDisabled,

src/librustc_codegen_llvm/debuginfo/type_names.rs renamed to src/librustc_codegen_ssa/debuginfo/type_names.rs

+29-34
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,34 @@
11
// Type Names for Debug Info.
22

3-
use crate::common::CodegenCx;
4-
use rustc::hir::def_id::DefId;
5-
use rustc::ty::subst::SubstsRef;
6-
use rustc::ty::{self, Ty};
7-
use rustc_codegen_ssa::traits::*;
3+
use rustc::hir::{self, def_id::DefId};
4+
use rustc::ty::{self, Ty, TyCtxt, subst::SubstsRef};
85
use rustc_data_structures::fx::FxHashSet;
96

10-
use rustc::hir;
11-
127
// Compute the name of the type as it should be stored in debuginfo. Does not do
138
// any caching, i.e., calling the function twice with the same type will also do
149
// the work twice. The `qualified` parameter only affects the first level of the
1510
// type name, further levels (i.e., type parameters) are always fully qualified.
16-
pub fn compute_debuginfo_type_name<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
11+
pub fn compute_debuginfo_type_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
1712
t: Ty<'tcx>,
1813
qualified: bool)
1914
-> String {
2015
let mut result = String::with_capacity(64);
2116
let mut visited = FxHashSet::default();
22-
push_debuginfo_type_name(cx, t, qualified, &mut result, &mut visited);
17+
push_debuginfo_type_name(tcx, t, qualified, &mut result, &mut visited);
2318
result
2419
}
2520

2621
// Pushes the name of the type as it should be stored in debuginfo on the
2722
// `output` String. See also compute_debuginfo_type_name().
28-
pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
23+
pub fn push_debuginfo_type_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
2924
t: Ty<'tcx>,
3025
qualified: bool,
3126
output: &mut String,
3227
visited: &mut FxHashSet<Ty<'tcx>>) {
3328

3429
// When targeting MSVC, emit C++ style type names for compatibility with
3530
// .natvis visualizers (and perhaps other existing native debuggers?)
36-
let cpp_like_names = cx.sess().target.target.options.is_like_msvc;
31+
let cpp_like_names = tcx.sess.target.target.options.is_like_msvc;
3732

3833
match t.sty {
3934
ty::Bool => output.push_str("bool"),
@@ -43,15 +38,15 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
4338
ty::Int(int_ty) => output.push_str(int_ty.ty_to_string()),
4439
ty::Uint(uint_ty) => output.push_str(uint_ty.ty_to_string()),
4540
ty::Float(float_ty) => output.push_str(float_ty.ty_to_string()),
46-
ty::Foreign(def_id) => push_item_name(cx, def_id, qualified, output),
41+
ty::Foreign(def_id) => push_item_name(tcx, def_id, qualified, output),
4742
ty::Adt(def, substs) => {
48-
push_item_name(cx, def.did, qualified, output);
49-
push_type_params(cx, substs, output, visited);
43+
push_item_name(tcx, def.did, qualified, output);
44+
push_type_params(tcx, substs, output, visited);
5045
},
5146
ty::Tuple(component_types) => {
5247
output.push('(');
5348
for &component_type in component_types {
54-
push_debuginfo_type_name(cx, component_type, true, output, visited);
49+
push_debuginfo_type_name(tcx, component_type, true, output, visited);
5550
output.push_str(", ");
5651
}
5752
if !component_types.is_empty() {
@@ -69,7 +64,7 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
6964
hir::MutMutable => output.push_str("mut "),
7065
}
7166

72-
push_debuginfo_type_name(cx, inner_type, true, output, visited);
67+
push_debuginfo_type_name(tcx, inner_type, true, output, visited);
7368

7469
if cpp_like_names {
7570
output.push('*');
@@ -83,16 +78,16 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
8378
output.push_str("mut ");
8479
}
8580

86-
push_debuginfo_type_name(cx, inner_type, true, output, visited);
81+
push_debuginfo_type_name(tcx, inner_type, true, output, visited);
8782

8883
if cpp_like_names {
8984
output.push('*');
9085
}
9186
},
9287
ty::Array(inner_type, len) => {
9388
output.push('[');
94-
push_debuginfo_type_name(cx, inner_type, true, output, visited);
95-
output.push_str(&format!("; {}", len.unwrap_usize(cx.tcx)));
89+
push_debuginfo_type_name(tcx, inner_type, true, output, visited);
90+
output.push_str(&format!("; {}", len.unwrap_usize(tcx)));
9691
output.push(']');
9792
},
9893
ty::Slice(inner_type) => {
@@ -102,7 +97,7 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
10297
output.push('[');
10398
}
10499

105-
push_debuginfo_type_name(cx, inner_type, true, output, visited);
100+
push_debuginfo_type_name(tcx, inner_type, true, output, visited);
106101

107102
if cpp_like_names {
108103
output.push('>');
@@ -112,12 +107,12 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
112107
},
113108
ty::Dynamic(ref trait_data, ..) => {
114109
if let Some(principal) = trait_data.principal() {
115-
let principal = cx.tcx.normalize_erasing_late_bound_regions(
110+
let principal = tcx.normalize_erasing_late_bound_regions(
116111
ty::ParamEnv::reveal_all(),
117112
&principal,
118113
);
119-
push_item_name(cx, principal.def_id, false, output);
120-
push_type_params(cx, principal.substs, output, visited);
114+
push_item_name(tcx, principal.def_id, false, output);
115+
push_type_params(tcx, principal.substs, output, visited);
121116
} else {
122117
output.push_str("dyn '_");
123118
}
@@ -142,24 +137,24 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
142137
}
143138

144139

145-
let sig = t.fn_sig(cx.tcx);
140+
let sig = t.fn_sig(tcx);
146141
if sig.unsafety() == hir::Unsafety::Unsafe {
147142
output.push_str("unsafe ");
148143
}
149144

150145
let abi = sig.abi();
151-
if abi != crate::abi::Abi::Rust {
146+
if abi != rustc_target::spec::abi::Abi::Rust {
152147
output.push_str("extern \"");
153148
output.push_str(abi.name());
154149
output.push_str("\" ");
155150
}
156151

157152
output.push_str("fn(");
158153

159-
let sig = cx.tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), &sig);
154+
let sig = tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), &sig);
160155
if !sig.inputs().is_empty() {
161156
for &parameter_type in sig.inputs() {
162-
push_debuginfo_type_name(cx, parameter_type, true, output, visited);
157+
push_debuginfo_type_name(tcx, parameter_type, true, output, visited);
163158
output.push_str(", ");
164159
}
165160
output.pop();
@@ -178,7 +173,7 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
178173

179174
if !sig.output().is_unit() {
180175
output.push_str(" -> ");
181-
push_debuginfo_type_name(cx, sig.output(), true, output, visited);
176+
push_debuginfo_type_name(tcx, sig.output(), true, output, visited);
182177
}
183178

184179

@@ -213,18 +208,18 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
213208
}
214209
}
215210

216-
fn push_item_name(cx: &CodegenCx<'_, '_>,
211+
fn push_item_name(tcx: TyCtxt<'a, 'tcx, 'tcx>,
217212
def_id: DefId,
218213
qualified: bool,
219214
output: &mut String) {
220215
if qualified {
221-
output.push_str(&cx.tcx.crate_name(def_id.krate).as_str());
222-
for path_element in cx.tcx.def_path(def_id).data {
216+
output.push_str(&tcx.crate_name(def_id.krate).as_str());
217+
for path_element in tcx.def_path(def_id).data {
223218
output.push_str("::");
224219
output.push_str(&path_element.data.as_interned_str().as_str());
225220
}
226221
} else {
227-
output.push_str(&cx.tcx.item_name(def_id).as_str());
222+
output.push_str(&tcx.item_name(def_id).as_str());
228223
}
229224
}
230225

@@ -233,7 +228,7 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
233228
// reconstructed for items from non-local crates. For local crates, this
234229
// would be possible but with inlining and LTO we have to use the least
235230
// common denominator - otherwise we would run into conflicts.
236-
fn push_type_params<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
231+
fn push_type_params<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
237232
substs: SubstsRef<'tcx>,
238233
output: &mut String,
239234
visited: &mut FxHashSet<Ty<'tcx>>) {
@@ -244,7 +239,7 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
244239
output.push('<');
245240

246241
for type_parameter in substs.types() {
247-
push_debuginfo_type_name(cx, type_parameter, true, output, visited);
242+
push_debuginfo_type_name(tcx, type_parameter, true, output, visited);
248243
output.push_str(", ");
249244
}
250245

0 commit comments

Comments
 (0)