about summary refs log tree commit diff
path: root/compiler/rustc_mir_transform
AgeCommit message (Collapse)AuthorLines
2024-04-24Stabilise `inline_const`Gary Guo-1/+1
2024-04-23filter required_consts during inliningRalf Jung-2/+6
2024-04-23properly fill a promoted's required_constsRalf Jung-22/+11
then we can also make all_required_consts_are_checked a constant instead of a function
2024-04-23interpret: sanity-check that required_consts captures all consts that can failRalf Jung-21/+20
2024-04-23compute required_consts before promotion, and add promoteds that may failRalf Jung-23/+43
2024-04-23promotion: do not promote const-fn calls in const when that may fail without ↵Ralf Jung-26/+87
the entire const failing
2024-04-23Rollup merge of #123993 - compiler-errors:coroutine-obl, r=lcnrLeón Orell Valerian Liehr-0/+40
Do `check_coroutine_obligations` once per typeck root We only need to do `check_coroutine_obligations` once per typeck root, especially since the new solver can't really (easily) associate which obligations correspond to which coroutines. This requires us to move the checks for sized coroutine fields into `mir_coroutine_witnesses`, but that's fine imo. r? lcnr
2024-04-23Rollup merge of #122598 - Nadrieril:full-derefpats, r=matthewjasperLeón Orell Valerian Liehr-2/+2
deref patterns: lower deref patterns to MIR This lowers deref patterns to MIR. This is a bit tricky because this is the first kind of pattern that requires storing a value in a temporary. Thanks to https://github.com/rust-lang/rust/pull/123324 false edges are no longer a problem. The thing I'm not confident about is the handling of fake borrows. This PR ignores any fake borrows inside a deref pattern. We are guaranteed to at least fake borrow the place of the first pointer value, which could be enough, but I'm not certain.
2024-04-23Rollup merge of #124067 - RalfJung:weak-lang-items, r=davidtwcoMatthias Krüger-2/+2
weak lang items are not allowed to be #[track_caller] For instance the panic handler will be called via this import ```rust extern "Rust" { #[lang = "panic_impl"] fn panic_impl(pi: &PanicInfo<'_>) -> !; } ``` A `#[track_caller]` would add an extra argument and thus make this the wrong signature. The 2nd commit is a consistency rename; based on the docs [here](https://doc.rust-lang.org/unstable-book/language-features/lang-items.html) and [here](https://rustc-dev-guide.rust-lang.org/lang-items.html) I figured "lang item" is more widely used. (In the compiler output, "lang item" and "language item" seem to be pretty even.)
2024-04-23Auto merge of #121801 - zetanumbers:async_drop_glue, r=oli-obkbors-4/+631
Add simple async drop glue generation This is a prototype of the async drop glue generation for some simple types. Async drop glue is intended to behave very similar to the regular drop glue except for being asynchronous. Currently it does not execute synchronous drops but only calls user implementations of `AsyncDrop::async_drop` associative function and awaits the returned future. It is not complete as it only recurses into arrays, slices, tuples, and structs and does not have same sensible restrictions as the old `Drop` trait implementation like having the same bounds as the type definition, while code assumes their existence (requires a future work). This current design uses a workaround as it does not create any custom async destructor state machine types for ADTs, but instead uses types defined in the std library called future combinators (deferred_async_drop, chain, ready_unit). Also I recommend reading my [explainer](https://zetanumbers.github.io/book/async-drop-design.html). This is a part of the [MCP: Low level components for async drop](https://github.com/rust-lang/compiler-team/issues/727) work. Feature completeness: - [x] `AsyncDrop` trait - [ ] `async_drop_in_place_raw`/async drop glue generation support for - [x] Trivially destructible types (integers, bools, floats, string slices, pointers, references, etc.) - [x] Arrays and slices (array pointer is unsized into slice pointer) - [x] ADTs (enums, structs, unions) - [x] tuple-like types (tuples, closures) - [ ] Dynamic types (`dyn Trait`, see explainer's [proposed design](https://github.com/zetanumbers/posts/blob/main/async-drop-design.md#async-drop-glue-for-dyn-trait)) - [ ] coroutines (https://github.com/rust-lang/rust/pull/123948) - [x] Async drop glue includes sync drop glue code - [x] Cleanup branch generation for `async_drop_in_place_raw` - [ ] Union rejects non-trivially async destructible fields - [ ] `AsyncDrop` implementation requires same bounds as type definition - [ ] Skip trivially destructible fields (optimization) - [ ] New [`TyKind::AdtAsyncDestructor`](https://github.com/zetanumbers/posts/blob/main/async-drop-design.md#adt-async-destructor-types) and get rid of combinators - [ ] [Synchronously undroppable types](https://github.com/zetanumbers/posts/blob/main/async-drop-design.md#exclusively-async-drop) - [ ] Automatic async drop at the end of the scope in async context
2024-04-22coverage: Separate branch pairs from other mapping kindsZalathar-25/+44
This clears the way for larger changes to how branches are handled by the coverage instrumentor, in order to support branch coverage for more language constructs.
2024-04-22coverage: Detach MC/DC branch spans from regular branch spansZalathar-23/+77
MC/DC's reliance on the existing branch coverage types is making it much harder to improve branch coverage.
2024-04-21Address more PR feedbackScott McMurray-3/+3
2024-04-21InstSimplify `from_raw_parts(p, ())` → `p as _`Scott McMurray-1/+35
2024-04-21Add an intrinsic that lowers to AggregateKind::RawPtrScott McMurray-0/+28
2024-04-21Add `AggregateKind::RawPtr` and enough support to compileScott McMurray-0/+4
2024-04-20Add a non-shallow fake borrowNadrieril-2/+2
2024-04-20Auto merge of #124194 - matthiaskrgr:rollup-40s0c4q, r=matthiaskrgrbors-23/+171
Rollup of 3 pull requests Successful merges: - #123409 (Implement Modified Condition/Decision Coverage) - #124104 (Fix capturing duplicated lifetimes via parent in `precise_captures` (`impl use<'...>`)) - #124137 (Match hyphen in multi-revision comment matchers) r? `@ghost` `@rustbot` modify labels: rollup
2024-04-20Rollup merge of #123409 - ZhuUx:master, r=oli-obkMatthias Krüger-23/+171
Implement Modified Condition/Decision Coverage This is an implementation based on llvm backend support (>= 18) by `@evodius96` and branch coverage support by `@Zalathar.` ### Major changes: * Add -Zcoverage-options=mcdc as switch. Now coverage options accept either `no-branch`, `branch`, or `mcdc`. `mcdc` also enables `branch` because it is essential to work. * Add coverage mapping for MCDCBranch and MCDCDecision. Note that MCDCParameter evolves from llvm 18 to llvm 19. The mapping in rust side mainly references to 19 and is casted to 18 types in llvm wrapper. * Add wrapper for mcdc instrinc functions from llvm. And inject associated statements to mir. * Add BcbMappingKind::Decision, I'm not sure is it proper but can't find a better way temporarily. * Let coverage-dump support parsing MCDCBranch and MCDCDecision from llvm ir. * Add simple tests to check whether mcdc works. * Same as clang, currently rustc does not generate instrument for decision with more than 6 condtions or only 1 condition due to considerations of resource. ### Implementation Details 1. To get information about conditions and decisions, `MCDCState` in `BranchInfoBuilder` is used during hir lowering to mir. For expressions with logical op we call `Builder::visit_coverage_branch_operation` to record its sub conditions, generate condition ids for them and save their spans (to construct the span of whole decision). This process mainly references to the implementation in clang and is described in comments over `MCDCState::record_conditions`. Also true marks and false marks introduced by branch coverage are used to detect where the decision evaluation ends: the next id of the condition == 0. 2. Once the `MCDCState::decision_stack` popped all recorded conditions, we can ensure that the decision is checked over and push it into `decision_spans`. We do not manually insert decision span to avoid complexity from then_else_break in nested if scopes. 3. When constructing CoverageSpans, add condition info to BcbMappingKind::Branch and decision info to BcbMappingKind::Decision. If the branch mapping has non-zero condition id it will be transformed to MCDCBranch mapping and insert `CondBitmapUpdate` statements to its evaluated blocks. While decision bcb mapping will insert `TestVectorBitmapUpdate` in all its end blocks. ### Usage ```bash echo "[build]\nprofiler=true" >> config.toml ./x build --stage 1 ./x test tests/coverage/mcdc_if.rs ``` to build the compiler and run tests. ```shell export PATH=path/to/llvm-build:$PATH rustup toolchain link mcdc build/host/stage1 cargo +mcdc rustc --bin foo -- -Cinstrument-coverage -Zcoverage-options=mcdc cd target/debug LLVM_PROFILE_FILE="foo.profraw" ./foo llvm-profdata merge -sparse foo.profraw -o foo.profdata llvm-cov show ./foo -instr-profile=foo.profdata --show-mcdc ``` to check "foo" code. ### Problems to solve For now decision mapping will insert statements to its all end blocks, which may be optimized by inserting a final block of the decision. To do this we must also trace the evaluated value at each end of the decision and join them separately. This implementation is not heavily tested so there should be some unrevealed issues. We are going to check our rust products in the next. Please let me know if you had any suggestions or comments.
2024-04-20Auto merge of #124156 - DianQK:disable-match_branches, r=RalfJungbors-1/+4
Disable SimplifyToExp in MatchBranchSimplification Due to the miscompilation mentioned in #124150, We need to disable MatchBranchSimplification temporarily. To fully resolve this issue, my plan is: 1. Disable SimplifyToExp in MatchBranchSimplification (this PR). 2. Remove all potentially unclear transforms in #124122. 3. Gradually add back the removed transforms (possibly multiple PRs). r? `@Nilstrieb` or `@oli-obk`
2024-04-20Disable SimplifyToExp in MatchBranchSimplificationDianQK-1/+4
2024-04-19Auto merge of #124113 - RalfJung:interpret-scalar-ops, r=oli-obkbors-6/+5
interpret: use ScalarInt for bin-ops; avoid PartialOrd for ScalarInt Best reviewed commit-by-commit r? `@oli-obk`
2024-04-20coverage. Lowering MC/DC statements to llvm-irzhuyunxing-1/+11
2024-04-19ScalarInt: add methods to assert being a (u)int of given sizeRalf Jung-6/+5
2024-04-19coverage. Generate Mappings of decisions and conditions for MC/DCzhuyunxing-22/+160
2024-04-18Ensure `[rust] debuginfo-level-std` doesn't change core's MIRScott McMurray-1/+11
2024-04-18At debuginfo=0, don't inline debuginfo when inliningScott McMurray-2/+4
2024-04-18Fix disabling the export of noop async_drop_in_place_rawDaria Sukhonina-25/+29
2024-04-17Use non-exhaustive matches for TyKindDaria Sukhonina-41/+43
Also no longer export noop async_drop_in_place_raw
2024-04-17consistency rename: language item -> lang itemRalf Jung-2/+2
2024-04-16Add simple async drop glue generationzetanumbers-4/+625
Explainer: https://zetanumbers.github.io/book/async-drop-design.html https://github.com/rust-lang/rust/pull/121801
2024-04-16Avoid unnecessary `rustc_span::DUMMY_SP` usage.Nicholas Nethercote-2/+2
In some cases `DUMMY_SP` is already imported. In other cases this commit adds the necessary import, in files where `DUMMY_SP` is used more than once.
2024-04-15Do check_coroutine_obligations once per typeck rootMichael Goulet-0/+40
2024-04-15Rollup merge of #123934 - WaffleLapkin:graph-mini-refactor, r=fmease许杰友 Jieyou Xu (Joe)-24/+9
`rustc_data_structures::graph` mini refactor Who doesn't love to breathe dust from the ancient times?
2024-04-15Use RPITIT for `Successors` and `Predecessors` traitsMaybe Waffle-6/+2
Now with RPITIT instead of GAT!
2024-04-14Rename `WithNumEdges` => `NumEdges` and `WithStartNode` => `StartNode`Maybe Waffle-2/+2
2024-04-14Merge `{With,Graph}{Successors,Predecessors}` into `{Successors,Predecessors}`Maybe Waffle-17/+8
Now with GAT!
2024-04-14Merge `WithNumNodes` into DirectedGraphMaybe Waffle-6/+4
2024-04-10Use a helper to zip together parent and child captures for coroutine-closuresMichael Goulet-68/+10
2024-04-10Only assert for child/parent projection compatibility AFTER checking that ↵Michael Goulet-1/+8
theyre coming from the same place
2024-04-10Rollup merge of #123668 - oli-obk:by_move_body_golfing, r=compiler-errorsMatthias Krüger-51/+43
async closure coroutine by move body MirPass refactoring Unsure about the last commit, but I think the other changes help in simplifying the control flow
2024-04-09Iterate over parent captures first, as there is a 1:N mapping of parent ↵Oli Scherer-71/+63
captures to child captures
2024-04-09Add a FIXMEOli Scherer-0/+1
2024-04-09Rollup merge of #123658 - compiler-errors:stop-assuming, r=oli-obkGuillaume Gomez-19/+17
Stop making any assumption about the projections applied to the upvars in the `ByMoveBody` pass So it turns out that because of subtle optimizations like [`truncate_capture_for_optimization`](https://github.com/rust-lang/rust/blob/ab5bda1aa70f707014e2e691e43bc37a8819252a/compiler/rustc_hir_typeck/src/upvar.rs#L2351), we simply cannot make any assumptions about the shape of the projections applied to the upvar locals in a coroutine body. So stop doing that -- the code is resilient to such projections, so the assertion really existed only to "protect against the unknown". r? oli-obk Fixes #123650
2024-04-09Shrink a loop to its looping part and move out the part that runs after the loopOli Scherer-50/+50
2024-04-09prefer `expect` over `let else bug!`Oli Scherer-3/+2
2024-04-09Split out a complex if condition into a named functionOli Scherer-18/+18
2024-04-09Auto merge of #122387 - DianQK:re-enable-early-otherwise-branch, r=cjgillotbors-119/+53
Re-enable the early otherwise branch optimization Closes #95162. Fixes #119014. This is the first part of #121397. An invalid enum discriminant can come from anywhere. We have to check to see if all successors contain the discriminant statement. This should have a pass to hoist instructions. r? cjgillot
2024-04-08Actually, stop making any assumption about the projections applied to the upvarMichael Goulet-19/+17
2024-04-08Auto merge of #123645 - matthiaskrgr:rollup-yd8d7f1, r=matthiaskrgrbors-35/+162
Rollup of 9 pull requests Successful merges: - #122781 (Fix argument ABI for overaligned structs on ppc64le) - #123367 (Safe Transmute: Compute transmutability from `rustc_target::abi::Layout`) - #123518 (Fix `ByMove` coroutine-closure shim (for 2021 precise closure capturing behavior)) - #123547 (bootstrap: remove unused pub fns) - #123564 (Don't emit divide-by-zero panic paths in `StepBy::len`) - #123578 (Restore `pred_known_to_hold_modulo_regions`) - #123591 (Remove unnecessary cast from `LLVMRustGetInstrProfIncrementIntrinsic`) - #123632 (parser: reduce visibility of unnecessary public `UnmatchedDelim`) - #123635 (CFI: Fix ICE in KCFI non-associated function pointers) r? `@ghost` `@rustbot` modify labels: rollup