Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
0bb8615
interpret: reduce usage of TypingEnv::fully_monomorphized
RalfJung Dec 9, 2024
0dbb31f
Fix an out-of-date comment.
nnethercote Nov 26, 2024
83f67c5
Remove unused dataflow trait impls and bounds.
nnethercote Dec 5, 2024
d490ea1
Remove lifetimes from `BorrowckDomain`.
nnethercote Nov 26, 2024
086233e
Refer to a couple of domains indirectly.
nnethercote Nov 26, 2024
2298104
Call all `Domain` values `state`.
nnethercote Nov 26, 2024
b059ea8
Rename `EntrySets` as `EntryStates`.
nnethercote Nov 26, 2024
119fbd3
Improve terminology in `elaborate_drops.rs`.
nnethercote Nov 26, 2024
1d56943
Rename some `Analysis` and `ResultsVisitor` methods.
nnethercote Nov 26, 2024
dddc09d
Reorder some `Analysis` methods.
nnethercote Nov 26, 2024
dd3b313
Adjust `alias-uninit-value.rs`
jieyouxu Dec 5, 2024
b5c7a55
Adjust `allow-non-lint-warnings.rs`
jieyouxu Dec 5, 2024
d734d22
Adjust `anonymous-higher-ranked-lifetime.rs`
jieyouxu Dec 5, 2024
4652b14
Adjust `artificial-block.rs`
jieyouxu Dec 5, 2024
56efa0a
Adjust `as-precedence.rs`
jieyouxu Dec 8, 2024
3f52583
Add test for resolve errors caused by mod with parse errors
estebank Dec 5, 2024
69fb612
Keep track of parse errors in `mod`s and don't emit resolve errors fo…
estebank Dec 5, 2024
27420c6
Silence `use foo::Bar;` error if `Bar` isn't found in `foo` and `foo.…
estebank Dec 5, 2024
b795264
Pass TyCtxt rather than Queries to after_expansion
bjorn3 Nov 26, 2023
21634cb
Pass rustc_ast::Crate rather than Queries to after_crate_root_parsing
bjorn3 Dec 12, 2024
8355132
Move type size and vtable size printing to start_codegen
bjorn3 Dec 10, 2024
7e37943
Remove 'tcx lifetime from QuerySystemFns
bjorn3 Nov 3, 2024
3b1adfa
Parsing unsafe binders
compiler-errors Aug 30, 2024
2a9e358
Lower AST and resolve lifetimes for unsafe binder types
compiler-errors Dec 10, 2024
3f97c6b
Add unwrap_unsafe_binder and wrap_unsafe_binder macro operators
compiler-errors Sep 13, 2024
c5d0223
Add tests
compiler-errors Dec 10, 2024
b8c5a0f
Fix tools
compiler-errors Dec 10, 2024
6ce7ba4
Fix typos in docs on provenance
purplesyringa Dec 12, 2024
ab0d792
Rollup merge of #133900 - jieyouxu:ui-cleanup-1, r=fmease
matthiaskrgr Dec 13, 2024
c181026
Rollup merge of #133937 - estebank:silence-resolve-errors-from-mod-wi…
matthiaskrgr Dec 13, 2024
c6ebe6f
Rollup merge of #133938 - nnethercote:rustc_mir_dataflow-renamings, r…
matthiaskrgr Dec 13, 2024
97dc513
Rollup merge of #134058 - RalfJung:interpret-typing-env, r=lcnr
matthiaskrgr Dec 13, 2024
9f6b07e
Rollup merge of #134130 - bjorn3:prepare_driver_query_removal, r=oli-obk
matthiaskrgr Dec 13, 2024
5c9b227
Rollup merge of #134140 - compiler-errors:unsafe-binders-ast, r=oli-obk
matthiaskrgr Dec 13, 2024
8cce32a
Rollup merge of #134229 - purplesyringa:provenance-docs, r=saethlin
matthiaskrgr Dec 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove lifetimes from BorrowckDomain.
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.
  • Loading branch information
