minor changes

This commit is contained in:
2026-04-11 19:06:26 +08:00
parent 9983458b31
commit e34cfc7add
9 changed files with 42 additions and 45 deletions
Generated
-2
View File
@@ -460,7 +460,6 @@ dependencies = [
"mimalloc", "mimalloc",
"rnix", "rnix",
"rustyline", "rustyline",
"smallvec",
"string-interner", "string-interner",
"tempfile", "tempfile",
"test-log", "test-log",
@@ -485,7 +484,6 @@ dependencies = [
"fix-builtins", "fix-builtins",
"fix-common", "fix-common",
"fix-ir", "fix-ir",
"gc-arena",
"hashbrown 0.16.1", "hashbrown 0.16.1",
"num_enum", "num_enum",
"rnix", "rnix",
+4
View File
@@ -14,6 +14,10 @@ members = [
inherits = "release" inherits = "release"
debug = true debug = true
[profile.lto]
inherits = "release"
lto = true
[workspace.dependencies] [workspace.dependencies]
bumpalo = { version = "3.20", features = [ bumpalo = { version = "3.20", features = [
"allocator-api2", "allocator-api2",
-1
View File
@@ -4,7 +4,6 @@ version = "0.1.0"
edition = "2024" edition = "2024"
[dependencies] [dependencies]
gc-arena = { workspace = true }
hashbrown = { workspace = true } hashbrown = { workspace = true }
num_enum = { workspace = true } num_enum = { workspace = true }
rnix = { workspace = true } rnix = { workspace = true }
+1 -1
View File
@@ -24,7 +24,7 @@ impl<T: Default + Copy, const N: usize> ArrayExt<N> for [T; N] {
} }
} }
pub trait RawStore: Sized { pub(crate) trait RawStore: Sized {
fn to_val(self, value: &mut Value); fn to_val(self, value: &mut Value);
fn from_val(value: &Value) -> Self; fn from_val(value: &Value) -> Self;
} }
+29 -30
View File
@@ -122,6 +122,7 @@ pub struct Vm<C: VmContext> {
struct GcRoot<'gc> { struct GcRoot<'gc> {
stack: Vec<Value<'gc>>, stack: Vec<Value<'gc>>,
call_stack: Vec<CallFrame<'gc>>, call_stack: Vec<CallFrame<'gc>>,
call_depth: usize,
with_env: Option<Gc<'gc, WithEnv<'gc>>>, with_env: Option<Gc<'gc, WithEnv<'gc>>>,
builtins: Value<'gc>, builtins: Value<'gc>,
empty_list: Value<'gc>, empty_list: Value<'gc>,
@@ -143,16 +144,16 @@ fn init_builtins<'gc>(mc: &Mutation<'gc>, ctx: &mut impl VmContext) -> Value<'gc
let consts = [ let consts = [
( (
"__currentSystem", "__currentSystem",
Value::new_gc(Gc::new(mc, NixString::new("x86_64-linux"))), Value::new_inline(ctx.intern_string("x86_64-linux")),
), ),
("__langVersion", Value::new_inline(6i32)), ("__langVersion", Value::new_inline(6i32)),
( (
"__nixVersion", "__nixVersion",
Value::new_gc(Gc::new(mc, NixString::new("2.24.0"))), Value::new_inline(ctx.intern_string("2.24.0")),
), ),
( (
"__storeDir", "__storeDir",
Value::new_gc(Gc::new(mc, NixString::new("/nix/store"))), Value::new_inline(ctx.intern_string("/nix/store")),
), ),
( (
"__nixPath", "__nixPath",
@@ -190,6 +191,7 @@ impl<'gc> GcRoot<'gc> {
GcRoot { GcRoot {
stack: Vec::with_capacity(8192), stack: Vec::with_capacity(8192),
call_stack: Vec::with_capacity(1024), call_stack: Vec::with_capacity(1024),
call_depth: 0,
with_env: None, with_env: None,
builtins, builtins,
empty_list: Value::new_gc(Gc::new(mc, List::default())), empty_list: Value::new_gc(Gc::new(mc, List::default())),
@@ -404,6 +406,21 @@ impl<'gc> GcRoot<'gc> {
} }
} }
}}; }};
(SelectKeyData, $n:expr) => {{
let mut keys = SmallVec::<[SelectKeyData; 4]>::with_capacity($n as usize);
for _ in 0..$n {
let tag = read!(u8);
let Ok(ty) = AttrKeyType::try_from_primitive(tag)
.map_err(|err| panic!("unknown key tag: {:#04x}", err.number));
match ty {
AttrKeyType::Static => {
keys.push(SelectKeyData::Static(read!(StringId)))
}
AttrKeyType::Dynamic => keys.push(SelectKeyData::Dynamic),
};
}
keys
}};
($type:ty) => { ($type:ty) => {
<$type>::from_le_bytes(read_array(ctx.bytecode(), pc)) <$type>::from_le_bytes(read_array(ctx.bytecode(), pc))
}; };
@@ -436,12 +453,12 @@ impl<'gc> GcRoot<'gc> {
ThunkState::Evaluated(v) => { ThunkState::Evaluated(v) => {
self.replace_stack($depth, v.relax()); self.replace_stack($depth, v.relax());
} }
ThunkState::Apply { .. } => todo!("force apply"),
ThunkState::Blackhole => { ThunkState::Blackhole => {
return Action::Done(Err(Error::eval_error( return Action::Done(Err(Error::eval_error(
"infinite recursion encountered", "infinite recursion encountered",
))); )));
} }
ThunkState::Apply { .. } => todo!("force apply"),
} }
} }
}}; }};
@@ -583,6 +600,10 @@ impl<'gc> GcRoot<'gc> {
Call => { Call => {
// force func // force func
try_force!(0, inst_start_pc); try_force!(0, inst_start_pc);
if self.call_depth > 10000 {
return Action::Done(Err(Error::eval_error("stack overflow; max-call-depth exceeded")))
}
self.call_depth += 1;
let func = self.pop_stack(); let func = self.pop_stack();
let arg = self.pop_stack(); let arg = self.pop_stack();
if let Some(closure) = func.as_gc::<Closure>() { if let Some(closure) = func.as_gc::<Closure>() {
@@ -649,19 +670,7 @@ impl<'gc> GcRoot<'gc> {
let n = read!(u16) as usize; let n = read!(u16) as usize;
let _span_id = read!(u32); let _span_id = read!(u32);
let mut keys = SmallVec::<[SelectKeyData; 4]>::with_capacity(n); let keys = read!(SelectKeyData, n);
for _ in 0..n {
let tag = read!(u8);
let Ok(ty) = AttrKeyType::try_from_primitive(tag)
.map_err(|err| panic!("unknown key tag: {:#04x}", err.number));
match ty {
AttrKeyType::Static => {
keys.push(SelectKeyData::Static(read!(StringId)))
}
AttrKeyType::Dynamic => keys.push(SelectKeyData::Dynamic),
};
}
let dyn_count = keys let dyn_count = keys
.iter() .iter()
.filter(|k| matches!(k, SelectKeyData::Dynamic)) .filter(|k| matches!(k, SelectKeyData::Dynamic))
@@ -736,19 +745,7 @@ impl<'gc> GcRoot<'gc> {
let n = read!(u16) as usize; let n = read!(u16) as usize;
let _span_id = read!(u32); let _span_id = read!(u32);
let mut keys = SmallVec::<[SelectKeyData; 4]>::with_capacity(n); let keys = read!(SelectKeyData, n);
for _ in 0..n {
let tag = read!(u8);
let Ok(ty) = AttrKeyType::try_from_primitive(tag)
.map_err(|err| panic!("unknown key tag: {:#04x}", err.number));
match ty {
AttrKeyType::Static => {
keys.push(SelectKeyData::Static(read!(StringId)))
}
AttrKeyType::Dynamic => keys.push(SelectKeyData::Dynamic),
};
}
let dyn_count = keys let dyn_count = keys
.iter() .iter()
.filter(|k| matches!(k, SelectKeyData::Dynamic)) .filter(|k| matches!(k, SelectKeyData::Dynamic))
@@ -1253,6 +1250,8 @@ impl<'gc> GcRoot<'gc> {
} }
} }
} }
} else {
self.call_depth -= 1;
} }
self.current_env = Some(env); self.current_env = Some(env);
self.with_env = with_env; self.with_env = with_env;
+4 -3
View File
@@ -22,13 +22,14 @@ mod private {
} }
/// # Safety /// # Safety
///
/// 1. TAG must be unique among all implementors. /// 1. TAG must be unique among all implementors.
/// 2. TAG must be within 1..=7 /// 2. TAG must be within 1..=7
pub(crate) unsafe trait Storable: private::Cealed { pub unsafe trait Storable: private::Cealed {
const TAG: (bool, u8); const TAG: (bool, u8);
} }
pub(crate) trait InlineStorable: Storable + RawStore {} pub trait InlineStorable: Storable + RawStore {}
pub(crate) trait GcStorable: Storable {} pub trait GcStorable: Storable {}
macro_rules! define_value_types { macro_rules! define_value_types {
( (
-1
View File
@@ -23,7 +23,6 @@ miette = { version = "7.4", features = ["fancy"] }
# Data Structure # Data Structure
hashbrown = { workspace = true } hashbrown = { workspace = true }
smallvec = { workspace = true }
string-interner = { workspace = true } string-interner = { workspace = true }
# Memory Management # Memory Management
+3
View File
@@ -509,6 +509,9 @@ struct OwnedIr {
} }
impl OwnedIr { impl OwnedIr {
/// # Safety
///
/// `ir` must be allocated from `bump`.
unsafe fn new(ir: RawIrRef<'_>, bump: Bump) -> Self { unsafe fn new(ir: RawIrRef<'_>, bump: Bump) -> Self {
Self { Self {
_bump: bump, _bump: bump,
+1 -7
View File
@@ -26,22 +26,16 @@
"rustfmt" "rustfmt"
"rust-analyzer" "rust-analyzer"
]) ])
cargo-outdated
cargo-machete cargo-machete
cargo-bloat
lldb lldb
valgrind valgrind
hyperfine hyperfine
just just
samply samply
jq
tokei tokei
nodejs
biome
claude-code claude-code
codex
opencode
]; ];
}; };
} }