Stream: t-compiler/major changes

Topic: Do not traverse HIR to generate metadata compiler-team#392


cjgillot (Dec 24 2020 at 13:08, on Zulip):

Creating the topic manually.

oli (Dec 26 2020 at 16:40, on Zulip):

As long as perf allows for it, I think we should do it. https://github.com/rust-lang/rust/pull/80347#issuecomment-751052175 already has some suggestions to resolve any potential perf problems that we encounter. Can you prep the PR in a way that makes it runnable for perf? (I'm not sure if tests need to pass for try builds to succeed)

cjgillot (Dec 26 2020 at 16:48, on Zulip):

The failing test is from polymorphization. I have no idea what is the failure. It says
error: test compilation failed although it shouldn't! on a build-fail test.

cjgillot (Dec 26 2020 at 16:49, on Zulip):

Still, I don't think perf needs passing tests.

oli (Dec 26 2020 at 17:32, on Zulip):

ok, I'll launch perf then

cjgillot (Dec 26 2020 at 21:11, on Zulip):

Perf says it need more work: https://perf.rust-lang.org/compare.html?start=30a42735a0ff678172f66f63aca746096a717293&end=2e325a37b8ff6a4cce0abcacff6dc1b64a3cf624

cjgillot (Dec 26 2020 at 21:13, on Zulip):

One of the issues is the number of calls to optimized_mir query. I am confused by the different tests in the old code around MIR encoding.
In which cases should MIR be encoded at all?

cjgillot (Dec 26 2020 at 21:15, on Zulip):

What is the use of the PrefetchVisitor instead of a plain loop?

for def_id in tcx.mir_keys(LOCAL_CRATE) {
  tcx.ensure().optimized_mir(def_id);;
  tcx.ensure().promoted_mir(def_id);;
}
cjgillot (Dec 26 2020 at 21:17, on Zulip):

Why is MIR emission sometimes gated? Example in Fn impl items:

let def_id = tcx.hir().local_def_id(impl_item.hir_id);
let generics = tcx.generics_of(def_id.to_def_id());
let needs_inline = generics.requires_monomorphization(tcx) || tcx.codegen_fn_attrs(def_id.to_def_id()).requests_inline();
let is_const_fn = sig.header.constness == hir::Constness::Const;
let emit_mir = needs_inline || is_const_fn;
Joshua Nelson (Dec 26 2020 at 21:18, on Zulip):

I think by default functions are compiled directly to assembly (or maybe bitcode?) and only generic functions need the MIR to be kept across crates

cjgillot (Dec 26 2020 at 21:19, on Zulip):

... but sometimes is not gated (example: trait items).

oli (Dec 26 2020 at 23:14, on Zulip):

trait items (not impl Trait for Type items), must be available, because implementations need to instantiate them

oli (Dec 26 2020 at 23:16, on Zulip):

So yea, especially for optimized_mir, you need to replicate the rules that prevent the emission of MIR. Maybe a smaller step to your PR would be to implement those rules as a function that is just based on DefId queries?

apiraino (Apr 14 2021 at 11:12, on Zulip):

MCP closed for inactivity

Last update: May 07 2021 at 07:45UTC