Download verification-forge/crates/vf-kernel/src/context.rs from Snapkitty/tlm-jxcl-forge: direct link, hf CLI and curl.
- Browser
- Download file 2.23 kB
-
https://huggingface.co/Snapkitty/tlm-jxcl-forge/resolve/main/verification-forge/crates/vf-kernel/src/context.rs
- Command line
-
hf download hf://Snapkitty/tlm-jxcl-forge/verification-forge/crates/vf-kernel/src/context.rs
-
curl -L -o context.rs https://huggingface.co/Snapkitty/tlm-jxcl-forge/resolve/main/verification-forge/crates/vf-kernel/src/context.rs
2.23 kB
| // Copyright (C) 2026 ERRANT DIGITAL INSTITUTE OF TECHNOLOGY (SEIT NGO) % SNAPKITTY COLLECTIVE | |
| // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial | |
| // See LICENSE-AGPL and LICENSE-COMMERCIAL in this repository for license terms. | |
| //! The kernel's local typing context: what type each in-scope, | |
| //! already-opened local variable has. See `vf-core`'s crate docs for | |
| //! why local variables are tracked this way (locally-nameless) rather | |
| //! than as a de-Bruijn-indexed list. | |
| use vf_core::{Symbol, TermId}; | |
| pub struct Context { | |
| bindings: Vec<(Symbol, TermId)>, | |
| } | |
| impl Context { | |
| pub fn new() -> Self { | |
| Context::default() | |
| } | |
| /// A new context with `sym : ty` added on top of `self`, shadowing | |
| /// any existing binding for `sym`. | |
| pub fn extended(&self, sym: Symbol, ty: TermId) -> Self { | |
| let mut bindings = self.bindings.clone(); | |
| bindings.push((sym, ty)); | |
| Context { bindings } | |
| } | |
| pub fn lookup(&self, sym: Symbol) -> Option<TermId> { | |
| self.bindings | |
| .iter() | |
| .rev() | |
| .find(|(s, _)| *s == sym) | |
| .map(|(_, t)| *t) | |
| } | |
| } | |
| mod tests { | |
| use super::*; | |
| use vf_core::{Interner, Sort, TermArena}; | |
| fn lookup_on_an_empty_context_is_none() { | |
| let mut interner = Interner::new(); | |
| let sym = interner.intern("x"); | |
| assert_eq!(Context::new().lookup(sym), None); | |
| } | |
| fn extended_context_finds_the_new_binding() { | |
| let mut arena = TermArena::new(); | |
| let mut interner = Interner::new(); | |
| let sym = interner.intern("x"); | |
| let ty = arena.sort(Sort::Type(0)); | |
| let ctx = Context::new().extended(sym, ty); | |
| assert_eq!(ctx.lookup(sym), Some(ty)); | |
| } | |
| fn a_shadowing_binding_takes_precedence() { | |
| let mut arena = TermArena::new(); | |
| let mut interner = Interner::new(); | |
| let sym = interner.intern("x"); | |
| let old_ty = arena.sort(Sort::Type(0)); | |
| let new_ty = arena.sort(Sort::Type(1)); | |
| let ctx = Context::new().extended(sym, old_ty).extended(sym, new_ty); | |
| assert_eq!(ctx.lookup(sym), Some(new_ty)); | |
| } | |
| } | |