Stream: t-compiler/help

Topic: What is a cgu or rcgu file?

osa1 (Aug 03 2020 at 07:16, on Zulip):

When I unpack a .a file generated for a staticlib I get lots of rcgu files with the same name, things like blah-cgu.15.rcgu.o. What do "cgu" and "rcgu" here mean? I'm guessing cgu stands for "code gen unit" but I'm not sure.

bjorn3 (Aug 03 2020 at 08:03, on Zulip):

Yes, cgu is "code gen unit". rcgu is "rust code gen unit".

osa1 (Aug 03 2020 at 08:33, on Zulip):

Thanks. I thought a crate is a single compilation for rustc, is this not correct anymore? Why and how does rustc split a crate into multiple compilation units?

bjorn3 (Aug 03 2020 at 08:57, on Zulip):

A crate is split into multiple codegen units just before codegen so multiple codegen units can be optimized in parallel. You can the control amount using -Ccodegen-units.

osa1 (Aug 03 2020 at 09:07, on Zulip):

Thanks! By "codegen" do you mean when generating LLVM modules of even before that? (maybe when generating MIR?) I just started passing -Ccodege-units to core, std, compiler_builtins and the main crate and it's much easier to find symbols I'm looking for now.

bjorn3 (Aug 03 2020 at 09:16, on Zulip):

"codegen" is generating and optimizing LLVM modules.

osa1 (Aug 03 2020 at 09:26, on Zulip):

So MIR optimizations applied to the whole crate, right?

bjorn3 (Aug 03 2020 at 09:30, on Zulip):

MIR optimizations normally look at a single MIR body at a time. Only MIR inlining looks at multiple MIR bodies at a time, but even in that case it can only change a single MIR body at a time and it needs a hackish scheme to prevent cycle errors, as it looks at the already optimized MIR of callees.

oli (Aug 03 2020 at 09:30, on Zulip):

MIR optimizations are per-function, but this can require pulling info from the rest of the crate or even other crates

oli (Aug 03 2020 at 09:32, on Zulip):

since MIR opts can trigger e.g. const eval, which itself can require the MIR for some const fns, there is a dependency tree here, but as bjorn3 said, only in inlining do you get cycle errors that are problematic. All other cycle errors that you get are legitly cycles in your code

matthiaskrgr (Aug 03 2020 at 14:16, on Zulip):

oh so there are no full-program mir opts?

oli (Aug 03 2020 at 14:57, on Zulip):


oli (Aug 03 2020 at 14:57, on Zulip):

full-program mir opts don't go very well with the query system.

Last update: Sep 28 2020 at 16:15UTC