Skip to content

Commit

Permalink
Move unused trait functions to inherent functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark-Simulacrum committed Aug 3, 2018
1 parent 5aec365 commit 6fdd6f6
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 101 deletions.
1 change: 1 addition & 0 deletions src/Cargo.lock
Expand Up @@ -2366,6 +2366,7 @@ name = "rustc_metadata_utils"
version = "0.0.0"
dependencies = [
"rustc 0.0.0",
"syntax 0.0.0",
"syntax_pos 0.0.0",
]

Expand Down
18 changes: 0 additions & 18 deletions src/librustc/middle/cstore.rs
Expand Up @@ -22,7 +22,6 @@
//! 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::{DefKey, DefPathTable};
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,28 +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 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 Down
3 changes: 1 addition & 2 deletions src/librustc_driver/lib.rs
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 @@ -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
5 changes: 5 additions & 0 deletions src/librustc_metadata/cstore.rs
Expand Up @@ -93,6 +93,11 @@ pub struct CStore {
pub metadata_loader: Box<dyn MetadataLoader + Sync>,
}

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

impl CStore {
pub fn new(metadata_loader: Box<dyn MetadataLoader + Sync>) -> CStore {
CStore {
Expand Down
149 changes: 71 additions & 78 deletions src/librustc_metadata/cstore_impl.rs
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use cstore;
use cstore::{self, LoadedMacro};
use encoder;
use link_args;
use native_libs;
Expand All @@ -17,8 +17,8 @@ use schema;

use rustc::ty::query::QueryConfig;
use rustc::middle::cstore::{CrateStore, DepKind,
MetadataLoader, LinkMeta,
LoadedMacro, EncodedMetadata, NativeLibraryKind};
LinkMeta,
EncodedMetadata, NativeLibraryKind};
use rustc::middle::exported_symbols::ExportedSymbol;
use rustc::middle::stability::DeprecationEntry;
use rustc::hir::def;
Expand Down Expand Up @@ -411,102 +411,37 @@ pub fn provide<'tcx>(providers: &mut Providers<'tcx>) {
};
}

