refactor test

This commit is contained in:
2026-04-04 02:13:39 +08:00
parent 0c517e3c18
commit 88dc8539b5
6 changed files with 279 additions and 253 deletions
+2 -8
View File
@@ -430,10 +430,7 @@ impl<'a, Ctx: BytecodeContext> BytecodeEmitter<'a, Ctx> {
.enumerate()
.map(|(i, &id)| (id, thunk_base + i as u32))
.collect();
self.scope_stack.push(ScopeInfo {
depth,
thunk_map,
});
self.scope_stack.push(ScopeInfo { depth, thunk_map });
}
fn pop_scope(&mut self) {
@@ -577,10 +574,7 @@ impl<'a, Ctx: BytecodeContext> BytecodeEmitter<'a, Ctx> {
self.emit_u32(span_id);
}
&Ir::Arg { layer } => {
self.emit_load(
layer.try_into().expect("scope too deep!"),
0,
);
self.emit_load(layer.try_into().expect("scope too deep!"), 0);
}
&Ir::TopLevel { body, ref thunks } => {
self.emit_toplevel_inner(body, thunks);
+11 -3
View File
@@ -140,15 +140,23 @@ impl<'a, Ctx: DisassemblerContext> Disassembler<'a, Ctx> {
temp
};
let extra_width = if start_pos > 0 { start_pos.ilog2() >> 4 } else { 0 };
let extra_width = if start_pos > 0 {
start_pos.ilog2() >> 4
} else {
0
};
if color {
let _ = write!(out, " ");
for _ in 0..extra_width { let _ = write!(out, " "); }
for _ in 0..extra_width {
let _ = write!(out, " ");
}
let _ = writeln!(out, " {:<14} |", bytes_str.green());
} else {
let _ = write!(out, " ");
for _ in 0..extra_width { let _ = write!(out, " "); }
for _ in 0..extra_width {
let _ = write!(out, " ");
}
let _ = writeln!(out, " {:<14} |", bytes_str);
}
}
+1 -2
View File
@@ -394,8 +394,7 @@ impl<'id: 'ir, 'ir, Ctx: DowngradeContext<'id, 'ir>> Downgrade<'id, 'ir, Ctx> fo
let param_sym = ctx.new_sym(id.to_string());
param = None;
body = ctx
.with_param_scope(param_sym, |ctx| body_ast.downgrade(ctx))?;
body = ctx.with_param_scope(param_sym, |ctx| body_ast.downgrade(ctx))?;
}
ast::Param::Pattern(pattern) => {
let alias = pattern
+3 -1
View File
@@ -128,7 +128,9 @@ pub enum Ir<'ir, Ref> {
param: Option<Param<'ir>>,
thunks: Vec<'ir, (ThunkId, Ref)>,
},
Arg { layer: usize },
Arg {
layer: usize,
},
Call {
func: Ref,
arg: Ref,
+25 -10
View File
@@ -94,6 +94,7 @@ impl<'gc> GcRoot<'gc> {
}
#[inline(always)]
#[track_caller]
pub(super) fn pop_stack_forced(&mut self) -> StrictValue<'gc> {
self.stack
.pop()
@@ -1282,7 +1283,10 @@ impl Runtime {
let (is_list, is_attrs) = self.arena.mutate_root(|_, root| {
let tos = *root.stack.tos().expect("stack underflow");
(tos.as_gc::<List<'_>>().is_some(), tos.as_gc::<AttrSet<'_>>().is_some())
(
tos.as_gc::<List<'_>>().is_some(),
tos.as_gc::<AttrSet<'_>>().is_some(),
)
});
if is_list {
@@ -1303,7 +1307,8 @@ impl Runtime {
});
if let err @ Action::Done(Err(_)) = self.force_tos() {
self.arena.mutate_root(|_, root| root.temp_stack.truncate(eval_base - len));
self.arena
.mutate_root(|_, root| root.temp_stack.truncate(eval_base - len));
return err;
}
@@ -1314,14 +1319,16 @@ impl Runtime {
}
self.arena.mutate_root(|mc, root| {
let items: SmallVec<[Value; 4]> = root.temp_stack[eval_base - len..eval_base].iter().copied().collect();
let items: SmallVec<[Value; 4]> = root.temp_stack[eval_base - len..eval_base]
.iter()
.copied()
.collect();
root.temp_stack.truncate(eval_base - len);
// Reconstruct List
let new_list = Gc::new(mc, List { inner: items });
root.push_stack(Value::new_gc(new_list));
});
} else if is_attrs {
let len = self.arena.mutate_root(|_, root| {
let attrs = root.pop_stack().as_gc::<AttrSet<'_>>().unwrap();
@@ -1341,7 +1348,8 @@ impl Runtime {
});
if let err @ Action::Done(Err(_)) = self.force_tos() {
self.arena.mutate_root(|_, root| root.temp_stack.truncate(eval_base - len * 2));
self.arena
.mutate_root(|_, root| root.temp_stack.truncate(eval_base - len * 2));
return err;
}
@@ -1378,7 +1386,10 @@ impl Runtime {
let (is_list, is_attrs) = self.arena.mutate_root(|_, root| {
let tos = *root.stack.tos().expect("stack underflow");
(tos.as_gc::<List<'_>>().is_some(), tos.as_gc::<AttrSet<'_>>().is_some())
(
tos.as_gc::<List<'_>>().is_some(),
tos.as_gc::<AttrSet<'_>>().is_some(),
)
});
if is_list {
@@ -1399,7 +1410,8 @@ impl Runtime {
});
if let err @ Action::Done(Err(_)) = self.force_tos_deep() {
self.arena.mutate_root(|_, root| root.temp_stack.truncate(eval_base - len));
self.arena
.mutate_root(|_, root| root.temp_stack.truncate(eval_base - len));
return err;
}
@@ -1410,12 +1422,14 @@ impl Runtime {
}
self.arena.mutate_root(|mc, root| {
let items: SmallVec<[Value; 4]> = root.temp_stack[eval_base - len..eval_base].iter().copied().collect();
let items: SmallVec<[Value; 4]> = root.temp_stack[eval_base - len..eval_base]
.iter()
.copied()
.collect();
root.temp_stack.truncate(eval_base - len);
let new_list = Gc::new(mc, List { inner: items });
root.push_stack(Value::new_gc(new_list));
});
} else if is_attrs {
let len = self.arena.mutate_root(|_, root| {
let attrs = root.pop_stack().as_gc::<AttrSet<'_>>().unwrap();
@@ -1435,7 +1449,8 @@ impl Runtime {
});
if let err @ Action::Done(Err(_)) = self.force_tos_deep() {
self.arena.mutate_root(|_, root| root.temp_stack.truncate(eval_base - len * 2));
self.arena
.mutate_root(|_, root| root.temp_stack.truncate(eval_base - len * 2));
return err;
}
+82 -74
View File
@@ -89,6 +89,9 @@ macro_rules! eval_fail_test {
};
}
mod okay {
use super::*;
eval_okay_test!(any_all);
eval_okay_test!(arithmetic);
eval_okay_test!(attrnames);
@@ -241,78 +244,83 @@ eval_okay_test!(types);
eval_okay_test!(versions);
eval_okay_test!(with);
eval_okay_test!(zipAttrsWith);
}
eval_fail_test!(fail_abort);
eval_fail_test!(fail_addDrvOutputDependencies_empty_context);
eval_fail_test!(fail_addDrvOutputDependencies_multi_elem_context);
eval_fail_test!(fail_addDrvOutputDependencies_wrong_element_kind);
eval_fail_test!(fail_addErrorRuntime_example);
eval_fail_test!(fail_assert);
eval_fail_test!(fail_assert_equal_attrs_names);
eval_fail_test!(fail_assert_equal_attrs_names_2);
eval_fail_test!(fail_assert_equal_derivations);
eval_fail_test!(fail_assert_equal_derivations_extra);
eval_fail_test!(fail_assert_equal_floats);
eval_fail_test!(fail_assert_equal_function_direct);
eval_fail_test!(fail_assert_equal_int_float);
eval_fail_test!(fail_assert_equal_ints);
eval_fail_test!(fail_assert_equal_list_length);
eval_fail_test!(fail_assert_equal_paths);
eval_fail_test!(fail_assert_equal_type);
eval_fail_test!(fail_assert_equal_type_nested);
eval_fail_test!(fail_assert_nested_bool);
eval_fail_test!(fail_attr_name_type);
eval_fail_test!(fail_attrset_merge_drops_later_rec);
eval_fail_test!(fail_bad_string_interpolation_1);
eval_fail_test!(fail_bad_string_interpolation_2);
eval_fail_test!(fail_bad_string_interpolation_3);
eval_fail_test!(fail_bad_string_interpolation_4);
eval_fail_test!(fail_blackhole);
eval_fail_test!(fail_call_primop);
eval_fail_test!(fail_deepseq);
eval_fail_test!(fail_derivation_name);
eval_fail_test!(fail_dup_dynamic_attrs);
eval_fail_test!(fail_duplicate_traces);
eval_fail_test!(fail_eol_1);
eval_fail_test!(fail_eol_2);
eval_fail_test!(fail_eol_3);
eval_fail_test!(fail_fetchTree_negative);
eval_fail_test!(fail_fetchurl_baseName);
eval_fail_test!(fail_fetchurl_baseName_attrs);
eval_fail_test!(fail_fetchurl_baseName_attrs_name);
eval_fail_test!(fail_flake_ref_to_string_negative_integer);
eval_fail_test!(fail_foldlStrict_strict_op_application);
eval_fail_test!(fail_fromJSON_keyWithNullByte);
eval_fail_test!(fail_fromJSON_overflowing);
eval_fail_test!(fail_fromJSON_valueWithNullByte);
eval_fail_test!(fail_fromTOML_keyWithNullByte);
eval_fail_test!(fail_fromTOML_timestamps);
eval_fail_test!(fail_fromTOML_valueWithNullByte);
eval_fail_test!(fail_hashfile_missing);
eval_fail_test!(fail_infinite_recursion_lambda);
eval_fail_test!(fail_list);
eval_fail_test!(fail_missing_arg);
eval_fail_test!(fail_mutual_recursion);
eval_fail_test!(fail_nested_list_items);
eval_fail_test!(fail_nonexist_path);
eval_fail_test!(fail_not_throws);
eval_fail_test!(fail_overflowing_add);
eval_fail_test!(fail_overflowing_div);
eval_fail_test!(fail_overflowing_mul);
eval_fail_test!(fail_overflowing_sub);
eval_fail_test!(fail_path_slash);
eval_fail_test!(fail_pipe_operators);
eval_fail_test!(fail_recursion);
eval_fail_test!(fail_remove);
eval_fail_test!(fail_scope_5);
eval_fail_test!(fail_seq);
eval_fail_test!(fail_set);
eval_fail_test!(fail_set_override);
eval_fail_test!(fail_string_nul_1);
eval_fail_test!(fail_string_nul_2);
eval_fail_test!(fail_substring);
eval_fail_test!(fail_toJSON);
eval_fail_test!(fail_toJSON_non_utf_8);
eval_fail_test!(fail_to_path);
eval_fail_test!(fail_undeclared_arg);
eval_fail_test!(fail_using_set_as_attr_name);
mod fail {
use super::*;
eval_fail_test!(abort);
eval_fail_test!(addDrvOutputDependencies_empty_context);
eval_fail_test!(addDrvOutputDependencies_multi_elem_context);
eval_fail_test!(addDrvOutputDependencies_wrong_element_kind);
eval_fail_test!(addErrorRuntime_example);
eval_fail_test!(assert);
eval_fail_test!(assert_equal_attrs_names);
eval_fail_test!(assert_equal_attrs_names_2);
eval_fail_test!(assert_equal_derivations);
eval_fail_test!(assert_equal_derivations_extra);
eval_fail_test!(assert_equal_floats);
eval_fail_test!(assert_equal_function_direct);
eval_fail_test!(assert_equal_int_float);
eval_fail_test!(assert_equal_ints);
eval_fail_test!(assert_equal_list_length);
eval_fail_test!(assert_equal_paths);
eval_fail_test!(assert_equal_type);
eval_fail_test!(assert_equal_type_nested);
eval_fail_test!(assert_nested_bool);
eval_fail_test!(attr_name_type);
eval_fail_test!(attrset_merge_drops_later_rec);
eval_fail_test!(bad_string_interpolation_1);
eval_fail_test!(bad_string_interpolation_2);
eval_fail_test!(bad_string_interpolation_3);
eval_fail_test!(bad_string_interpolation_4);
eval_fail_test!(blackhole);
eval_fail_test!(call_primop);
eval_fail_test!(deepseq);
eval_fail_test!(derivation_name);
eval_fail_test!(dup_dynamic_attrs);
eval_fail_test!(duplicate_traces);
eval_fail_test!(eol_1);
eval_fail_test!(eol_2);
eval_fail_test!(eol_3);
eval_fail_test!(fetchTree_negative);
eval_fail_test!(fetchurl_baseName);
eval_fail_test!(fetchurl_baseName_attrs);
eval_fail_test!(fetchurl_baseName_attrs_name);
eval_fail_test!(flake_ref_to_string_negative_integer);
eval_fail_test!(foldlStrict_strict_op_application);
eval_fail_test!(fromJSON_keyWithNullByte);
eval_fail_test!(fromJSON_overflowing);
eval_fail_test!(fromJSON_valueWithNullByte);
eval_fail_test!(fromTOML_keyWithNullByte);
eval_fail_test!(fromTOML_timestamps);
eval_fail_test!(fromTOML_valueWithNullByte);
eval_fail_test!(hashfile_missing);
eval_fail_test!(infinite_recursion_lambda);
eval_fail_test!(list);
eval_fail_test!(missing_arg);
eval_fail_test!(mutual_recursion);
eval_fail_test!(nested_list_items);
eval_fail_test!(nonexist_path);
eval_fail_test!(not_throws);
eval_fail_test!(overflowing_add);
eval_fail_test!(overflowing_div);
eval_fail_test!(overflowing_mul);
eval_fail_test!(overflowing_sub);
eval_fail_test!(path_slash);
eval_fail_test!(pipe_operators);
eval_fail_test!(recursion);
eval_fail_test!(remove);
eval_fail_test!(scope_5);
eval_fail_test!(seq);
eval_fail_test!(set);
eval_fail_test!(set_override);
eval_fail_test!(string_nul_1);
eval_fail_test!(string_nul_2);
eval_fail_test!(substring);
eval_fail_test!(toJSON);
eval_fail_test!(toJSON_non_utf_8);
eval_fail_test!(to_path);
eval_fail_test!(undeclared_arg);
eval_fail_test!(using_set_as_attr_name);
}