-
Couldn't load subscription status.
- Fork 13.9k
Cleanup old trans #38302
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
Cleanup old trans #38302
Conversation
|
Nice! You don't have to wait for my shim-MIR PR - I can handle that. |
src/librustc_trans/adt.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC this function is redundant now. Is cleaning that up in scope for this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I also commented on it, there's a bunch like this.
|
I will want to look over the PR later. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! Most of changes I have in mind are further cleanup (fully removing the global builder and its debuginfo machinery, _builder fn variants, Block etc.).
src/librustc/middle/lang_items.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I meant was actually to add this at the implementation site in liballoc, in case someone changes it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to put this into liballoc. Is this a new requirement, or just a new comment? Since we know the discussion about panic on oom will come back.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we ever decide to allow allocation to panic, we’ll have to change trans. Not a hard requirement, but not a comment either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, actually it looks like it's possible to make this panic friendly; but I may be wrong. @eddyb what we need for that is ownership of BAB, right? We have that, so if that's what we need, I can "fix" this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can simply change how MIR for allocation is generated. No need to fiddle in trans… unless there’s some old cruft in old trans that still generates calls to this itself… in which case you’ll have a hard and bad time fixing this :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, this is only called from MIR. In fact, the actual function should be inlined.
src/librustc_trans/adt.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can change trans_field_ptr_builder to trans_field_ptr, including its signature. The _builder split was for the old B(.
src/librustc_trans/base.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same thing here, load_ty_builder should not exist anymore.
src/librustc_trans/base.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same _builder cleanup needed.
src/librustc_trans/base.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can probably inline these 2 at their callsites now.
src/librustc_trans/intrinsic.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, everywhere you have a call that's not to drop glue or box_free you can just put None instead of bcx.lpad().and_then(|b| b.bundle()) - the latter is for cleanup blocks (unwinding landing pads) which are restricted in MIR, e.g. they can't just have arbitrary function calls like intrinsics.
src/librustc_trans/mir/block.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extraneous space after =.
src/librustc_trans/mir/operand.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename this function to store_operand.
src/librustc_trans/mir/rvalue.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the only call? Because then you could inline it.
src/librustc_trans/tvec.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this due to over-zealous inference 😞?
|
Let me test whether this fixes issue |
|
Nope, #35566 is still not fixed. |
|
Update: looks like @est31 was hitting the bug at stage0, which ofc is not fixed. I've suggested a manual way to test that the bug is indeed fixed at stage1 and later. |
|
Now it fails when compiling stage1 std artifacts: |
d87189d to
a81bc72
Compare
|
About the drop_in_place change, is this an example of a program that changes behaviour? Just to understand. Current stable/beta/nightly doesn't run the "B" drop after the panic of "A". struct PrintDrop(&'static str);
impl Drop for PrintDrop {
fn drop(&mut self) {
println!("Dropping {}", self.0);
if self.0 == "A" {
panic!();
}
}
}
use std::mem::forget;
use std::ptr::drop_in_place;
fn main() {
let mut x = (PrintDrop("A"), PrintDrop("B"));
unsafe {
drop_in_place(&mut x);
forget(x);
}
} |
|
The example @eddyb gave me for the |
src/librustc_trans/common.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should probably name this alloca_builder.
src/librustc_trans/common.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still need to kill this.
src/librustc_trans/common.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the LLVMGetFirstInstruction call is needed and you can just the result of the .load(...).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The load returns the ValueRef for the first instruction?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The load is the first instruction.
src/librustc_trans/common.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh this is weird, I wonder if this should maybe be inlined.
src/librustc_trans/common.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
llty can be computed on this branch alone. Which IMO should not exist anymore.
src/librustc_trans/common.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should rename the method on Builder to dynamic_alloca or something.
src/librustc_trans/context.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like the underlying builder is not exactly gone.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also OwnedBuilder should be the only Builder, i.e. the latter should not be a distinct type.
src/librustc_trans/common.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this used at all anymore?
src/librustc_trans/common.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... or this?
f02257a to
bcfe02d
Compare
src/librustc_trans/common.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you avoid having two variables named val, i.e. can you move this up a bit more? Maybe rename it to dummy.
5a2f7d8 to
11fb0a1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be a regular reference?
src/librustc_trans/mir/mod.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this get away with being a reference?
832e1e4 to
ff3829d
Compare
src/librustc_trans/adt.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation is off here.
src/librustc_trans/base.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just an alias for build_return_block and the latter should be inlined.
In some cases there is no return value, in the rest the ABI should match so it's just a matter of passing a return pointer in where applicable and returning the result of the call elsewhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looked again and I think trans_ctor_shim is the only place that needs an alloca for the return value, sometimes (and then only a few cases in build_return_block apply).
src/librustc_trans/base.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, all of this should be unnecessary, it'd be a waste of time to actually write something to an alloca and read it later.
src/librustc_trans/callee.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something tells me all remaining uses have None for lpad. Also, trans_call_inner can be inlined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait, that's poorly named, it should be cleanup_bundle.
src/librustc_trans/callee.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment is outdated heh.
src/librustc_trans/intrinsic.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can be folded into the get_simple_intrinsic use below.
src/librustc_trans/mir/block.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs to be ret_bcx.set_source_location(...).
src/librustc_trans/mir/block.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function can probably just iterate over cleanup_kinds to produce funclets, without the RPO visit order (as CleanupKind::Internal doesn't need to reference a different functlets entry).
src/librustc_trans/mir/mod.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what I mean, the order is irrelevant here now.
src/librustc_trans/tvec.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is mildly confusing, heh, it'd make more sense as header_bcx.add_incoming_to_phi(...).
|
☔ The latest upstream changes (presumably #37429) made this pull request unmergeable. Please resolve the merge conflicts. |
d4f0717 to
aa9b367
Compare
src/librustc_trans/glue.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can't ever be the case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, here and a few times above, builder has a ccx of its own. trans::debuginfo should maybe take just debug_context, not the whole mir context.
src/librustc_trans/mir/mod.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I'd rather these not be made public.
This does not make unreachable and other terminators take self by-value because it is deemed too difficult. We would need to create by-value methods on BAB that call into Builder, due to the Deref to builder.
We cannot inline due to it being recursive.
Also improves cache quality.
7d03df9 to
0013d4c
Compare
|
Rebased. |
|
@bors r+ |
|
📌 Commit 0013d4c has been approved by |
Cleanup old trans This is a cleanup of old trans, with the following main points: - Remove the `build.rs` API (prefer using `Builder` directly, which is now passed where needed through `BlockAndBuilder`). - Remove `Block` (inlining it into `BlockAndBuilder`) - Remove `Callee::call`, primarily through inlining and simplification of code. - Thinned `FunctionContext`: - `mir`, `debug_scopes`, `scopes`, and `fn_ty` are moved to `MirContext`. - `param_env` is moved to `SharedCrateContext` and renamed to `empty_param_env`. - `llretslotptr` is removed, replaced with more careful management of the return values in calls. - `landingpad_alloca` is inlined into cleanup. - `param_substs` are moved to `MirContext`. - `span` is removed, it was never set to anything but `None`. - `block_arena` and `lpad_arena` are removed, since neither was necessary (landing pads and block are quite small, and neither needs arena allocation). - Fixed `drop_in_place` not running other destructors in the same function. Fixes #35566 (thanks to @est31 for confirming).
This is a cleanup of old trans, with the following main points:
build.rsAPI (prefer usingBuilderdirectly, which is now passed where needed throughBlockAndBuilder).Block(inlining it intoBlockAndBuilder)Callee::call, primarily through inlining and simplification of code.FunctionContext:mir,debug_scopes,scopes, andfn_tyare moved toMirContext.param_envis moved toSharedCrateContextand renamed toempty_param_env.llretslotptris removed, replaced with more careful management of the return values in calls.landingpad_allocais inlined into cleanup.param_substsare moved toMirContext.spanis removed, it was never set to anything butNone.block_arenaandlpad_arenaare removed, since neither was necessary (landing pads and block are quite small, and neither needs arena allocation).drop_in_placenot running other destructors in the same function.Fixes #35566 (thanks to @est31 for confirming).