From 3b1a2279134cca08757e66d826f2f8a6d6512289 Mon Sep 17 00:00:00 2001 From: Chris Fallin Date: Sat, 14 Feb 2026 15:17:16 -0800 Subject: [PATCH] Add a few more const fns to deal with registers and machine environments. As part of updating Cranelift to use the new const-fn-friendly MachineEnv changes in #254, I found I needed a few more bits here. In particular the `from_bits` method duplicates a `From` impl, but `From::from` is not a `const fn`, so we can't use it. A little awkward but this replicates what we've done elsewhere. --- src/lib.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 1c9fa178..c3af0569 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -257,7 +257,7 @@ impl PRegSet { } /// Add a physical register (PReg) to the set. - pub fn add(&mut self, reg: PReg) { + pub const fn add(&mut self, reg: PReg) { let (index, bit) = Self::split_index(reg); self.bits[index] |= 1 << bit; } @@ -462,6 +462,11 @@ impl VReg { pub const fn bits(self) -> usize { self.bits as usize } + + #[inline(always)] + pub const fn from_bits(bits: u32) -> VReg { + Self { bits } + } } impl From for VReg {