smokes: add curated LLVM runner; archive legacy smokes; PHI-off unified across Bridge/Builder; LLVM resolver tracing; minimal Throw lowering; config env getters; dev profile and root cleaner; docs updated; CI workflow runs curated LLVM (PHI-on/off)

This commit is contained in:
Selfhosting Dev
2025-09-16 23:49:36 +09:00
parent 97a76c0571
commit 5c9213cd03
104 changed files with 8094 additions and 2930 deletions

View File

@ -9,6 +9,8 @@ use super::super::types::{to_bool, map_mirtype_to_basic};
use super::builder_cursor::BuilderCursor;
use super::Resolver;
fn phi_trace_on() -> bool { std::env::var("NYASH_LLVM_TRACE_PHI").ok().as_deref() == Some("1") }
pub(in super::super) fn emit_return<'ctx, 'b>(
codegen: &CodegenContext<'ctx>,
cursor: &mut BuilderCursor<'ctx, 'b>,
@ -82,6 +84,9 @@ pub(in super::super) fn emit_jump<'ctx, 'b>(
cursor.emit_term(bid, |b| {
b.build_unconditional_branch(tbb).map_err(|e| e.to_string()).unwrap();
});
if phi_trace_on() {
eprintln!("[PHI:jump] pred={} -> succ={}", bid.as_u32(), target.as_u32());
}
Ok(())
}
@ -335,10 +340,10 @@ pub(in super::super) fn finalize_phis<'ctx, 'b>(
});
}
let pred_bb = *bb_map.get(pred).ok_or("pred bb missing")?;
if std::env::var("NYASH_CLI_VERBOSE").ok().as_deref() == Some("1") {
if phi_trace_on() {
eprintln!(
"[PHI] finalize add pred_bb={} val={} ty={}",
pred.as_u32(), in_vid.as_u32(),
"[PHI:finalize] succ={} pred={} vid={} ty={}",
succ_bb.as_u32(), pred.as_u32(), in_vid.as_u32(),
phi.as_basic_value().get_type().print_to_string().to_string()
);
}
@ -359,10 +364,10 @@ pub(in super::super) fn finalize_phis<'ctx, 'b>(
BT::PointerType(pt) => pt.const_zero().into(),
_ => return Err("unsupported phi type for zero synth (finalize)".to_string()),
};
if std::env::var("NYASH_CLI_VERBOSE").ok().as_deref() == Some("1") {
if phi_trace_on() {
eprintln!(
"[PHI] finalize add (synth) pred_bb={} zero-ty={}",
pred.as_u32(), bt.print_to_string().to_string()
"[PHI:finalize] succ={} pred={} vid=? ty={} src=synth_zero",
succ_bb.as_u32(), pred.as_u32(), bt.print_to_string().to_string()
);
}
match z {
@ -431,6 +436,12 @@ pub(in super::super) fn localize_to_i64<'ctx, 'b>(
};
});
phi.add_incoming(&[(&iv_out, pred_bb)]);
if phi_trace_on() {
eprintln!(
"[PHI:resolve] cur={} pred={} vid={} ty=i64",
cur_bid.as_u32(), p.as_u32(), vid.as_u32()
);
}
}
// Restore insertion point
if let Some(bb) = saved_ip { codegen.builder.position_at_end(bb); }

View File

@ -134,3 +134,49 @@ pub(in super::super) fn lower_load<'ctx, 'b>(
vmap.insert(*dst, lv);
Ok(())
}
// Lower Copy: define dst in the current block by localizing src via Resolver
pub(in super::super) fn lower_copy<'ctx, 'b>(
codegen: &CodegenContext<'ctx>,
cursor: &mut BuilderCursor<'ctx, 'b>,
resolver: &mut super::Resolver<'ctx>,
cur_bid: BasicBlockId,
func: &crate::mir::function::MirFunction,
vmap: &mut HashMap<ValueId, BasicValueEnum<'ctx>>,
dst: &ValueId,
src: &ValueId,
bb_map: &std::collections::HashMap<crate::mir::BasicBlockId, inkwell::basic_block::BasicBlock<'ctx>>,
preds: &std::collections::HashMap<crate::mir::BasicBlockId, Vec<crate::mir::BasicBlockId>>,
block_end_values: &std::collections::HashMap<crate::mir::BasicBlockId, std::collections::HashMap<ValueId, BasicValueEnum<'ctx>>>,
) -> Result<(), String> {
// Choose resolution kind based on metadata type preference
use inkwell::types::BasicTypeEnum as BT;
let expected_bt: Option<BT> = func
.metadata
.value_types
.get(dst)
.or_else(|| func.metadata.value_types.get(src))
.map(|mt| super::super::types::map_mirtype_to_basic(codegen.context, mt));
let out: BasicValueEnum<'ctx> = match expected_bt {
Some(BT::IntType(_)) | None => {
// Prefer i64 for unknown
let iv = resolver.resolve_i64(codegen, cursor, cur_bid, *src, bb_map, preds, block_end_values, vmap)?;
iv.into()
}
Some(BT::PointerType(_)) => {
let pv = resolver.resolve_ptr(codegen, cursor, cur_bid, *src, bb_map, preds, block_end_values, vmap)?;
pv.into()
}
Some(BT::FloatType(_)) => {
let fv = resolver.resolve_f64(codegen, cursor, cur_bid, *src, bb_map, preds, block_end_values, vmap)?;
fv.into()
}
_ => {
// Fallback i64
let iv = resolver.resolve_i64(codegen, cursor, cur_bid, *src, bb_map, preds, block_end_values, vmap)?;
iv.into()
}
};
vmap.insert(*dst, out);
Ok(())
}

View File

@ -24,6 +24,7 @@ pub(super) use newbox::lower_newbox;
pub(super) use boxcall::{lower_boxcall, lower_boxcall_boxed, lower_boxcall_via_ctx};
pub(super) use arith::lower_compare;
pub(super) use mem::{lower_load, lower_store};
pub(super) use mem::lower_copy;
pub(super) use consts::lower_const;
pub(super) use arith_ops::{lower_binop, lower_unary};
pub(super) use call::lower_call;