llvm: gate empty PHI sanitize behind NYASH_LLVM_SANITIZE_EMPTY_PHI=1; docs: AGENTS.md note. perf: begin clone() reduction plan — TypeBox.name/type_parameters to Arc<str>, adjusted builders/registry; no behavior change

This commit is contained in:
Selfhosting Dev
2025-09-19 11:54:28 +09:00
parent 21d326333d
commit 4f82edf901
4 changed files with 39 additions and 28 deletions

View File

@ -212,6 +212,7 @@ Flags
- Do not commit secrets. Plugin paths and native libs are configured via `nyash.toml`.
- LLVM builds require system LLVM 18; install via apt.llvm.org in CI.
- Optional logs: enable `NYASH_CLI_VERBOSE=1` for detailed emit diagnostics.
- LLVM harness safety valve (dev only): set `NYASH_LLVM_SANITIZE_EMPTY_PHI=1` to drop malformed empty PHI lines from IR before llvmlite parses it. Keep OFF for normal runs; use only to unblock bring-up when `finalize_phis` is being debugged.
## Codex Async Workflow (Background Jobs)
- Purpose: run Codex tasks in the background and notify a tmux session on completion.

View File

@ -24,6 +24,14 @@ Refactor Progress (2025-09-19, noon)
- Behavior preserved: once/birth_once/computed generation identical to prior inline branch, including cache/poison and self-cycle guard.
- Postfix handlers (catch/cleanup) remain supported under Stage3 gate and are wrapped into TryCatch on the member body.
P0/P1 Safety Fixes (2025-09-19)
- UserDefinedBoxFactory
- Added safe init stub: call InstanceBox::init(args) after creation (no panic; ignore error). Birth/init AST execution remains interpreter-owned.
- HTTPResponseBox interior mutability (thread-safe)
- Replaced fields with Mutex-based interior mutability and implemented setters: set_status/set_header/set_body/append_body.
- Updated to_http_string and Display/to_string to read via locks; manual Clone implemented.
- Removes RefCell TODOs at http_message_box.rs:292330 without violating BoxCore Send+Sync.
Refactor Plan (next 12 weeks)
1) Split parse_box_declaration (667 lines) in src/parser/declarations/box_definition.rs
- Targets (line ranges are indicative):

View File

@ -1207,7 +1207,9 @@ class NyashLLVMBuilder:
# Compile
ir_text = str(self.module)
# Sanitize: drop any empty PHI rows (no incoming list) to satisfy IR parser
# Optional sanitize: drop any empty PHI rows (no incoming list) to satisfy IR parser.
# Gate with NYASH_LLVM_SANITIZE_EMPTY_PHI=1. Default OFF.
if os.environ.get('NYASH_LLVM_SANITIZE_EMPTY_PHI') == '1':
try:
fixed_lines = []
for line in ir_text.splitlines():

View File

@ -52,7 +52,7 @@ impl MethodSignature {
#[derive(Debug, Clone)]
pub struct TypeBox {
/// 型名
pub name: String,
pub name: Arc<str>,
/// フィールド情報 (field_name -> field_type)
pub fields: HashMap<String, Arc<TypeBox>>,
@ -64,7 +64,7 @@ pub struct TypeBox {
pub parent_type: Option<Arc<TypeBox>>,
/// ジェネリクス型パラメータ
pub type_parameters: Vec<String>,
pub type_parameters: Vec<Arc<str>>,
/// インスタンス化された具体型(ジェネリクス用)
pub concrete_types: HashMap<String, Arc<TypeBox>>,
@ -80,7 +80,7 @@ impl TypeBox {
/// 新しいTypeBoxを作成
pub fn new(name: &str) -> Self {
Self {
name: name.to_string(),
name: Arc::<str>::from(name),
fields: HashMap::new(),
methods: HashMap::new(),
parent_type: None,
@ -114,8 +114,8 @@ impl TypeBox {
}
/// 型パラメータを追加
pub fn add_type_parameter(&mut self, param: String) {
self.type_parameters.push(param);
pub fn add_type_parameter<S: Into<Arc<str>>>(&mut self, param: S) {
self.type_parameters.push(param.into());
}
/// 具体型を設定(ジェネリクス用)
@ -183,9 +183,9 @@ impl TypeBox {
/// 型名を完全表示(ジェネリクス対応)
pub fn full_name(&self) -> String {
if self.concrete_types.is_empty() {
self.name.clone()
self.name.as_ref().to_string()
} else {
let mut result = self.name.clone();
let mut result = self.name.as_ref().to_string();
result.push('<');
let concrete_names: Vec<String> = self
@ -193,9 +193,9 @@ impl TypeBox {
.iter()
.map(|param| {
self.concrete_types
.get(param)
.map(|t| t.name.clone())
.unwrap_or_else(|| param.clone())
.get(param.as_ref())
.map(|t| t.name.as_ref().to_string())
.unwrap_or_else(|| param.as_ref().to_string())
})
.collect();
@ -331,18 +331,18 @@ impl TypeRegistry {
/// 型を登録
pub fn register_type(&mut self, type_box: Arc<TypeBox>) {
let name = type_box.name.clone();
let name_s: String = type_box.name.as_ref().to_string();
// 継承チェーンを構築
let mut chain = vec![name.clone()];
let mut chain = vec![name_s.clone()];
let mut current = &type_box.parent_type;
while let Some(parent) = current {
chain.push(parent.name.clone());
chain.push(parent.name.as_ref().to_string());
current = &parent.parent_type;
}
self.inheritance_chains.insert(name.clone(), chain);
self.types.insert(name, type_box);
self.inheritance_chains.insert(name_s.clone(), chain);
self.types.insert(name_s, type_box);
}
/// 型を取得
@ -393,7 +393,7 @@ impl TypeRegistry {
// 新しい具体化型を作成
let mut concrete_type = (*base).clone();
concrete_type.name = format!("{}_{}", base_type, concrete_types.join("_"));
concrete_type.name = format!("{}_{}", base_type, concrete_types.join("_")).into();
concrete_type.concrete_types.clear();
// 具体型を設定
@ -446,7 +446,7 @@ impl TypeBoxBuilder {
/// 型パラメータを追加
pub fn type_param(mut self, param: &str) -> Self {
self.type_box.add_type_parameter(param.to_string());
self.type_box.add_type_parameter(param);
self
}