nnethercote committed Dec 10, 2024
commit d490ea1f395910234c6c567db15b6dab0dac9ef0
23 changes: 14 additions & 9 deletions compiler/rustc_borrowck/src/dataflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ use rustc_middle::mir::{
};
use rustc_middle::ty::{RegionVid, TyCtxt};
use rustc_mir_dataflow::fmt::DebugWithContext;
use rustc_mir_dataflow::impls::{EverInitializedPlaces, MaybeUninitializedPlaces};
use rustc_mir_dataflow::impls::{
EverInitializedPlaces, EverInitializedPlacesDomain, MaybeUninitializedPlaces,
MaybeUninitializedPlacesDomain,
};
use rustc_mir_dataflow::{Analysis, GenKill, JoinSemiLattice, SwitchIntEdgeEffects};
use tracing::debug;

Expand All @@ -24,7 +27,7 @@ pub(crate) struct Borrowck<'a, 'tcx> {
}

impl<'a, 'tcx> Analysis<'tcx> for Borrowck<'a, 'tcx> {
type Domain = BorrowckDomain<'a, 'tcx>;
type Domain = BorrowckDomain;

const NAME: &'static str = "borrowck";

Expand Down Expand Up @@ -110,14 +113,14 @@ impl<'a, 'tcx> Analysis<'tcx> for Borrowck<'a, 'tcx> {
}
}

