Skip to content

Commit

Permalink
Add MeetSemiLattice
Browse files Browse the repository at this point in the history
The upstream version is removed, so we have to vendor the trait in.
  • Loading branch information
nbdd0121 committed Nov 28, 2024
1 parent 5876bc6 commit 25bc709
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
20 changes: 20 additions & 0 deletions src/lattice.rs
Original file line number Diff line number Diff line change
@@ -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;
}
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ mod ctxt;
mod atomic_context;
mod attribute;
mod infallible_allocation;
mod lattice;
mod mir;
mod monomorphize_collector;
mod preempt_count;
Expand Down
2 changes: 1 addition & 1 deletion src/preempt_count/expectation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ 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;

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(
Expand Down
2 changes: 1 addition & 1 deletion src/preempt_count/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 25bc709

Please sign in to comment.