about summary refs log tree commit diff
path: root/compiler/rustc_mir_build/src/build/expr
AgeCommit message (Collapse)AuthorLines
2024-12-17Rename `rustc_mir_build::build` to `builder`Zalathar-3194/+0
2024-12-16Rollup merge of #134371 - scottmcm:fix-134352, r=oli-obkMatthias Krüger-7/+25
Check for array lengths that aren't actually `usize` I wish typeck wouldn't give us `ty::Array`s that have this problem in the first place, but we can check for it. Fixes #134352 cc ``@matthiaskrgr``
2024-12-16Rollup merge of #134314 - compiler-errors:default-struct-value-const, r=estebankMatthias Krüger-5/+11
Make sure to use normalized ty for unevaluated const in default struct value This cleans up the way that we construct the `mir::Const::Unevaluated` for default struct values. We were previously using `from_unevaluated`, which doesn't normalize the type, and is really only used for inline assembly. Other codepaths (such as `ExprKind::NamedConst`) use the type from the body. Also, let's stop using `literal_operand`, which also is really not meant for calls other than for literal comparisons in pattern lowering. Also move all of the tests to a separate subdirectory so they don't need to have the same prefix on all the test files. Fixes #134298 r? estebank or reassign
2024-12-15Check for array lengths that aren't actually `usize`Scott McMurray-7/+25
2024-12-14Auto merge of #133734 - scottmcm:lower-indexing-to-ptrmetadata, ↵bors-9/+83
r=davidtwco,RalfJung Bounds-check with PtrMetadata instead of Len in MIR Rather than emitting `Len(*_n)` in array index bounds checks, emit `PtrMetadata(copy _n)` instead -- with some asterisks for arrays and `&mut` that need it to be done slightly differently. We're getting pretty close to removing `Len` entirely, actually. I think just one more PR after this (for slice drop shims). r? mir
2024-12-14Make sure to use normalized ty for unevaluated const for default struct valueMichael Goulet-5/+11
2024-12-13Don't retag the `PtrMetadata(&raw const *_n)` in slice indexingScott McMurray-2/+11
2024-12-09review comments: rewordingsEsteban Küber-1/+1
2024-12-09Introduce `default_field_values` featureEsteban Küber-20/+44
Initial implementation of `#[feature(default_field_values]`, proposed in https://github.com/rust-lang/rfcs/pull/3681. Support default fields in enum struct variant Allow default values in an enum struct variant definition: ```rust pub enum Bar { Foo { bar: S = S, baz: i32 = 42 + 3, } } ``` Allow using `..` without a base on an enum struct variant ```rust Bar::Foo { .. } ``` `#[derive(Default)]` doesn't account for these as it is still gating `#[default]` only being allowed on unit variants. Support `#[derive(Default)]` on enum struct variants with all defaulted fields ```rust pub enum Bar { #[default] Foo { bar: S = S, baz: i32 = 42 + 3, } } ``` Check for missing fields in typeck instead of mir_build. Expand test with `const` param case (needs `generic_const_exprs` enabled). Properly instantiate MIR const The following works: ```rust struct S<A> { a: Vec<A> = Vec::new(), } S::<i32> { .. } ``` Add lint for default fields that will always fail const-eval We *allow* this to happen for API writers that might want to rely on users' getting a compile error when using the default field, different to the error that they would get when the field isn't default. We could change this to *always* error instead of being a lint, if we wanted. This will *not* catch errors for partially evaluated consts, like when the expression relies on a const parameter. Suggestions when encountering `Foo { .. }` without `#[feature(default_field_values)]`: - Suggest adding a base expression if there are missing fields. - Suggest enabling the feature if all the missing fields have optional values. - Suggest removing `..` if there are no missing fields.
2024-12-03Bounds-check with PtrMetadata instead of Len in MIRScott McMurray-8/+73
2024-12-02remove `Ty::is_copy_modulo_regions`lcnr-1/+1
2024-11-28fix a comment with uneven number of backticks in rustc_mir_buildMaybe Lapkin-1/+1
this is funny though! apparently tidy parsed `.gitignore`, but did not recognize unignore lines (`!...`), so tidy was ignoring `rustc_mir_build` this whole time (at least for some lints?).
2024-11-20reduce false positives of tail-expr-drop-order from consumed valuesDing Xiang Fei-35/+57
take 2 open up coroutines tweak the wordings the lint works up until 2021 We were missing one case, for ADTs, which was causing `Result` to yield incorrect results. only include field spans with significant types deduplicate and eliminate field spans switch to emit spans to impl Drops Co-authored-by: Niko Matsakis <nikomat@amazon.com> collect drops instead of taking liveness diff apply some suggestions and add explantory notes small fix on the cache let the query recurse through coroutine new suggestion format with extracted variable name fine-tune the drop span and messages bugfix on runtime borrows tweak message wording filter out ecosystem types earlier apply suggestions clippy check lint level at session level further restrict applicability of the lint translate bid into nop for stable mir detect cycle in type structure
2024-11-19move `fn is_item_raw` to `TypingEnv`lcnr-4/+2
2024-11-18reviewlcnr-0/+2
2024-11-18use `TypingEnv` when no `infcx` is availablelcnr-13/+18
the behavior of the type system not only depends on the current assumptions, but also the currentnphase of the compiler. This is mostly necessary as we need to decide whether and how to reveal opaque types. We track this via the `TypingMode`.
2024-10-30compiler: Switch to rustc_abi in hir_pretty, lint_defs, and mir_buildJubilee Young-3/+3
Completely abandon usage of rustc_target in these crates, as they need no special knowledge of rustc's target tuples.
2024-10-29compiler: `rustc_abi::Abi` => `BackendRepr`Jubilee Young-2/+2
The initial naming of "Abi" was an awful mistake, conveying wrong ideas about how psABIs worked and even more about what the enum meant. It was only meant to represent the way the value would be described to a codegen backend as it was lowered to that intermediate representation. It was never meant to mean anything about the actual psABI handling! The conflation is because LLVM typically will associate a certain form with a certain ABI, but even that does not hold when the special cases that actually exist arise, plus the IR annotations that modify the ABI. Reframe `rustc_abi::Abi` as the `BackendRepr` of the type, and rename `BackendRepr::Aggregate` as `BackendRepr::Memory`. Unfortunately, due to the persistent misunderstandings, this too is now incorrect: - Scattered ABI-relevant code is entangled with BackendRepr - We do not always pre-compute a correct BackendRepr that reflects how we "actually" want this value to be handled, so we leave the backend interface to also inject various special-cases here - In some cases `BackendRepr::Memory` is a "real" aggregate, but in others it is in fact using memory, and in some cases it is a scalar! Our rustc-to-backend lowering code handles this sort of thing right now. That will eventually be addressed by lifting duplicated lowering code to either rustc_codegen_ssa or rustc_target as appropriate.
2024-10-23nightly feature tracking: get rid of the per-feature bool fieldsRalf Jung-1/+1
2024-10-06various fixes for `naked_asm!` implementationFolkert de Vries-6/+13
- fix for divergence - fix error message - fix another cranelift test - fix some cranelift things - don't set the NORETURN option for naked asm - fix use of naked_asm! in doc comment - fix use of naked_asm! in run-make test - use `span_bug` in unreachable branch
2024-09-24be even more precise about "cast" vs "coercion"Lukas Markeffsky-2/+4
2024-09-24use more accurate spans for user type ascriptionsLukas Markeffsky-6/+8
2024-09-23Rollup merge of #130715 - compiler-errors:mir-build-const-eval, r=BoxyUwUMatthias Krüger-1/+1
Replace calls to `ty::Const::{try_}eval` in mir build/pattern analysis We normalize consts in writeback: #130645. This means that consts are gonna be as normalized as they're ever gonna get in MIR building and pattern analysis. Therefore we can just use `try_to_target_usize` rather than calling `eval_target_usize`. Regarding the `.expect` calls, I'm not totally certain whether they're correct given rigid unevaluated consts. But this PR shouldn't make *more* ICEs occur; we may have to squash these ICEs when mGCE comes around, tho 😺
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-133/+103
2024-09-22Replace calls to Const::eval in mir buildMichael Goulet-1/+1
2024-09-11rescope temp lifetime in let-chain into IfElseDing Xiang Fei-0/+10
apply rules by span edition
2024-08-25Avoid taking reference of &TyKindMichael Goulet-1/+1
2024-08-18rename AddressOf -> RawBorrow inside the compilerRalf Jung-5/+5
2024-08-06miri: make vtable addresses not globally uniqueRalf Jung-2/+4
2024-07-29Reformat `use` declarations.Nicholas Nethercote-30/+34
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-17Rollup merge of #127472 - Zalathar:block-and-unit, r=fmeaseMatthias Krüger-23/+24
MIR building: Stop using `unpack!` for `BlockAnd<()>` This is a subset of #127416, containing only the parts related to `BlockAnd<()>`. The first patch removes the non-assigning form of the `unpack!` macro, because it is frustratingly inconsistent with the main form. We can replace it with an ordinary method that discards the `()` and returns the block. The second patch then finds all of the remaining code that was using `unpack!` with `BlockAnd<()>`, and updates it to use that new method instead. --- Changes since original review of #127416: - Renamed `fn unpack_block` → `fn into_block` - Removed `fn unpack_discard`, replacing it with `let _: BlockAnd<()> = ...` (2 occurrences) - Tweaked `arm_end_blocks` to unpack earlier and build `Vec<BasicBlock>` instead of `Vec<BlockAnd<()>>`
2024-07-14Add cache for `allocate_str`Adwin White-1/+1
2024-07-08Stop using `unpack!` for `BlockAnd<()>`Zalathar-12/+9
2024-07-08Remove the non-assigning form of `unpack!`Zalathar-11/+15
This kind of unpacking can be expressed as an ordinary method on `BlockAnd<()>`.
2024-07-07Fix conflicts after rebaseMaybe Lapkin-1/+1
- r-l/r 126784 - r-l/r 127113 - r-l/miri 3562
2024-07-07Properly handle drops for tail callsDrMeepster-18/+22
2024-07-07Support tail calls in mir via `TerminatorKind::TailCall`Maybe Waffle-2/+33
2024-07-02chore: remove duplicate wordshattizai-1/+1
2024-06-30Replace a magic boolean with enum `DeclareLetBindings`Zalathar-2/+3
The new enum `DeclareLetBindings` has three variants: - `Yes`: Declare `let` bindings as normal, for `if` conditions. - `No`: Don't declare bindings, for match guards and let-else. - `LetNotPermitted`: Assert that `let` expressions should not occur.
2024-06-21Save 2 pointers in `TerminatorKind` (96 → 80 bytes)Scott McMurray-4/+5
These things don't need to be `Vec`s; boxed slices are enough. The frequent one here is call arguments, but MIR building knows the number of arguments from the THIR, so the collect is always getting the allocation right in the first place, and thus this shouldn't ever add the shrink-in-place overhead.
2024-06-19Rollup merge of #125766 - RenjiSann:fresh-mcdc-branch-on-bool, r=nnethercoteLeón Orell Valerian Liehr-0/+3
MCDC Coverage: instrument last boolean RHS operands from condition coverage Fresh PR from #124652 -- This PR ensures that the top-level boolean expressions that are not part of the control flow are correctly instrumented thanks to condition coverage. See discussion on https://github.com/rust-lang/rust/issues/124120. Depends on `@Zalathar` 's condition coverage implementation #125756.
2024-06-19coverage: Make MCDC take in account last RHS of condition-coverageDorian Péron-0/+3
Condition coverage extends branch coverage to treat the specific case of last operands of boolean decisions not involved in control flow. This is ultimately made for MCDC to be exhaustive on all boolean expressions. This patch adds a call to `visit_branch_coverage_operation` to track the top-level operand of the said decisions, and changes `visit_coverage_standalone_condition` so MCDC branch registration is called when enabled on these _last RHS_ cases.
2024-06-14Use is_lang_item more aggressivelyMichael Goulet-1/+2
2024-06-05Add `Ty` to `mir::Const::Ty`Boxy-3/+5
2024-06-05Basic removal of `Ty` from places (boring)Boxy-4/+2
2024-06-04Reduce `pub` exposure.Nicholas Nethercote-3/+3
A lot of errors don't need to be visible outside the crate, and some other things as well.
2024-05-30coverage: Instrument the RHS value of lazy logical operatorsZalathar-2/+6
When a lazy logical operator (`&&` or `||`) occurs outside of an `if` condition, it normally doesn't have any associated control-flow branch, so we don't have an existing way to track whether it was true or false. This patch adds special code to handle this case, by inserting extra MIR blocks in a diamond shape after evaluating the RHS. This gives us a place to insert the appropriate marker statements, which can then be given their own counters.
2024-05-24Better ICE message for unresolved upvarsMichael Goulet-2/+13
2024-05-23Remove `#[macro_use] extern crate tracing` from `rustc_mir_build`.Nicholas Nethercote-0/+7
2024-05-17Remove `Rvalue::CheckedBinaryOp`Scott McMurray-1/+3