impl JoinSemiLattice for BorrowckDomain<'_, '_> {
impl JoinSemiLattice for BorrowckDomain {
fn join(&mut self, _other: &Self) -> bool {
// This is only reachable from `iterate_to_fixpoint`, which this analysis doesn't use.
unreachable!();
}
}

impl<'tcx, C> DebugWithContext<C> for BorrowckDomain<'_, 'tcx>
impl<'tcx, C> DebugWithContext<C> for BorrowckDomain
where
C: rustc_mir_dataflow::move_paths::HasMoveData<'tcx>,
{
Expand Down Expand Up @@ -160,10 +163,10 @@ where

/// The transient state of the dataflow analyses used by the borrow checker.
#[derive(Clone, Debug, PartialEq, Eq)]
pub(crate) struct BorrowckDomain<'a, 'tcx> {
pub(crate) borrows: <Borrows<'a, 'tcx> as Analysis<'tcx>>::Domain,
pub(crate) uninits: <MaybeUninitializedPlaces<'a, 'tcx> as Analysis<'tcx>>::Domain,
pub(crate) ever_inits: <EverInitializedPlaces<'a, 'tcx> as Analysis<'tcx>>::Domain,
pub(crate) struct BorrowckDomain {
pub(crate) borrows: BorrowsDomain,
pub(crate) uninits: MaybeUninitializedPlacesDomain,
pub(crate) ever_inits: EverInitializedPlacesDomain,
}

rustc_index::newtype_index! {
Expand Down Expand Up @@ -566,6 +569,8 @@ impl<'a, 'tcx> Borrows<'a, 'tcx> {
}
}

type BorrowsDomain = BitSet<BorrowIndex>;

/// Forward dataflow computation of the set of borrows that are in scope at a particular location.
/// - we gen the introduced loans
/// - we kill loans on locals going out of (regular) scope
Expand All @@ -574,7 +579,7 @@ impl<'a, 'tcx> Borrows<'a, 'tcx> {
/// - we also kill loans of conflicting places when overwriting a shared path: e.g. borrows of
/// `a.b.c` when `a` is overwritten.
impl<'tcx> rustc_mir_dataflow::Analysis<'tcx> for Borrows<'_, 'tcx> {
type Domain = BitSet<BorrowIndex>;
type Domain = BorrowsDomain;

const NAME: &'static str = "borrows";

Expand Down
41 changes: 16 additions & 25 deletions compiler/rustc_borrowck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ impl<'a, 'tcx> ResultsVisitor<'a, 'tcx, Borrowck<'a, 'tcx>> for MirBorrowckCtxt<
fn visit_statement_before_primary_effect(
&mut self,
_results: &mut Results<'tcx, Borrowck<'a, 'tcx>>,
state: &BorrowckDomain<'a, 'tcx>,
state: &BorrowckDomain,
stmt: &'a Statement<'tcx>,
location: Location,
) {
Expand Down Expand Up @@ -677,7 +677,7 @@ impl<'a, 'tcx> ResultsVisitor<'a, 'tcx, Borrowck<'a, 'tcx>> for MirBorrowckCtxt<
fn visit_terminator_before_primary_effect(
&mut self,
_results: &mut Results<'tcx, Borrowck<'a, 'tcx>>,
state: &BorrowckDomain<'a, 'tcx>,
state: &BorrowckDomain,
term: &'a Terminator<'tcx>,
loc: Location,
) {
Expand Down Expand Up @@ -790,7 +790,7 @@ impl<'a, 'tcx> ResultsVisitor<'a, 'tcx, Borrowck<'a, 'tcx>> for MirBorrowckCtxt<
fn visit_terminator_after_primary_effect(
&mut self,
_results: &mut Results<'tcx, Borrowck<'a, 'tcx>>,
state: &BorrowckDomain<'a, 'tcx>,
state: &BorrowckDomain,
term: &'a Terminator<'tcx>,
loc: Location,
) {
Expand Down Expand Up @@ -983,7 +983,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
place_span: (Place<'tcx>, Span),
kind: (AccessDepth, ReadOrWrite),
is_local_mutation_allowed: LocalMutationIsAllowed,
state: &BorrowckDomain<'a, 'tcx>,
state: &BorrowckDomain,
) {
let (sd, rw) = kind;

Expand Down Expand Up @@ -1032,7 +1032,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
place_span: (Place<'tcx>, Span),
sd: AccessDepth,
rw: ReadOrWrite,
state: &BorrowckDomain<'a, 'tcx>,
state: &BorrowckDomain,
) -> bool {
let mut error_reported = false;

Expand Down Expand Up @@ -1172,7 +1172,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
location: Location,
place_span: (Place<'tcx>, Span),
kind: AccessDepth,
state: &BorrowckDomain<'a, 'tcx>,
state: &BorrowckDomain,
) {
// Write of P[i] or *P requires P init'd.
self.check_if_assigned_path_is_moved(location, place_span, state);
Expand All @@ -1190,7 +1190,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
&mut self,
location: Location,
(rvalue, span): (&'a Rvalue<'tcx>, Span),
state: &BorrowckDomain<'a, 'tcx>,
state: &BorrowckDomain,
) {
match rvalue {
&Rvalue::Ref(_ /*rgn*/, bk, place) => {
Expand Down Expand Up @@ -1448,7 +1448,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
&mut self,
location: Location,
(operand, span): (&'a Operand<'tcx>, Span),
state: &BorrowckDomain<'a, 'tcx>,
state: &BorrowckDomain,
) {
match *operand {
Operand::Copy(place) => {
Expand Down Expand Up @@ -1568,12 +1568,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
}
}

fn check_activations(
&mut self,
location: Location,
span: Span,
state: &BorrowckDomain<'a, 'tcx>,
) {
fn check_activations(&mut self, location: Location, span: Span, state: &BorrowckDomain) {
// Two-phase borrow support: For each activation that is newly
// generated at this statement, check if it interferes with
// another borrow.
Expand Down Expand Up @@ -1731,7 +1726,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
location: Location,
desired_action: InitializationRequiringAction,
place_span: (PlaceRef<'tcx>, Span),
state: &BorrowckDomain<'a, 'tcx>,
state: &BorrowckDomain,
) {
let maybe_uninits = &state.uninits;

Expand Down Expand Up @@ -1836,7 +1831,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
location: Location,
desired_action: InitializationRequiringAction,
place_span: (PlaceRef<'tcx>, Span),
state: &BorrowckDomain<'a, 'tcx>,
state: &BorrowckDomain,
) {
let maybe_uninits = &state.uninits;

Expand Down Expand Up @@ -1935,7 +1930,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
&mut self,
location: Location,
(place, span): (Place<'tcx>, Span),
state: &BorrowckDomain<'a, 'tcx>,
state: &BorrowckDomain,
) {
debug!("check_if_assigned_path_is_moved place: {:?}", place);

Expand Down Expand Up @@ -2001,7 +1996,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
location: Location,
base: PlaceRef<'tcx>,
span: Span,
state: &BorrowckDomain<'a, 'tcx>,
state: &BorrowckDomain,
) {
// rust-lang/rust#21232: Until Rust allows reads from the
// initialized parts of partially initialized structs, we
Expand Down Expand Up @@ -2092,7 +2087,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
(place, span): (Place<'tcx>, Span),
kind: ReadOrWrite,
is_local_mutation_allowed: LocalMutationIsAllowed,
state: &BorrowckDomain<'a, 'tcx>,
state: &BorrowckDomain,
location: Location,
) -> bool {
debug!(
Expand Down Expand Up @@ -2206,18 +2201,14 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
}
}

fn is_local_ever_initialized(
&self,
local: Local,
state: &BorrowckDomain<'a, 'tcx>,
) -> Option<InitIndex> {
fn is_local_ever_initialized(&self, local: Local, state: &BorrowckDomain) -> Option<InitIndex> {
let mpi = self.move_data.rev_lookup.find_local(local)?;
let ii = &self.move_data.init_path_map[mpi];
ii.into_iter().find(|&&index| state.ever_inits.contains(index)).copied()
}

/// Adds the place into the used mutable variables set
fn add_used_mut(&mut self, root_place: RootPlace<'tcx>, state: &BorrowckDomain<'a, 'tcx>) {
fn add_used_mut(&mut self, root_place: RootPlace<'tcx>, state: &BorrowckDomain) {
match root_place {
RootPlace { place_local: local, place_projection: [], is_local_mutation_allowed } => {
// If the local may have been initialized, and it is now currently being
Expand Down
16 changes: 10 additions & 6 deletions compiler/rustc_mir_dataflow/src/impls/initialized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,12 @@ impl<'tcx> Analysis<'tcx> for MaybeInitializedPlaces<'_, 'tcx> {
}
}

/// There can be many more `MovePathIndex` than there are locals in a MIR body.
/// We use a mixed bitset to avoid paying too high a memory footprint.
pub type MaybeUninitializedPlacesDomain = MixedBitSet<MovePathIndex>;

impl<'tcx> Analysis<'tcx> for MaybeUninitializedPlaces<'_, 'tcx> {
/// There can be many more `MovePathIndex` than there are locals in a MIR body.
/// We use a mixed bitset to avoid paying too high a memory footprint.
type Domain = MixedBitSet<MovePathIndex>;
type Domain = MaybeUninitializedPlacesDomain;

const NAME: &'static str = "maybe_uninit";

Expand Down Expand Up @@ -490,10 +492,12 @@ impl<'tcx> Analysis<'tcx> for MaybeUninitializedPlaces<'_, 'tcx> {
}
}

/// There can be many more `InitIndex` than there are locals in a MIR body.
/// We use a mixed bitset to avoid paying too high a memory footprint.
pub type EverInitializedPlacesDomain = MixedBitSet<InitIndex>;

impl<'tcx> Analysis<'tcx> for EverInitializedPlaces<'_, 'tcx> {
/// There can be many more `InitIndex` than there are locals in a MIR body.
/// We use a mixed bitset to avoid paying too high a memory footprint.
type Domain = MixedBitSet<InitIndex>;
type Domain = EverInitializedPlacesDomain;

const NAME: &'static str = "ever_init";

Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_mir_dataflow/src/impls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ mod storage_liveness;

pub use self::borrowed_locals::{MaybeBorrowedLocals, borrowed_locals};
pub use self::initialized::{
EverInitializedPlaces, MaybeInitializedPlaces, MaybeUninitializedPlaces,
EverInitializedPlaces, EverInitializedPlacesDomain, MaybeInitializedPlaces,
MaybeUninitializedPlaces, MaybeUninitializedPlacesDomain,
};
pub use self::liveness::{
MaybeLiveLocals, MaybeTransitiveLiveLocals, TransferFunction as LivenessTransferFunction,
Expand Down