diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 18:31:44 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 18:31:44 +0000 |
commit | c23a457e72abe608715ac76f076f47dc42af07a5 (patch) | |
tree | 2772049aaf84b5c9d0ed12ec8d86812f7a7904b6 /compiler/rustc_middle/src/infer/unify_key.rs | |
parent | Releasing progress-linux version 1.73.0+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-c23a457e72abe608715ac76f076f47dc42af07a5.tar.xz rustc-c23a457e72abe608715ac76f076f47dc42af07a5.zip |
Merging upstream version 1.74.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_middle/src/infer/unify_key.rs')
-rw-r--r-- | compiler/rustc_middle/src/infer/unify_key.rs | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/compiler/rustc_middle/src/infer/unify_key.rs b/compiler/rustc_middle/src/infer/unify_key.rs index 85fb9214d..7ca964759 100644 --- a/compiler/rustc_middle/src/infer/unify_key.rs +++ b/compiler/rustc_middle/src/infer/unify_key.rs @@ -188,3 +188,53 @@ impl<'tcx> UnifyValue for ConstVarValue<'tcx> { }) } } + +/// values for the effect inference variable +#[derive(Clone, Copy, Debug)] +pub enum EffectVarValue<'tcx> { + /// The host effect is on, enabling access to syscalls, filesystem access, etc. + Host, + /// The host effect is off. Execution is restricted to const operations only. + NoHost, + Const(ty::Const<'tcx>), +} + +impl<'tcx> EffectVarValue<'tcx> { + pub fn as_const(self, tcx: TyCtxt<'tcx>) -> ty::Const<'tcx> { + match self { + EffectVarValue::Host => tcx.consts.true_, + EffectVarValue::NoHost => tcx.consts.false_, + EffectVarValue::Const(c) => c, + } + } +} + +impl<'tcx> UnifyValue for EffectVarValue<'tcx> { + type Error = (EffectVarValue<'tcx>, EffectVarValue<'tcx>); + fn unify_values(value1: &Self, value2: &Self) -> Result<Self, Self::Error> { + match (value1, value2) { + (EffectVarValue::Host, EffectVarValue::Host) => Ok(EffectVarValue::Host), + (EffectVarValue::NoHost, EffectVarValue::NoHost) => Ok(EffectVarValue::NoHost), + (EffectVarValue::NoHost | EffectVarValue::Host, _) + | (_, EffectVarValue::NoHost | EffectVarValue::Host) => Err((*value1, *value2)), + (EffectVarValue::Const(_), EffectVarValue::Const(_)) => { + bug!("equating two const variables, both of which have known values") + } + } + } +} + +impl<'tcx> UnifyKey for ty::EffectVid<'tcx> { + type Value = Option<EffectVarValue<'tcx>>; + #[inline] + fn index(&self) -> u32 { + self.index + } + #[inline] + fn from_index(i: u32) -> Self { + ty::EffectVid { index: i, phantom: PhantomData } + } + fn tag() -> &'static str { + "EffectVid" + } +} |