vm(resolve): add text-based prelude merge for selfhost compilation
- Add merge_prelude_text() function for fast using system support - Implement normalize_text_for_inline() for parser robustness - Update selfhost.rs to use text-based merge when NYASH_USING_AST=1 - Add merge_prelude_text export to mod.rs - Improves Phase 15 selfhost compilation speed and reliability Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
This commit is contained in:
@ -22,19 +22,33 @@ impl NyashRunner {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
// Optional Phase-15: strip `using` lines and register modules (same policy as execute_nyash_file)
|
||||
// Optional Phase-15: using prelude merge (text-based for speed)
|
||||
let mut code_ref: std::borrow::Cow<'_, str> = std::borrow::Cow::Borrowed(&code);
|
||||
if crate::config::env::enable_using() {
|
||||
match crate::runner::modes::common_util::resolve::resolve_prelude_paths_profiled(self, &code, filename) {
|
||||
Ok((clean, paths)) => {
|
||||
if !paths.is_empty() && !crate::config::env::using_ast_enabled() {
|
||||
eprintln!("[ny-compiler] using: AST prelude merge is disabled in this profile. Enable NYASH_USING_AST=1 or remove 'using' lines.");
|
||||
let using_ast = crate::config::env::using_ast_enabled();
|
||||
if using_ast {
|
||||
// Text-based merge: faster for inline/selfhost execution
|
||||
match crate::runner::modes::common_util::resolve::merge_prelude_text(self, &code, filename) {
|
||||
Ok(merged) => {
|
||||
code_ref = std::borrow::Cow::Owned(merged);
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("[ny-compiler] using text merge error: {}", e);
|
||||
return false;
|
||||
}
|
||||
code_ref = std::borrow::Cow::Owned(clean);
|
||||
// Selfhost compile path does not need to parse prelude ASTs here.
|
||||
}
|
||||
Err(e) => { eprintln!("[ny-compiler] {}", e); return false; }
|
||||
} else {
|
||||
// Legacy: strip only (no prelude merge)
|
||||
match crate::runner::modes::common_util::resolve::resolve_prelude_paths_profiled(self, &code, filename) {
|
||||
Ok((clean, paths)) => {
|
||||
if !paths.is_empty() {
|
||||
eprintln!("[ny-compiler] using: AST prelude merge is disabled in this profile. Enable NYASH_USING_AST=1 or remove 'using' lines.");
|
||||
return false;
|
||||
}
|
||||
code_ref = std::borrow::Cow::Owned(clean);
|
||||
}
|
||||
Err(e) => { eprintln!("[ny-compiler] {}", e); return false; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user