impl CrateStore for cstore::CStore {
fn crate_data_as_rc_any(&self, krate: CrateNum) -> Lrc<dyn Any> {
self.get_crate_data(krate)
}

fn metadata_loader(&self) -> &dyn MetadataLoader {
&*self.metadata_loader
}

fn item_generics_cloned_untracked(&self, def: DefId, sess: &Session) -> ty::Generics {
self.get_crate_data(def.krate).get_generics(def.index, sess)
}

fn associated_item_cloned_untracked(&self, def: DefId) -> ty::AssociatedItem
{
self.get_crate_data(def.krate).get_associated_item(def.index)
}

fn dep_kind_untracked(&self, cnum: CrateNum) -> DepKind
{
let data = self.get_crate_data(cnum);
let r = *data.dep_kind.lock();
r
}

fn export_macros_untracked(&self, cnum: CrateNum) {
impl cstore::CStore {
pub fn export_macros_untracked(&self, cnum: CrateNum) {
let data = self.get_crate_data(cnum);
let mut dep_kind = data.dep_kind.lock();
if *dep_kind == DepKind::UnexportedMacrosOnly {
*dep_kind = DepKind::MacrosOnly;
}
}

fn crate_name_untracked(&self, cnum: CrateNum) -> Symbol
{
self.get_crate_data(cnum).name
}

fn crate_disambiguator_untracked(&self, cnum: CrateNum) -> CrateDisambiguator
{
self.get_crate_data(cnum).root.disambiguator
}

fn crate_hash_untracked(&self, cnum: CrateNum) -> hir::svh::Svh
{
self.get_crate_data(cnum).root.hash
pub fn dep_kind_untracked(&self, cnum: CrateNum) -> DepKind {
let data = self.get_crate_data(cnum);
let r = *data.dep_kind.lock();
r
}

fn crate_edition_untracked(&self, cnum: CrateNum) -> Edition
{
pub fn crate_edition_untracked(&self, cnum: CrateNum) -> Edition {
self.get_crate_data(cnum).root.edition
}

/// Returns the `DefKey` for a given `DefId`. This indicates the
/// parent `DefId` as well as some idea of what kind of data the
/// `DefId` refers to.
fn def_key(&self, def: DefId) -> DefKey {
// Note: loading the def-key (or def-path) for a def-id is not
// a *read* of its metadata. This is because the def-id is
// really just an interned shorthand for a def-path, which is the
// canonical name for an item.
//
// self.dep_graph.read(DepNode::MetaData(def));
self.get_crate_data(def.krate).def_key(def.index)
}

fn def_path(&self, def: DefId) -> DefPath {
// See `Note` above in `def_key()` for why this read is
// commented out:
//
// self.dep_graph.read(DepNode::MetaData(def));
self.get_crate_data(def.krate).def_path(def.index)
}

fn def_path_hash(&self, def: DefId) -> DefPathHash {
self.get_crate_data(def.krate).def_path_hash(def.index)
}

fn def_path_table(&self, cnum: CrateNum) -> Lrc<DefPathTable> {
self.get_crate_data(cnum).def_path_table.clone()
}

fn struct_field_names_untracked(&self, def: DefId) -> Vec<ast::Name>
{
pub fn struct_field_names_untracked(&self, def: DefId) -> Vec<ast::Name> {
self.get_crate_data(def.krate).get_struct_field_names(def.index)
}

fn item_children_untracked(&self, def_id: DefId, sess: &Session) -> Vec<def::Export>
{
pub fn item_children_untracked(&self, def_id: DefId, sess: &Session) -> Vec<def::Export> {
let mut result = vec![];
self.get_crate_data(def_id.krate)
.each_child_of_item(def_id.index, |child| result.push(child), sess);
result
}

fn load_macro_untracked(&self, id: DefId, sess: &Session) -> LoadedMacro {
pub fn load_macro_untracked(&self, id: DefId, sess: &Session) -> LoadedMacro {
let data = self.get_crate_data(id.krate);
if let Some(ref proc_macros) = data.proc_macros {
return LoadedMacro::ProcMacro(proc_macros[id.index.to_proc_macro_index()].1.clone());
Expand Down Expand Up @@ -555,6 +490,64 @@ impl CrateStore for cstore::CStore {
})
}

pub fn associated_item_cloned_untracked(&self, def: DefId) -> ty::AssociatedItem {
self.get_crate_data(def.krate).get_associated_item(def.index)
}
}

impl CrateStore for cstore::CStore {
fn crate_data_as_rc_any(&self, krate: CrateNum) -> Lrc<dyn Any> {
self.get_crate_data(krate)
}

fn item_generics_cloned_untracked(&self, def: DefId, sess: &Session) -> ty::Generics {
self.get_crate_data(def.krate).get_generics(def.index, sess)
}

fn crate_name_untracked(&self, cnum: CrateNum) -> Symbol
{
self.get_crate_data(cnum).name
}

fn crate_disambiguator_untracked(&self, cnum: CrateNum) -> CrateDisambiguator
{
self.get_crate_data(cnum).root.disambiguator
}

fn crate_hash_untracked(&self, cnum: CrateNum) -> hir::svh::Svh
{
self.get_crate_data(cnum).root.hash
}

/// Returns the `DefKey` for a given `DefId`. This indicates the
/// parent `DefId` as well as some idea of what kind of data the
/// `DefId` refers to.
fn def_key(&self, def: DefId) -> DefKey {
// Note: loading the def-key (or def-path) for a def-id is not
// a *read* of its metadata. This is because the def-id is
// really just an interned shorthand for a def-path, which is the
// canonical name for an item.
//
// self.dep_graph.read(DepNode::MetaData(def));
self.get_crate_data(def.krate).def_key(def.index)
}

fn def_path(&self, def: DefId) -> DefPath {
// See `Note` above in `def_key()` for why this read is
// commented out:
//
// self.dep_graph.read(DepNode::MetaData(def));
self.get_crate_data(def.krate).def_path(def.index)
}

fn def_path_hash(&self, def: DefId) -> DefPathHash {
self.get_crate_data(def.krate).def_path_hash(def.index)
}

fn def_path_table(&self, cnum: CrateNum) -> Lrc<DefPathTable> {
self.get_crate_data(cnum).def_path_table.clone()
}

fn crates_untracked(&self) -> Vec<CrateNum>
{
let mut result = vec![];
Expand Down
1 change: 1 addition & 0 deletions src/librustc_metadata_utils/Cargo.toml
Expand Up @@ -10,4 +10,5 @@ crate-type = ["dylib"]

[dependencies]
rustc = { path = "../librustc" }
syntax = { path = "../libsyntax" }
syntax_pos = { path = "../libsyntax_pos" }
2 changes: 1 addition & 1 deletion src/librustc_resolve/build_reduced_graph.rs
Expand Up @@ -21,11 +21,11 @@ use {PerNS, Resolver, ResolverArenas};
use Namespace::{self, TypeNS, ValueNS, MacroNS};
use {resolve_error, resolve_struct_error, ResolutionError};

use rustc::middle::cstore::LoadedMacro;
use rustc::hir::def::*;
use rustc::hir::def_id::{BUILTIN_MACROS_CRATE, CRATE_DEF_INDEX, LOCAL_CRATE, DefId};
use rustc::ty;
use rustc::middle::cstore::CrateStore;
use rustc_metadata::cstore::LoadedMacro;

use std::cell::Cell;
use rustc_data_structures::sync::Lrc;
Expand Down
1 change: 0 additions & 1 deletion src/librustc_resolve/resolve_imports.rs
Expand Up @@ -25,7 +25,6 @@ use rustc::hir::def_id::{CRATE_DEF_INDEX, DefId};
use rustc::hir::def::*;
use rustc::session::DiagnosticMessageId;
use rustc::util::nodemap::{FxHashMap, FxHashSet};
use rustc::middle::cstore::CrateStore;

use syntax::ast::{Ident, Name, NodeId, CRATE_NODE_ID};
use syntax::ext::base::Determinacy::{self, Determined, Undetermined};
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/clean/inline.rs
Expand Up @@ -19,7 +19,7 @@ use syntax_pos::Span;
use rustc::hir;
use rustc::hir::def::{Def, CtorKind};
use rustc::hir::def_id::DefId;
use rustc::middle::cstore::{CrateStore, LoadedMacro};
use rustc_metadata::cstore::LoadedMacro;
use rustc::ty;
use rustc::util::nodemap::FxHashSet;

Expand Down

0 comments on commit 6fdd6f6

Please sign in to comment.