feat(llvm): Implement Context Boxing pattern for cleaner APIs

Major improvement to reduce parameter explosion (15+ args → 3-4 contexts):
- Add LowerFnCtx/BlockCtx for grouping related parameters
- Add lightweight StrHandle/StrPtr newtypes for string safety
- Implement boxed API wrappers for boxcall/fields/invoke
- Add dev checks infrastructure (NYASH_DEV_CHECK_DISPATCH_ONLY_PHI)

Key achievements:
- lower_boxcall: 16 args → 7 args via boxed API
- fields/invoke: Similar parameter reduction
- BuilderCursor discipline enforced throughout
- String handle invariant: i64 across blocks, i8* only at call sites

Status:
- Internal migration in progress (fields → invoke → marshal)
- Full cutover pending due to borrow checker constraints
- dep_tree_min_string.o generation successful (sealed=ON)

Next: Complete internal migration before flipping to boxed APIs

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Selfhosting Dev
2025-09-13 00:07:38 +09:00
parent 8b48480844
commit 3bef7e8608
11 changed files with 436 additions and 35 deletions

View File

@ -4,6 +4,7 @@ use inkwell::{values::BasicValueEnum as BVE, AddressSpace};
use crate::backend::llvm::context::CodegenContext;
use crate::mir::{function::MirFunction, ValueId};
use super::super::ctx::{LowerFnCtx, BlockCtx};
// use super::marshal::{get_i64, get_tag_const};
@ -240,3 +241,33 @@ fn store_invoke_return<'ctx>(
}
Ok(())
}
// Boxed wrapper delegating to the existing implementation
pub(super) fn try_handle_tagged_invoke_boxed<'ctx, 'b>(
ctx: &mut LowerFnCtx<'ctx, 'b>,
blk: &BlockCtx<'ctx>,
dst: &Option<ValueId>,
mid: u16,
type_id: i64,
recv_h: inkwell::values::IntValue<'ctx>,
args: &[ValueId],
entry_builder: &inkwell::builder::Builder<'ctx>,
) -> Result<(), String> {
try_handle_tagged_invoke(
ctx.codegen,
ctx.func,
ctx.cursor,
ctx.resolver,
ctx.vmap,
dst,
mid,
type_id,
recv_h,
args,
entry_builder,
blk.cur_bid,
ctx.bb_map,
ctx.preds,
ctx.block_end_values,
)
}