-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
trans: discrepancies between (MIR-based) collector and non-MIR translation. #34151
Comments
…nd monomorphizations. See issue rust-lang#34151 for more information.
…nd monomorphizations. See issue rust-lang#34151 for more information.
…nd monomorphizations. See issue rust-lang#34151 for more information.
@michaelwoerister Now that MIR is the only option, is this still relevant? And if so, what needs to be done? |
Drop glue might still be needed, but on-demand monomorphizations are gone. Somewhat relatedly, @arielb1 has expressed interest in working on making the collector generate MIR bodies for all the needed shims and drop glues. |
The code for instantiating it on demand is still there, but it should not be needed anymore. |
Is there a pointer for what likely needs removing if I wanted to do this? |
@ahmedcharles The relevant code is here: rust/src/librustc_trans/glue.rs Line 227 in 86dde9b
You can just delete anything below that line in that function. The trickier part is finding out if this causes any breakage. If |
I removed the code, changed the debug! to a panic! and got this:
|
That means that the collector did not anticipate that drop-glue for this type would be needed. It's not entirely surprising that this happens to be a closure type. Closures are special in a few ways. This looks like the collector is missing the drop glue because it is only accessed via the closures vtable. |
Could be from This is where @arielb1's plans for generating shim/glue MIR would come in real handy. |
Yes, that would remove some special cases from the collector. |
Any ideas on how to fix it? Well, given that I don't really know what drop glue is (I assume it's code that calls the drop function on things when they go out of scope), it seems hard to fix. :) |
@arielb1 wants to fix this by generating MIR for those cases as-needed. Don't think there's a much simpler solution. |
old-trans is gone 🎉 |
The translation item collector in
trans::collector
is supposed to find all monomorphizations and instantiations of local and extern functions and drop-glue that need to go into the binary currently being compiled. It does so by analyzing the MIR of every function, following calls, references, drops, etc.In theory this is a sound strategy.
However, in combination with legacy-trans, which is not based on MIR, we are running into problems: Since the MIR is heavily optimized before being passed into the collector, it might not contain references to what really is dead code. HIR-based trans, however, does not have this knowledge and will have to translate everything. This leads to situations where HIR-based trans will insert references to what only MIR-based analysis knows to be dead code. Thus we end up with "dangling references" and, subsequently, linker errors.
In order to still support HIR-based trans for the time being, there's some code in trans that will instantiate functions and drop-glue on demand if the collector "missed" it. This code should be removed once HIR-based trans has been removed from the compiler.
Specifically, this concerns
trans::monomorphize::monomorphic_fn()
andtrans::glue::get_drop_glue_core()
.The text was updated successfully, but these errors were encountered: