Skip to content

Commit 8aae6ed

Browse files
committed
auto merge of #7710 : michaelwoerister/rust/WP4, r=jdm
This pull request includes various improvements: + Composite types (structs, tuples, boxes, etc) are now handled more cleanly by debuginfo generation. Most notably, field offsets are now extracted directly from LLVM types, as opposed to trying to reconstruct them. This leads to more stable handling of edge cases (e.g. packed structs or structs implementing drop). + `debuginfo.rs` in general has seen a major cleanup. This includes better formatting, more readable variable and function names, removal of dead code, and better factoring of functionality. + Handling of `VariantInfo` in `ty.rs` has been improved. That is, the `type VariantInfo = @VariantInfo_` typedef has been replaced with explicit uses of @VariantInfo, and the duplicated logic for creating VariantInfo instances in `ty::enum_variants()` and `typeck::check::mod::check_enum_variants()` has been unified into a single constructor function. Both function now look nicer too :) + Debug info generation for enum types is now mostly supported. This includes: + Good support for C-style enums. Both DWARF and `gdb` know how to handle them. + Proper description of tuple- and struct-style enum variants as unions of structs. + Proper handling of univariant enums without discriminator field. + Unfortunately `gdb` always prints all possible interpretations of a union, so debug output of enums is verbose and unintuitive. Neither `LLVM` nor `gdb` support DWARF's `DW_TAG_variant` which allows to properly describe tagged unions. Adding support for this to `LLVM` seems doable. `gdb` however is another story. In the future we might be able to use `gdb`'s Python scripting support to alleviate this problem. In agreement with @jdm this is not a high priority for now. + The debuginfo test suite has been extended with 14 test files including tests for packed structs (with Drop), boxed structs, boxed vecs, vec slices, c-style enums (standalone and embedded), empty enums, tuple- and struct-style enums, and various pointer types to the above. ~~What is not yet included is DI support for some enum edge-cases represented as described in `trans::adt::NullablePointer`.~~ Cheers, Michael PS: closes #7819, fixes #7712
2 parents 3a1db2d + a1303cc commit 8aae6ed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+2728
-741
lines changed

src/librustc/lib/llvm.rs

+39
Original file line numberDiff line numberDiff line change
@@ -1635,6 +1635,14 @@ pub mod llvm {
16351635
#[fast_ffi]
16361636
pub unsafe fn LLVMABIAlignmentOfType(TD: TargetDataRef,
16371637
Ty: TypeRef) -> c_uint;
1638+
1639+
/** Computes the byte offset of the indexed struct element for a target. */
1640+
#[fast_ffi]
1641+
pub unsafe fn LLVMOffsetOfElement(TD: TargetDataRef,
1642+
StructTy: TypeRef,
1643+
Element: c_uint)
1644+
-> c_ulonglong;
1645+
16381646
/**
16391647
* Returns the minimum alignment of a type when part of a call frame.
16401648
*/
@@ -2089,6 +2097,37 @@ pub mod llvm {
20892097
Val: ValueRef,
20902098
VarInfo: DIVariable,
20912099
InsertBefore: ValueRef) -> ValueRef;
2100+
2101+
#[fast_ffi]
2102+
pub unsafe fn LLVMDIBuilderCreateEnumerator(
2103+
Builder: DIBuilderRef,
2104+
Name: *c_char,
2105+
Val: c_ulonglong) -> ValueRef;
2106+
2107+
#[fast_ffi]
2108+
pub unsafe fn LLVMDIBuilderCreateEnumerationType(
2109+
Builder: DIBuilderRef,
2110+
Scope: ValueRef,
2111+
Name: *c_char,
2112+
File: ValueRef,
2113+
LineNumber: c_uint,
2114+
SizeInBits: c_ulonglong,
2115+
AlignInBits: c_ulonglong,
2116+
Elements: ValueRef,
2117+
ClassType: ValueRef) -> ValueRef;
2118+
2119+
#[fast_ffi]
2120+
pub unsafe fn LLVMDIBuilderCreateUnionType(
2121+
Builder: DIBuilderRef,
2122+
Scope: ValueRef,
2123+
Name: *c_char,
2124+
File: ValueRef,
2125+
LineNumber: c_uint,
2126+
SizeInBits: c_ulonglong,
2127+
AlignInBits: c_ulonglong,
2128+
Flags: c_uint ,
2129+
Elements: ValueRef,
2130+
RunTimeLang: c_uint) -> ValueRef;
20922131
}
20932132
}
20942133

src/librustc/metadata/csearch.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ pub fn maybe_get_item_ast(tcx: ty::ctxt, def: ast::def_id,
9090
}
9191

