-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #89619 - michaelwoerister:incr-vtables, r=nagisa
Turn vtable_allocation() into a query This PR removes the untracked vtable-const-allocation cache from the `tcx` and turns the `vtable_allocation()` method into a query. The change is pretty straightforward and should be backportable without too much effort. Fixes #89598.
- Loading branch information
Showing
10 changed files
with
125 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// revisions:rpass1 rpass2 | ||
|
||
// This test case makes sure re-order the methods in a vtable will | ||
// trigger recompilation of codegen units that instantiate it. | ||
// | ||
// See https://github.com/rust-lang/rust/issues/89598 | ||
|
||
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() { | ||
// Before #89598 was fixed, the vtable allocation would be cached during | ||
// a MIR optimization pass and then the codegen pass for the main object | ||
// file would not register a dependency on it (because of the missing | ||
// dep-tracking). | ||
// | ||
// In the rpass2 session, the main object file would not be re-compiled, | ||
// thus the mod1::foo(x) call would pass in an outdated vtable, while the | ||
// mod1 object would expect the new, re-ordered vtable, resulting in a | ||
// call to the wrong method. | ||
let x: &dyn Foo = &0u32; | ||
assert_eq!(mod1::foo(x), 17); | ||
} | ||
|
||
mod mod1 { | ||
pub(super) fn foo(x: &dyn super::Foo) -> u32 { | ||
x.method1() | ||
} | ||
} |