-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Special case repeating fieldless enum variants #104452
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1004,10 +1004,13 @@ pub enum Rvalue<'tcx> { | |
/// This is the cause of a bug in the case where the repetition count is zero because the value | ||
/// is not dropped, see [#74836]. | ||
/// | ||
/// The third param is true if the value we're repeating is an enum variant | ||
/// with no fields so we can emit a memset. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So what is the behavior of I agree with @scottmcm, encoding this in the syntax of MIR seems wrong. MIR is a programming language and you wouldn't usually expect the syntax of a language to encode redundant information like this. (Also unnamed booloeans are pretty bad, so if we stick with this design, this should be turned into a struct variant where the fields have names.) |
||
/// | ||
/// Corresponds to source code like `[x; 32]`. | ||
/// | ||
/// [#74836]: https://github.com/rust-lang/rust/issues/74836 | ||
Repeat(Operand<'tcx>, ty::Const<'tcx>), | ||
Repeat(Operand<'tcx>, ty::Const<'tcx>, bool), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It feels weird to need this specific property on (Also, primitives in tuple-variants are often a bad idea, since there's no type hint for what it means.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I put the property into the rvalue since the actual variant being written is lost at the point I use the information - we only have a value loaded from the generated temporary (i.e. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this is known at MIR building but not later, one possibility might be to add a (That's still an addition to the language that would need a spec, so it's still better to avoid if possible, but it's much lower impact than changing a top-level statement.) |
||
|
||
/// Creates a reference of the indicated kind to the place. | ||
/// | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// compile-flags: -O | ||
|
||
#![crate_type = "lib"] | ||
|
||
// CHECK-LABEL: @none_repeat | ||
#[no_mangle] | ||
pub fn none_repeat() -> [Option<u8>; 64] { | ||
// CHECK: call void @llvm.memset | ||
// CHECK-NEXT: ret void | ||
[None; 64] | ||
} | ||
|
||
// CHECK-LABEL: @some_repeat | ||
#[no_mangle] | ||
pub fn some_repeat() -> [Option<u8>; 64] { | ||
// CHECK: call void @llvm.memset | ||
// CHECK-NEXT: ret void | ||
[Some(1); 64] | ||
} |
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 there is possible UB due to that boolean being wrong, then the interpreter must be adjusted to be able to detect that UB.
There must never be a bit of valid MIR (in the sense of MIR that passes the MIR checker) where the interpreter and codegen behave differently.