🚀 Major LLVM breakthrough by ChatGPT5\!

PHI type coercion and core-first routing fixes:
- Auto type conversion for PHI nodes (i64↔i8*↔i1↔f64)
- Fixed ArrayBox.get misrouting to Map path
- Core-first strategy for Array/Map creation
- Added comprehensive debug logging ([PHI], [ARR], [MAP])

Results:
 Array smoke test: 'Result: 3'
 Map smoke test: 'Map: v=42, size=1'

After 34+ minutes of battling Rust lifetime errors,
ChatGPT5 achieved a major breakthrough\!

Key insight: The bug wasn't in PHI/SSA logic but in
Box type routing - ArrayBox.get was incorrectly caught
by Map fallback due to missing annotations.

We're SO CLOSE to Nyash self-hosting paradise\! 🌟
Once this stabilizes, everything can be written in
simple, beautiful Nyash code instead of Rust complexity.
This commit is contained in:
Selfhosting Dev
2025-09-12 12:07:07 +09:00
parent 1f5ba5f829
commit 4fe1212d36
9 changed files with 203 additions and 14 deletions

View File

@ -16,13 +16,17 @@ pub(super) fn try_handle_map_method<'ctx>(
args: &[ValueId],
recv_h: inkwell::values::IntValue<'ctx>,
) -> Result<bool, String> {
let is_map = matches!(func.metadata.value_types.get(box_val), Some(crate::mir::MirType::Box(b)) if b == "MapBox");
if !is_map {
// Only when receiver is annotated as MapBox
let is_map_annot = matches!(func.metadata.value_types.get(box_val), Some(crate::mir::MirType::Box(b)) if b == "MapBox");
if !is_map_annot {
return Ok(false);
}
let i64t = codegen.context.i64_type();
match method {
"size" => {
if std::env::var("NYASH_CLI_VERBOSE").ok().as_deref() == Some("1") {
eprintln!("[LLVM] lower Map.size (core)");
}
if !args.is_empty() {
return Err("MapBox.size expects 0 arg".to_string());
}
@ -45,6 +49,9 @@ pub(super) fn try_handle_map_method<'ctx>(
Ok(true)
}
"has" => {
if std::env::var("NYASH_CLI_VERBOSE").ok().as_deref() == Some("1") {
eprintln!("[LLVM] lower Map.has (core)");
}
if args.len() != 1 {
return Err("MapBox.has expects 1 arg".to_string());
}
@ -76,6 +83,9 @@ pub(super) fn try_handle_map_method<'ctx>(
Ok(true)
}
"get" => {
if std::env::var("NYASH_CLI_VERBOSE").ok().as_deref() == Some("1") {
eprintln!("[LLVM] lower Map.get (core)");
}
if args.len() != 1 {
return Err("MapBox.get expects 1 arg".to_string());
}
@ -131,6 +141,9 @@ pub(super) fn try_handle_map_method<'ctx>(
Ok(true)
}
"set" => {
if std::env::var("NYASH_CLI_VERBOSE").ok().as_deref() == Some("1") {
eprintln!("[LLVM] lower Map.set (core)");
}
if args.len() != 2 {
return Err("MapBox.set expects 2 args (key, value)".to_string());
}
@ -166,4 +179,3 @@ pub(super) fn try_handle_map_method<'ctx>(
_ => Ok(false),
}
}