This commit is contained in:
2026-06-30 18:41:42 +08:00
parent f0e3f1eeca
commit dde3052e2d
13 changed files with 79 additions and 106 deletions
-2
View File
@@ -6,8 +6,6 @@ edition = "2024"
[dependencies]
gc-arena = { workspace = true }
hashbrown = { workspace = true }
likely_stable = { workspace = true }
num_enum = { workspace = true }
smallvec = { workspace = true }
sptr = "0.3"
string-interner = { workspace = true }
+23 -20
View File
@@ -1,5 +1,3 @@
#![allow(dead_code)]
use std::cell::RefCell;
use std::fmt;
use std::marker::PhantomData;
@@ -10,7 +8,6 @@ use fix_lang::*;
use gc_arena::barrier::Unlock;
use gc_arena::collect::Trace;
use gc_arena::{Collect, Gc, GcRefLock, Mutation, RefLock};
use num_enum::TryFromPrimitive;
use smallvec::SmallVec;
use string_interner::Symbol;
use string_interner::symbol::SymbolU32;
@@ -24,14 +21,12 @@ mod private {
/// # Safety
///
/// TAG must be unique among all implementors.
#[allow(private_interfaces)]
pub unsafe trait Storable: private::Cealed {
/// [`Self::TAG`] must be unique among all implementors.
unsafe trait Storable: private::Cealed {
const TAG: RawTag;
}
#[allow(private_bounds)]
pub trait InlineStorable: Storable + RawStore {}
pub trait GcStorable: Storable {}
trait InlineStorable: Storable + RawStore {}
trait GcStorable: Storable {}
macro_rules! define_value_types {
(
@@ -39,7 +34,6 @@ macro_rules! define_value_types {
gc { $($gtype:ty => $gtag:expr, $gname:literal;)* }
) => {
$(
#[allow(private_interfaces)]
unsafe impl Storable for $itype {
const TAG: RawTag = $itag;
}
@@ -47,7 +41,6 @@ macro_rules! define_value_types {
impl private::Cealed for $itype {}
)*
$(
#[allow(private_interfaces)]
unsafe impl Storable for $gtype {
const TAG: RawTag = $gtag;
}
@@ -116,16 +109,16 @@ define_value_types! {
Null => RawTag::P3, "Null";
StringId => RawTag::P4, "SmallString";
PrimOp => RawTag::P5, "PrimOp";
Path => RawTag::N6, "Path";
Path => RawTag::P6, "Path";
}
gc {
i64 => RawTag::P6, "BigInt";
NixString => RawTag::P7, "String";
AttrSet<'_> => RawTag::N1, "AttrSet";
List<'_> => RawTag::N2, "List";
Thunk<'_> => RawTag::N3, "Thunk";
Closure<'_> => RawTag::N4, "Closure";
PrimOpApp<'_> => RawTag::N5, "PrimOpApp";
i64 => RawTag::P7, "BigInt";
NixString => RawTag::N1, "String";
AttrSet<'_> => RawTag::N2, "AttrSet";
List<'_> => RawTag::N3, "List";
Thunk<'_> => RawTag::N4, "Thunk";
Closure<'_> => RawTag::N5, "Closure";
PrimOpApp<'_> => RawTag::N6, "PrimOpApp";
}
}
@@ -185,11 +178,13 @@ impl<'gc> Value<'gc> {
}
#[inline]
#[allow(private_bounds)]
pub fn new_inline<T: InlineStorable>(val: T) -> Self {
Self::from_raw_value(RawValue::store(T::TAG, val))
}
#[inline]
#[allow(private_bounds)]
pub fn new_gc<T: GcStorable>(gc: Gc<'gc, T>) -> Self {
let ptr = Gc::as_ptr(gc);
Self::from_raw_value(RawValue::store(T::TAG, ptr))
@@ -212,6 +207,7 @@ impl<'gc> Value<'gc> {
}
#[inline]
#[allow(private_bounds)]
pub fn is<T: Storable>(self) -> bool {
self.tag() == Some(T::TAG)
}
@@ -224,6 +220,7 @@ impl<'gc> Value<'gc> {
}
#[inline]
#[allow(private_bounds)]
pub fn as_inline<T: InlineStorable>(self) -> Option<T> {
if self.is::<T>() {
Some(unsafe {
@@ -236,6 +233,7 @@ impl<'gc> Value<'gc> {
}
#[inline]
#[allow(private_bounds)]
pub fn as_gc<T: GcStorable>(self) -> Option<Gc<'gc, T>> {
if self.is::<T>() {
Some(unsafe {
@@ -307,11 +305,13 @@ impl<'gc> Value<'gc> {
}
#[inline]
#[allow(private_bounds)]
pub fn expect_inline<T: InlineStorable>(self) -> Result<T, NixType> {
self.as_inline::<T>().ok_or_else(|| self.ty())
}
#[inline]
#[allow(private_bounds)]
pub fn expect_gc<T: GcStorable>(self) -> Result<Gc<'gc, T>, NixType> {
self.as_gc::<T>().ok_or_else(|| self.ty())
}
@@ -350,6 +350,7 @@ impl StaticValue {
Self(Value::new_float(val))
}
#[inline]
#[allow(private_bounds)]
pub fn new_inline<T: InlineStorable>(val: T) -> Self {
Self(Value::new_inline(val))
}
@@ -366,6 +367,7 @@ impl StaticValue {
self.0.is_float()
}
#[inline]
#[allow(private_bounds)]
pub fn is<T: InlineStorable>(self) -> bool {
self.0.is::<T>()
}
@@ -374,6 +376,7 @@ impl StaticValue {
self.0.as_float()
}
#[inline]
#[allow(private_bounds)]
pub fn as_inline<T: InlineStorable>(self) -> Option<T> {
self.0.as_inline::<T>()
}
@@ -637,7 +640,7 @@ impl RawStore for PrimOp {
fn from_val(value: &RawValue) -> Self {
let [id, arity, bytes @ ..] = *value.data();
Self {
id: BuiltinId::try_from_primitive(id).expect("invalid BuiltinId"),
id: BuiltinId::try_from(id).expect("invalid BuiltinId"),
arity,
dispatch_ip: u32::from_le_bytes(bytes),
}