about summary refs log tree commit diff
path: root/compiler/rustc_borrowck/src
AgeCommit message (Collapse)AuthorLines
2024-12-18introduce `LateParamRegionKind`lcnr-15/+17
2024-12-18we aren't actually sanitizing anything anymorelcnr-40/+31
2024-12-18merge PlaceTy field_ty computationlcnr-105/+12
2024-12-18TypeVerifier: stop computing types for later uselcnr-172/+74
2024-12-18rm TypeChecker::sanitize_typelcnr-19/+1
2024-12-18get_ambient_variance to inherent methodlcnr-17/+2
2024-12-18address review commentsRémy Rakic-29/+27
- move constraints to an Option - check `-Zpolonius=next` only once - rewrite fixme comments to make the actionable part clear
2024-12-18introduce beginnings of polonius MIR dumpRémy Rakic-0/+118
This is mostly for test purposes to show the localized constraints until the MIR debugger is set up.
2024-12-18extract main NLL MIR dump functionRémy Rakic-34/+46
this will allow calling from polonius MIR
2024-12-18set up skeleton for localized constraints conversionRémy Rakic-1/+164
2024-12-18add general documentation on the polonius moduleRémy Rakic-0/+35
this describes the rough algorithm using the localized constraint graph
2024-12-18introduce localized outlives constraintsRémy Rakic-0/+48
these are the basic blocks of the naive polonius constraint graph implementation.
2024-12-18Auto merge of #134243 - nnethercote:re-export-more-rustc_span, r=jieyouxubors-21/+11
Re-export more `rustc_span::symbol` things from `rustc_span`. `rustc_span::symbol` defines some things that are re-exported from `rustc_span`, such as `Symbol` and `sym`. But it doesn't re-export some closely related things such as `Ident` and `kw`. So you can do `use rustc_span::{Symbol, sym}` but you have to do `use rustc_span::symbol::{Ident, kw}`, which is inconsistent for no good reason. This commit re-exports `Ident`, `kw`, and `MacroRulesNormalizedIdent`, and changes many `rustc_span::symbol::` qualifiers to `rustc_span::`. This is a 300+ net line of code reduction, mostly because many files with two `use rustc_span` items can be reduced to one. r? `@jieyouxu`
2024-12-18Re-export more `rustc_span::symbol` things from `rustc_span`.Nicholas Nethercote-21/+11
`rustc_span::symbol` defines some things that are re-exported from `rustc_span`, such as `Symbol` and `sym`. But it doesn't re-export some closely related things such as `Ident` and `kw`. So you can do `use rustc_span::{Symbol, sym}` but you have to do `use rustc_span::symbol::{Ident, kw}`, which is inconsistent for no good reason. This commit re-exports `Ident`, `kw`, and `MacroRulesNormalizedIdent`, and changes many `rustc_span::symbol::` qualifiers in `compiler/` to `rustc_span::`. This is a 200+ net line of code reduction, mostly because many files with two `use rustc_span` items can be reduced to one.
2024-12-17Rollup merge of #134378 - lqd:polonius-next-episode-2, r=jackh726Matthias Krüger-260/+240
An octuple of polonius fact generation cleanups This PR is extracted from https://github.com/rust-lang/rust/pull/134268 for easier review and contains its first 8 commits. They have already been reviewed by ````@jackh726```` over there. r? ````@jackh726````
2024-12-17Rollup merge of #134412 - lcnr:borrowck-cleanup-trivial, r=jackh726Jacob Pratt-18/+17
small borrowck cleanup the already approved parts of #133909 and #133961 r? `@jackh726`
2024-12-17Rollup merge of #134397 - Enselic:raw-mut, r=compiler-errorsJacob Pratt-10/+20
rustc_borrowck: Suggest changing `&raw const` to `&raw mut` if applicable Closes #127562 For reference, here is the diff compared to the original error reported in that issue before #134244 stopped suggesting the invalid syntax: ``` diff --git a/tests/ui/borrowck/no-invalid-mut-suggestion-for-raw-pointer-issue-127562.stderr b/tests/ui/borrowck/no-invalid-mut-suggestion-for-raw-pointer-issue-127562.stderr index 0da5d15cf7f..dbe834b6b78 100644 --- a/tests/ui/borrowck/no-invalid-mut-suggestion-for-raw-pointer-issue-127562.stderr +++ b/tests/ui/borrowck/no-invalid-mut-suggestion-for-raw-pointer-issue-127562.stderr ``@@`` -6,8 +6,8 ``@@`` LL | unsafe { *ptr = 3; } | help: consider changing this to be a mutable pointer | -LL | let ptr = &mut raw const val; - | +++ +LL | let ptr = &raw mut val; + | ~~~ error: aborting due to 1 previous error ```
2024-12-17small refactor to region error handlinglcnr-11/+13
2024-12-17move variable initializationlcnr-7/+4
2024-12-16rustc_borrowck: Suggest changing `&raw const` to `&raw mut` if applicableMartin Nordholts-4/+15
2024-12-16rustc_borrowck: suggest_ampmut(): Inline unneeded local varMartin Nordholts-2/+1
Since the previos commit renamed `assignment_rhs_span` to just `rhs_span` there is no need for a variable just to shorten the expression on the next line. Inline the variable.
2024-12-16rustc_borrowck: suggest_ampmut(): Just rename some variablesMartin Nordholts-6/+6
By making the variable names more descriptive it becomes easier to understand the code. Especially with the more complicated code in the next commit.
2024-12-16Avoid wrapping a trivially defaultable type in `Option`Oli Scherer-6/+3
2024-12-16Simplify dataflow `SwitchInt` handling.Nicholas Nethercote-11/+1
Current `SwitchInt` handling has complicated control flow. - The dataflow engine calls `Analysis::apply_switch_int_edge_effects`, passing in an "applier" that impls `SwitchIntEdgeEffects`. - `apply_switch_int_edge_effects` possibly calls `apply` on the applier, passing it a closure. - The `apply` method calls the closure on each `SwitchInt` edge. - The closure operates on the edge. I.e. control flow goes from the engine, to the analysis, to the applier (which came from the engine), to the closure (which came from the analysis). It took me a while to work this out. This commit changes to a simpler structure that maintains the important characteristics. - The dataflow engine calls `Analysis::get_switch_int_data`. - `get_switch_int_data` returns an `Option<Self::SwitchIntData>` value. - If that returned value was `Some`, the dataflow engine calls `Analysis::apply_switch_int_edge_effect` on each edge, passing the `Self::SwitchIntData` value. - `Analysis::apply_switch_int_edge_effect` operates on the edge. I.e. control flow goes from the engine, to the analysis, to the engine, to the analysis. Added: - The `Analysis::SwitchIntData` assoc type and the `Analysis::get_switch_int_data` method. Both only need to be defined by analyses that look at `SwitchInt` terminators. - The `MaybePlacesSwitchIntData` struct, which has three fields. Changes: - `Analysis::apply_switch_int_edge_effects` becomes `Analysis::apply_switch_int_edge_effect`, which is a little simpler because it's dealing with a single edge instead of all edges. Removed: - The `SwitchIntEdgeEffects` trait, and its two impls: `BackwardSwitchIntEdgeEffectsApplier` (which has six fields) and `ForwardSwitchIntEdgeEffectsApplier` structs (which has four fields). - The closure. The new structure is more concise and simpler.
2024-12-15improve consistency within fact genRémy Rakic-46/+44
- fix names - fix ordering of arguments
2024-12-15refactor `type_check` module slightlyRémy Rakic-47/+48
- use a consistent name for `TypeChecker`, which is usually referred to as `typeck` - remove an incorrect doc comment - remove a single-use local
2024-12-15simplify `emit_outlives_facts`Rémy Rakic-13/+7
- integrate into `emit_facts` and remove from typeck
2024-12-15simplify `emit_access_facts` and fact generationRémy Rakic-58/+21
- integrate it within existing fact generation instead of being called in typeck - simplify access fact extraction - also remove single use fact emit functions in root fact generation
2024-12-15use let else more consistently in fact generationRémy Rakic-49/+43
also remove a useless trace
2024-12-15clean up `translate_outlives_facts`Rémy Rakic-37/+48
- remove dependency on `TypeChecker` - move to legacy fact generation module - group facts emitted during typeck together
2024-12-15clean up `emit_drop_facts`Rémy Rakic-29/+32
- remove dependency on `TypeChecker` - move to legacy fact generation module - remove polonius module from liveness
2024-12-15clean up `emit_access_facts`Rémy Rakic-104/+120
- remove dependency on `TypeChecker` - move to legacy fact generation module
2024-12-15Rollup merge of #134315 - lqd:polonius-next-episode-1, r=jackh726Stuart Cook-265/+253
A couple of polonius fact generation cleanups This PR is extracted from #134268 for easier review and contains its first two commits. They have already been reviewed by `@jackh726.` r? `@jackh726`
2024-12-14refactor access fact generationRémy Rakic-80/+67
- use consistent names - inline single use functions - dedupe and simplify some paths - fix fact generation timer activity: it was missing the walk and extraction process
2024-12-14move datalog fact generation into a legacy moduleRémy Rakic-185/+186
2024-12-14Rollup merge of #134191 - willcrichton:dev, r=RalfJung,lqdMatthias Krüger-4/+50
Make some types and methods related to Polonius + Miri public We have a tool, [Aquascope](https://github.com/cognitive-engineering-lab/aquascope/), which uses Polonius and Miri to visualize the compile-time and run-time semantics of a Rust program. Changes in the last few months to both APIs have hidden away details we depend upon. This PR re-exposes some of those details, specifically: **Polonius:** - `BorrowSet` and `BorrowData` are added to `rustc_borrowck::consumers`, and their fields are made `pub` instead of `pub(crate)`. We need this to interpret the `BorrowIndex`es generated by Polonius. - `BorrowSet::build` is now `pub`. We need this because the borrowck API doesn't provide access to the `BorrowSet` constructed during checking. - `PoloniusRegionVid` is added to `rustc_borrowck::consumers`. We need this because it's also contained in the Polonius facts. **Miri:** - `InterpCx::local_to_op` is now a special case of `local_at_frame_to_op`, which allows querying locals in any frame. We need this because we walk the whole stack at each step to collect the state of memory. - `InterpCx::layout_of_local` is now `pub`. We need this because we need to know the layout of every local at each step. If these changes go against some design goal for keeping certain types private, please let me know so we can hash out a better solution. Additionally, if there's a better way to document that it's important that certain types stay public, also let me know. For example, `BorrowSet` was previously public but was hidden in 6676cec, breaking our build. cc ```@RalfJung``` ```@nnethercote``` ```@gavinleroy```
2024-12-14Auto merge of #134185 - compiler-errors:impl-trait-in-bindings, r=oli-obkbors-6/+10
(Re-)Implement `impl_trait_in_bindings` This reimplements the `impl_trait_in_bindings` feature for local bindings. "`impl Trait` in bindings" serve as a form of *trait* ascription, where the type basically functions as an infer var but additionally registering the `impl Trait`'s trait bounds for the infer type. These trait bounds can be used to enforce that predicates hold, and can guide inference (e.g. for closure signature inference): ```rust let _: impl Fn(&u8) -> &u8 = |x| x; ``` They are implemented as an additional set of bounds that are registered when the type is lowered during typeck, and then these bounds are tied to a given `CanonicalUserTypeAscription` for borrowck. We enforce these `CanonicalUserTypeAscription` bounds during borrowck to make sure that the `impl Trait` types are sensitive to lifetimes: ```rust trait Static: 'static {} impl<T> Static for T where T: 'static {} let local = 1; let x: impl Static = &local; //~^ ERROR `local` does not live long enough ``` r? oli-obk cc #63065 --- Why can't we just use TAIT inference or something? Well, TAITs in bodies have the problem that they cannot reference lifetimes local to a body. For example: ```rust type TAIT = impl Display; let local = 0; let x: TAIT = &local; //~^ ERROR `local` does not live long enough ``` That's because TAITs requires us to do *opaque type inference* which is pretty strict, since we need to remap all of the lifetimes of the hidden type to universal regions. This is simply not possible here. --- I consider this part of the "impl trait everywhere" experiment. I'm not certain if this needs yet another lang team experiment.
2024-12-14(Re-)Implement impl_trait_in_bindingsMichael Goulet-1/+1
2024-12-14Split UserTypeAnnotation to have a kindMichael Goulet-6/+10
2024-12-14Rollup merge of #134244 - Enselic:no-mut-hint-for-raw-ref, r=jieyouxuMatthias Krüger-16/+53
rustc_borrowck: Stop suggesting the invalid syntax `&mut raw const` A legitimate suggestion would be to change from &raw const val to &raw mut val But until we have figured out how to make that happen we should at least stop suggesting invalid syntax. I recommend review commit-by-commit. Part of #127562
2024-12-13Rollup merge of #133938 - nnethercote:rustc_mir_dataflow-renamings, r=oli-obkMatthias Krüger-78/+74
`rustc_mir_dataflow` cleanups, including some renamings Some opinionated commits in this collection, let's see how we go. r? `@cjgillot`
2024-12-13rustc_borrowck: Convert suggest_ampmut() 4-tuple to struct for readabilityMartin Nordholts-13/+46
2024-12-13rustc_borrowck: Stop suggesting the invalid syntax `&mut raw const`Martin Nordholts-0/+5
A legitimate suggestion would be to change from &raw const val to &raw mut val But until we have figured out how to make that happen we should at least stop suggesting invalid syntax.
2024-12-13rustc_borrowck: Make suggest_ampmut() return type match its useMartin Nordholts-9/+8
So that it becomes easy for a later commit to return `None`.
2024-12-12Make BorrowSet/BorrowData fields accessible via public gettersWill Crichton-10/+56
2024-12-11Make some types and methods related to Polonius + Miri public.Will Crichton-14/+14
2024-12-10Rename some `Analysis` and `ResultsVisitor` methods.Nicholas Nethercote-23/+23
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-10Call all `Domain` values `state`.Nicholas Nethercote-15/+15
Currently they are called (most common) `state`, or `trans`, or (rare) `on_entry`. I think `trans` is short for "transfer function", which perhaps made more sense when `GenKillAnalysis` existed. Using `state` everywhere now is more consistent.
2024-12-10Remove lifetimes from `BorrowckDomain`.Nicholas Nethercote-34/+30
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.