Skip to content

Commit

Permalink
Auto merge of rust-lang#52927 - Mark-Simulacrum:cratestore-cleanup, r…
Browse files Browse the repository at this point in the history
…=alexcrichton

Crate store cleanup

Each commit mostly stands on its own.

Most of the diff is lifetime-related and uninteresting.
  • Loading branch information
bors committed Aug 4, 2018
2 parents 3edb355 + 6fdd6f6 commit c11f2d2
Show file tree
Hide file tree
Showing 28 changed files with 255 additions and 302 deletions.
12 changes: 12 additions & 0 deletions src/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2219,6 +2219,7 @@ dependencies = [
"rustc 0.0.0",
"rustc_data_structures 0.0.0",
"rustc_incremental 0.0.0",
"rustc_metadata_utils 0.0.0",
"rustc_mir 0.0.0",
"rustc_target 0.0.0",
"syntax 0.0.0",
Expand Down Expand Up @@ -2352,13 +2353,23 @@ dependencies = [
"rustc 0.0.0",
"rustc_data_structures 0.0.0",
"rustc_errors 0.0.0",
"rustc_metadata_utils 0.0.0",
"rustc_target 0.0.0",
"serialize 0.0.0",
"syntax 0.0.0",
"syntax_ext 0.0.0",
"syntax_pos 0.0.0",
]

[[package]]
name = "rustc_metadata_utils"
version = "0.0.0"
dependencies = [
"rustc 0.0.0",
"syntax 0.0.0",
"syntax_pos 0.0.0",
]

[[package]]
name = "rustc_mir"
version = "0.0.0"
Expand Down Expand Up @@ -2441,6 +2452,7 @@ dependencies = [
"rustc 0.0.0",
"rustc_data_structures 0.0.0",
"rustc_errors 0.0.0",
"rustc_metadata 0.0.0",
"syntax 0.0.0",
"syntax_pos 0.0.0",
]
Expand Down
131 changes: 1 addition & 130 deletions src/librustc/middle/cstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@
//! are *mostly* used as a part of that interface, but these should
//! probably get a better home if someone can find one.

use hir::def;
use hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
use hir::map as hir_map;
use hir::map::definitions::{Definitions, DefKey, DefPathTable};
use hir::map::definitions::{DefKey, DefPathTable};
use hir::svh::Svh;
use ty::{self, TyCtxt};
use session::{Session, CrateDisambiguator};
Expand All @@ -34,8 +33,6 @@ use session::search_paths::PathKind;
use std::any::Any;
use std::path::{Path, PathBuf};
use syntax::ast;
use syntax::edition::Edition;
use syntax::ext::base::SyntaxExtension;
use syntax::symbol::Symbol;
use syntax_pos::Span;
use rustc_target::spec::Target;
Expand Down Expand Up @@ -140,11 +137,6 @@ pub struct ForeignModule {
pub def_id: DefId,
}

pub enum LoadedMacro {
MacroDef(ast::Item),
ProcMacro(Lrc<SyntaxExtension>),
}

#[derive(Copy, Clone, Debug)]
pub struct ExternCrate {
pub src: ExternCrateSource,
Expand Down Expand Up @@ -221,29 +213,18 @@ pub trait MetadataLoader {
pub trait CrateStore {
fn crate_data_as_rc_any(&self, krate: CrateNum) -> Lrc<dyn Any>;

// access to the metadata loader
fn metadata_loader(&self) -> &dyn MetadataLoader;

// resolve
fn def_key(&self, def: DefId) -> DefKey;
fn def_path(&self, def: DefId) -> hir_map::DefPath;
fn def_path_hash(&self, def: DefId) -> hir_map::DefPathHash;
fn def_path_table(&self, cnum: CrateNum) -> Lrc<DefPathTable>;

// "queries" used in resolve that aren't tracked for incremental compilation
fn visibility_untracked(&self, def: DefId) -> ty::Visibility;
fn export_macros_untracked(&self, cnum: CrateNum);
fn dep_kind_untracked(&self, cnum: CrateNum) -> DepKind;
fn crate_name_untracked(&self, cnum: CrateNum) -> Symbol;
fn crate_disambiguator_untracked(&self, cnum: CrateNum) -> CrateDisambiguator;
fn crate_hash_untracked(&self, cnum: CrateNum) -> Svh;
fn crate_edition_untracked(&self, cnum: CrateNum) -> Edition;
fn struct_field_names_untracked(&self, def: DefId) -> Vec<ast::Name>;
fn item_children_untracked(&self, did: DefId, sess: &Session) -> Vec<def::Export>;
fn load_macro_untracked(&self, did: DefId, sess: &Session) -> LoadedMacro;
fn extern_mod_stmt_cnum_untracked(&self, emod_id: ast::NodeId) -> Option<CrateNum>;
fn item_generics_cloned_untracked(&self, def: DefId, sess: &Session) -> ty::Generics;
fn associated_item_cloned_untracked(&self, def: DefId) -> ty::AssociatedItem;
fn postorder_cnums_untracked(&self) -> Vec<CrateNum>;

// This is basically a 1-based range of ints, which is a little
Expand All @@ -260,116 +241,6 @@ pub trait CrateStore {

pub type CrateStoreDyn = dyn CrateStore + sync::Sync;

// FIXME: find a better place for this?
pub fn validate_crate_name(sess: Option<&Session>, s: &str, sp: Option<Span>) {
let mut err_count = 0;
{
let mut say = |s: &str| {
match (sp, sess) {
(_, None) => bug!("{}", s),
(Some(sp), Some(sess)) => sess.span_err(sp, s),
(None, Some(sess)) => sess.err(s),
}
err_count += 1;
};
if s.is_empty() {
say("crate name must not be empty");
}
for c in s.chars() {
if c.is_alphanumeric() { continue }
if c == '_' { continue }
say(&format!("invalid character `{}` in crate name: `{}`", c, s));
}
}

if err_count > 0 {
sess.unwrap().abort_if_errors();
}
}

/// A dummy crate store that does not support any non-local crates,
/// for test purposes.
pub struct DummyCrateStore;

#[allow(unused_variables)]
impl CrateStore for DummyCrateStore {
fn crate_data_as_rc_any(&self, krate: CrateNum) -> Lrc<dyn Any>
{ bug!("crate_data_as_rc_any") }
// item info
fn visibility_untracked(&self, def: DefId) -> ty::Visibility { bug!("visibility") }
fn item_generics_cloned_untracked(&self, def: DefId, sess: &Session) -> ty::Generics
{ bug!("item_generics_cloned") }

// trait/impl-item info
fn associated_item_cloned_untracked(&self, def: DefId) -> ty::AssociatedItem
{ bug!("associated_item_cloned") }

// crate metadata
fn dep_kind_untracked(&self, cnum: CrateNum) -> DepKind { bug!("is_explicitly_linked") }
fn export_macros_untracked(&self, cnum: CrateNum) { bug!("export_macros") }
fn crate_name_untracked(&self, cnum: CrateNum) -> Symbol { bug!("crate_name") }
fn crate_disambiguator_untracked(&self, cnum: CrateNum) -> CrateDisambiguator {
bug!("crate_disambiguator")
}
fn crate_hash_untracked(&self, cnum: CrateNum) -> Svh { bug!("crate_hash") }
fn crate_edition_untracked(&self, cnum: CrateNum) -> Edition { bug!("crate_edition_untracked") }

// resolve
fn def_key(&self, def: DefId) -> DefKey { bug!("def_key") }
fn def_path(&self, def: DefId) -> hir_map::DefPath {
bug!("relative_def_path")
}
fn def_path_hash(&self, def: DefId) -> hir_map::DefPathHash {
bug!("def_path_hash")
}
fn def_path_table(&self, cnum: CrateNum) -> Lrc<DefPathTable> {
bug!("def_path_table")
}
fn struct_field_names_untracked(&self, def: DefId) -> Vec<ast::Name> {
bug!("struct_field_names")
}
fn item_children_untracked(&self, did: DefId, sess: &Session) -> Vec<def::Export> {
bug!("item_children")
}
fn load_macro_untracked(&self, did: DefId, sess: &Session) -> LoadedMacro { bug!("load_macro") }

fn crates_untracked(&self) -> Vec<CrateNum> { vec![] }

// utility functions
fn extern_mod_stmt_cnum_untracked(&self, emod_id: ast::NodeId) -> Option<CrateNum> { None }
fn encode_metadata<'a, 'tcx>(&self,
tcx: TyCtxt<'a, 'tcx, 'tcx>,
link_meta: &LinkMeta)
-> EncodedMetadata {
bug!("encode_metadata")
}
fn metadata_encoding_version(&self) -> &[u8] { bug!("metadata_encoding_version") }
fn postorder_cnums_untracked(&self) -> Vec<CrateNum> { bug!("postorder_cnums_untracked") }

// access to the metadata loader
fn metadata_loader(&self) -> &dyn MetadataLoader { bug!("metadata_loader") }
}

pub trait CrateLoader {
fn process_extern_crate(&mut self, item: &ast::Item, defs: &Definitions) -> CrateNum;

fn process_path_extern(
&mut self,
name: Symbol,
span: Span,
) -> CrateNum;

fn process_use_extern(
&mut self,
name: Symbol,
span: Span,
id: ast::NodeId,
defs: &Definitions,
) -> CrateNum;

fn postprocess(&mut self, krate: &ast::Crate);
}

// This method is used when generating the command line to pass through to
// system linker. The linker expects undefined symbols on the left of the
// command line to be defined in libraries on the right, not the other way
Expand Down
1 change: 1 addition & 0 deletions src/librustc_codegen_utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ rustc_target = { path = "../librustc_target" }
rustc_data_structures = { path = "../librustc_data_structures" }
rustc_mir = { path = "../librustc_mir" }
rustc_incremental = { path = "../librustc_incremental" }
rustc_metadata_utils = { path = "../librustc_metadata_utils" }
1 change: 1 addition & 0 deletions src/librustc_codegen_utils/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ extern crate rustc_incremental;
extern crate syntax;
extern crate syntax_pos;
#[macro_use] extern crate rustc_data_structures;
extern crate rustc_metadata_utils;

use rustc::ty::TyCtxt;

Expand Down
5 changes: 3 additions & 2 deletions src/librustc_codegen_utils/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@

use rustc::session::config::{self, OutputFilenames, Input, OutputType};
use rustc::session::Session;
use rustc::middle::cstore::{self, LinkMeta};
use rustc::middle::cstore::LinkMeta;
use rustc::hir::svh::Svh;
use std::path::{Path, PathBuf};
use syntax::{ast, attr};
use syntax_pos::Span;
use rustc_metadata_utils::validate_crate_name;

pub fn out_filename(sess: &Session,
crate_type: config::CrateType,
Expand Down Expand Up @@ -61,7 +62,7 @@ pub fn find_crate_name(sess: Option<&Session>,
attrs: &[ast::Attribute],
input: &Input) -> String {
let validate = |s: String, span: Option<Span>| {
cstore::validate_crate_name(sess, &s, span);
validate_crate_name(sess, &s, span);
s
};

Expand Down
15 changes: 7 additions & 8 deletions src/librustc_driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use rustc::session::config::{self, Input, OutputFilenames, OutputType};
use rustc::session::search_paths::PathKind;
use rustc::lint;
use rustc::middle::{self, reachable, resolve_lifetime, stability};
use rustc::middle::cstore::CrateStoreDyn;
use rustc::middle::privacy::AccessLevels;
use rustc::ty::{self, AllArenas, Resolutions, TyCtxt};
use rustc::traits;
Expand Down Expand Up @@ -484,7 +483,7 @@ impl<'a> ::CompilerCalls<'a> for CompileController<'a> {
codegen_backend: &dyn (::CodegenBackend),
matches: &::getopts::Matches,
sess: &Session,
cstore: &dyn (::CrateStore),
cstore: &CStore,
input: &Input,
odir: &Option<PathBuf>,
ofile: &Option<PathBuf>,
Expand Down Expand Up @@ -728,9 +727,9 @@ pub struct ExpansionResult {
pub hir_forest: hir_map::Forest,
}

pub struct InnerExpansionResult<'a> {
pub struct InnerExpansionResult<'a, 'b: 'a> {
pub expanded_crate: ast::Crate,
pub resolver: Resolver<'a>,
pub resolver: Resolver<'a, 'b>,
pub hir_forest: hir_map::Forest,
}

Expand Down Expand Up @@ -806,7 +805,7 @@ where

/// Same as phase_2_configure_and_expand, but doesn't let you keep the resolver
/// around
pub fn phase_2_configure_and_expand_inner<'a, F>(
pub fn phase_2_configure_and_expand_inner<'a, 'b: 'a, F>(
sess: &'a Session,
cstore: &'a CStore,
mut krate: ast::Crate,
Expand All @@ -815,9 +814,9 @@ pub fn phase_2_configure_and_expand_inner<'a, F>(
addl_plugins: Option<Vec<String>>,
make_glob_map: MakeGlobMap,
resolver_arenas: &'a ResolverArenas<'a>,
crate_loader: &'a mut CrateLoader,
crate_loader: &'a mut CrateLoader<'b>,
after_expand: F,
) -> Result<InnerExpansionResult<'a>, CompileIncomplete>
) -> Result<InnerExpansionResult<'a, 'b>, CompileIncomplete>
where
F: FnOnce(&ast::Crate) -> CompileResult,
{
Expand Down Expand Up @@ -1209,7 +1208,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(
codegen_backend: &dyn CodegenBackend,
control: &CompileController,
sess: &'tcx Session,
cstore: &'tcx CrateStoreDyn,
cstore: &'tcx CStore,
hir_map: hir_map::Map<'tcx>,
mut analysis: ty::CrateAnalysis,
resolutions: Resolutions,
Expand Down
9 changes: 4 additions & 5 deletions src/librustc_driver/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ use rustc::session::filesearch;
use rustc::session::{early_error, early_warn};
use rustc::lint::Lint;
use rustc::lint;
use rustc::middle::cstore::CrateStore;
use rustc_metadata::locator;
use rustc_metadata::cstore::CStore;
use rustc_metadata::dynamic_lib::DynamicLibrary;
Expand Down Expand Up @@ -676,7 +675,7 @@ pub trait CompilerCalls<'a> {
_: &dyn CodegenBackend,
_: &getopts::Matches,
_: &Session,
_: &dyn CrateStore,
_: &CStore,
_: &Input,
_: &Option<PathBuf>,
_: &Option<PathBuf>)
Expand Down Expand Up @@ -884,7 +883,7 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
codegen_backend: &dyn CodegenBackend,
matches: &getopts::Matches,
sess: &Session,
cstore: &dyn CrateStore,
cstore: &CStore,
input: &Input,
odir: &Option<PathBuf>,
ofile: &Option<PathBuf>)
Expand Down Expand Up @@ -990,7 +989,7 @@ pub fn enable_save_analysis(control: &mut CompileController) {

impl RustcDefaultCalls {
pub fn list_metadata(sess: &Session,
cstore: &dyn CrateStore,
cstore: &CStore,
matches: &getopts::Matches,
input: &Input)
-> Compilation {
Expand All @@ -1002,7 +1001,7 @@ impl RustcDefaultCalls {
let mut v = Vec::new();
locator::list_file_metadata(&sess.target.target,
path,
cstore.metadata_loader(),
&*cstore.metadata_loader,
&mut v)
.unwrap();
println!("{}", String::from_utf8(v).unwrap());
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_driver/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ use {abort_on_err, driver};
use rustc::ty::{self, TyCtxt, Resolutions, AllArenas};
use rustc::cfg;
use rustc::cfg::graphviz::LabelledCFG;
use rustc::middle::cstore::CrateStoreDyn;
use rustc::session::Session;
use rustc::session::config::{Input, OutputFilenames};
use rustc_borrowck as borrowck;
use rustc_borrowck::graphviz as borrowck_dot;
use rustc_metadata::cstore::CStore;

use rustc_mir::util::{write_mir_pretty, write_mir_graphviz};

Expand Down Expand Up @@ -199,7 +199,7 @@ impl PpSourceMode {
}
fn call_with_pp_support_hir<'tcx, A, F>(&self,
sess: &'tcx Session,
cstore: &'tcx CrateStoreDyn,
cstore: &'tcx CStore,
hir_map: &hir_map::Map<'tcx>,
analysis: &ty::CrateAnalysis,
resolutions: &Resolutions,
Expand Down Expand Up @@ -918,7 +918,7 @@ pub fn print_after_parsing(sess: &Session,
}

pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
cstore: &'tcx CrateStoreDyn,
cstore: &'tcx CStore,
hir_map: &hir_map::Map<'tcx>,
analysis: &ty::CrateAnalysis,
resolutions: &Resolutions,
Expand Down Expand Up @@ -1074,7 +1074,7 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
// with a different callback than the standard driver, so that isn't easy.
// Instead, we call that function ourselves.
fn print_with_analysis<'tcx, 'a: 'tcx>(sess: &'a Session,
cstore: &'a CrateStoreDyn,
cstore: &'a CStore,
hir_map: &hir_map::Map<'tcx>,
analysis: &ty::CrateAnalysis,
resolutions: &Resolutions,
Expand Down
Loading

0 comments on commit c11f2d2

Please sign in to comment.