Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1242,11 +1242,12 @@ fn analysis_interfaces(tcx: TyCtxt<'_>, (): ()) {
if tcx.sess.opts.unstable_opts.public_api_hash
&& tcx.dep_graph.is_fully_enabled()
&& tcx.crate_types() == [CrateType::Rlib]
&& !tcx.codegen_output_mode(()).0
&& (!tcx.codegen_output_mode(()).0 || tcx.sess.opts.unstable_opts.embed_metadata)
{
// These queries allocate definition indices for captured lifetimes and anonymous
// associated types. Visit their owners in HIR order before interface checking can
// allocate the same definitions in a different order during an incremental check.
// allocate the same definitions in a different order during incremental compilation.
// Native rlibs with embedded metadata can reuse the same item prefix.
for opaque in tcx.hir_crate_items(()).opaques() {
let owner = tcx.local_def_id_to_hir_id(opaque).owner;
let _ = tcx.resolve_bound_vars(owner);
Expand Down
35 changes: 22 additions & 13 deletions tests/run-make/incremental-opaque-definition-order/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,27 @@ use run_make_support::{rfs, rustc};

fn main() {
// A private body edit keeps all the opaque definitions and their source positions unchanged.
for value in [1, 2] {
rfs::write("private.rs", format!("#[expect(dead_code)] fn value() -> u32 {{ {value} }}"));
let output = rustc()
.input("lib.rs")
.edition("2024")
.crate_type("rlib")
.emit("metadata")
.incremental("incremental")
.arg("-Zpublic-api-hash")
.arg("-Zthreads=8")
.env("RUSTC_LOG", "ohm_metadata_reuse=info")
.run();
assert_eq!(output.stderr_utf8().contains("reused metadata item prefix"), value == 2);
for (emit, cache) in [("metadata", "check"), ("metadata,link", "build")] {
for value in [1, 2] {
rfs::write(
"private.rs",
format!("#[expect(dead_code)] fn value() -> u32 {{ {value} }}"),
);
let output = rustc()
.input("lib.rs")
.edition("2024")
.crate_type("rlib")
.emit(emit)
.incremental(cache)
.arg("-Zpublic-api-hash")
.arg("-Zthreads=8")
.env("RUSTC_LOG", "ohm_metadata_reuse=info")
.run();
assert_eq!(
output.stderr_utf8().contains("reused metadata item prefix"),
value == 2,
"{emit}"
);
}
}
}
Loading