Skip to content

Commit 01b2771

Browse files
michaelwoeristeralexcrichton
authored andcommitted
---
yaml --- r: 150695 b: refs/heads/try2 c: c26d254 h: refs/heads/master i: 150693: 3e9c715 150691: 0f3922d 150687: 1e3d11f v: v3
1 parent 5f1d6a6 commit 01b2771

File tree

2 files changed

+52
-18
lines changed

2 files changed

+52
-18
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 43e8ace76b01820032679f276f3e298b92288ad6
8+
refs/heads/try2: c26d25466d93cefea6cf81ec3f0e64200a7150be
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/librustc/middle/trans/debuginfo.rs

Lines changed: 51 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ use driver::session::{FullDebugInfo, LimitedDebugInfo, NoDebugInfo};
130130
use lib::llvm::llvm;
131131
use lib::llvm::{ModuleRef, ContextRef, ValueRef};
132132
use lib::llvm::debuginfo::*;
133+
use metadata::csearch;
133134
use middle::trans::adt;
134135
use middle::trans::common::*;
135136
use middle::trans::datum::{Datum, Lvalue};
@@ -178,6 +179,7 @@ pub struct CrateDebugContext {
178179
current_debug_location: Cell<DebugLocation>,
179180
created_files: RefCell<HashMap<~str, DIFile>>,
180181
created_types: RefCell<HashMap<uint, DIType>>,
182+
created_enum_disr_types: RefCell<HashMap<ast::DefId, DIType>>,
181183
namespace_map: RefCell<HashMap<Vec<ast::Name> , @NamespaceTreeNode>>,
182184
// This collection is used to assert that composite types (structs, enums, ...) have their
183185
// members only set once:
@@ -196,6 +198,7 @@ impl CrateDebugContext {
196198
current_debug_location: Cell::new(UnknownLocation),
197199
created_files: RefCell::new(HashMap::new()),
198200
created_types: RefCell::new(HashMap::new()),
201+
created_enum_disr_types: RefCell::new(HashMap::new()),
199202
namespace_map: RefCell::new(HashMap::new()),
200203
composite_types_completed: RefCell::new(HashSet::new()),
201204
};
@@ -1542,24 +1545,45 @@ fn prepare_enum_metadata(cx: &CrateContext,
15421545
.collect();
15431546

15441547
let discriminant_type_metadata = |inttype| {
1545-
let discriminant_llvm_type = adt::ll_inttype(cx, inttype);
1546-
let (discriminant_size, discriminant_align) = size_and_align_of(cx, discriminant_llvm_type);
1547-
let discriminant_base_type_metadata = type_metadata(cx, adt::ty_of_inttype(inttype),
1548-
codemap::DUMMY_SP);
1549-
enum_name.with_c_str(|enum_name| {
1550-
unsafe {
1551-
llvm::LLVMDIBuilderCreateEnumerationType(
1552-
DIB(cx),
1553-
containing_scope,
1554-
enum_name,
1555-
file_metadata,
1556-
loc.line as c_uint,
1557-
bytes_to_bits(discriminant_size),
1558-
bytes_to_bits(discriminant_align),
1559-
create_DIArray(DIB(cx), enumerators_metadata.as_slice()),
1560-
discriminant_base_type_metadata)
1548+
// We can reuse the type of the discriminant for all monomorphized instances of an enum
1549+
// because it doesn't depend on any type parameters. The def_id, uniquely identifying the
1550+
// enum's polytype acts as key in this cache.
1551+
let cached_discriminant_type_metadata = debug_context(cx).created_enum_disr_types
1552+
.borrow()
1553+
.find_copy(&enum_def_id);
1554+
match cached_discriminant_type_metadata {
1555+
Some(discriminant_type_metadata) => discriminant_type_metadata,
1556+
None => {
1557+
let discriminant_llvm_type = adt::ll_inttype(cx, inttype);
1558+
let (discriminant_size, discriminant_align) =
1559+
size_and_align_of(cx, discriminant_llvm_type);
1560+
let discriminant_base_type_metadata = type_metadata(cx,
1561+
adt::ty_of_inttype(inttype),
1562+
codemap::DUMMY_SP);
1563+
let discriminant_name = get_enum_discriminant_name(cx, enum_def_id);
1564+
1565+
let discriminant_type_metadata = discriminant_name.get().with_c_str(|name| {
1566+
unsafe {
1567+
llvm::LLVMDIBuilderCreateEnumerationType(
1568+
DIB(cx),
1569+
containing_scope,
1570+
name,
1571+
file_metadata,
1572+
loc.line as c_uint,
1573+
bytes_to_bits(discriminant_size),
1574+
bytes_to_bits(discriminant_align),
1575+
create_DIArray(DIB(cx), enumerators_metadata.as_slice()),
1576+
discriminant_base_type_metadata)
1577+
}
1578+
});
1579+
1580+
debug_context(cx).created_enum_disr_types
1581+
.borrow_mut()
1582+
.insert(enum_def_id, discriminant_type_metadata);
1583+
1584+
discriminant_type_metadata
15611585
}
1562-
})
1586+
}
15631587
};
15641588

15651589
let type_rep = adt::represent_type(cx, enum_type);
@@ -1648,6 +1672,16 @@ fn prepare_enum_metadata(cx: &CrateContext,
16481672
}
16491673
}
16501674
};
1675+
1676+
fn get_enum_discriminant_name(cx: &CrateContext, def_id: ast::DefId) -> token::InternedString {
1677+
let name = if def_id.krate == ast::LOCAL_CRATE {
1678+
cx.tcx.map.get_path_elem(def_id.node).name()
1679+
} else {
1680+
csearch::get_item_path(&cx.tcx, def_id).last().unwrap().name()
1681+
};
1682+
1683+
token::get_name(name)
1684+
}
16511685
}
16521686

16531687
enum MemberOffset {

0 commit comments

Comments
 (0)