9292
pub fn get_enum_variants(tcx: ty::ctxt, def: ast::def_id)
93-
-> ~[ty::VariantInfo] {
93+
-> ~[@ty::VariantInfo] {
9494
let cstore = tcx.cstore;
9595
let cdata = cstore::get_crate_data(cstore, def.crate);
9696
return decoder::get_enum_variants(cstore.intr, cdata, def.node, tcx)

src/librustc/metadata/decoder.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -737,11 +737,11 @@ pub fn maybe_get_item_ast(cdata: cmd, tcx: ty::ctxt,
737737
}
738738

739739
pub fn get_enum_variants(intr: @ident_interner, cdata: cmd, id: ast::node_id,
740-
tcx: ty::ctxt) -> ~[ty::VariantInfo] {
740+
tcx: ty::ctxt) -> ~[@ty::VariantInfo] {
741741
let data = cdata.data;
742742
let items = reader::get_doc(reader::Doc(data), tag_items);
743743
let item = find_item(id, items);
744-
let mut infos: ~[ty::VariantInfo] = ~[];
744+
let mut infos: ~[@ty::VariantInfo] = ~[];
745745
let variant_ids = enum_variant_ids(item, cdata);
746746
let mut disr_val = 0;
747747
for variant_ids.iter().advance |did| {
@@ -757,11 +757,16 @@ pub fn get_enum_variants(intr: @ident_interner, cdata: cmd, id: ast::node_id,
757757
Some(val) => { disr_val = val; }
758758
_ => { /* empty */ }
759759
}
760-
infos.push(@ty::VariantInfo_{args: arg_tys,
761-
ctor_ty: ctor_ty, name: name,
762-
// I'm not even sure if we encode visibility
763-
// for variants -- TEST -- tjc
764-
id: *did, disr_val: disr_val, vis: ast::inherited});
760+
infos.push(@ty::VariantInfo{
761+
args: arg_tys,
762+
arg_names: None,
763+
ctor_ty: ctor_ty,
764+
name: name,
765+
// I'm not even sure if we encode visibility
766+
// for variants -- TEST -- tjc
767+
id: *did,
768+
disr_val: disr_val,
769+
vis: ast::inherited});
765770
disr_val += 1;
766771
}
767772
return infos;

src/librustc/middle/trans/adt.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ pub enum Repr {
9494
}
9595

9696
/// For structs, and struct-like parts of anything fancier.
97-
struct Struct {
97+
pub struct Struct {
9898
size: u64,
9999
align: u64,
100100
packed: bool,

src/librustc/middle/trans/base.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ pub fn iter_structural_ty(cx: block, av: ValueRef, t: ty::t,
670670
let _icx = push_ctxt("iter_structural_ty");
671671

672672
fn iter_variant(cx: block, repr: &adt::Repr, av: ValueRef,
673-
variant: ty::VariantInfo,
673+
variant: @ty::VariantInfo,
674674
tps: &[ty::t], f: val_and_ty_fn) -> block {
675675
let _icx = push_ctxt("iter_variant");
676676
let tcx = cx.tcx();
@@ -1141,7 +1141,7 @@ pub fn trans_stmt(cx: block, s: &ast::stmt) -> block {
11411141
bcx = init_local(bcx, *local);
11421142
if cx.sess().opts.extra_debuginfo
11431143
&& fcx_has_nonzero_span(bcx.fcx) {
1144-
debuginfo::create_local_var(bcx, *local);
1144+
debuginfo::create_local_var_metadata(bcx, *local);
11451145
}
11461146
}
11471147
ast::decl_item(i) => trans_item(cx.fcx.ccx, i)
@@ -1773,7 +1773,7 @@ pub fn copy_args_to_allocas(fcx: fn_ctxt,
17731773
bcx = _match::store_arg(bcx, args[arg_n].pat, llarg);
17741774

17751775
if fcx.ccx.sess.opts.extra_debuginfo && fcx_has_nonzero_span(fcx) {
1776-
debuginfo::create_arg(bcx, &args[arg_n], args[arg_n].ty.span);
1776+
debuginfo::create_argument_metadata(bcx, &args[arg_n], args[arg_n].ty.span);
17771777
}
17781778
}
17791779

@@ -1947,7 +1947,7 @@ pub fn trans_fn(ccx: @mut CrateContext,
19471947
|fcx| {
19481948
if ccx.sess.opts.extra_debuginfo
19491949
&& fcx_has_nonzero_span(fcx) {
1950-
debuginfo::create_function(fcx);
1950+
debuginfo::create_function_metadata(fcx);
19511951
}
19521952
},
19531953
|_bcx| { });
@@ -2109,7 +2109,7 @@ pub fn trans_enum_variant_or_tuple_like_struct<A:IdAndTy>(
21092109
}
21102110

21112111
pub fn trans_enum_def(ccx: @mut CrateContext, enum_definition: &ast::enum_def,
2112-
id: ast::node_id, vi: @~[ty::VariantInfo],
2112+
id: ast::node_id, vi: @~[@ty::VariantInfo],
21132113
i: &mut uint) {
21142114
for enum_definition.variants.iter().advance |variant| {
21152115
let disr_val = vi[*i].disr_val;

0 commit comments

Comments
 (0)