-
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
Better documentation of our MIR dialects #86299
Comments
For drop-elaboration: Maybe split For |
I asked @alexcrichton exactly that question in #86155. :)
That would be another option, indeed. However, the question of whether the Abstract Machine keeps track of drop flags seems like a rather global one, where a dialect switch seems appropriate to me. Otherwise we have to make slightly subtle arguments based on the fact that yes, drop flags exist in the Abstract Machine, and they are always updated by moving or dropping, but if there are no more |
That can make code slower. In case of rust/compiler/rustc_codegen_ssa/src/mir/block.rs Lines 755 to 765 in a216131
I have been meaning to change the call arguments from |
https://mlir.llvm.org encourages and supports to have more dialects. |
How is that observable? Making an extra copy seems fine here. In MIR, as far as I am aware (i.e. in the preliminary spec in my head), EDIT: Oh, I now realize you just said it can make code slower, not that it is wrong. Sure, but that's not relevant. I didn't say that it is a smart or useful change to make. I just said that it is a correct change to make. That is all that matters. |
I think dialects are fine if they are treated explicitly in a principled way. Possibly we could take some ideas from MLIR there, are you familiar with the details? What I am worried about is "accidental" dialects without proper documentation and care. |
Dialects in MLIR are almost for free. You can define your own operations independent of other dialects. It sounds as if you are talking about two implicit dialects (pre and post drop-elaboration). Maybe make the distinction explicit and call them out as two dialects with different names. I assume the second dialect would be simpler than the first one. It smells, if you distinguish dialects by a bit or an enum instead of types. |
@rustbot label +C-enhancement +T-compiler +T-doc |
This is not user-facing documentation, so I don't think it it relevant to the doc team. @rustbot label -T-doc |
#86155 landed, so we now also have a phase during which "unwinding from a fn call inside a nounwind function" implicitly aborts, and another phase during which it is UB. |
Would this be better in the rustc API docs or the rustc dev guide, or maybe parts of both? |
Parts of it is actual code (like a |
#99102 made some progress here (Cc @JakobDegen). One thing I am a bit confused by is that the transition from "conditional drop + implicit abort-on-unwind" to making both of these explicit seems to happen atomically when doing from analysis MIR to runtime MIR, but AFAIK these are two separate passes. So what do we say about the MIR in between those passes? |
My current approach is basically that we say nothing, and that the fact that this atomic transition occurs over two implementations of |
We like to pretend that MIR is a single language, but that is not actually true. There are at least two different languages represented by MIR; I will call them MIR "dialects" in the following:
Move
operands and callingDrop
sets that flag. TheDrop
andDropAndReplace
terminators honor that flag and do not calldrop_in_place
when the drop flag indicates this variable has already been moved/dropped.Drop
terminator indicates an unconditional call todrop_in_place
. (DropAndReplace
terminators AFAIK cannot exist any more in this dialect.)The problem with multiple dialects is that they can have different rules for interpreters, code generators, and optimizations, so we need to be careful not to use the wrong optimization with the wrong dialect.
Miri can only interpret the latter dialect. All our optimizations run post-drop-elaboration, so I assume they are all correct only for that second dialect (though some might also be correct for the first one).
I'd like to propose that we treat these dialects more explicitly: a
mir::Body
should indicate which dialect it is written in, such that optimizations, codegen, and Miri can ensure they are working with MIR of the right dialect. This becomes more pressing since #86155 is suggesting to add yet another dialect.Cc @oli-obk -- there is some overlap here with the "phase" in the MIR validator, but I don't think this is entirely the same concept. Different dialects correspond to different phases, but we might have phases within a dialect where certain instructions are being lowered without changing the operational semantics of the language.
Cc @bjorn3 @rust-lang/wg-mir-opt
The text was updated successfully, but these errors were encountered: