about summary refs log tree commit diff
path: root/compiler/rustc_borrowck/src/lib.rs
AgeCommit message (Collapse)AuthorLines
2024-12-18set up skeleton for localized constraints conversionRémy Rakic-0/+1
2024-12-17move variable initializationlcnr-7/+4
2024-12-10Rename some `Analysis` and `ResultsVisitor` methods.Nicholas Nethercote-3/+3
The words "before" and "after" have an obvious temporal meaning, e.g. `seek_before_primary_effect`, `visit_statement_{before,after}_primary_effect`. But "before" is also used to name the effect that occurs before the primary effect of a statement/terminator; this is `Effect::Before`. This leads to the confusing possibility of talking about things happening "before/after the before event". This commit removes this awkward overloading of "before" by renaming `Effect::Before` as `Effect::Early`. It also renames some of the `Analysis` and `ResultsVisitor` methods to be more consistent. Here are the before and after names: - `Effect::{Before,Primary}` -> `Effect::{Early,Primary}` - `apply_before_statement_effect` -> `apply_early_statement_effect` - `apply_statement_effect` -> `apply_primary_statement_effect` - `visit_statement_before_primary_effect` -> `visit_after_early_statement_effect` - `visit_statement_after_primary_effect` -> `visit_after_primary_statement_effect` (And s/statement/terminator/ for all the terminator events.)
2024-12-10Rename `EntrySets` as `EntryStates`.Nicholas Nethercote-6/+6
"Set" doesn't make much sense here, we refer to domain values as "state" everywhere else. (This name confused me for a while.)
2024-12-10Remove lifetimes from `BorrowckDomain`.Nicholas Nethercote-25/+16
They are only present because it's currently defined in terms of the domains of `Borrows` and `MaybeUninitializedPlaces` and `EverInitializedPlaces` via associated types. This commit introduces typedefs for those domains, avoiding the lifetimes.
2024-12-05Change `ChunkedBitSet<MovePathIndex>`s to `MixedBitSet`.Nicholas Nethercote-2/+2
It's a performance win because `MixedBitSet` is faster and uses less memory than `ChunkedBitSet`. Also reflow some overlong comment lines in `lint_tail_expr_drop_order.rs`.
2024-11-28uplift fold_regions to rustc_type_irlcnr-1/+2
2024-11-20reduce false positives of tail-expr-drop-order from consumed valuesDing Xiang Fei-0/+2
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-19Pass `flow_inits` by value.Nicholas Nethercote-6/+2
It's simpler that way, and we don't need the explicit `drop`.
2024-11-19Put `param_env` into `infcx`.Nicholas Nethercote-8/+4
Because they get passed around together a lot.
2024-11-19Compute `upvars` lazily.Nicholas Nethercote-1/+0
It can be computed from `tcx` on demand, instead of computing it eagerly and passing it around.
2024-11-05Remove `ResultsVisitable`.Nicholas Nethercote-10/+6
Now that `Results` is the only impl of `ResultsVisitable`, the trait can be removed. This simplifies things by removining unnecessary layers of indirection and abstraction. - `ResultsVisitor` is simpler. - Its type parameter changes from `R` (an analysis result) to the simpler `A` (an analysis). - It no longer needs the `Domain` associated type, because it can use `A::Domain`. - Occurrences of `R` become `Results<'tcx, A>`, because there is now only one kind of analysis results. - `save_as_intervals` also changes type parameter from `R` to `A`. - The `results.reconstruct_*` method calls are replaced with `results.analysis.apply_*` method calls, which are equivalent. - `Direction::visit_results_in_block` is simpler, with a single generic param (`A`) instead of two (`D` and `R`/`F`, with a bound connecting them). Likewise for `visit_results`. - The `ResultsVisitor` impls for `MirBorrowCtxt` and `StorageConflictVisitor` are now specific about the type of the analysis results they work with. They both used to have a type param `R` but they weren't genuinely generic. In both cases there was only a single results type that made sense to instantiate them with.
2024-11-05Replace `BorrowckResults` with `Borrowck`.Nicholas Nethercote-30/+49
The results of most analyses end up in a `Results<'tcx, A>`, where `A` is the analysis. It's then possible to traverse the results via a `ResultsVisitor`, which relies on the `ResultsVisitable` trait. (That trait ends up using the same `apply_*` methods that were used when computing the analysis, albeit indirectly.) This pattern of "compute analysis results, then visit them" is common. But there is one exception. For borrow checking we compute three separate analyses (`Borrows`, `MaybeUninitializedPlaces`, and `EverInitializedPlaces`), combine them into a single `BorrowckResults`, and then do a single visit of that `BorrowckResults` with `MirBorrowckResults`. `BorrowckResults` is just different enough from `Results` that it requires the existence of `ResultsVisitable`, which abstracts over the traversal differences between `Results` and `BorrowckResults`. This commit changes things by introducing `Borrowck` and bundling the three borrowck analysis results into a standard `Results<Borrowck>` instead of the exceptional `BorrowckResults`. Once that's done, the results can be visited like any other analysis results. `BorrowckResults` is removed, as is `impl ResultsVisitable for BorrowckResults`. (It's instructive to see how similar the added `impl Analysis for Borrowck` is to the removed `impl ResultsVisitable for BorrowckResults`. They're both doing exactly the same things.) Overall this increases the number of lines of code and might not seem like a win. But it enables the removal of `ResultsVisitable` in the next commit, which results in many simplifications.
2024-11-04`BorrowckDiags` tweaks.Nicholas Nethercote-13/+5
- Store a mut ref to a `BorrowckDiags` in `MirBorrowckCtxt` instead of owning it, to save having to pass ownership in and out of `promoted_mbcx`. - Use `buffer_error` in a couple of suitable places.
2024-11-04Tidy up comments and some formatting.Nicholas Nethercote-19/+15
Mostly by wrapping overly long comment lines, plus a few other things.
2024-11-04Move some `use` declarations.Nicholas Nethercote-13/+12
So they're all in the one place. Also prepend with `crate::`, à la the `unqualified_local_imports` lint.
2024-11-04Reduce visibilities.Nicholas Nethercote-2/+2
2024-11-02compiler: Replace rustc_target with _abi in _borrowckJubilee Young-1/+1
2024-10-30Rollup merge of #132338 - nnethercote:rm-Engine, r=nnethercoteMatthias Krüger-15/+16
Remove `Engine` It's just unnecessary plumbing. Removing it results in less code, and simpler code. r? ``@cjgillot``
2024-10-30Remove `Analysis::into_engine`.Nicholas Nethercote-15/+16
This is a standard pattern: ``` MyAnalysis.into_engine(tcx, body).iterate_to_fixpoint() ``` `into_engine` and `iterate_to_fixpoint` are always called in pairs, but sometimes with a builder-style `pass_name` call between them. But a builder-style interface is overkill here. This has been bugging me a for a while. This commit: - Merges `Engine::new` and `Engine::iterate_to_fixpoint`. This removes the need for `Engine` to have fields, leaving it as a trivial type that the next commit will remove. - Renames `Analysis::into_engine` as `Analysis::iterate_to_fixpoint`, gives it an extra argument for the optional pass name, and makes it call `Engine::iterate_to_fixpoint` instead of `Engine::new`. This turns the pattern from above into this: ``` MyAnalysis.iterate_to_fixpoint(tcx, body, None) ``` which is shorter at every call site, and there's less plumbing required to support it.
2024-10-29TypingMode :thinking:lcnr-2/+2
2024-10-19Get rid of const eval_* and try_eval_* helpersMichael Goulet-2/+2
2024-10-07Rollup merge of #131225 - nnethercote:rustc_borrowck-mm, r=lqdJubilee-22/+14
`rustc_borrowck` memory management tweaks Minor cleanups in `rustc_borrowck` relating to memory management. r? `@lqd`
2024-10-06various fixes for `naked_asm!` implementationFolkert de Vries-0/+1
- 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-10-04Avoid `Rc` in `BodyWithBorrowckFacts`.Nicholas Nethercote-3/+2
It can own these two fields.
2024-10-04Use `Box` instead of `Rc` for `polonius_output`.Nicholas Nethercote-1/+1
Refcounting isn't needed.
2024-10-04Use `Rc` less in `MirBorrowckCtxt`.Nicholas Nethercote-22/+15
The `regioncx` and `borrow_set` fields can be references instead of `Rc`. They use the existing `'a` lifetime. This avoids some heap allocations and is a bit simpler.
2024-09-25Stabilize the `map`/`value` methods on `ControlFlow`Scott McMurray-1/+0
And fix the stability attribute on the `pub use` in `core::ops`.
2024-09-24Dogfood `feature(file_buffered)`Josh Stone-0/+1
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-9/+5
2024-09-13Rollup merge of #130297 - nnethercote:dataflow-cleanups, r=cjgillotMatthias Krüger-86/+85
Dataflow cleanups r? `@cjgillot`
2024-09-13Rename `FlowState` as `Domain`.Nicholas Nethercote-86/+85
Because that's what it is; no point having a different name for it.
2024-09-11Simplify some nested if statementsMichael Goulet-5/+5
2024-09-09Remove unnecessary lifetimes in dataflow structs.Nicholas Nethercote-39/+34
There are four related dataflow structs: `MaybeInitializedPlaces`, `MaybeUninitializedPlaces`, and `EverInitializedPlaces`, `DefinitelyInitializedPlaces`. They all have a `&Body` and a `&MoveData<'tcx>` field. The first three use different lifetimes for the two fields, but the last one uses the same lifetime for both. This commit changes the first three to use the same lifetime, removing the need for one of the lifetimes. Other structs that also lose a lifetime as a result of this are `LivenessContext`, `LivenessResults`, `InitializationData`. It then does similar things in various other structs.
2024-09-04propagate `tainted_by_errors` in `MirBorrowckCtxt::emit_errors`Folkert de Vries-1/+1
2024-08-31Rollup merge of #129767 - nnethercote:rm-extern-crate-tracing-4, r=jieyouxuMatthias Krüger-3/+1
Remove `#[macro_use] extern crate tracing`, round 4 Because explicit importing of macros via use items is nicer (more standard and readable) than implicit importing via #[macro_use]. Continuing the work from #124511, #124914, and #125434. After this PR no `rustc_*` crates use `#[macro_use] extern crate tracing` except for `rustc_codegen_gcc` which is a special case and I will do separately. r? ```@jieyouxu```
2024-08-30Remove `#[macro_use] extern crate tracing` from `rustc_borrowck`.Nicholas Nethercote-3/+1
2024-08-30add borrows to NLL MIR dumpsRémy Rakic-1/+1
explicitly disable `-Zmir-include-spans` in mir-opt tests This will override the NLL default of true, and keep the blessed dumps easier to work with.
2024-08-30refactor NLL MIR dump entry pointRémy Rakic-1/+1
2024-08-27Rollup merge of #126013 - nnethercote:unreachable_pub, r=UrgauMatthias Krüger-11/+15
Add `#[warn(unreachable_pub)]` to a bunch of compiler crates By default `unreachable_pub` identifies things that need not be `pub` and tells you to make them `pub(crate)`. But sometimes those things don't need any kind of visibility. So they way I did these was to remove the visibility entirely for each thing the lint identifies, and then add `pub(crate)` back in everywhere the compiler said it was necessary. (Or occasionally `pub(super)` when context suggested that was appropriate.) Tedious, but results in more `pub` removal. There are plenty more crates to do but this seems like enough for a first PR. r? `@compiler-errors`
2024-08-18rename AddressOf -> RawBorrow inside the compilerRalf Jung-1/+1
2024-08-16Add `warn(unreachable_pub)` to `rustc_borrowck`.Nicholas Nethercote-11/+15
2024-08-09Shrink `TyKind::FnPtr`.Nicholas Nethercote-2/+2
By splitting the `FnSig` within `TyKind::FnPtr` into `FnSigTys` and `FnHeader`, which can be packed more efficiently. This reduces the size of the hot `TyKind` type from 32 bytes to 24 bytes on 64-bit platforms. This reduces peak memory usage by a few percent on some benchmarks. It also reduces cache misses and page faults similarly, though this doesn't translate to clear cycles or wall-time improvements on CI.
2024-07-29Stop using MoveDataParamEnv for places that don't need a param-envMichael Goulet-9/+7
2024-07-29Reformat `use` declarations.Nicholas Nethercote-21/+19
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-11Revert accidental comment deletionGiacomo Stevanato-0/+2
2024-07-08Auto merge of #113128 - WaffleLapkin:become_trully_unuwuable, r=oli-obk,RalfJungbors-2/+7
Support tail calls in mir via `TerminatorKind::TailCall` This is one of the interesting bits in tail call implementation — MIR support. This adds a new `TerminatorKind` which represents a tail call: ```rust TailCall { func: Operand<'tcx>, args: Vec<Operand<'tcx>>, fn_span: Span, }, ``` *Structurally* this is very similar to a normal `Call` but is missing a few fields: - `destination` — tail calls don't write to destination, instead they pass caller's destination to the callee (such that eventual `return` will write to the caller of the function that used tail call) - `target` — similarly to `destination` tail calls pass the caller's return address to the callee, so there is nothing to do - `unwind` — I _think_ this is applicable too, although it's a bit confusing - `call_source` — `become` forbids operators and is not created as a lowering of something else; tail calls always come from HIR (at least for now) It might be helpful to read the interpreter implementation to understand what `TailCall` means exactly, although I've tried documenting it too. ----- There are a few `FIXME`-questions still left, ideally we'd be able to answer them during review ':) ----- r? `@oli-obk` cc `@scottmcm` `@DrMeepster` `@JakobDegen`
2024-07-07Support tail calls in mir via `TerminatorKind::TailCall`Maybe Waffle-2/+7
2024-07-04Auto merge of #127170 - bjorn3:no_specialize_index_borrowck, r=michaelwoeristerbors-1/+0
Stop using specialization in rustc_index and rustc_borrowck For rustc_borrowck the version with specialization isn't much more readable anyway IMO. For rustc_index it probably doesn't affect perf in any noticeable way anyway.
2024-06-30Remove usage of specialization from rustc_borrowckbjorn3-1/+0