Isolate CrateNum
creation to TyCtxt
methods
This commit is contained in:
parent
fbc9b94064
commit
0025c9cc50
2 changed files with 18 additions and 12 deletions
|
@ -168,26 +168,22 @@ impl CStore {
|
|||
tcx: TyCtxt<'tcx>,
|
||||
) -> Result<CrateNum, CrateError> {
|
||||
assert_eq!(self.metas.len(), tcx.untracked().stable_crate_ids.read().len());
|
||||
if let Some(&existing) =
|
||||
tcx.untracked().stable_crate_ids.read().get(&root.stable_crate_id())
|
||||
{
|
||||
let num = tcx.create_crate_num(root.stable_crate_id()).map_err(|existing| {
|
||||
// Check for (potential) conflicts with the local crate
|
||||
if existing == LOCAL_CRATE {
|
||||
Err(CrateError::SymbolConflictsCurrent(root.name()))
|
||||
CrateError::SymbolConflictsCurrent(root.name())
|
||||
} else if let Some(crate_name1) = self.metas[existing].as_ref().map(|data| data.name())
|
||||
{
|
||||
let crate_name0 = root.name();
|
||||
Err(CrateError::StableCrateIdCollision(crate_name0, crate_name1))
|
||||
CrateError::StableCrateIdCollision(crate_name0, crate_name1)
|
||||
} else {
|
||||
Err(CrateError::NotFound(root.name()))
|
||||
CrateError::NotFound(root.name())
|
||||
}
|
||||
} else {
|
||||
})?;
|
||||
|
||||
self.metas.push(None);
|
||||
let num = CrateNum::new(tcx.untracked().stable_crate_ids.read().len());
|
||||
tcx.untracked().stable_crate_ids.write().insert(root.stable_crate_id(), num);
|
||||
Ok(num)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn has_crate_data(&self, cnum: CrateNum) -> bool {
|
||||
self.metas[cnum].is_some()
|
||||
|
|
|
@ -1261,6 +1261,16 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
feed
|
||||
}
|
||||
|
||||
pub fn create_crate_num(self, stable_crate_id: StableCrateId) -> Result<CrateNum, CrateNum> {
|
||||
if let Some(&existing) = self.untracked().stable_crate_ids.read().get(&stable_crate_id) {
|
||||
return Err(existing);
|
||||
}
|
||||
|
||||
let num = CrateNum::new(self.untracked().stable_crate_ids.read().len());
|
||||
self.untracked().stable_crate_ids.write().insert(stable_crate_id, num);
|
||||
Ok(num)
|
||||
}
|
||||
|
||||
pub fn iter_local_def_id(self) -> impl Iterator<Item = LocalDefId> + 'tcx {
|
||||
// Create a dependency to the red node to be sure we re-execute this when the amount of
|
||||
// definitions change.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue