layer: usize -> u8

This commit is contained in:
2026-05-01 15:30:21 +08:00
parent 0ca5e8af92
commit 0df38f374f
5 changed files with 28 additions and 20 deletions
+9 -5
View File
@@ -431,9 +431,10 @@ impl<'ctx: 'ir, 'id, 'ir, R: VmRuntimeCtx> DowngradeContext<'id, 'ir>
abs_layer,
} => {
if param_sym == sym {
return Ok(MaybeThunk::Arg {
layer: self.thunk_scopes.len() - abs_layer,
});
let layers: u8 =
self.thunk_scopes.len().try_into().expect("scope too deep!");
let layer = layers - abs_layer;
return Ok(MaybeThunk::Arg { layer });
}
}
}
@@ -484,7 +485,7 @@ impl<'ctx: 'ir, 'id, 'ir, R: VmRuntimeCtx> DowngradeContext<'id, 'ir>
{
self.scopes.push(Scope::Param {
sym,
abs_layer: self.thunk_scopes.len(),
abs_layer: self.thunk_scopes.len().try_into().expect("scope too deep!"),
});
let mut guard = ScopeGuard { ctx: self };
f(guard.as_ctx())
@@ -510,6 +511,9 @@ impl<'ctx: 'ir, 'id, 'ir, R: VmRuntimeCtx> DowngradeContext<'id, 'ir>
where
F: FnOnce(&mut Self) -> Ret,
{
if self.thunk_scopes.len() == u8::MAX as usize {
panic!("scope too deep!");
}
self.thunk_scopes.push(ThunkScope::new_in(self.bump));
let ret = f(self);
(
@@ -564,7 +568,7 @@ enum Scope<'ctx> {
Repl(&'ctx HashSet<StringId>),
ScopedImport(HashSet<StringId>),
Let(HashMap<StringId, ThunkId>),
Param { sym: StringId, abs_layer: usize },
Param { sym: StringId, abs_layer: u8 },
}
struct ScopeGuard<'a, 'ctx, 'id, 'ir, R: VmRuntimeCtx> {