Skip to content

Commit c11f2d2

Browse files
committed
Auto merge of #52927 - Mark-Simulacrum:cratestore-cleanup, r=alexcrichton
Crate store cleanup Each commit mostly stands on its own. Most of the diff is lifetime-related and uninteresting.
2 parents 3edb355 + 6fdd6f6 commit c11f2d2

File tree

28 files changed

+255
-302
lines changed

28 files changed

+255
-302
lines changed

src/Cargo.lock

+12
Original file line numberDiff line numberDiff line change
@@ -2219,6 +2219,7 @@ dependencies = [
22192219
"rustc 0.0.0",
22202220
"rustc_data_structures 0.0.0",
22212221
"rustc_incremental 0.0.0",
2222+
"rustc_metadata_utils 0.0.0",
22222223
"rustc_mir 0.0.0",
22232224
"rustc_target 0.0.0",
22242225
"syntax 0.0.0",
@@ -2352,13 +2353,23 @@ dependencies = [
23522353
"rustc 0.0.0",
23532354
"rustc_data_structures 0.0.0",
23542355
"rustc_errors 0.0.0",
2356+
"rustc_metadata_utils 0.0.0",
23552357
"rustc_target 0.0.0",
23562358
"serialize 0.0.0",
23572359
"syntax 0.0.0",
23582360
"syntax_ext 0.0.0",
23592361
"syntax_pos 0.0.0",
23602362
]
23612363

2364+
[[package]]
2365+
name = "rustc_metadata_utils"
2366+
version = "0.0.0"
2367+
dependencies = [
2368+
"rustc 0.0.0",
2369+
"syntax 0.0.0",
2370+
"syntax_pos 0.0.0",
2371+
]
2372+
23622373
[[package]]
23632374
name = "rustc_mir"
23642375
version = "0.0.0"
@@ -2441,6 +2452,7 @@ dependencies = [
24412452
"rustc 0.0.0",
24422453
"rustc_data_structures 0.0.0",
24432454
"rustc_errors 0.0.0",
2455+
"rustc_metadata 0.0.0",
24442456
"syntax 0.0.0",
24452457
"syntax_pos 0.0.0",
24462458
]

src/librustc/middle/cstore.rs

+1-130
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@
2222
//! are *mostly* used as a part of that interface, but these should
2323
//! probably get a better home if someone can find one.
2424
25-
use hir::def;
2625
use hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
2726
use hir::map as hir_map;
28-
use hir::map::definitions::{Definitions, DefKey, DefPathTable};
27+
use hir::map::definitions::{DefKey, DefPathTable};
2928
use hir::svh::Svh;
3029
use ty::{self, TyCtxt};
3130
use session::{Session, CrateDisambiguator};
@@ -34,8 +33,6 @@ use session::search_paths::PathKind;
3433
use std::any::Any;
3534
use std::path::{Path, PathBuf};
3635
use syntax::ast;
37-
use syntax::edition::Edition;
38-
use syntax::ext::base::SyntaxExtension;
3936
use syntax::symbol::Symbol;
4037
use syntax_pos::Span;
4138
use rustc_target::spec::Target;
@@ -140,11 +137,6 @@ pub struct ForeignModule {
140137
pub def_id: DefId,
141138
}
142139

143-
pub enum LoadedMacro {
144-
MacroDef(ast::Item),
145-
ProcMacro(Lrc<SyntaxExtension>),
146-
}
147-
148140
#[derive(Copy, Clone, Debug)]
149141
pub struct ExternCrate {
150142
pub src: ExternCrateSource,
@@ -221,29 +213,18 @@ pub trait MetadataLoader {
221213
pub trait CrateStore {
222214
fn crate_data_as_rc_any(&self, krate: CrateNum) -> Lrc<dyn Any>;
223215

224-
// access to the metadata loader
225-
fn metadata_loader(&self) -> &dyn MetadataLoader;
226-
227216
// resolve
228217
fn def_key(&self, def: DefId) -> DefKey;
229218
fn def_path(&self, def: DefId) -> hir_map::DefPath;
230219
fn def_path_hash(&self, def: DefId) -> hir_map::DefPathHash;
231220
fn def_path_table(&self, cnum: CrateNum) -> Lrc<DefPathTable>;
232221

233222
// "queries" used in resolve that aren't tracked for incremental compilation
234-
fn visibility_untracked(&self, def: DefId) -> ty::Visibility;
235-
fn export_macros_untracked(&self, cnum: CrateNum);
236-
fn dep_kind_untracked(&self, cnum: CrateNum) -> DepKind;
237223
fn crate_name_untracked(&self, cnum: CrateNum) -> Symbol;
238224
fn crate_disambiguator_untracked(&self, cnum: CrateNum) -> CrateDisambiguator;
239225
fn crate_hash_untracked(&self, cnum: CrateNum) -> Svh;
240-
fn crate_edition_untracked(&self, cnum: CrateNum) -> Edition;
241-
fn struct_field_names_untracked(&self, def: DefId) -> Vec<ast::Name>;
242-
fn item_children_untracked(&self, did: DefId, sess: &Session) -> Vec<def::Export>;
243-
fn load_macro_untracked(&self, did: DefId, sess: &Session) -> LoadedMacro;
244226
fn extern_mod_stmt_cnum_untracked(&self, emod_id: ast::NodeId) -> Option<CrateNum>;
245227
fn item_generics_cloned_untracked(&self, def: DefId, sess: &Session) -> ty::Generics;
246-
fn associated_item_cloned_untracked(&self, def: DefId) -> ty::AssociatedItem;
247228
fn postorder_cnums_untracked(&self) -> Vec<CrateNum>;
248229

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

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

263-
// FIXME: find a better place for this?
264-
pub fn validate_crate_name(sess: Option<&Session>, s: &str, sp: Option<Span>) {
265-
let mut err_count = 0;
266-
{
267-
let mut say = |s: &str| {
268-
match (sp, sess) {
269-
(_, None) => bug!("{}", s),
270-
(Some(sp), Some(sess)) => sess.span_err(sp, s),
271-
(None, Some(sess)) => sess.err(s),
272-
}
273-
err_count += 1;
274-
};
275-
if s.is_empty() {
276-
say("crate name must not be empty");
277-
}
278-
for c in s.chars() {
279-
if c.is_alphanumeric() { continue }
280-
if c == '_' { continue }
281-
say(&format!("invalid character `{}` in crate name: `{}`", c, s));
282-
}
283-
}
284-
285-
if err_count > 0 {
286-
sess.unwrap().abort_if_errors();
287-
}
288-
}
289-
290-
/// A dummy crate store that does not support any non-local crates,
291-
/// for test purposes.
292-
pub struct DummyCrateStore;
293-
294-
#[allow(unused_variables)]
295-
impl CrateStore for DummyCrateStore {
296-
fn crate_data_as_rc_any(&self, krate: CrateNum) -> Lrc<dyn Any>
297-
{ bug!("crate_data_as_rc_any") }
298-
// item info
299-
fn visibility_untracked(&self, def: DefId) -> ty::Visibility { bug!("visibility") }
300-
fn item_generics_cloned_untracked(&self, def: DefId, sess: &Session) -> ty::Generics
301-
{ bug!("item_generics_cloned") }
302-
303-
// trait/impl-item info
304-
fn associated_item_cloned_untracked(&self, def: DefId) -> ty::AssociatedItem
305-
{ bug!("associated_item_cloned") }
306-
307-
// crate metadata
308-
fn dep_kind_untracked(&self, cnum: CrateNum) -> DepKind { bug!("is_explicitly_linked") }
309-
fn export_macros_untracked(&self, cnum: CrateNum) { bug!("export_macros") }
310-
fn crate_name_untracked(&self, cnum: CrateNum) -> Symbol { bug!("crate_name") }
311-
fn crate_disambiguator_untracked(&self, cnum: CrateNum) -> CrateDisambiguator {
312-
bug!("crate_disambiguator")
313-
}
314-
fn crate_hash_untracked(&self, cnum: CrateNum) -> Svh { bug!("crate_hash") }
315-
fn crate_edition_untracked(&self, cnum: CrateNum) -> Edition { bug!("crate_edition_untracked") }
316-
317-
// resolve
318-
fn def_key(&self, def: DefId) -> DefKey { bug!("def_key") }
319-
fn def_path(&self, def: DefId) -> hir_map::DefPath {
320-
bug!("relative_def_path")
321-
}
322-
fn def_path_hash(&self, def: DefId) -> hir_map::DefPathHash {
323-
bug!("def_path_hash")
324-
}
325-
fn def_path_table(&self, cnum: CrateNum) -> Lrc<DefPathTable> {
326-
bug!("def_path_table")
327-
}
328-
fn struct_field_names_untracked(&self, def: DefId) -> Vec<ast::Name> {
329-
bug!("struct_field_names")
330-
}
331-
fn item_children_untracked(&self, did: DefId, sess: &Session) -> Vec<def::Export> {
332-
bug!("item_children")
333-
}
334-
fn load_macro_untracked(&self, did: DefId, sess: &Session) -> LoadedMacro { bug!("load_macro") }
335-
336-
fn crates_untracked(&self) -> Vec<CrateNum> { vec![] }
337-
338-
// utility functions
339-
fn extern_mod_stmt_cnum_untracked(&self, emod_id: ast::NodeId) -> Option<CrateNum> { None }
340-
fn encode_metadata<'a, 'tcx>(&self,
341-
tcx: TyCtxt<'a, 'tcx, 'tcx>,
342-
link_meta: &LinkMeta)
343-
-> EncodedMetadata {
344-
bug!("encode_metadata")
345-
}
346-
fn metadata_encoding_version(&self) -> &[u8] { bug!("metadata_encoding_version") }
347-
fn postorder_cnums_untracked(&self) -> Vec<CrateNum> { bug!("postorder_cnums_untracked") }
348-
349-
// access to the metadata loader
350-
fn metadata_loader(&self) -> &dyn MetadataLoader { bug!("metadata_loader") }
351-
}
352-
353-
pub trait CrateLoader {
354-
fn process_extern_crate(&mut self, item: &ast::Item, defs: &Definitions) -> CrateNum;
355-
356-
fn process_path_extern(
357-
&mut self,
358-
name: Symbol,
359-
span: Span,
360-
) -> CrateNum;
361-
362-
fn process_use_extern(
363-
&mut self,
364-
name: Symbol,
365-
span: Span,
366-
id: ast::NodeId,
367-
defs: &Definitions,
368-
) -> CrateNum;
369-
370-
fn postprocess(&mut self, krate: &ast::Crate);
371-
}
372-
373244
// This method is used when generating the command line to pass through to
374245
// system linker. The linker expects undefined symbols on the left of the
375246
// command line to be defined in libraries on the right, not the other way

src/librustc_codegen_utils/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ rustc_target = { path = "../librustc_target" }
2020
rustc_data_structures = { path = "../librustc_data_structures" }
2121
rustc_mir = { path = "../librustc_mir" }
2222
rustc_incremental = { path = "../librustc_incremental" }
23+
rustc_metadata_utils = { path = "../librustc_metadata_utils" }

src/librustc_codegen_utils/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ extern crate rustc_incremental;
3737
extern crate syntax;
3838
extern crate syntax_pos;
3939
#[macro_use] extern crate rustc_data_structures;
40+
extern crate rustc_metadata_utils;
4041

4142
use rustc::ty::TyCtxt;
4243

src/librustc_codegen_utils/link.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@
1010

1111
use rustc::session::config::{self, OutputFilenames, Input, OutputType};
1212
use rustc::session::Session;
13-
use rustc::middle::cstore::{self, LinkMeta};
13+
use rustc::middle::cstore::LinkMeta;
1414
use rustc::hir::svh::Svh;
1515
use std::path::{Path, PathBuf};
1616
use syntax::{ast, attr};
1717
use syntax_pos::Span;
18+
use rustc_metadata_utils::validate_crate_name;
1819

1920
pub fn out_filename(sess: &Session,
2021
crate_type: config::CrateType,
@@ -61,7 +62,7 @@ pub fn find_crate_name(sess: Option<&Session>,
6162
attrs: &[ast::Attribute],
6263
input: &Input) -> String {
6364
let validate = |s: String, span: Option<Span>| {
64-
cstore::validate_crate_name(sess, &s, span);
65+
validate_crate_name(sess, &s, span);
6566
s
6667
};
6768

src/librustc_driver/driver.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use rustc::session::config::{self, Input, OutputFilenames, OutputType};
2020
use rustc::session::search_paths::PathKind;
2121
use rustc::lint;
2222
use rustc::middle::{self, reachable, resolve_lifetime, stability};
23-
use rustc::middle::cstore::CrateStoreDyn;
2423
use rustc::middle::privacy::AccessLevels;
2524
use rustc::ty::{self, AllArenas, Resolutions, TyCtxt};
2625
use rustc::traits;
@@ -484,7 +483,7 @@ impl<'a> ::CompilerCalls<'a> for CompileController<'a> {
484483
codegen_backend: &dyn (::CodegenBackend),
485484
matches: &::getopts::Matches,
486485
sess: &Session,
487-
cstore: &dyn (::CrateStore),
486+
cstore: &CStore,
488487
input: &Input,
489488
odir: &Option<PathBuf>,
490489
ofile: &Option<PathBuf>,
@@ -728,9 +727,9 @@ pub struct ExpansionResult {
728727
pub hir_forest: hir_map::Forest,
729728
}
730729

731-
pub struct InnerExpansionResult<'a> {
730+
pub struct InnerExpansionResult<'a, 'b: 'a> {
732731
pub expanded_crate: ast::Crate,
733-
pub resolver: Resolver<'a>,
732+
pub resolver: Resolver<'a, 'b>,
734733
pub hir_forest: hir_map::Forest,
735734
}
736735

@@ -806,7 +805,7 @@ where
806805

807806
/// Same as phase_2_configure_and_expand, but doesn't let you keep the resolver
808807
/// around
809-
pub fn phase_2_configure_and_expand_inner<'a, F>(
808+
pub fn phase_2_configure_and_expand_inner<'a, 'b: 'a, F>(
810809
sess: &'a Session,
811810
cstore: &'a CStore,
812811
mut krate: ast::Crate,
@@ -815,9 +814,9 @@ pub fn phase_2_configure_and_expand_inner<'a, F>(
815814
addl_plugins: Option<Vec<String>>,
816815
make_glob_map: MakeGlobMap,
817816
resolver_arenas: &'a ResolverArenas<'a>,
818-
crate_loader: &'a mut CrateLoader,
817+
crate_loader: &'a mut CrateLoader<'b>,
819818
after_expand: F,
820-
) -> Result<InnerExpansionResult<'a>, CompileIncomplete>
819+
) -> Result<InnerExpansionResult<'a, 'b>, CompileIncomplete>
821820
where
822821
F: FnOnce(&ast::Crate) -> CompileResult,
823822
{
@@ -1209,7 +1208,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(
12091208
codegen_backend: &dyn CodegenBackend,
12101209
control: &CompileController,
12111210
sess: &'tcx Session,
1212-
cstore: &'tcx CrateStoreDyn,
1211+
cstore: &'tcx CStore,
12131212
hir_map: hir_map::Map<'tcx>,
12141213
mut analysis: ty::CrateAnalysis,
12151214
resolutions: Resolutions,

src/librustc_driver/lib.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ use rustc::session::filesearch;
7878
use rustc::session::{early_error, early_warn};
7979
use rustc::lint::Lint;
8080
use rustc::lint;
81-
use rustc::middle::cstore::CrateStore;
8281
use rustc_metadata::locator;
8382
use rustc_metadata::cstore::CStore;
8483
use rustc_metadata::dynamic_lib::DynamicLibrary;
@@ -676,7 +675,7 @@ pub trait CompilerCalls<'a> {
676675
_: &dyn CodegenBackend,
677676
_: &getopts::Matches,
678677
_: &Session,
679-
_: &dyn CrateStore,
678+
_: &CStore,
680679
_: &Input,
681680
_: &Option<PathBuf>,
682681
_: &Option<PathBuf>)
@@ -884,7 +883,7 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
884883
codegen_backend: &dyn CodegenBackend,
885884
matches: &getopts::Matches,
886885
sess: &Session,
887-
cstore: &dyn CrateStore,
886+
cstore: &CStore,
888887
input: &Input,
889888
odir: &Option<PathBuf>,
890889
ofile: &Option<PathBuf>)
@@ -990,7 +989,7 @@ pub fn enable_save_analysis(control: &mut CompileController) {
990989

991990
impl RustcDefaultCalls {
992991
pub fn list_metadata(sess: &Session,
993-
cstore: &dyn CrateStore,
992+
cstore: &CStore,
994993
matches: &getopts::Matches,
995994
input: &Input)
996995
-> Compilation {
@@ -1002,7 +1001,7 @@ impl RustcDefaultCalls {
10021001
let mut v = Vec::new();
10031002
locator::list_file_metadata(&sess.target.target,
10041003
path,
1005-
cstore.metadata_loader(),
1004+
&*cstore.metadata_loader,
10061005
&mut v)
10071006
.unwrap();
10081007
println!("{}", String::from_utf8(v).unwrap());

src/librustc_driver/pretty.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ use {abort_on_err, driver};
2020
use rustc::ty::{self, TyCtxt, Resolutions, AllArenas};
2121
use rustc::cfg;
2222
use rustc::cfg::graphviz::LabelledCFG;
23-
use rustc::middle::cstore::CrateStoreDyn;
2423
use rustc::session::Session;
2524
use rustc::session::config::{Input, OutputFilenames};
2625
use rustc_borrowck as borrowck;
2726
use rustc_borrowck::graphviz as borrowck_dot;
27+
use rustc_metadata::cstore::CStore;
2828

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

@@ -199,7 +199,7 @@ impl PpSourceMode {
199199
}
200200
fn call_with_pp_support_hir<'tcx, A, F>(&self,
201201
sess: &'tcx Session,
202-
cstore: &'tcx CrateStoreDyn,
202+
cstore: &'tcx CStore,
203203
hir_map: &hir_map::Map<'tcx>,
204204
analysis: &ty::CrateAnalysis,
205205
resolutions: &Resolutions,
@@ -918,7 +918,7 @@ pub fn print_after_parsing(sess: &Session,
918918
}
919919

920920
pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
921-
cstore: &'tcx CrateStoreDyn,
921+
cstore: &'tcx CStore,
922922
hir_map: &hir_map::Map<'tcx>,
923923
analysis: &ty::CrateAnalysis,
924924
resolutions: &Resolutions,
@@ -1074,7 +1074,7 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
10741074
// with a different callback than the standard driver, so that isn't easy.
10751075
// Instead, we call that function ourselves.
10761076
fn print_with_analysis<'tcx, 'a: 'tcx>(sess: &'a Session,
1077-
cstore: &'a CrateStoreDyn,
1077+
cstore: &'a CStore,
10781078
hir_map: &hir_map::Map<'tcx>,
10791079
analysis: &ty::CrateAnalysis,
10801080
resolutions: &Resolutions,

0 commit comments

Comments
 (0)