docs/ci: selfhost bootstrap/exe-first workflows; add ny-llvmc scaffolding + JSON v0 schema validation; plan: unify to Nyash ABI v2 (no backwards compat)

This commit is contained in:
Selfhosting Dev
2025-09-17 20:33:19 +09:00
parent a5054a271b
commit 4ea3ca2685
56 changed files with 2275 additions and 1623 deletions

View File

@ -51,7 +51,8 @@ def lower_atomic_op(
resolver=None,
preds=None,
block_end_values=None,
bb_map=None
bb_map=None,
ctx=None,
) -> None:
"""
Lower atomic operations
@ -66,7 +67,12 @@ def lower_atomic_op(
ordering: Memory ordering
"""
# Get pointer
if resolver is not None and preds is not None and block_end_values is not None and bb_map is not None:
if ctx is not None:
try:
ptr = ctx.resolver.resolve_ptr(ptr_vid, builder.block, ctx.preds, ctx.block_end_values, ctx.vmap)
except Exception:
ptr = vmap.get(ptr_vid)
elif resolver is not None and preds is not None and block_end_values is not None and bb_map is not None:
ptr = resolver.resolve_ptr(ptr_vid, builder.block, preds, block_end_values, vmap)
else:
ptr = vmap.get(ptr_vid)
@ -85,7 +91,12 @@ def lower_atomic_op(
elif op == "store":
# Atomic store
if val_vid is not None:
if resolver is not None and preds is not None and block_end_values is not None and bb_map is not None:
if ctx is not None:
try:
val = ctx.resolver.resolve_i64(val_vid, builder.block, ctx.preds, ctx.block_end_values, ctx.vmap, ctx.bb_map)
except Exception:
val = vmap.get(val_vid, ir.Constant(ir.IntType(64), 0))
elif resolver is not None and preds is not None and block_end_values is not None and bb_map is not None:
val = resolver.resolve_i64(val_vid, builder.block, preds, block_end_values, vmap, bb_map)
else:
val = vmap.get(val_vid, ir.Constant(ir.IntType(64), 0))
@ -94,7 +105,12 @@ def lower_atomic_op(
elif op == "add":
# Atomic add (fetch_add)
if val_vid is not None:
if resolver is not None and preds is not None and block_end_values is not None and bb_map is not None:
if ctx is not None:
try:
val = ctx.resolver.resolve_i64(val_vid, builder.block, ctx.preds, ctx.block_end_values, ctx.vmap, ctx.bb_map)
except Exception:
val = ir.Constant(ir.IntType(64), 1)
elif resolver is not None and preds is not None and block_end_values is not None and bb_map is not None:
val = resolver.resolve_i64(val_vid, builder.block, preds, block_end_values, vmap, bb_map)
else:
val = ir.Constant(ir.IntType(64), 1)

View File

@ -5,6 +5,7 @@ Core of Nyash's "Everything is Box" philosophy
import llvmlite.ir as ir
from typing import Dict, List, Optional, Any
from instructions.safepoint import insert_automatic_safepoint
def _declare(module: ir.Module, name: str, ret, args):
for f in module.functions:
@ -68,6 +69,13 @@ def lower_boxcall(
i64 = ir.IntType(64)
i8 = ir.IntType(8)
i8p = i8.as_pointer()
# Insert a safepoint around potential heavy boxcall sites (pre-call)
try:
import os
if os.environ.get('NYASH_LLVM_AUTO_SAFEPOINT', '1') == '1':
insert_automatic_safepoint(builder, module, "boxcall")
except Exception:
pass
# Short-hands with ctx (backward-compatible fallback)
r = resolver

View File

@ -6,6 +6,7 @@ Handles regular function calls (not BoxCall or ExternCall)
import llvmlite.ir as ir
from typing import Dict, List, Optional, Any
from trace import debug as trace_debug
from instructions.safepoint import insert_automatic_safepoint
def lower_call(
builder: ir.IRBuilder,
@ -45,6 +46,13 @@ def lower_call(
bb_map = ctx.bb_map
except Exception:
pass
# Insert an automatic safepoint after the function call
try:
import os
if os.environ.get('NYASH_LLVM_AUTO_SAFEPOINT', '1') == '1':
insert_automatic_safepoint(builder, module, "function_call")
except Exception:
pass
# Short-hands with ctx (backward-compatible fallback)
r = resolver
p = preds

View File

@ -4,6 +4,7 @@ Lowering helpers for while-control flow (regular structured)
from typing import List, Dict, Any
import llvmlite.ir as ir
from instructions.safepoint import insert_automatic_safepoint
def lower_while_regular(
builder: ir.IRBuilder,
@ -57,6 +58,13 @@ def lower_while_regular(
else:
cond_val = ir.Constant(i1, 0)
# Insert a safepoint at loop header to allow cooperative GC
try:
import os
if os.environ.get('NYASH_LLVM_AUTO_SAFEPOINT', '1') == '1':
insert_automatic_safepoint(cbuild, builder.block.parent.module, "loop_header")
except Exception:
pass
cbuild.cbranch(cond_val, body_bb, exit_bb)
# Body block
@ -77,4 +85,3 @@ def lower_while_regular(
# Continue at exit
builder.position_at_end(exit_bb)

View File

@ -5,6 +5,7 @@ Minimal mapping for NyRT-exported symbols (console/log family等)
import llvmlite.ir as ir
from typing import Dict, List, Optional, Any
from instructions.safepoint import insert_automatic_safepoint
def lower_externcall(
builder: ir.IRBuilder,
@ -197,3 +198,10 @@ def lower_externcall(
vmap[dst_vid] = ir.Constant(i64, 0)
else:
vmap[dst_vid] = result
# Insert an automatic safepoint after externcall
try:
import os
if os.environ.get('NYASH_LLVM_AUTO_SAFEPOINT', '1') == '1':
insert_automatic_safepoint(builder, module, "extern_call")
except Exception:
pass

View File

@ -7,6 +7,7 @@ import os
import llvmlite.ir as ir
from dataclasses import dataclass
from typing import Dict, Tuple, List, Optional, Any
from instructions.safepoint import insert_automatic_safepoint
@dataclass
class LoopFormContext:
@ -53,7 +54,8 @@ def lower_while_loopform(
bb_map: Dict[int, ir.Block],
resolver=None,
preds=None,
block_end_values=None
block_end_values=None,
ctx=None,
) -> bool:
"""
Lower a while loop using LoopForm structure
@ -72,9 +74,22 @@ def lower_while_loopform(
builder.position_at_end(lf.preheader)
builder.branch(lf.header)
# Header: Evaluate condition
# Header: Evaluate condition (insert a safepoint at loop header)
builder.position_at_end(lf.header)
if resolver is not None and preds is not None and block_end_values is not None:
try:
import os
if os.environ.get('NYASH_LLVM_AUTO_SAFEPOINT', '1') == '1':
insert_automatic_safepoint(builder, func.module, "loop_header")
except Exception:
pass
if ctx is not None:
try:
cond64 = ctx.resolver.resolve_i64(condition_vid, builder.block, ctx.preds, ctx.block_end_values, ctx.vmap, ctx.bb_map)
zero64 = ir.IntType(64)(0)
cond = builder.icmp_unsigned('!=', cond64, zero64)
except Exception:
cond = vmap.get(condition_vid, ir.Constant(ir.IntType(1), 0))
elif resolver is not None and preds is not None and block_end_values is not None:
cond64 = resolver.resolve_i64(condition_vid, builder.block, preds, block_end_values, vmap, bb_map)
zero64 = ir.IntType(64)(0)
cond = builder.icmp_unsigned('!=', cond64, zero64)