{
"$type": "site.standard.document",
"bskyPostRef": {
"cid": "bafyreif5s4ucbu4b66nao5wqfq3gawki67d6hbbuv5q3wagbloaliehx6e",
"uri": "at://did:plc:ivbknywyskln22er3nkssdhl/app.bsky.feed.post/3miw7f7om3vu2"
},
"path": "/t/design-idea-modeling-lifetimes-as-rotational-phases/24140#post_1",
"publishedAt": "2026-04-07T16:27:15.000Z",
"site": "https://internals.rust-lang.org",
"textContent": "Hi Rust internals folk,\n\nI've been staring at borrow checker errors all weekend (classic), and it got me thinking about a different way to model the whole problem. Instead of the usual linear lifetime segments that Polonius tries to track, I started sketching out a model based on rotational phase-syncing.\n\nThe idea is to use Typestate and const generics to treat memory access as a phase-angle on a stationary axis. It’s a bit of a shift, but it seems to handle self-referential patterns surprisingly well by treating them as a 360° completion rather than a lifetime violation.\n\nHere’s a rough look at the core logic:\n\n\n use std::cell::UnsafeCell;\n use std::marker::PhantomData;\n\n /// SigmaAxis: The stationary center point (0°).\n pub struct SigmaAxis<T> {\n inner: UnsafeCell<T>,\n }\n\n /// Phase: Represents a specific angle on the axis.\n /// Leverages the 'Non-Copy' property: a phase cannot be duplicated.\n pub struct Phase<'a, T, const ANGLE: u16> {\n axis: &'a SigmaAxis<T>,\n _marker: PhantomData<&'a T>,\n }\n\n impl<T> SigmaAxis<T> {\n pub const fn new(data: T) -> Self {\n Self { inner: UnsafeCell::new(data) }\n }\n\n /// Initializes the system from the zero-point.\n pub fn initialize(&self) -> Phase<'_, T, 0> {\n Phase {\n axis: self,\n _marker: PhantomData,\n }\n }\n }\n\n impl<'a, T, const ANGLE: u16> Phase<'a, T, ANGLE> {\n /// Executes an operation at the current phase.\n /// Returns itself or allows chaining.\n pub fn execute<F, R>(&mut self, f: F) -> R\n where\n F: FnOnce(&mut T) -> R\n {\n // SAFETY: The Typestate model guarantees that only one phase object\n // exists for this axis at any given time.\n unsafe { f(&mut *self.axis.inner.get()) }\n }\n\n /// Transitions the system to a new angle by consuming (moving) the previous phase.\n /// This prevents Aliasing: the old angle ceases to exist for the compiler.\n pub fn rotate<const NEXT_ANGLE: u16>(self) -> Phase<'a, T, NEXT_ANGLE> {\n Phase {\n axis: self.axis,\n _marker: PhantomData,\n }\n }\n\n /// 360° Integration: Returns the system to the zero-point.\n pub fn complete_cycle(self) -> Phase<'a, T, 0> {\n Phase {\n axis: self.axis,\n _marker: PhantomData,\n }\n }\n }\n\n fn main() {\n let axis = SigmaAxis::new(100);\n\n // 1. Start from zero-point\n let phase_0 = axis.initialize();\n\n // 2. Rotate the cycle: 0 -> 90 -> 180 -> 270 -> 0\n // Each .rotate() consumes the previous variable, preventing illegal references.\n let mut phase_90 = phase_0.rotate::<90>();\n phase_90.execute(|d| *d += 10);\n\n let mut phase_180 = phase_90.rotate::<180>();\n phase_180.execute(|d| *d *= 2);\n\n let mut phase_270 = phase_180.rotate::<270>();\n phase_270.execute(|d| *d -= 5);\n\n // 3. Return to zero-point (360 degrees completed)\n let mut final_sync = phase_270.complete_cycle();\n\n final_sync.execute(|result| {\n println!(\"Sigma-Rotation complete. Result: {}\", result);\n assert_eq!(*result, 215);\n });\n\n println!(\"Geometric integrity verified by the compiler.\");\n }\n\n\nBy using `rotate<const NEXT_ANGLE>(self)`, the state transitions are explicit and the previous phase is consumed. It feels like a way to get solid soundness without the compiler having to do the heavy path-sensitive lifting we see in NLL.\n\nCurious to hear if this approach to \"geometric\" state tracking has been explored before or if I'm just over-engineering my weekend project.",
"title": "Design idea: Modeling lifetimes as rotational phases"
}