From 25bc709bb31ffc4988c233daa225453ffdf1873e Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Thu, 28 Nov 2024 10:52:51 +0000 Subject: [PATCH] Add MeetSemiLattice The upstream version is removed, so we have to vendor the trait in. --- src/lattice.rs | 20 ++++++++++++++++++++ src/main.rs | 1 + src/preempt_count/expectation.rs | 2 +- src/preempt_count/mod.rs | 2 +- 4 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 src/lattice.rs diff --git a/src/lattice.rs b/src/lattice.rs new file mode 100644 index 0000000..3903336 --- /dev/null +++ b/src/lattice.rs @@ -0,0 +1,20 @@ +// Copyright Gary Guo. +// +// SPDX-License-Identifier: MIT OR Apache-2.0 + +/// A [partially ordered set][poset] that has a [greatest lower bound][glb] for any pair of +/// elements in the set. +/// +/// Dataflow analyses only require that their domains implement [`JoinSemiLattice`], not +/// `MeetSemiLattice`. However, types that will be used as dataflow domains should implement both +/// so that they can be used with [`Dual`]. +/// +/// [glb]: https://en.wikipedia.org/wiki/Infimum_and_supremum +/// [poset]: https://en.wikipedia.org/wiki/Partially_ordered_set +pub trait MeetSemiLattice: Eq { + /// Computes the greatest lower bound of two elements, storing the result in `self` and + /// returning `true` if `self` has changed. + /// + /// The lattice meet operator is abbreviated as `∧`. + fn meet(&mut self, other: &Self) -> bool; +} diff --git a/src/main.rs b/src/main.rs index 68635e5..63a7e06 100755 --- a/src/main.rs +++ b/src/main.rs @@ -49,6 +49,7 @@ mod ctxt; mod atomic_context; mod attribute; mod infallible_allocation; +mod lattice; mod mir; mod monomorphize_collector; mod preempt_count; diff --git a/src/preempt_count/expectation.rs b/src/preempt_count/expectation.rs index b51e121..5866f62 100644 --- a/src/preempt_count/expectation.rs +++ b/src/preempt_count/expectation.rs @@ -9,7 +9,6 @@ use rustc_middle::mir::{self, Body, TerminatorKind}; use rustc_middle::ty::{ self, GenericArgs, Instance, PseudoCanonicalInput, Ty, TypingEnv, TypingMode, }; -use rustc_mir_dataflow::lattice::MeetSemiLattice; use rustc_mir_dataflow::Analysis; use rustc_span::DUMMY_SP; use rustc_trait_selection::infer::TyCtxtInferExt; @@ -17,6 +16,7 @@ use rustc_trait_selection::infer::TyCtxtInferExt; use super::dataflow::AdjustmentComputation; use super::{AdjustmentBounds, Error, ExpectationRange, PolyDisplay, UseSite, UseSiteKind}; use crate::ctxt::AnalysisCtxt; +use crate::lattice::MeetSemiLattice; impl<'tcx> AnalysisCtxt<'tcx> { pub fn terminator_expectation( diff --git a/src/preempt_count/mod.rs b/src/preempt_count/mod.rs index c73ba4d..4bd56f4 100644 --- a/src/preempt_count/mod.rs +++ b/src/preempt_count/mod.rs @@ -10,10 +10,10 @@ pub mod expectation; use rustc_errors::ErrorGuaranteed; use rustc_middle::ty::{Instance, PseudoCanonicalInput}; -use rustc_mir_dataflow::lattice::MeetSemiLattice; use rustc_span::Span; use self::dataflow::AdjustmentBounds; +use crate::lattice::MeetSemiLattice; #[derive(Clone, Copy, Debug, PartialEq, Eq, Encodable, Decodable)] pub enum Error {