make check works

This commit is contained in:
Ariel Ben-Yehuda 2015-11-22 21:02:04 +02:00 committed by Ariel Ben-Yehuda
parent d45dd9423e
commit 26b19206d3
7 changed files with 130 additions and 79 deletions

View File

@ -19,7 +19,7 @@ use middle::def;
use middle::lang_items;
use middle::ty::{self, Ty};
use middle::def_id::{DefId, DefIndex};
use util::nodemap::{NodeMap, NodeSet};
use util::nodemap::{FnvHashMap, NodeMap, NodeSet};
use std::any::Any;
use std::cell::RefCell;
@ -75,6 +75,7 @@ pub trait CrateStore<'tcx> : Any {
fn item_symbol(&self, def: DefId) -> String;
fn trait_def(&self, tcx: &ty::ctxt<'tcx>, def: DefId)-> ty::TraitDef<'tcx>;
fn adt_def(&self, tcx: &ty::ctxt<'tcx>, def: DefId) -> ty::AdtDefMaster<'tcx>;
fn method_arg_names(&self, did: DefId) -> Vec<String>;
fn inherent_implementations_for_type(&self, def_id: DefId) -> Vec<DefId>;
// trait info
@ -104,10 +105,12 @@ pub trait CrateStore<'tcx> : Any {
fn is_const_fn(&self, did: DefId) -> bool;
fn is_defaulted_trait(&self, did: DefId) -> bool;
fn is_impl(&self, did: DefId) -> bool;
fn is_static_method(&self, did: DefId) -> bool;
fn is_default_impl(&self, impl_did: DefId) -> bool;
fn is_extern_fn(&self, tcx: &ty::ctxt<'tcx>, did: DefId) -> bool;
fn is_static(&self, did: DefId) -> bool;
fn is_static_method(&self, did: DefId) -> bool;
fn is_statically_included_foreign_item(&self, id: ast::NodeId) -> bool;
fn is_typedef(&self, did: DefId) -> bool;
// crate metadata
fn dylib_dependency_formats(&self, cnum: ast::CrateNum)
@ -117,8 +120,11 @@ pub trait CrateStore<'tcx> : Any {
fn is_staged_api(&self, cnum: ast::CrateNum) -> bool;
fn is_explicitly_linked(&self, cnum: ast::CrateNum) -> bool;
fn is_allocator(&self, cnum: ast::CrateNum) -> bool;
fn crate_attrs(&self, cnum: ast::CrateNum) -> Vec<ast::Attribute>;
fn crate_name(&self, cnum: ast::CrateNum) -> String;
fn crate_hash(&self, cnum: ast::CrateNum) -> Svh;
fn crate_struct_field_attrs(&self, cnum: ast::CrateNum)
-> FnvHashMap<DefId, Vec<ast::Attribute>>;
fn plugin_registrar_fn(&self, cnum: ast::CrateNum) -> Option<DefId>;
fn native_libraries(&self, cnum: ast::CrateNum) -> Vec<(NativeLibraryKind, String)>;
fn reachable_ids(&self, cnum: ast::CrateNum) -> Vec<DefId>;
@ -232,6 +238,12 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore {
decoder::get_adt_def(&self.intr, &*cdata, def.index, tcx)
}
fn method_arg_names(&self, did: DefId) -> Vec<String>
{
let cdata = self.get_crate_data(did.krate);
decoder::get_method_arg_names(&cdata, did.index)
}
fn item_path(&self, def: DefId) -> Vec<ast_map::PathElem> {
let cdata = self.get_crate_data(def.krate);
let path = decoder::get_item_path(&*cdata, def.index);
@ -352,10 +364,9 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore {
decoder::is_impl(&*cdata, did.index)
}
fn is_static_method(&self, def: DefId) -> bool
{
let cdata = self.get_crate_data(def.krate);
decoder::is_static_method(&*cdata, def.index)
fn is_default_impl(&self, impl_did: DefId) -> bool {
let cdata = self.get_crate_data(impl_did.krate);
decoder::is_default_impl(&*cdata, impl_did.index)
}
fn is_extern_fn(&self, tcx: &ty::ctxt<'tcx>, did: DefId) -> bool
@ -370,11 +381,22 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore {
decoder::is_static(&*cdata, did.index)
}
fn is_static_method(&self, def: DefId) -> bool
{
let cdata = self.get_crate_data(def.krate);
decoder::is_static_method(&*cdata, def.index)
}
fn is_statically_included_foreign_item(&self, id: ast::NodeId) -> bool
{
self.do_is_statically_included_foreign_item(id)
}
fn is_typedef(&self, did: DefId) -> bool {
let cdata = self.get_crate_data(did.krate);
decoder::is_typedef(&*cdata, did.index)
}
fn dylib_dependency_formats(&self, cnum: ast::CrateNum)
-> Vec<(ast::CrateNum, LinkagePreference)>
{
@ -414,6 +436,11 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore {
self.get_crate_data(cnum).is_allocator()
}
fn crate_attrs(&self, cnum: ast::CrateNum) -> Vec<ast::Attribute>
{
decoder::get_crate_attributes(self.get_crate_data(cnum).data())
}
fn crate_name(&self, cnum: ast::CrateNum) -> String
{
self.get_crate_data(cnum).name.clone()
@ -425,6 +452,12 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore {
decoder::get_crate_hash(cdata.data())
}
fn crate_struct_field_attrs(&self, cnum: ast::CrateNum)
-> FnvHashMap<DefId, Vec<ast::Attribute>>
{
decoder::get_struct_field_attrs(&*self.get_crate_data(cnum))
}
fn plugin_registrar_fn(&self, cnum: ast::CrateNum) -> Option<DefId>
{
let cdata = self.get_crate_data(cnum);

View File

@ -16,8 +16,7 @@ use syntax::ast;
use syntax::attr::AttrMetaMethods;
use rustc_front::hir;
use rustc::metadata::csearch;
use rustc::metadata::decoder;
use rustc::metadata::util::{self as mdutil, CrateStore};
use rustc::middle::def;
use rustc::middle::def_id::DefId;
use rustc::middle::ty;
@ -129,8 +128,7 @@ fn try_inline_def(cx: &DocContext, tcx: &ty::ctxt,
pub fn load_attrs(cx: &DocContext, tcx: &ty::ctxt,
did: DefId) -> Vec<clean::Attribute> {
let attrs = csearch::get_item_attrs(&tcx.sess.cstore, did);
attrs.into_iter().map(|a| a.clean(cx)).collect()
tcx.get_attrs(did).iter().map(|a| a.clean(cx)).collect()
}
/// Record an external fully qualified name in the external_paths cache.
@ -140,7 +138,7 @@ pub fn load_attrs(cx: &DocContext, tcx: &ty::ctxt,
pub fn record_extern_fqn(cx: &DocContext, did: DefId, kind: clean::TypeKind) {
match cx.tcx_opt() {
Some(tcx) => {
let fqn = csearch::get_item_path(tcx, did);
let fqn = tcx.sess.cstore.item_path(did);
let fqn = fqn.into_iter().map(|i| i.to_string()).collect();
cx.external_paths.borrow_mut().as_mut().unwrap().insert(did, (fqn, kind));
}
@ -211,7 +209,7 @@ fn build_type(cx: &DocContext, tcx: &ty::ctxt, did: DefId) -> clean::ItemEnum {
let t = tcx.lookup_item_type(did);
let predicates = tcx.lookup_predicates(did);
match t.ty.sty {
ty::TyEnum(edef, _) if !csearch::is_typedef(&tcx.sess.cstore, did) => {
ty::TyEnum(edef, _) if !tcx.sess.cstore.is_typedef(did) => {
return clean::EnumItem(clean::Enum {
generics: (&t.generics, &predicates, subst::TypeSpace).clean(cx),
variants_stripped: false,
@ -250,23 +248,19 @@ pub fn build_impls(cx: &DocContext, tcx: &ty::ctxt,
// type being inlined, but impls can also be used when generating
// documentation for primitives (no way to find those specifically).
if cx.populated_crate_impls.borrow_mut().insert(did.krate) {
csearch::each_top_level_item_of_crate(&tcx.sess.cstore,
did.krate,
|def, _, _| {
populate_impls(cx, tcx, def, &mut impls)
});
for item in tcx.sess.cstore.crate_top_level_items(did.krate) {
populate_impls(cx, tcx, item.def, &mut impls);
}
fn populate_impls(cx: &DocContext, tcx: &ty::ctxt,
def: decoder::DefLike,
def: mdutil::DefLike,
impls: &mut Vec<clean::Item>) {
match def {
decoder::DlImpl(did) => build_impl(cx, tcx, did, impls),
decoder::DlDef(def::DefMod(did)) => {
csearch::each_child_of_item(&tcx.sess.cstore,
did,
|def, _, _| {
populate_impls(cx, tcx, def, impls)
})
mdutil::DlImpl(did) => build_impl(cx, tcx, did, impls),
mdutil::DlDef(def::DefMod(did)) => {
for item in tcx.sess.cstore.item_children(did) {
populate_impls(cx, tcx, item.def, impls)
}
}
_ => {}
}
@ -285,7 +279,7 @@ pub fn build_impl(cx: &DocContext,
}
let attrs = load_attrs(cx, tcx, did);
let associated_trait = csearch::get_impl_trait(tcx, did);
let associated_trait = tcx.impl_trait_ref(did);
if let Some(ref t) = associated_trait {
// If this is an impl for a #[doc(hidden)] trait, be sure to not inline
let trait_attrs = load_attrs(cx, tcx, t.def_id);
@ -295,7 +289,7 @@ pub fn build_impl(cx: &DocContext,
}
// If this is a defaulted impl, then bail out early here
if csearch::is_default_impl(&tcx.sess.cstore, did) {
if tcx.sess.cstore.is_default_impl(did) {
return ret.push(clean::Item {
inner: clean::DefaultImplItem(clean::DefaultImpl {
// FIXME: this should be decoded
@ -315,7 +309,7 @@ pub fn build_impl(cx: &DocContext,
}
let predicates = tcx.lookup_predicates(did);
let trait_items = csearch::get_impl_items(&tcx.sess.cstore, did)
let trait_items = tcx.sess.cstore.impl_items(did)
.iter()
.filter_map(|did| {
let did = did.def_id();
@ -393,7 +387,7 @@ pub fn build_impl(cx: &DocContext,
}
}
}).collect::<Vec<_>>();
let polarity = csearch::get_impl_polarity(tcx, did);
let polarity = tcx.trait_impl_polarity(did);
let ty = tcx.lookup_item_type(did);
let trait_ = associated_trait.clean(cx).map(|bound| {
match bound {
@ -454,24 +448,24 @@ fn build_module(cx: &DocContext, tcx: &ty::ctxt,
// two namespaces, so the target may be listed twice. Make sure we only
// visit each node at most once.
let mut visited = HashSet::new();
csearch::each_child_of_item(&tcx.sess.cstore, did, |def, _, vis| {
match def {
decoder::DlDef(def::DefForeignMod(did)) => {
for item in tcx.sess.cstore.item_children(did) {
match item.def {
mdutil::DlDef(def::DefForeignMod(did)) => {
fill_in(cx, tcx, did, items);
}
decoder::DlDef(def) if vis == hir::Public => {
mdutil::DlDef(def) if item.vis == hir::Public => {
if !visited.insert(def) { return }
match try_inline_def(cx, tcx, def) {
Some(i) => items.extend(i),
None => {}
}
}
decoder::DlDef(..) => {}
mdutil::DlDef(..) => {}
// All impls were inlined above
decoder::DlImpl(..) => {}
decoder::DlField => panic!("unimplemented field"),
mdutil::DlImpl(..) => {}
mdutil::DlField => panic!("unimplemented field"),
}
});
}
}
}

View File

@ -35,9 +35,7 @@ use syntax::parse::token::{self, InternedString, special_idents};
use syntax::ptr::P;
use rustc_trans::back::link;
use rustc::metadata::cstore;
use rustc::metadata::csearch;
use rustc::metadata::decoder;
use rustc::metadata::util::{self as mdutil, CrateStore};
use rustc::middle::def;
use rustc::middle::def_id::{DefId, DefIndex};
use rustc::middle::subst::{self, ParamSpace, VecPerParamSpace};
@ -126,6 +124,8 @@ pub struct Crate {
pub external_traits: HashMap<DefId, Trait>,
}
struct CrateNum(ast::CrateNum);
impl<'a, 'tcx> Clean<Crate> for visit_ast::RustdocVisitor<'a, 'tcx> {
fn clean(&self, cx: &DocContext) -> Crate {
use rustc::session::config::Input;
@ -135,9 +135,9 @@ impl<'a, 'tcx> Clean<Crate> for visit_ast::RustdocVisitor<'a, 'tcx> {
}
let mut externs = Vec::new();
cx.sess().cstore.iter_crate_data(|n, meta| {
externs.push((n, meta.clean(cx)));
});
for cnum in cx.sess().cstore.crates() {
externs.push((cnum, CrateNum(cnum).clean(cx)));
}
externs.sort_by(|&(a, _), &(b, _)| a.cmp(&b));
// Figure out the name of this crate
@ -219,24 +219,22 @@ pub struct ExternalCrate {
pub primitives: Vec<PrimitiveType>,
}
impl Clean<ExternalCrate> for cstore::crate_metadata {
impl Clean<ExternalCrate> for CrateNum {
fn clean(&self, cx: &DocContext) -> ExternalCrate {
let mut primitives = Vec::new();
cx.tcx_opt().map(|tcx| {
csearch::each_top_level_item_of_crate(&tcx.sess.cstore,
self.cnum,
|def, _, _| {
let did = match def {
decoder::DlDef(def::DefMod(did)) => did,
_ => return
for item in tcx.sess.cstore.crate_top_level_items(self.0) {
let did = match item.def {
mdutil::DlDef(def::DefMod(did)) => did,
_ => continue
};
let attrs = inline::load_attrs(cx, tcx, did);
PrimitiveType::find(&attrs).map(|prim| primitives.push(prim));
})
}
});
ExternalCrate {
name: self.name.to_string(),
attrs: decoder::get_crate_attributes(self.data()).clean(cx),
name: cx.sess().cstore.crate_name(self.0),
attrs: cx.sess().cstore.crate_attrs(self.0).clean(cx),
primitives: primitives,
}
}
@ -656,7 +654,7 @@ impl Clean<TyParamBound> for ty::BuiltinBound {
(tcx.lang_items.sync_trait().unwrap(),
external_path(cx, "Sync", None, vec![], &empty)),
};
let fqn = csearch::get_item_path(tcx, did);
let fqn = tcx.sess.cstore.item_path(did);
let fqn = fqn.into_iter().map(|i| i.to_string()).collect();
cx.external_paths.borrow_mut().as_mut().unwrap().insert(did,
(fqn, TypeTrait));
@ -678,7 +676,7 @@ impl<'tcx> Clean<TyParamBound> for ty::TraitRef<'tcx> {
Some(tcx) => tcx,
None => return RegionBound(Lifetime::statik())
};
let fqn = csearch::get_item_path(tcx, self.def_id);
let fqn = tcx.sess.cstore.item_path(self.def_id);
let fqn = fqn.into_iter().map(|i| i.to_string())
.collect::<Vec<String>>();
let path = external_path(cx, fqn.last().unwrap(),
@ -1140,7 +1138,7 @@ impl<'a, 'tcx> Clean<FnDecl> for (DefId, &'a ty::PolyFnSig<'tcx>) {
let mut names = if let Some(_) = cx.map.as_local_node_id(did) {
vec![].into_iter()
} else {
csearch::get_method_arg_names(&cx.tcx().sess.cstore, did).into_iter()
cx.tcx().sess.cstore.method_arg_names(did).into_iter()
}.peekable();
if names.peek().map(|s| &**s) == Some("self") {
let _ = names.next();
@ -1665,7 +1663,7 @@ impl<'tcx> Clean<Type> for ty::Ty<'tcx> {
ty::TyStruct(def, substs) |
ty::TyEnum(def, substs) => {
let did = def.did;
let fqn = csearch::get_item_path(cx.tcx(), did);
let fqn = cx.tcx().sess.cstore.item_path(did);
let fqn: Vec<_> = fqn.into_iter().map(|i| i.to_string()).collect();
let kind = match self.sty {
ty::TyStruct(..) => TypeStruct,
@ -1683,7 +1681,7 @@ impl<'tcx> Clean<Type> for ty::Ty<'tcx> {
}
ty::TyTrait(box ty::TraitTy { ref principal, ref bounds }) => {
let did = principal.def_id();
let fqn = csearch::get_item_path(cx.tcx(), did);
let fqn = cx.tcx().sess.cstore.item_path(did);
let fqn: Vec<_> = fqn.into_iter().map(|i| i.to_string()).collect();
let (typarams, bindings) = bounds.clean(cx);
let path = external_path(cx, &fqn.last().unwrap().to_string(),
@ -1737,9 +1735,9 @@ impl Clean<Item> for hir::StructField {
impl<'tcx> Clean<Item> for ty::FieldDefData<'tcx, 'static> {
fn clean(&self, cx: &DocContext) -> Item {
use syntax::parse::token::special_idents::unnamed_field;
use rustc::metadata::csearch;
let attr_map = csearch::get_struct_field_attrs(&cx.tcx().sess.cstore, self.did);
// FIXME: possible O(n^2)-ness! Not my fault.
let attr_map =
cx.tcx().sess.cstore.crate_struct_field_attrs(self.did.krate);
let (name, attrs) = if self.name == unnamed_field.name {
(None, None)
@ -2815,7 +2813,7 @@ fn lang_struct(cx: &DocContext, did: Option<DefId>,
Some(did) => did,
None => return fallback(box t.clean(cx)),
};
let fqn = csearch::get_item_path(cx.tcx(), did);
let fqn = cx.tcx().sess.cstore.item_path(did);
let fqn: Vec<String> = fqn.into_iter().map(|i| {
i.to_string()
}).collect();

View File

@ -12,6 +12,7 @@ pub use self::MaybeTyped::*;
use rustc_lint;
use rustc_driver::{driver, target_features};
use rustc::session::{self, config};
use rustc::metadata::cstore::CStore;
use rustc::middle::def_id::DefId;
use rustc::middle::privacy::AccessLevels;
use rustc::middle::ty;
@ -23,9 +24,11 @@ use rustc_front::lowering::{lower_crate, LoweringContext};
use syntax::{ast, codemap, diagnostic};
use syntax::feature_gate::UnstableFeatures;
use syntax::parse::token;
use std::cell::{RefCell, Cell};
use std::collections::{HashMap, HashSet};
use std::rc::Rc;
use visit_ast::RustdocVisitor;
use clean;
@ -118,8 +121,10 @@ pub fn run_core(search_paths: SearchPaths, cfgs: Vec<String>, externs: Externs,
let span_diagnostic_handler =
diagnostic::SpanHandler::new(diagnostic_handler, codemap);
let cstore = Rc::new(CStore::new(token::get_ident_interner()));
let cstore_ = ::rustc_driver::cstore_to_cratestore(cstore.clone());
let sess = session::build_session_(sessopts, cpath,
span_diagnostic_handler);
span_diagnostic_handler, cstore_);
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
let mut cfg = config::build_configuration(&sess);
@ -130,7 +135,7 @@ pub fn run_core(search_paths: SearchPaths, cfgs: Vec<String>, externs: Externs,
let name = link::find_crate_name(Some(&sess), &krate.attrs,
&input);
let krate = driver::phase_2_configure_and_expand(&sess, krate, &name, None)
let krate = driver::phase_2_configure_and_expand(&sess, &cstore, krate, &name, None)
.expect("phase_2_configure_and_expand aborted in rustdoc!");
let krate = driver::assign_node_ids(&sess, krate);
@ -141,6 +146,7 @@ pub fn run_core(search_paths: SearchPaths, cfgs: Vec<String>, externs: Externs,
let hir_map = driver::make_map(&sess, &mut hir_forest);
driver::phase_3_run_analysis_passes(&sess,
&cstore,
hir_map,
&arenas,
&name,

View File

@ -19,12 +19,14 @@ use std::io::prelude::*;
use std::io;
use std::path::PathBuf;
use std::process::Command;
use std::rc::Rc;
use std::str;
use std::sync::{Arc, Mutex};
use testing;
use rustc_lint;
use rustc::front::map as hir_map;
use rustc::metadata::cstore::CStore;
use rustc::session::{self, config};
use rustc::session::config::{get_unstable_features_setting, OutputType};
use rustc::session::search_paths::{SearchPaths, PathKind};
@ -33,6 +35,7 @@ use rustc_back::tempdir::TempDir;
use rustc_driver::{driver, Compilation};
use syntax::codemap::CodeMap;
use syntax::diagnostic;
use syntax::parse::token;
use core;
use clean;
@ -73,15 +76,18 @@ pub fn run(input: &str,
let span_diagnostic_handler =
diagnostic::SpanHandler::new(diagnostic_handler, codemap);
let cstore = Rc::new(CStore::new(token::get_ident_interner()));
let cstore_ = ::rustc_driver::cstore_to_cratestore(cstore.clone());
let sess = session::build_session_(sessopts,
Some(input_path.clone()),
span_diagnostic_handler);
Some(input_path.clone()),
span_diagnostic_handler,
cstore_);
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
let mut cfg = config::build_configuration(&sess);
cfg.extend(config::parse_cfgspecs(cfgs));
let krate = driver::phase_1_parse_input(&sess, cfg, &input);
let krate = driver::phase_2_configure_and_expand(&sess, krate,
let krate = driver::phase_2_configure_and_expand(&sess, &cstore, krate,
"rustdoc-test", None)
.expect("phase_2_configure_and_expand aborted in rustdoc!");
let krate = driver::assign_node_ids(&sess, krate);
@ -223,9 +229,12 @@ fn runtest(test: &str, cratename: &str, libs: SearchPaths,
let span_diagnostic_handler =
diagnostic::SpanHandler::new(diagnostic_handler, codemap);
let cstore = Rc::new(CStore::new(token::get_ident_interner()));
let cstore_ = ::rustc_driver::cstore_to_cratestore(cstore.clone());
let sess = session::build_session_(sessopts,
None,
span_diagnostic_handler);
span_diagnostic_handler,
cstore_);
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
let outdir = TempDir::new("rustdoctest").ok().expect("rustdoc needs a tempdir");
@ -236,7 +245,7 @@ fn runtest(test: &str, cratename: &str, libs: SearchPaths,
if no_run {
control.after_analysis.stop = Compilation::Stop;
}
driver::compile_input(sess, cfg, &input, &out, &None, None, control);
driver::compile_input(sess, &cstore, cfg, &input, &out, &None, None, control);
if no_run { return }

View File

@ -22,11 +22,12 @@ extern crate syntax;
use std::ffi::{CStr, CString};
use std::mem::transmute;
use std::path::PathBuf;
use std::rc::Rc;
use std::thread::Builder;
use rustc::front::map as ast_map;
use rustc::llvm;
use rustc::metadata::cstore::RequireDynamic;
use rustc::metadata::cstore::{CStore, RequireDynamic};
use rustc::metadata::util::CrateStore;
use rustc::middle::ty;
use rustc::session::config::{self, basic_options, build_configuration, Input, Options};
@ -37,6 +38,7 @@ use rustc_resolve::MakeGlobMap;
use libc::c_void;
use syntax::diagnostics::registry::Registry;
use syntax::parse::token;
fn main() {
let program = r#"
@ -211,7 +213,10 @@ fn compile_program(input: &str, sysroot: PathBuf)
let handle = thread.spawn(move || {
let opts = build_exec_options(sysroot);
let sess = build_session(opts, None, Registry::new(&rustc::DIAGNOSTICS));
let cstore = Rc::new(CStore::new(token::get_ident_interner()));
let cstore_ = ::rustc_driver::cstore_to_cratestore(cstore.clone());
let sess = build_session(opts, None, Registry::new(&rustc::DIAGNOSTICS),
cstore_);
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
let cfg = build_configuration(&sess);
@ -220,7 +225,7 @@ fn compile_program(input: &str, sysroot: PathBuf)
let krate = driver::phase_1_parse_input(&sess, cfg, &input);
let krate = driver::phase_2_configure_and_expand(&sess, krate, &id, None)
let krate = driver::phase_2_configure_and_expand(&sess, &cstore, krate, &id, None)
.expect("phase_2 returned `None`");
let krate = driver::assign_node_ids(&sess, krate);
@ -230,11 +235,12 @@ fn compile_program(input: &str, sysroot: PathBuf)
let ast_map = driver::make_map(&sess, &mut hir_forest);
driver::phase_3_run_analysis_passes(
&sess, ast_map, &arenas, &id, MakeGlobMap::No, |tcx, mir_map, analysis| {
&sess, &cstore, ast_map, &arenas, &id,
MakeGlobMap::No, |tcx, mir_map, analysis| {
let trans = driver::phase_4_translate_to_llvm(tcx, mir_map, analysis);
let crates = tcx.sess.cstore.get_used_crates(RequireDynamic);
let crates = tcx.sess.cstore.used_crates(RequireDynamic);
// Collect crates used in the session.
// Reverse order finds dependencies first.

View File

@ -15,12 +15,15 @@ extern crate rustc_driver;
extern crate rustc_lint;
extern crate syntax;
use rustc::metadata::cstore::CStore;
use rustc::session::{build_session, Session};
use rustc::session::config::{basic_options, build_configuration, Input, OutputType};
use rustc_driver::driver::{compile_input, CompileController};
use syntax::diagnostics::registry::Registry;
use syntax::parse::token;
use std::path::PathBuf;
use std::rc::Rc;
fn main() {
let src = r#"
@ -44,23 +47,25 @@ fn main() {
compile(src.to_string(), tmpdir.join("out"), sysroot.clone());
}
fn basic_sess(sysroot: PathBuf) -> Session {
fn basic_sess(sysroot: PathBuf) -> (Session, Rc<CStore>) {
let mut opts = basic_options();
opts.output_types.insert(OutputType::Exe, None);
opts.maybe_sysroot = Some(sysroot);
let descriptions = Registry::new(&rustc::DIAGNOSTICS);
let sess = build_session(opts, None, descriptions);
let cstore = Rc::new(CStore::new(token::get_ident_interner()));
let cstore_ = ::rustc_driver::cstore_to_cratestore(cstore.clone());
let sess = build_session(opts, None, descriptions, cstore_);
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
sess
(sess, cstore)
}
fn compile(code: String, output: PathBuf, sysroot: PathBuf) {
let sess = basic_sess(sysroot);
let (sess, cstore) = basic_sess(sysroot);
let cfg = build_configuration(&sess);
let control = CompileController::basic();
compile_input(sess,
compile_input(sess, &cstore,
cfg,
&Input::Str(code),
&None,