Skip to content

Commit 6791021

Browse files
committed
auto merge of #8554 : michaelwoerister/rust/generics, r=brson
This pull request includes support for generic functions and self arguments in methods, and combinations thereof. This also encompasses any kind of trait methods, regular and static, with and without default implementation. The implementation is backed up by a felt ton of test cases `:)` This is a very important step towards being able to compile larger programs with debug info, since practically any generic function caused an ICE before. One point worth discussing is that activating debug info now automatically (and silently) sets the `no_monomorphic_collapse` flag. Otherwise debug info would show wrong type names in all but one instance of the monomorphized function. Another thing to note is that the handling of generic types does not strictly follow the DWARF specification. That is, variables with type `T` (where `T=int`) are described as having type `int` and not as having type `T`. In other words, we are losing information whether a variable has been declared with a type parameter as its type. In practice this should not make much of difference though since the concrete type is mostly what one is interested in. I'll post an issue later so this won't be forgotten. Also included are a number of bug fixes: * Closes #1758 * Closes #8513 * Closes #8443 * Fixes handling of field names in tuple structs * Fixes and re-enables test case for option-like enums that relied on undefined behavior before * Closes #1339 (should have been closed a while ago) Cheers, Michael
2 parents cb8a231 + 80fb2f2 commit 6791021

28 files changed

+2226
-100
lines changed

src/librustc/driver/driver.rs

+8
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,14 @@ pub fn build_session_options(binary: @str,
691691
let extra_debuginfo = debugging_opts & session::extra_debug_info != 0;
692692
let debuginfo = debugging_opts & session::debug_info != 0 ||
693693
extra_debuginfo;
694+
695+
// If debugging info is generated, do not collapse monomorphized function instances.
696+
// Functions with equivalent llvm code still need separate debugging descriptions because names
697+
// might differ.
698+
if debuginfo {
699+
debugging_opts |= session::no_monomorphic_collapse;
700+
}
701+
694702
let statik = debugging_opts & session::statik != 0;
695703

696704
let addl_lib_search_paths = getopts::opt_strs(matches, "L").map(|s| Path(*s));

src/librustc/lib/llvm.rs

+10
Original file line numberDiff line numberDiff line change
@@ -2086,6 +2086,16 @@ pub mod llvm {
20862086

20872087
#[fast_ffi]
20882088
pub fn LLVMSetUnnamedAddr(GlobalVar: ValueRef, UnnamedAddr: Bool);
2089+
2090+
#[fast_ffi]
2091+
pub fn LLVMDIBuilderCreateTemplateTypeParameter(Builder: DIBuilderRef,
2092+
Scope: ValueRef,
2093+
Name: *c_char,
2094+
Ty: ValueRef,
2095+
File: ValueRef,
2096+
LineNo: c_uint,
2097+
ColumnNo: c_uint)
2098+
-> ValueRef;
20892099
}
20902100
}
20912101

src/librustc/middle/trans/base.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ pub fn push_ctxt(s: &'static str) -> _InsnCtxt {
133133

134134
fn fcx_has_nonzero_span(fcx: &FunctionContext) -> bool {
135135
match fcx.span {
136-
None => true,
136+
None => false,
137137
Some(span) => *span.lo != 0 || *span.hi != 0
138138
}
139139
}
@@ -1739,6 +1739,10 @@ pub fn copy_args_to_allocas(fcx: @mut FunctionContext,
17391739

17401740
fcx.llself = Some(ValSelfData {v: self_val, ..slf});
17411741
add_clean(bcx, self_val, slf.t);
1742+
1743+
if fcx.ccx.sess.opts.extra_debuginfo && fcx_has_nonzero_span(fcx) {
1744+
debuginfo::create_self_argument_metadata(bcx, slf.t, self_val);
1745+
}
17421746
}
17431747
_ => {}
17441748
}
@@ -1859,6 +1863,10 @@ pub fn trans_closure(ccx: @mut CrateContext,
18591863
set_fixed_stack_segment(fcx.llfn);
18601864
}
18611865

1866+
if ccx.sess.opts.debuginfo && fcx_has_nonzero_span(fcx) {
1867+
debuginfo::create_function_metadata(fcx);
1868+
}
1869+
18621870
// Create the first basic block in the function and keep a handle on it to
18631871
// pass to finish_fn later.
18641872
let bcx_top = fcx.entry_bcx.unwrap();
@@ -1929,12 +1937,7 @@ pub fn trans_fn(ccx: @mut CrateContext,
19291937
id,
19301938
attrs,
19311939
output_type,
1932-
|fcx| {
1933-
if ccx.sess.opts.debuginfo
1934-
&& fcx_has_nonzero_span(fcx) {
1935-
debuginfo::create_function_metadata(fcx);
1936-
}
1937-
});
1940+
|_fcx| { });
19381941
}
19391942

19401943
fn insert_synthetic_type_entries(bcx: @mut Block,

0 commit comments

Comments
 (0)