Skip to content

Commit 6388b91

Browse files
committed
Rollup merge of rust-lang#33602 - eddyb:no-trans--check, r=michaelwoerister
Save metadata even with -Z no-trans (e.g. for multi-crate cargo check). Removes the item symbol map in metadata, as we can now generate them in a deterministic manner. The `-Z no-trans` change lets the LLVM passes and linking run, but with just metadata and no code. It fails while trying to link a binary because there's no `main` function, which is correct but not good UX. There's also no way to easily throw away all of the artifacts to rebuild with actual code generation. We might want `cargo check` to do that using cargo-internal information and then it would just work. cc @alexcrichton @nikomatsakis @Aatch @michaelwoerister
2 parents 62ee403 + 07e8975 commit 6388b91

File tree

34 files changed

+565
-401
lines changed

34 files changed

+565
-401
lines changed

src/librustc/middle/cstore.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@ use mir::mir_map::MirMap;
3333
use session::Session;
3434
use session::config::PanicStrategy;
3535
use session::search_paths::PathKind;
36-
use util::nodemap::{FnvHashMap, NodeMap, NodeSet, DefIdMap};
36+
use util::nodemap::{FnvHashMap, NodeSet, DefIdMap};
3737
use std::any::Any;
38-
use std::cell::RefCell;
3938
use std::rc::Rc;
4039
use std::path::PathBuf;
4140
use syntax::ast;
@@ -174,7 +173,6 @@ pub trait CrateStore<'tcx> : Any {
174173
fn item_super_predicates<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
175174
-> ty::GenericPredicates<'tcx>;
176175
fn item_attrs(&self, def_id: DefId) -> Vec<ast::Attribute>;
177-
fn item_symbol(&self, def: DefId) -> String;
178176
fn trait_def<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)-> ty::TraitDef<'tcx>;
179177
fn adt_def<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId) -> ty::AdtDefMaster<'tcx>;
180178
fn method_arg_names(&self, did: DefId) -> Vec<String>;
@@ -210,6 +208,7 @@ pub trait CrateStore<'tcx> : Any {
210208
fn is_impl(&self, did: DefId) -> bool;
211209
fn is_default_impl(&self, impl_did: DefId) -> bool;
212210
fn is_extern_item<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, did: DefId) -> bool;
211+
fn is_foreign_item(&self, did: DefId) -> bool;
213212
fn is_static_method(&self, did: DefId) -> bool;
214213
fn is_statically_included_foreign_item(&self, id: ast::NodeId) -> bool;
215214
fn is_typedef(&self, did: DefId) -> bool;
@@ -275,7 +274,6 @@ pub trait CrateStore<'tcx> : Any {
275274
fn extern_mod_stmt_cnum(&self, emod_id: ast::NodeId) -> Option<ast::CrateNum>;
276275
fn encode_metadata<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>,
277276
reexports: &def::ExportMap,
278-
item_symbols: &RefCell<NodeMap<String>>,
279277
link_meta: &LinkMeta,
280278
reachable: &NodeSet,
281279
mir_map: &MirMap<'tcx>,
@@ -353,7 +351,6 @@ impl<'tcx> CrateStore<'tcx> for DummyCrateStore {
353351
fn item_super_predicates<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
354352
-> ty::GenericPredicates<'tcx> { bug!("item_super_predicates") }
355353
fn item_attrs(&self, def_id: DefId) -> Vec<ast::Attribute> { bug!("item_attrs") }
356-
fn item_symbol(&self, def: DefId) -> String { bug!("item_symbol") }
357354
fn trait_def<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)-> ty::TraitDef<'tcx>
358355
{ bug!("trait_def") }
359356
fn adt_def<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId) -> ty::AdtDefMaster<'tcx>
@@ -394,6 +391,7 @@ impl<'tcx> CrateStore<'tcx> for DummyCrateStore {
394391
fn is_default_impl(&self, impl_did: DefId) -> bool { bug!("is_default_impl") }
395392
fn is_extern_item<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, did: DefId) -> bool
396393
{ bug!("is_extern_item") }
394+
fn is_foreign_item(&self, did: DefId) -> bool { bug!("is_foreign_item") }
397395
fn is_static_method(&self, did: DefId) -> bool { bug!("is_static_method") }
398396
fn is_statically_included_foreign_item(&self, id: ast::NodeId) -> bool { false }
399397
fn is_typedef(&self, did: DefId) -> bool { bug!("is_typedef") }
@@ -476,7 +474,6 @@ impl<'tcx> CrateStore<'tcx> for DummyCrateStore {
476474
fn extern_mod_stmt_cnum(&self, emod_id: ast::NodeId) -> Option<ast::CrateNum> { None }
477475
fn encode_metadata<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>,
478476
reexports: &def::ExportMap,
479-
item_symbols: &RefCell<NodeMap<String>>,
480477
link_meta: &LinkMeta,
481478
reachable: &NodeSet,
482479
mir_map: &MirMap<'tcx>,

src/librustc/middle/dependency_format.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,10 @@ fn calculate_type(sess: &session::Session,
115115
// got long ago), so don't bother with anything.
116116
config::CrateTypeRlib => return Vec::new(),
117117

118-
// Staticlibs must have all static dependencies. If any fail to be
119-
// found, we generate some nice pretty errors.
120-
config::CrateTypeStaticlib => {
118+
// Staticlibs and cdylibs must have all static dependencies. If any fail
119+
// to be found, we generate some nice pretty errors.
120+
config::CrateTypeStaticlib |
121+
config::CrateTypeCdylib => {
121122
match attempt_static(sess) {
122123
Some(v) => return v,
123124
None => {}

src/librustc/middle/reachable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
145145
// Creates a new reachability computation context.
146146
fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> ReachableContext<'a, 'tcx> {
147147
let any_library = tcx.sess.crate_types.borrow().iter().any(|ty| {
148-
*ty != config::CrateTypeExecutable
148+
*ty == config::CrateTypeRlib || *ty == config::CrateTypeDylib
149149
});
150150
ReachableContext {
151151
tcx: tcx,

src/librustc/middle/weak_lang_items.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ fn verify(sess: &Session, items: &lang_items::LanguageItems) {
7070
let needs_check = sess.crate_types.borrow().iter().any(|kind| {
7171
match *kind {
7272
config::CrateTypeDylib |
73+
config::CrateTypeCdylib |
7374
config::CrateTypeExecutable |
7475
config::CrateTypeStaticlib => true,
7576
config::CrateTypeRlib => false,

src/librustc/session/config.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ pub enum CrateType {
300300
CrateTypeDylib,
301301
CrateTypeRlib,
302302
CrateTypeStaticlib,
303+
CrateTypeCdylib,
303304
}
304305

305306
#[derive(Clone)]
@@ -1103,7 +1104,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
11031104
let no_analysis = debugging_opts.no_analysis;
11041105

11051106
let mut output_types = HashMap::new();
1106-
if !debugging_opts.parse_only && !no_trans {
1107+
if !debugging_opts.parse_only {
11071108
for list in matches.opt_strs("emit") {
11081109
for output_type in list.split(',') {
11091110
let mut parts = output_type.splitn(2, '=');
@@ -1326,6 +1327,7 @@ pub fn parse_crate_types_from_list(list_list: Vec<String>) -> Result<Vec<CrateTy
13261327
"rlib" => CrateTypeRlib,
13271328
"staticlib" => CrateTypeStaticlib,
13281329
"dylib" => CrateTypeDylib,
1330+
"cdylib" => CrateTypeCdylib,
13291331
"bin" => CrateTypeExecutable,
13301332
_ => {
13311333
return Err(format!("unknown crate type: `{}`",
@@ -1413,7 +1415,8 @@ impl fmt::Display for CrateType {
14131415
CrateTypeExecutable => "bin".fmt(f),
14141416
CrateTypeDylib => "dylib".fmt(f),
14151417
CrateTypeRlib => "rlib".fmt(f),
1416-
CrateTypeStaticlib => "staticlib".fmt(f)
1418+
CrateTypeStaticlib => "staticlib".fmt(f),
1419+
CrateTypeCdylib => "cdylib".fmt(f),
14171420
}
14181421
}
14191422
}

src/librustc/session/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
use hir::def_id::DefIndex;
12+
use hir::svh::Svh;
1113
use lint;
1214
use middle::cstore::CrateStore;
1315
use middle::dependency_format;
@@ -310,6 +312,14 @@ impl Session {
310312
pub fn nonzeroing_move_hints(&self) -> bool {
311313
self.opts.debugging_opts.enable_nonzeroing_move_hints
312314
}
315+
316+
/// Returns the symbol name for the registrar function,
317+
/// given the crate Svh and the function DefIndex.
318+
pub fn generate_plugin_registrar_symbol(&self, svh: &Svh, index: DefIndex)
319+
-> String {
320+
format!("__rustc_plugin_registrar__{}_{}", svh, index.as_usize())
321+
}
322+
313323
pub fn sysroot<'a>(&'a self) -> &'a Path {
314324
match self.opts.maybe_sysroot {
315325
Some (ref sysroot) => sysroot,

src/librustc/ty/item_path.rs

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,38 @@ use hir::def_id::{DefId, CRATE_DEF_INDEX};
1414
use ty::{self, Ty, TyCtxt};
1515
use syntax::ast;
1616

17+
use std::cell::Cell;
18+
19+
thread_local! {
20+
static FORCE_ABSOLUTE: Cell<bool> = Cell::new(false)
21+
}
22+
23+
/// Enforces that item_path_str always returns an absolute path.
24+
/// This is useful when building symbols that contain types,
25+
/// where we want the crate name to be part of the symbol.
26+
pub fn with_forced_absolute_paths<F: FnOnce() -> R, R>(f: F) -> R {
27+
FORCE_ABSOLUTE.with(|force| {
28+
let old = force.get();
29+
force.set(true);
30+
let result = f();
31+
force.set(old);
32+
result
33+
})
34+
}
35+
1736
impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
1837
/// Returns a string identifying this def-id. This string is
1938
/// suitable for user output. It is relative to the current crate
20-
/// root.
39+
/// root, unless with_forced_absolute_paths was used.
2140
pub fn item_path_str(self, def_id: DefId) -> String {
22-
let mut buffer = LocalPathBuffer::new(RootMode::Local);
41+
let mode = FORCE_ABSOLUTE.with(|force| {
42+
if force.get() {
43+
RootMode::Absolute
44+
} else {
45+
RootMode::Local
46+
}
47+
});
48+
let mut buffer = LocalPathBuffer::new(mode);
2349
self.push_item_path(&mut buffer, def_id);
2450
buffer.into_string()
2551
}
@@ -75,7 +101,11 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
75101
RootMode::Absolute => {
76102
// In absolute mode, just write the crate name
77103
// unconditionally.
78-
buffer.push(&self.crate_name(cnum));
104+
if cnum == LOCAL_CRATE {
105+
buffer.push(&self.crate_name(cnum));
106+
} else {
107+
buffer.push(&self.sess.cstore.original_crate_name(cnum));
108+
}
79109
}
80110
}
81111
}

src/librustc_driver/driver.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,6 +1175,9 @@ pub fn collect_crate_types(session: &Session, attrs: &[ast::Attribute]) -> Vec<c
11751175
Some(ref n) if *n == "dylib" => {
11761176
Some(config::CrateTypeDylib)
11771177
}
1178+
Some(ref n) if *n == "cdylib" => {
1179+
Some(config::CrateTypeCdylib)
1180+
}
11781181
Some(ref n) if *n == "lib" => {
11791182
Some(config::default_lib_output())
11801183
}

src/librustc_driver/lib.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -504,10 +504,6 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
504504
control.after_write_deps.stop = Compilation::Stop;
505505
}
506506

507-
if sess.opts.no_trans {
508-
control.after_analysis.stop = Compilation::Stop;
509-
}
510-
511507
if !sess.opts.output_types.keys().any(|&i| i == OutputType::Exe) {
512508
control.after_llvm.stop = Compilation::Stop;
513509
}

src/librustc_metadata/common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub const tag_items_data_item_family: usize = 0x24;
3333

3434
pub const tag_items_data_item_type: usize = 0x25;
3535

36-
pub const tag_items_data_item_symbol: usize = 0x26;
36+
// GAP 0x26
3737

3838
pub const tag_items_data_item_variant: usize = 0x27;
3939

0 commit comments

Comments
 (0)