Skip to content

Commit

Permalink
Clean up handling of symbol export information.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelwoerister committed Mar 6, 2018
1 parent e5ee011 commit 33d5da1
Show file tree
Hide file tree
Showing 8 changed files with 231 additions and 209 deletions.
7 changes: 2 additions & 5 deletions src/librustc/middle/cstore.rs
Expand Up @@ -32,7 +32,6 @@ use ich;
use ty::{self, TyCtxt};
use session::{Session, CrateDisambiguator};
use session::search_paths::PathKind;
use util::nodemap::NodeSet;

use std::any::Any;
use std::collections::BTreeMap;
Expand Down Expand Up @@ -258,8 +257,7 @@ pub trait CrateStore {
// utility functions
fn encode_metadata<'a, 'tcx>(&self,
tcx: TyCtxt<'a, 'tcx, 'tcx>,
link_meta: &LinkMeta,
reachable: &NodeSet)
link_meta: &LinkMeta)
-> EncodedMetadata;
fn metadata_encoding_version(&self) -> &[u8];
}
Expand Down Expand Up @@ -342,8 +340,7 @@ impl CrateStore for DummyCrateStore {
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,
reachable: &NodeSet)
link_meta: &LinkMeta)
-> EncodedMetadata {
bug!("encode_metadata")
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/ty/context.rs
Expand Up @@ -46,7 +46,7 @@ use ty::layout::{LayoutDetails, TargetDataLayout};
use ty::maps;
use ty::steal::Steal;
use ty::BindingMode;
use util::nodemap::{NodeMap, NodeSet, DefIdSet, ItemLocalMap};
use util::nodemap::{NodeMap, DefIdSet, ItemLocalMap};
use util::nodemap::{FxHashMap, FxHashSet};
use rustc_data_structures::accumulate_vec::AccumulateVec;
use rustc_data_structures::stable_hasher::{HashStable, hash_stable_hashmap,
Expand Down Expand Up @@ -1417,10 +1417,10 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
}

impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
pub fn encode_metadata(self, link_meta: &LinkMeta, reachable: &NodeSet)
pub fn encode_metadata(self, link_meta: &LinkMeta)
-> EncodedMetadata
{
self.cstore.encode_metadata(self, link_meta, reachable)
self.cstore.encode_metadata(self, link_meta)
}
}

Expand Down
7 changes: 3 additions & 4 deletions src/librustc_metadata/cstore_impl.rs
Expand Up @@ -27,7 +27,7 @@ use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE, CRATE_DEF_INDEX};
use rustc::hir::map::{DefKey, DefPath, DefPathHash};
use rustc::hir::map::blocks::FnLikeNode;
use rustc::hir::map::definitions::DefPathTable;
use rustc::util::nodemap::{NodeSet, DefIdMap};
use rustc::util::nodemap::DefIdMap;

use std::any::Any;
use rustc_data_structures::sync::Lrc;
Expand Down Expand Up @@ -517,11 +517,10 @@ impl CrateStore for cstore::CStore {

fn encode_metadata<'a, 'tcx>(&self,
tcx: TyCtxt<'a, 'tcx, 'tcx>,
link_meta: &LinkMeta,
reachable: &NodeSet)
link_meta: &LinkMeta)
-> EncodedMetadata
{
encoder::encode_metadata(tcx, link_meta, reachable)
encoder::encode_metadata(tcx, link_meta)
}

fn metadata_encoding_version(&self) -> &[u8]
Expand Down
19 changes: 9 additions & 10 deletions src/librustc_metadata/encoder.rs
Expand Up @@ -27,7 +27,7 @@ use rustc::ty::{self, Ty, TyCtxt, ReprOptions};
use rustc::ty::codec::{self as ty_codec, TyEncoder};

use rustc::session::config::{self, CrateTypeProcMacro};
use rustc::util::nodemap::{FxHashMap, NodeSet};
use rustc::util::nodemap::{FxHashMap, DefIdSet};

use rustc_data_structures::stable_hasher::StableHasher;
use rustc_serialize::{Encodable, Encoder, SpecializedEncoder, opaque};
Expand All @@ -53,7 +53,6 @@ pub struct EncodeContext<'a, 'tcx: 'a> {
opaque: opaque::Encoder<'a>,
pub tcx: TyCtxt<'a, 'tcx, 'tcx>,
link_meta: &'a LinkMeta,
reachable_non_generics: &'a NodeSet,

lazy_state: LazyState,
type_shorthands: FxHashMap<Ty<'tcx>, usize>,
Expand Down Expand Up @@ -395,9 +394,10 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {

// Encode exported symbols info.
i = self.position();
let reachable_non_generics = self.tcx.reachable_non_generics(LOCAL_CRATE);
let reachable_non_generics = self.tracked(
IsolatedEncoder::encode_reachable_non_generics,
self.reachable_non_generics);
&reachable_non_generics);
let reachable_non_generics_bytes = self.position() - i;

// Encode and index the items.
Expand Down Expand Up @@ -1389,11 +1389,12 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
// symbol associated with them (they weren't translated) or if they're an FFI
// definition (as that's not defined in this crate).
fn encode_reachable_non_generics(&mut self,
reachable_non_generics: &NodeSet)
reachable_non_generics: &DefIdSet)
-> LazySeq<DefIndex> {
let tcx = self.tcx;
self.lazy_seq(reachable_non_generics.iter()
.map(|&id| tcx.hir.local_def_id(id).index))
self.lazy_seq(reachable_non_generics.iter().map(|def_id| {
debug_assert!(def_id.is_local());
def_id.index
}))
}

fn encode_dylib_dependency_formats(&mut self, _: ()) -> LazySeq<Option<LinkagePreference>> {
Expand Down Expand Up @@ -1666,8 +1667,7 @@ impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for ImplVisitor<'a, 'tcx> {
// generated regardless of trailing bytes that end up in it.

pub fn encode_metadata<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
link_meta: &LinkMeta,
reachable_non_generics: &NodeSet)
link_meta: &LinkMeta)
-> EncodedMetadata
{
let mut cursor = Cursor::new(vec![]);
Expand All @@ -1681,7 +1681,6 @@ pub fn encode_metadata<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
opaque: opaque::Encoder::new(&mut cursor),
tcx,
link_meta,
reachable_non_generics,
lazy_state: LazyState::NoNode,
type_shorthands: Default::default(),
predicate_shorthands: Default::default(),
Expand Down

0 comments on commit 33d5da1

Please sign in to comment.