Skip to content
Browse files

Discover additional DefIds by looking in the def_path_table.

The "definition path table" is a mapping from DefIds to definition
paths. There's an entry for every item than appears in the compiler's
metadata, thus making it an excellent discovery tool for our serialiser
code to find DefIds in dependent crates (if you run with `-Z

We also switch to using tcx.mir_keys() for finding the DefIds in the
current crate. Previously we used tcx.collect_and_partition_mono_items()
which may miss some stuff.

A future change will remove the work list used in the serialised, as this
code supersedes it. That will be a fairly large change, so saving it for
another PR.

Another future change will enable `-Z always-encode-mir` by default for

One of the tests we disabled here is being discussed upstream here:

When this is resolved, we might have to revisit this test in our fork.
  • Loading branch information...
vext01 committed Aug 16, 2019
1 parent 15821ef commit a2898b056f3413701c2cb98b656d2e4386960e99
@@ -215,6 +215,7 @@ pub trait CrateStore {
tcx: TyCtxt<'a, 'tcx, 'tcx>)
-> EncodedMetadata;
fn metadata_encoding_version(&self) -> &[u8];
fn all_metadata_defids(&self) -> Vec<DefId>;

pub type CrateStoreDyn = dyn CrateStore + sync::Sync;
@@ -64,7 +64,7 @@ use std::hash::{Hash, Hasher};
use std::fmt;
use std::mem;
use std::ops::{Deref, Bound};
use std::iter;
use std::iter::{self, FromIterator};
use std::sync::mpsc;
use std::sync::Arc;
use std::marker::PhantomData;
@@ -1462,6 +1462,10 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {

pub fn all_metadata_defids(&self) -> DefIdSet {

// Note that this is *untracked* and should only be used within the query
// system if the result is otherwise tracked through queries
pub fn crate_data_as_rc_any(self, cnum: CrateNum) -> Lrc<dyn Any> {
@@ -64,7 +64,7 @@ use std::fs;
use std::io::{self, Write};
use std::iter;
use std::path::{Path, PathBuf};
use std::sync::mpsc;
use std::sync::{mpsc, Arc};
use std::cell::RefCell;
use std::rc::Rc;
use std::mem;
@@ -1102,7 +1102,9 @@ pub fn start_codegen<'tcx>(

// Output Yorick debug sections into binary targets.
if tcx.sess.crate_types.borrow().contains(&config::CrateType::Executable) {
let (def_ids, _) = tcx.collect_and_partition_mono_items(LOCAL_CRATE);
let mut def_ids = tcx.all_metadata_defids();

let sir_mode = if tcx.sess.opts.output_types.contains_key(&OutputType::YkSir) {
// The user passed "--emit yk-sir" so we will output textual SIR and stop.
@@ -15,7 +15,7 @@ use rustc::hir;
use rustc::session::{CrateDisambiguator, Session};
use rustc::ty::{self, TyCtxt};
use rustc::ty::query::Providers;
use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE, CRATE_DEF_INDEX};
use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE, CRATE_DEF_INDEX, DefIndex};
use rustc::hir::map::{DefKey, DefPath, DefPathHash};
use rustc::hir::map::definitions::DefPathTable;
use rustc::util::nodemap::DefIdMap;
@@ -561,4 +561,16 @@ impl CrateStore for cstore::CStore {

// Returns a vector of the DefIds contained within all (loaded) meta-data.
fn all_metadata_defids(&self) -> Vec<DefId> {
let mut res = Vec::new();
self.iter_crate_data(|cnum, md| {
let def_idxs =;
DefId { krate: cnum, index: DefIndex::from_usize(idx) }).collect());

@@ -1,5 +1,6 @@
// ignore-windows failing on win32 bot
// ignore-android: FIXME(#10381)
// ignore-test FIXME swt_ignore
// compile-flags:-g
// min-gdb-version: 7.7
// min-lldb-version: 310
@@ -1,4 +1,6 @@
// min-lldb-version: 310
// ignore-test FIXME swt_ignore
// ^-- See

// compile-flags:-g

0 comments on commit a2898b0

Please sign in to comment.
You can’t perform that action at this time.