Skip to content

Commit 862911d

Browse files
Implement the translation item collector.
The purpose of the translation item collector is to find all monomorphic instances of functions, methods and statics that need to be translated into LLVM IR in order to compile the current crate. So far these instances have been discovered lazily during the trans path. For incremental compilation we want to know the set of these instances in advance, and that is what the trans::collect module provides. In the future, incremental and regular translation will be driven by the collector implemented here.
1 parent b279c5b commit 862911d

Some content is hidden

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

46 files changed

+3296
-61
lines changed

configure

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,6 +1409,7 @@ do
14091409
make_dir $h/test/debuginfo-gdb
14101410
make_dir $h/test/debuginfo-lldb
14111411
make_dir $h/test/codegen
1412+
make_dir $h/test/codegen-units
14121413
make_dir $h/test/rustdoc
14131414
done
14141415

mk/tests.mk

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ check-stage$(1)-T-$(2)-H-$(3)-exec: \
310310
check-stage$(1)-T-$(2)-H-$(3)-debuginfo-gdb-exec \
311311
check-stage$(1)-T-$(2)-H-$(3)-debuginfo-lldb-exec \
312312
check-stage$(1)-T-$(2)-H-$(3)-codegen-exec \
313+
check-stage$(1)-T-$(2)-H-$(3)-codegen-units-exec \
313314
check-stage$(1)-T-$(2)-H-$(3)-doc-exec \
314315
check-stage$(1)-T-$(2)-H-$(3)-pretty-exec
315316

