refactor with

This commit is contained in:
2026-05-04 15:43:35 +08:00
parent 8c093a8d42
commit 2e06c3ced5
13 changed files with 162 additions and 344 deletions
+3 -11
View File
@@ -44,7 +44,7 @@ pub trait DowngradeContext<'id: 'ir, 'ir> {
fn intern_string(&mut self, sym: impl AsRef<str>) -> StringId;
fn resolve_sym(&self, id: StringId) -> Symbol<'_>;
fn lookup(&self, sym: StringId, span: TextRange) -> Result<GhostRoMaybeThunkRef<'id, 'ir>>;
fn lookup(&mut self, sym: StringId, span: TextRange) -> Result<GhostRoMaybeThunkRef<'id, 'ir>>;
fn get_current_source(&self) -> Source;
@@ -54,7 +54,7 @@ pub trait DowngradeContext<'id: 'ir, 'ir> {
fn with_let_scope<F, R>(&mut self, bindings: &[StringId], f: F) -> Result<R>
where
F: FnOnce(&mut Self) -> Result<(Vec<'ir, GhostRoMaybeThunkRef<'id, 'ir>>, R)>;
fn with_with_scope<F, R>(&mut self, f: F) -> R
fn with_with_scope<F, R>(&mut self, namespace: GhostRoMaybeThunkRef<'id, 'ir>, f: F) -> R
where
F: FnOnce(&mut Self) -> R;
fn with_thunk_scope<F, R>(&mut self, f: F) -> (R, Vec<'ir, (ThunkId, GhostRoIrRef<'id, 'ir>)>)
@@ -448,15 +448,7 @@ impl<'id: 'ir, 'ir, Ctx: DowngradeContext<'id, 'ir>> Downgrade<'id, 'ir, Ctx> fo
let namespace = ctx.maybe_thunk(namespace);
let body_expr = self.body().require(ctx, span)?;
let (body, thunks) =
ctx.with_thunk_scope(|ctx| ctx.with_with_scope(|ctx| body_expr.downgrade(ctx)));
let body = body?;
Ok(ctx.new_expr(Ir::With {
namespace,
body,
thunks,
}))
ctx.with_with_scope(namespace, |ctx| body_expr.downgrade(ctx))
}
}
+3 -6
View File
@@ -93,7 +93,6 @@ pub enum MaybeThunk {
Builtins,
ReplBinding(StringId),
ScopedImportBinding(StringId),
WithLookup(StringId),
}
pub trait Ref<'ir> {
@@ -182,12 +181,10 @@ pub enum Ir<'ir, R: RefExt<'ir> + ?Sized + 'ir> {
span: TextRange,
},
With {
namespace: R::MaybeThunkRef,
body: R::IrRef,
thunks: Vec<'ir, (ThunkId, R::IrRef)>,
WithLookup {
sym: StringId,
namespaces: Vec<'ir, R::MaybeThunkRef>,
},
WithLookup(StringId),
// Function related
Func {