Skip to content

Commit

Permalink
Remove untracked vtable-const-allocation cache from tcx
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelwoerister committed Oct 7, 2021
1 parent a479766 commit a1e2c0f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
7 changes: 1 addition & 6 deletions compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::lint::{struct_lint_level, LintDiagnosticBuilder, LintLevelSource};
use crate::middle;
use crate::middle::resolve_lifetime::{self, LifetimeScopeForPath, ObjectLifetimeDefault};
use crate::middle::stability;
use crate::mir::interpret::{self, AllocId, Allocation, ConstValue, Scalar};
use crate::mir::interpret::{self, Allocation, ConstValue, Scalar};
use crate::mir::{Body, Field, Local, Place, PlaceElem, ProjectionKind, Promoted};
use crate::thir::Thir;
use crate::traits;
Expand Down Expand Up @@ -1047,10 +1047,6 @@ pub struct GlobalCtxt<'tcx> {
pub(crate) alloc_map: Lock<interpret::AllocMap<'tcx>>,

output_filenames: Arc<OutputFilenames>,

// FIXME(eddyb) this doesn't belong here and should be using a query.
pub(super) vtables_cache:
Lock<FxHashMap<(Ty<'tcx>, Option<ty::PolyExistentialTraitRef<'tcx>>), AllocId>>,
}

impl<'tcx> TyCtxt<'tcx> {
Expand Down Expand Up @@ -1189,7 +1185,6 @@ impl<'tcx> TyCtxt<'tcx> {
const_stability_interner: Default::default(),
alloc_map: Lock::new(interpret::AllocMap::new()),
output_filenames: Arc::new(output_filenames),
vtables_cache: Default::default(),
}
}

Expand Down
10 changes: 1 addition & 9 deletions compiler/rustc_middle/src/ty/vtable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,6 @@ impl<'tcx> TyCtxt<'tcx> {
poly_trait_ref: Option<ty::PolyExistentialTraitRef<'tcx>>,
) -> AllocId {
let tcx = self;
let vtables_cache = tcx.vtables_cache.lock();
if let Some(alloc_id) = vtables_cache.get(&(ty, poly_trait_ref)).cloned() {
return alloc_id;
}
drop(vtables_cache);

let vtable_entries = if let Some(poly_trait_ref) = poly_trait_ref {
let trait_ref = poly_trait_ref.with_self_ty(tcx, ty);
Expand Down Expand Up @@ -119,9 +114,6 @@ impl<'tcx> TyCtxt<'tcx> {
}

vtable.mutability = Mutability::Not;
let alloc_id = tcx.create_memory_alloc(tcx.intern_const_alloc(vtable));
let mut vtables_cache = self.vtables_cache.lock();
vtables_cache.insert((ty, poly_trait_ref), alloc_id);
alloc_id
tcx.create_memory_alloc(tcx.intern_const_alloc(vtable))
}
}
27 changes: 27 additions & 0 deletions src/test/incremental/reorder_vtable.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// revisions:rpass1 rpass2

trait Foo {
#[cfg(rpass1)]
fn method1(&self) -> u32;

fn method2(&self) -> u32;

#[cfg(rpass2)]
fn method1(&self) -> u32;
}

impl Foo for u32 {
fn method1(&self) -> u32 { 17 }
fn method2(&self) -> u32 { 42 }
}

fn main() {
let x: &dyn Foo = &0u32;
assert_eq!(mod1::foo(x), 17);
}

mod mod1 {
pub fn foo(x: &dyn super::Foo) -> u32 {
x.method1()
}
}

0 comments on commit a1e2c0f

Please sign in to comment.