@@ -473,6 +474,7 @@ DEBUGINFO_GDB_RS := $(wildcard $(S)src/test/debuginfo/*.rs)
473474
DEBUGINFO_LLDB_RS := $(wildcard $(S)src/test/debuginfo/*.rs)
474475
CODEGEN_RS := $(wildcard $(S)src/test/codegen/*.rs)
475476
CODEGEN_CC := $(wildcard $(S)src/test/codegen/*.cc)
477+
CODEGEN_UNITS_RS := $(wildcard $(S)src/test/codegen-units/*.rs)
476478
RUSTDOCCK_RS := $(wildcard $(S)src/test/rustdoc/*.rs)
477479

478480
RPASS_TESTS := $(RPASS_RS)
@@ -488,6 +490,7 @@ PRETTY_TESTS := $(PRETTY_RS)
488490
DEBUGINFO_GDB_TESTS := $(DEBUGINFO_GDB_RS)
489491
DEBUGINFO_LLDB_TESTS := $(DEBUGINFO_LLDB_RS)
490492
CODEGEN_TESTS := $(CODEGEN_RS) $(CODEGEN_CC)
493+
CODEGEN_UNITS_TESTS := $(CODEGEN_UNITS_RS)
491494
RUSTDOCCK_TESTS := $(RUSTDOCCK_RS)
492495

493496
CTEST_SRC_BASE_rpass = run-pass
@@ -550,6 +553,11 @@ CTEST_BUILD_BASE_codegen = codegen
550553
CTEST_MODE_codegen = codegen
551554
CTEST_RUNTOOL_codegen = $(CTEST_RUNTOOL)
552555

556+
CTEST_SRC_BASE_codegen-units = codegen-units
557+
CTEST_BUILD_BASE_codegen-units = codegen-units
558+
CTEST_MODE_codegen-units = codegen-units
559+
CTEST_RUNTOOL_codegen-units = $(CTEST_RUNTOOL)
560+
553561
CTEST_SRC_BASE_rustdocck = rustdoc
554562
CTEST_BUILD_BASE_rustdocck = rustdoc
555563
CTEST_MODE_rustdocck = rustdoc
@@ -673,6 +681,7 @@ CTEST_DEPS_debuginfo-lldb_$(1)-T-$(2)-H-$(3) = $$(DEBUGINFO_LLDB_TESTS) \
673681
$(S)src/etc/lldb_batchmode.py \
674682
$(S)src/etc/lldb_rust_formatters.py
675683
CTEST_DEPS_codegen_$(1)-T-$(2)-H-$(3) = $$(CODEGEN_TESTS)
684+
CTEST_DEPS_codegen-units_$(1)-T-$(2)-H-$(3) = $$(CODEGEN_UNITS_TESTS)
676685
CTEST_DEPS_rustdocck_$(1)-T-$(2)-H-$(3) = $$(RUSTDOCCK_TESTS) \
677686
$$(HBIN$(1)_H_$(3))/rustdoc$$(X_$(3)) \
678687
$(S)src/etc/htmldocck.py
@@ -739,7 +748,7 @@ endif
739748
endef
740749

741750
CTEST_NAMES = rpass rpass-valgrind rpass-full rfail-full cfail-full rfail cfail pfail \
742-
bench debuginfo-gdb debuginfo-lldb codegen rustdocck
751+
bench debuginfo-gdb debuginfo-lldb codegen codegen-units rustdocck
743752

744753
$(foreach host,$(CFG_HOST), \
745754
$(eval $(foreach target,$(CFG_TARGET), \
@@ -917,6 +926,7 @@ TEST_GROUPS = \
917926
debuginfo-gdb \
918927
debuginfo-lldb \
919928
codegen \
929+
codegen-units \
920930
doc \
921931
$(foreach docname,$(DOC_NAMES),doc-$(docname)) \
922932
pretty \

src/compiletest/common.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub enum Mode {
2525
DebugInfoLldb,
2626
Codegen,
2727
Rustdoc,
28+
CodegenUnits
2829
}
2930

3031
impl FromStr for Mode {
@@ -41,6 +42,7 @@ impl FromStr for Mode {
4142
"debuginfo-gdb" => Ok(DebugInfoGdb),
4243
"codegen" => Ok(Codegen),
4344
"rustdoc" => Ok(Rustdoc),
45+
"codegen-units" => Ok(CodegenUnits),
4446
_ => Err(()),
4547
}
4648
}
@@ -59,6 +61,7 @@ impl fmt::Display for Mode {
5961
DebugInfoLldb => "debuginfo-lldb",
6062
Codegen => "codegen",
6163
Rustdoc => "rustdoc",
64+
CodegenUnits => "codegen-units",
6265
}, f)
6366
}
6467
}

src/compiletest/runtest.rs

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@
1010

1111
use common::Config;
1212
use common::{CompileFail, ParseFail, Pretty, RunFail, RunPass, RunPassValgrind};
13-
use common::{Codegen, DebugInfoLldb, DebugInfoGdb, Rustdoc};
13+
use common::{Codegen, DebugInfoLldb, DebugInfoGdb, Rustdoc, CodegenUnits};
1414
use errors;
1515
use header::TestProps;
1616
use header;
1717
use procsrv;
1818
use util::logv;
1919

2020
use std::env;
21+
use std::collections::HashSet;
2122
use std::fmt;
2223
use std::fs::{self, File};
2324
use std::io::BufReader;
@@ -56,6 +57,7 @@ pub fn run(config: Config, testfile: &Path) {
5657
DebugInfoLldb => run_debuginfo_lldb_test(&config, &props, &testfile),
5758
Codegen => run_codegen_test(&config, &props, &testfile),
5859
Rustdoc => run_rustdoc_test(&config, &props, &testfile),
60+
CodegenUnits => run_codegen_units_test(&config, &props, &testfile),
5961
}
6062
}
6163

@@ -1747,3 +1749,44 @@ fn run_rustdoc_test(config: &Config, props: &TestProps, testfile: &Path) {
17471749
fatal_proc_rec("htmldocck failed!", &res);
17481750
}
17491751
}
1752+
1753+
fn run_codegen_units_test(config: &Config, props: &TestProps, testfile: &Path) {
1754+
let proc_res = compile_test(config, props, testfile);
1755+
1756+
if !proc_res.status.success() {
1757+
fatal_proc_rec("compilation failed!", &proc_res);
1758+
}
1759+
1760+
check_no_compiler_crash(&proc_res);
1761+
1762+
let prefix = "TRANS_ITEM ";
1763+
1764+
let actual: HashSet<String> = proc_res
1765+
.stdout
1766+
.lines()
1767+
.filter(|line| line.starts_with(prefix))
1768+
.map(|s| (&s[prefix.len()..]).to_string())
1769+
.collect();
1770+
1771+
let expected: HashSet<String> = errors::load_errors(testfile)
1772+
.iter()
1773+
.map(|e| e.msg.trim().to_string())
1774+
.collect();
1775+
1776+
if actual != expected {
1777+
let mut missing: Vec<_> = expected.difference(&actual).collect();
1778+
missing.sort();
1779+
1780+
let mut too_much: Vec<_> = actual.difference(&expected).collect();
1781+
too_much.sort();
1782+
1783+
println!("Expected and actual sets of codegen-items differ.\n\
1784+
These items should have been contained but were not:\n\n\
1785+
{}\n\n\
1786+
These items were contained but should not have been:\n\n\
1787+
{}\n\n",
1788+
missing.iter().fold("".to_string(), |s1, s2| s1 + "\n" + s2),
1789+
too_much.iter().fold("".to_string(), |s1, s2| s1 + "\n" + s2));
1790+
panic!();
1791+
}
1792+
}

src/librustc/front/map/definitions.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -196,33 +196,33 @@ impl DefPathData {
196196

197197
PositionalField |
198198
Field(hir::StructFieldKind::UnnamedField(_)) => {
199-
InternedString::new("<field>")
199+
InternedString::new("{{field}}")
200200
}
201201

202202
// note that this does not show up in user printouts
203203
CrateRoot => {
204-
InternedString::new("<root>")
204+
InternedString::new("{{root}}")
205205
}
206206

207207
// note that this does not show up in user printouts
208208
InlinedRoot(_) => {
209-
InternedString::new("<inlined-root>")
209+
InternedString::new("{{inlined-root}}")
210210
}
211211

212212
Misc => {
213-
InternedString::new("?")
213+
InternedString::new("{{?}}")
214214
}
215215

216216
ClosureExpr => {
217-
InternedString::new("<closure>")
217+
InternedString::new("{{closure}}")
218218
}
219219

220220
StructCtor => {
221-
InternedString::new("<constructor>")
221+
InternedString::new("{{constructor}}")
222222
}
223223

224224
Initializer => {
225-
InternedString::new("<initializer>")
225+
InternedString::new("{{initializer}}")
226226
}
227227
}
228228
}

src/librustc/middle/cstore.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,8 @@ pub trait CrateStore<'tcx> : Any {
223223
-> FoundAst<'tcx>;
224224
fn maybe_get_item_mir(&self, tcx: &ty::ctxt<'tcx>, def: DefId)
225225
-> Option<Mir<'tcx>>;
226+
fn is_item_mir_available(&self, def: DefId) -> bool;
227+
226228
// This is basically a 1-based range of ints, which is a little
227229
// silly - I may fix that.
228230
fn crates(&self) -> Vec<ast::CrateNum>;
@@ -397,6 +399,9 @@ impl<'tcx> CrateStore<'tcx> for DummyCrateStore {
397399
-> FoundAst<'tcx> { unimplemented!() }
398400
fn maybe_get_item_mir(&self, tcx: &ty::ctxt<'tcx>, def: DefId)
399401
-> Option<Mir<'tcx>> { unimplemented!() }
402+
fn is_item_mir_available(&self, def: DefId) -> bool {
403+
unimplemented!()
404+
}
400405

401406
// This is basically a 1-based range of ints, which is a little
402407
// silly - I may fix that.

src/librustc/middle/ty/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ impl<'tcx> ctxt<'tcx> {
563563
const_qualif_map: RefCell::new(NodeMap()),
564564
custom_coerce_unsized_kinds: RefCell::new(DefIdMap()),
565565
cast_kinds: RefCell::new(NodeMap()),
566-
fragment_infos: RefCell::new(DefIdMap()),
566+
fragment_infos: RefCell::new(DefIdMap())
567567
}, f)
568568
}
569569
}

src/librustc/middle/ty/maps.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use middle::def_id::DefId;
1313
use middle::ty;
1414
use std::marker::PhantomData;
1515
use std::rc::Rc;
16-
use syntax::attr;
16+
use syntax::{attr, ast};
1717

1818
macro_rules! dep_map_ty {
1919
($ty_name:ident : $node_name:ident ($key:ty) -> $value:ty) => {
@@ -42,3 +42,4 @@ dep_map_ty! { InherentImpls: InherentImpls(DefId) -> Rc<Vec<DefId>> }
4242
dep_map_ty! { ImplItems: ImplItems(DefId) -> Vec<ty::ImplOrTraitItemId> }
4343
dep_map_ty! { TraitItems: TraitItems(DefId) -> Rc<Vec<ty::ImplOrTraitItem<'tcx>>> }
4444
dep_map_ty! { ReprHints: ReprHints(DefId) -> Rc<Vec<attr::ReprAttr>> }
45+
dep_map_ty! { InlinedClosures: Hir(DefId) -> ast::NodeId }

src/librustc/mir/repr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ pub enum Rvalue<'tcx> {
721721
InlineAsm(InlineAsm),
722722
}
723723

724-
#[derive(Clone, Debug, PartialEq, Eq, RustcEncodable, RustcDecodable)]
724+
#[derive(Clone, Copy, Debug, PartialEq, Eq, RustcEncodable, RustcDecodable)]
725725
pub enum CastKind {
726726
Misc,
727727

src/librustc/session/config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
643643
"keep the AST after lowering it to HIR"),
644644
show_span: Option<String> = (None, parse_opt_string,
645645
"show spans for compiler debugging (expr|pat|ty)"),
646+
print_trans_items: Option<String> = (None, parse_opt_string,
647+
"print the result of the translation item collection pass"),
646648
}
647649

648650
pub fn default_lib_output() -> CrateType {

src/librustc_metadata/astencode.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ pub fn decode_inlined_item<'tcx>(cdata: &cstore::crate_metadata,
177177
}
178178
_ => { }
179179
}
180+
180181
Ok(ii)
181182
}
182183
}

src/librustc_metadata/csearch.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,11 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore {
445445
decoder::maybe_get_item_mir(&*cdata, tcx, def.index)
446446
}
447447

448+
fn is_item_mir_available(&self, def: DefId) -> bool {
449+
let cdata = self.get_crate_data(def.krate);
450+
decoder::is_item_mir_available(&*cdata, def.index)
451+
}
452+
448453
fn crates(&self) -> Vec<ast::CrateNum>
449454
{
450455
let mut result = vec![];

src/librustc_metadata/decoder.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,14 @@ pub fn maybe_get_item_ast<'tcx>(cdata: Cmd,
830830
}
831831
}
832832

833+
pub fn is_item_mir_available<'tcx>(cdata: Cmd, id: DefIndex) -> bool {
834+
if let Some(item_doc) = cdata.get_item(id) {
835+
return reader::maybe_get_doc(item_doc, tag_mir as usize).is_some();
836+
}
837+
838+
false
839+
}
840+
833841
pub fn maybe_get_item_mir<'tcx>(cdata: Cmd,
834842
tcx: &ty::ctxt<'tcx>,
835843
id: DefIndex)
@@ -849,6 +857,8 @@ pub fn maybe_get_item_mir<'tcx>(cdata: Cmd,
849857
})
850858
}).unwrap();
851859

860+
assert!(decoder.position() == mir_doc.end);
861+
852862
let mut def_id_and_span_translator = MirDefIdAndSpanTranslator {
853863
crate_metadata: cdata,
854864
codemap: tcx.sess.codemap(),

0 commit comments

Comments
 (0)