diff --git a/.gitignore b/.gitignore index 1fc9466c..831ccc8e 100644 --- a/.gitignore +++ b/.gitignore @@ -101,6 +101,10 @@ stats_output.txt *.o *.exe a.out +app_*_llvm +app_link +string_len_app +*_app # Nekocode analysis files (大きなJSONファイル) .nekocode_sessions/ diff --git a/CURRENT_TASK.md b/CURRENT_TASK.md index f5e8eb93..b0726d91 100644 --- a/CURRENT_TASK.md +++ b/CURRENT_TASK.md @@ -161,6 +161,34 @@ Update (2025-09-01 AM / JIT handoff follow-up) 2) b1 返り値 ABI を有効化する場合の経路確認(feature `jit-b1-abi`)。 3) ドキュメント整備(CraneliftBuilder 単一出口方針と TRACE 変数の最終化)。 +Update (2025-09-02 / JIT seal・PHI安定化 + builder分割 進捗) + +- 完了(JIT / jit-direct 最小3本グリーン) + - seal 管理の一本化(途中seal撤廃、end_functionで最終seal)。 + - PHI(min) 合流: 事前スキャン→ensure_block_params、br/jump時のargs/append秩序確立。 + - Return の安定化(known/param/slot優先、フォールバック const materialize)。 + - 診断ログ整備(NYASH_JIT_DUMP/TRACE_*)。 +- スモーク(debug/release): mir-branch-ret=1, mir-phi-min=10, mir-branch-multi=1。 + +- リファクタリング(builder 1,000行目安に向けて段階実施) + - 分離済み: + - `src/jit/lower/builder/noop.rs`(NoopBuilder) + - `src/jit/lower/builder/object.rs`(AOT .o 用 ObjectBuilder、finish対応) + - `src/jit/lower/builder/rt_shims.rs`(nyash_jit_dbg_i64 等の小シム群) + - `src/jit/lower/builder/tls.rs`(clif_tls と TLS 呼び出しヘルパ) + - 動作維持: pub use で既存パス互換。jit-direct スモーク通過。 + +- 残タスク(次手) + - [ ] CraneliftBuilder 本体を `builder/cranelift.rs` に分離(大枠)。 + - [ ] `builder.rs` を薄い “ハブ” 化(trait/enum/API公開 + pub use)。 + - [ ] 分離ごとに jit-direct 3本(debug/release)スモーク再確認。 + - [ ] LowerCore の段階分割(`analysis.rs` / `cfg.rs` / `ops.rs`)検討(別PRでも可)。 + +- 実行メモ(JIT) + - Build: `cargo build --release --features cranelift-jit` + - jit-direct: `NYASH_JIT_THRESHOLD=1 ./target/release/nyash --jit-direct apps/tests/mir-branch-ret/main.nyash` + - 診断: `NYASH_JIT_DUMP=1 NYASH_JIT_TRACE_BLOCKS=1 NYASH_JIT_TRACE_RET=1` 併用可。 + Update (2025-09-01 PM2 / Interpreter parity blockers) - 目的: Semantics 層での VM/JIT/Interpreter パリティ検証に向け、Interpreter 側の既知不具合を記録・引き継ぎ。 diff --git a/app_array_ret_llvm b/app_array_ret_llvm deleted file mode 100644 index 0ad9af6f..00000000 Binary files a/app_array_ret_llvm and /dev/null differ diff --git a/app_echo_llvm b/app_echo_llvm deleted file mode 100644 index cf0a7ee5..00000000 Binary files a/app_echo_llvm and /dev/null differ diff --git a/app_link b/app_link deleted file mode 100644 index d30713dc..00000000 Binary files a/app_link and /dev/null differ diff --git a/app_map_llvm b/app_map_llvm deleted file mode 100644 index 93a4ff80..00000000 Binary files a/app_map_llvm and /dev/null differ diff --git a/app_vinvoke_llvm b/app_vinvoke_llvm deleted file mode 100644 index 405bc18a..00000000 Binary files a/app_vinvoke_llvm and /dev/null differ diff --git a/app_vinvoke_ret_llvm b/app_vinvoke_ret_llvm deleted file mode 100644 index 0b15c4c2..00000000 Binary files a/app_vinvoke_ret_llvm and /dev/null differ diff --git a/app_vinvoke_ret_size_llvm b/app_vinvoke_ret_size_llvm deleted file mode 100644 index cd732ad7..00000000 Binary files a/app_vinvoke_ret_size_llvm and /dev/null differ diff --git a/logs/archive/err3.txt b/logs/archive/err3.txt new file mode 100644 index 00000000..6b81b1cc --- /dev/null +++ b/logs/archive/err3.txt @@ -0,0 +1,606 @@ + Compiling nyash-rust v0.1.0 (/mnt/c/git/nyash-project/nyash) +warning: unused imports: `IntegerBox` and `VoidBox` + --> src/boxes/jit_stats_box.rs:1:54 + | +1 | use crate::box_trait::{NyashBox, StringBox, BoolBox, IntegerBox, VoidBox, BoxCore, BoxBase}; + | ^^^^^^^^^^ ^^^^^^^ + | + = note: `#[warn(unused_imports)]` on by default + +warning: unused import: `VoidBox` + --> src/boxes/aot_compiler_box.rs:1:54 + | +1 | use crate::box_trait::{NyashBox, StringBox, BoolBox, VoidBox, BoxCore, BoxBase}; + | ^^^^^^^ + +warning: unused import: `NyashResultBox` + --> src/boxes/p2p_box.rs:41:39 + | +41 | use crate::boxes::result::{ResultBox, NyashResultBox}; + | ^^^^^^^^^^^^^^ + +warning: unused import: `IntegerBox` + --> src/interpreter/mod.rs:10:45 + | +10 | use crate::box_trait::{NyashBox, StringBox, IntegerBox, BoolBox, VoidBox, ErrorBox, BoxCore}; + | ^^^^^^^^^^ + +warning: unused import: `RangeBox` + --> src/interpreter/mod.rs:14:39 + | +14 | use crate::boxes::math_box::{MathBox, RangeBox}; + | ^^^^^^^^ + +warning: unused import: `TimeBox` + --> src/interpreter/mod.rs:15:30 + | +15 | use crate::boxes::time_box::{TimeBox, TimerBox}; + | ^^^^^^^ + +warning: unused import: `crate::boxes::map_box::MapBox` + --> src/interpreter/mod.rs:16:5 + | +16 | use crate::boxes::map_box::MapBox; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +warning: unused import: `crate::boxes::sound_box::SoundBox` + --> src/interpreter/mod.rs:18:5 + | +18 | use crate::boxes::sound_box::SoundBox; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +warning: unused import: `crate::method_box::MethodBox` + --> src/interpreter/mod.rs:20:5 + | +20 | use crate::method_box::MethodBox; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +warning: unused import: `crate::parser::ParseError` + --> src/interpreter/core.rs:11:5 + | +11 | use crate::parser::ParseError; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +warning: unused import: `RwLock` + --> src/interpreter/core.rs:15:29 + | +15 | use std::sync::{Arc, Mutex, RwLock}; + | ^^^^^^ + +warning: unused import: `BoxDeclaration` + --> src/interpreter/core.rs:17:26 + | +17 | use super::{ControlFlow, BoxDeclaration, ConstructorContext, StaticBoxDefinition, StaticBoxState}; + | ^^^^^^^^^^^^^^ + +warning: unused macro definition: `debug_trace` + --> src/interpreter/core.rs:35:14 + | +35 | macro_rules! debug_trace { + | ^^^^^^^^^^^ + | + = note: `#[warn(unused_macros)]` on by default + +warning: unused import: `StringBox` + --> src/interpreter/eval.rs:4:43 + | +4 | use crate::box_trait::{NyashBox, VoidBox, StringBox}; + | ^^^^^^^^^ + +warning: unused import: `BoolBox` + --> src/interpreter/expressions/calls.rs:7:57 + | +7 | use crate::box_trait::{NyashBox, StringBox, IntegerBox, BoolBox, VoidBox}; + | ^^^^^^^ + +warning: unused imports: `ArrayBox`, `FloatBox`, and `FutureBox` + --> src/interpreter/expressions/calls.rs:8:20 + | +8 | use crate::boxes::{ArrayBox, FloatBox, MapBox, FutureBox}; + | ^^^^^^^^ ^^^^^^^^ ^^^^^^^^^ + +warning: unused imports: `BufferBox`, `HttpClientBox`, `JSONBox`, `RegexBox`, and `StreamBox` + --> src/interpreter/expressions/calls.rs:9:20 + | +9 | use crate::boxes::{BufferBox, JSONBox, HttpClientBox, StreamBox, RegexBox, IntentBox, SocketBox}; + | ^^^^^^^^^ ^^^^^^^ ^^^^^^^^^^^^^ ^^^^^^^^^ ^^^^^^^^ + +warning: unused imports: `MathBox` and `TimeBox` + --> src/interpreter/expressions/calls.rs:10:68 + | +10 | use crate::boxes::{HTTPServerBox, HTTPRequestBox, HTTPResponseBox, MathBox, TimeBox, DateTimeBox}; + | ^^^^^^^ ^^^^^^^ + +warning: unused import: `crate::channel_box::ChannelBox` + --> src/interpreter/expressions/calls.rs:13:5 + | +13 | use crate::channel_box::ChannelBox; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +warning: unused import: `crate::interpreter::finalization` + --> src/interpreter/expressions/calls.rs:15:5 + | +15 | use crate::interpreter::finalization; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +warning: unused import: `crate::box_trait::BoolBox` + --> src/interpreter/methods/p2p_methods.rs:11:5 + | +11 | use crate::box_trait::BoolBox; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +warning: unused imports: `StringBox` and `VoidBox` + --> src/interpreter/methods/system_methods.rs:10:34 + | +10 | use crate::box_trait::{NyashBox, VoidBox, StringBox, BoolBox}; + | ^^^^^^^ ^^^^^^^^^ + +warning: unused import: `core::*` + --> src/interpreter/mod.rs:109:9 + | +109 | pub use core::*; + | ^^^^^^^ + +warning: unused import: `TypeOpKind` + --> src/mir/optimizer.rs:11:71 + | +11 | use super::{MirModule, MirFunction, MirInstruction, ValueId, MirType, TypeOpKind, EffectMask, Effect}; + | ^^^^^^^^^^ + +warning: unused import: `MirType` + --> src/mir/optimizer.rs:340:42 + | +340 | use super::{MirInstruction as I, MirType}; + | ^^^^^^^ + +warning: unnecessary parentheses around function argument + --> src/mir/passes/method_id_inject.rs:48:56 + | +48 | ... Ok(mh) => Some((mh.method_id as u16)), + | ^ ^ + | + = note: `#[warn(unused_parens)]` on by default +help: remove these parentheses + | +48 - Ok(mh) => Some((mh.method_id as u16)), +48 + Ok(mh) => Some(mh.method_id as u16), + | + +warning: unnecessary parentheses around function argument + --> src/mir/passes/method_id_inject.rs:66:52 + | +66 | ... Ok(mh) => Some((mh.method_id as u16)), + | ^ ^ + | +help: remove these parentheses + | +66 - Ok(mh) => Some((mh.method_id as u16)), +66 + Ok(mh) => Some(mh.method_id as u16), + | + +warning: unused imports: `BinaryOp`, `CompareOp`, and `UnaryOp` + --> src/backend/vm.rs:10:70 + | +10 | use crate::mir::{MirModule, MirFunction, MirInstruction, ConstValue, BinaryOp, CompareOp, UnaryOp, ValueId, BasicBlockId}; + | ^^^^^^^^ ^^^^^^^^^ ^^^^^^^ + +warning: unused import: `IRBuilder` + --> src/backend/cranelift/mod.rs:14:48 + | +14 | use crate::jit::lower::{builder::{NoopBuilder, IRBuilder}, core::LowerCore}; + | ^^^^^^^^^ + +warning: unused import: `FunctionBuilderContext` + --> src/backend/cranelift/context.rs:6:43 + | +6 | use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext}; + | ^^^^^^^^^^^^^^^^^^^^^^ + +warning: unused import: `cranelift_codegen::isa` + --> src/backend/cranelift/jit.rs:4:5 + | +4 | use cranelift_codegen::isa; + | ^^^^^^^^^^^^^^^^^^^^^^ + +warning: unused import: `crate::backend::vm::VMValue as V` + --> src/backend/cranelift/mod.rs:89:21 + | +89 | use crate::backend::vm::VMValue as V; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +warning: unused imports: `BinaryOp` and `CompareOp` + --> src/jit/lower/core.rs:1:59 + | +1 | use crate::mir::{MirFunction, MirInstruction, ConstValue, BinaryOp, CompareOp, ValueId}; + | ^^^^^^^^ ^^^^^^^^^ + +warning: unused import: `CmpKind` + --> src/jit/lower/core.rs:2:44 + | +2 | use super::builder::{IRBuilder, BinOpKind, CmpKind}; + | ^^^^^^^ + +warning: unnecessary parentheses around `if` condition + --> src/jit/lower/core.rs:705:20 + | +705 | if (bt == "PyRuntimeBox" && (m == "import")) { + | ^ ^ + | +help: remove these parentheses + | +705 - if (bt == "PyRuntimeBox" && (m == "import")) { +705 + if bt == "PyRuntimeBox" && (m == "import") { + | + +warning: unnecessary parentheses around `if` condition + --> src/jit/lower/core.rs:714:27 + | +714 | } else if (bt == "PyRuntimeBox" && (m == "getattr" || m == "call")) { + | ^ ^ + | +help: remove these parentheses + | +714 - } else if (bt == "PyRuntimeBox" && (m == "getattr" || m == "call")) { +714 + } else if bt == "PyRuntimeBox" && (m == "getattr" || m == "call") { + | + +warning: unexpected `cfg` condition value: `never` + --> src/jit/lower/builder.rs:1627:7 + | +1627 | #[cfg(feature = "never")] + | ^^^^^^^^^^^^^^^^^ + | + = note: expected values for `feature` are: `all-examples`, `cli`, `cranelift-jit`, `default`, `dynamic-file`, `gui`, `gui-examples`, `llvm`, `mir_modular_builder`, `mir_refbarrier_unify_poc`, `mir_typeop_poc`, `plugins`, and `wasm-backend` + = help: consider adding `never` as a feature in `Cargo.toml` + = note: see for more information about checking conditional configuration + = note: `#[warn(unexpected_cfgs)]` on by default + +warning: unexpected `cfg` condition value: `never` + --> src/jit/lower/builder.rs:1648:7 + | +1648 | #[cfg(feature = "never")] + | ^^^^^^^^^^^^^^^^^ + | + = note: expected values for `feature` are: `all-examples`, `cli`, `cranelift-jit`, `default`, `dynamic-file`, `gui`, `gui-examples`, `llvm`, `mir_modular_builder`, `mir_refbarrier_unify_poc`, `mir_typeop_poc`, `plugins`, and `wasm-backend` + = help: consider adding `never` as a feature in `Cargo.toml` + = note: see for more information about checking conditional configuration + +warning: unexpected `cfg` condition value: `never` + --> src/jit/lower/builder.rs:1699:7 + | +1699 | #[cfg(feature = "never")] + | ^^^^^^^^^^^^^^^^^ + | + = note: expected values for `feature` are: `all-examples`, `cli`, `cranelift-jit`, `default`, `dynamic-file`, `gui`, `gui-examples`, `llvm`, `mir_modular_builder`, `mir_refbarrier_unify_poc`, `mir_typeop_poc`, `plugins`, and `wasm-backend` + = help: consider adding `never` as a feature in `Cargo.toml` + = note: see for more information about checking conditional configuration + +warning: unused import: `cranelift_codegen::ir::StackSlotData` + --> src/jit/lower/builder/object.rs:71:13 + | +71 | use cranelift_codegen::ir::StackSlotData; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +warning: unused import: `cranelift_codegen::ir::types` + --> src/jit/lower/builder/object.rs:87:91 + | +87 | fn emit_const_f64(&mut self, val: f64) { use cranelift_frontend::FunctionBuilder; use cranelift_codegen::ir::types; let mut fb = Func... + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +warning: unnecessary parentheses around function argument + --> src/jit/lower/builder.rs:306:72 + | +306 | let mut buf = crate::runtime::plugin_ffi_common::encode_tlv_header((argc.saturating_sub(1).max(0) as u16)); + | ^ ^ + | +help: remove these parentheses + | +306 - let mut buf = crate::runtime::plugin_ffi_common::encode_tlv_header((argc.saturating_sub(1).max(0) as u16)); +306 + let mut buf = crate::runtime::plugin_ffi_common::encode_tlv_header(argc.saturating_sub(1).max(0) as u16); + | + +warning: unnecessary parentheses around function argument + --> src/jit/lower/builder.rs:448:72 + | +448 | let mut buf = crate::runtime::plugin_ffi_common::encode_tlv_header((argc.saturating_sub(1).max(0) as u16)); + | ^ ^ + | +help: remove these parentheses + | +448 - let mut buf = crate::runtime::plugin_ffi_common::encode_tlv_header((argc.saturating_sub(1).max(0) as u16)); +448 + let mut buf = crate::runtime::plugin_ffi_common::encode_tlv_header(argc.saturating_sub(1).max(0) as u16); + | + +warning: unnecessary parentheses around function argument + --> src/jit/lower/builder.rs:557:72 + | +557 | let mut buf = crate::runtime::plugin_ffi_common::encode_tlv_header((argc.saturating_sub(1).max(0) as u16)); + | ^ ^ + | +help: remove these parentheses + | +557 - let mut buf = crate::runtime::plugin_ffi_common::encode_tlv_header((argc.saturating_sub(1).max(0) as u16)); +557 + let mut buf = crate::runtime::plugin_ffi_common::encode_tlv_header(argc.saturating_sub(1).max(0) as u16); + | + +warning: unused imports: `Effect as OpEffect`, `MirFunction`, `MirType`, and `jit::events` + --> src/jit/lower/builder.rs:624:11 + | +624 | mir::{MirType, Effect as OpEffect, MirFunction}, + | ^^^^^^^ ^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^ +625 | jit::events, + | ^^^^^^^^^^^ + +warning: unexpected `cfg` condition value: `jit-b1-abi` + --> src/jit/lower/builder.rs:739:27 + | +739 | #[cfg(feature = "jit-b1-abi")] + | ^^^^^^^^^^^^^^^^^^^^^^ + | + = note: expected values for `feature` are: `all-examples`, `cli`, `cranelift-jit`, `default`, `dynamic-file`, `gui`, `gui-examples`, `llvm`, `mir_modular_builder`, `mir_refbarrier_unify_poc`, `mir_typeop_poc`, `plugins`, and `wasm-backend` + = help: consider adding `jit-b1-abi` as a feature in `Cargo.toml` + = note: see for more information about checking conditional configuration + +warning: unexpected `cfg` condition value: `jit-b1-abi` + --> src/jit/lower/builder.rs:759:23 + | +759 | #[cfg(feature = "jit-b1-abi")] + | ^^^^^^^^^^^^^^^^^^^^^^ + | + = note: expected values for `feature` are: `all-examples`, `cli`, `cranelift-jit`, `default`, `dynamic-file`, `gui`, `gui-examples`, `llvm`, `mir_modular_builder`, `mir_refbarrier_unify_poc`, `mir_typeop_poc`, `plugins`, and `wasm-backend` + = help: consider adding `jit-b1-abi` as a feature in `Cargo.toml` + = note: see for more information about checking conditional configuration + +warning: unexpected `cfg` condition value: `jit-b1-abi` + --> src/jit/lower/builder.rs:804:31 + | +804 | #[cfg(feature = "jit-b1-abi")] + | ^^^^^^^^^^^^^^^^^^^^^^ + | + = note: expected values for `feature` are: `all-examples`, `cli`, `cranelift-jit`, `default`, `dynamic-file`, `gui`, `gui-examples`, `llvm`, `mir_modular_builder`, `mir_refbarrier_unify_poc`, `mir_typeop_poc`, `plugins`, and `wasm-backend` + = help: consider adding `jit-b1-abi` as a feature in `Cargo.toml` + = note: see for more information about checking conditional configuration + +warning: unused import: `cranelift_codegen::ir::types` + --> src/jit/lower/builder.rs:1045:13 + | +1045 | use cranelift_codegen::ir::types; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +warning: unused import: `condcodes::IntCC` + --> src/jit/lower/builder.rs:1159:44 + | +1159 | use cranelift_codegen::ir::{types, condcodes::IntCC}; + | ^^^^^^^^^^^^^^^^ + +warning: unused import: `cranelift_frontend::FunctionBuilder` + --> src/jit/lower/builder.rs:1187:13 + | +1187 | use cranelift_frontend::FunctionBuilder; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +warning: unused import: `cranelift_frontend::FunctionBuilder` + --> src/jit/lower/builder.rs:1211:13 + | +1211 | use cranelift_frontend::FunctionBuilder; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +warning: unused import: `cranelift_frontend::FunctionBuilder` + --> src/jit/lower/builder.rs:1249:13 + | +1249 | use cranelift_frontend::FunctionBuilder; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +warning: unused import: `cranelift_frontend::FunctionBuilder` + --> src/jit/lower/builder.rs:1328:13 + | +1328 | use cranelift_frontend::FunctionBuilder; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +warning: unused import: `std::io::Write` + --> src/jit/lower/cfg_dot.rs:2:9 + | +2 | use std::io::Write; + | ^^^^^^^^^^^^^^ + +warning: unused import: `ParamKind` + --> src/semantics/clif_adapter.rs:2:65 + | +2 | use crate::jit::lower::builder::{IRBuilder, BinOpKind, CmpKind, ParamKind}; + | ^^^^^^^^^ + +error[E0599]: no method named `finalize_definitions` found for struct `ObjectModule` in the current scope + --> src/jit/lower/builder/object.rs:79:29 + | +79 | let _ = self.module.finalize_definitions(); + | ^^^^^^^^^^^^^^^^^^^^ method not found in `ObjectModule` + +warning: unused import: `crate::box_trait::NyashBox` + --> src/runtime/plugin_loader_v2.rs:546:21 + | +546 | use crate::box_trait::NyashBox as _; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +warning: unused import: `super` + --> src/jit/lower/builder.rs:136:9 + | +136 | use super::*; + | ^^^^^ + +warning: variable does not need to be mutable + --> src/boxes/aot_compiler_box.rs:34:13 + | +34 | let mut c = cmd.arg("--backend").arg("vm") // ensures runner path + | ----^ + | | + | help: remove this `mut` + | + = note: `#[warn(unused_mut)]` on by default + +warning: variable does not need to be mutable + --> src/boxes/socket_box.rs:218:19 + | +218 | if let Ok(mut guard) = self.listener.write() { + | ----^^^^^ + | | + | help: remove this `mut` + +warning: variable does not need to be mutable + --> src/boxes/socket_box.rs:322:20 + | +322 | Ok(mut stream_clone) => { + | ----^^^^^^^^^^^^ + | | + | help: remove this `mut` + +warning: variable does not need to be mutable + --> src/boxes/p2p_box.rs:109:21 + | +109 | let mut t = InProcessTransport::new(node_id.clone()); + | ----^ + | | + | help: remove this `mut` + +warning: variable does not need to be mutable + --> src/interpreter/core.rs:102:13 + | +102 | let mut this = Self { + | ----^^^^ + | | + | help: remove this `mut` + +warning: variable does not need to be mutable + --> src/interpreter/core.rs:143:13 + | +143 | let mut this = Self { + | ----^^^^ + | | + | help: remove this `mut` + +warning: unused variable: `b` + --> src/interpreter/expressions/builtins.rs:50:31 + | +50 | if let Ok(b) = reg.create_box("MathBox", &[]) { + | ^ help: if this is intentional, prefix it with an underscore: `_b` + | + = note: `#[warn(unused_variables)]` on by default + +warning: variable does not need to be mutable + --> src/interpreter/objects/fields.rs:105:17 + | +105 | let mut is_builtin = is_builtin_box(parent_name); + | ----^^^^^^^^^^ + | | + | help: remove this `mut` + +warning: variable does not need to be mutable + --> src/backend/vm.rs:1059:17 + | +1059 | let mut coerce_num = |b: &Box| -> Box { + | ----^^^^^^^^^^ + | | + | help: remove this `mut` + +warning: value assigned to `class_label` is never read + --> src/backend/vm_instructions.rs:668:21 + | +668 | let mut class_label: Option = None; + | ^^^^^^^^^^^ + | + = help: maybe it is overwritten before being read? + = note: `#[warn(unused_assignments)]` on by default + +warning: unreachable pattern + --> src/backend/vm_values.rs:142:13 + | +100 | (VMValue::BoxRef(li), VMValue::BoxRef(ri)) => { + | ------------------------------------------ matches all the relevant values +... +142 | (VMValue::BoxRef(lb), VMValue::BoxRef(rb)) => { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no value can reach this + | + = note: `#[warn(unreachable_patterns)]` on by default + +warning: variable does not need to be mutable + --> src/jit/lower/core.rs:1044:41 + | +1044 | ... let mut argc = 1usize; + | ----^^^^ + | | + | help: remove this `mut` + +warning: unused variable: `a1` + --> src/jit/lower/builder.rs:513:74 + | +513 | fn nyash_plugin_invoke_name_common_i64(method: &str, argc: i64, a0: i64, a1: i64, a2: i64) -> i64 { + | ^^ help: if this is intentional, prefix it with an underscore: `_a1` + +warning: unused variable: `a2` + --> src/jit/lower/builder.rs:513:83 + | +513 | fn nyash_plugin_invoke_name_common_i64(method: &str, argc: i64, a0: i64, a1: i64, a2: i64) -> i64 { + | ^^ help: if this is intentional, prefix it with an underscore: `_a2` + +warning: variable does not need to be mutable + --> src/jit/lower/builder.rs:758:21 + | +758 | let mut used_b1 = false; + | ----^^^^^^^ + | | + | help: remove this `mut` + +warning: variable does not need to be mutable + --> src/jit/lower/builder.rs:803:29 + | +803 | let mut used_b1 = false; + | ----^^^^^^^ + | | + | help: remove this `mut` + +warning: variable does not need to be mutable + --> src/jit/lower/builder.rs:1059:17 + | +1059 | let mut use_f64 = native_f64 && (lty == types::F64 || rty == types::F64); + | ----^^^^^^^ + | | + | help: remove this `mut` + +warning: unused variable: `arg_types` + --> src/jit/lower/core_hostcall.rs:226:29 + | +226 | ... let arg_types: Vec<&'static str> = observed_kinds.iter().map(|k| match k { ArgKind::I64 => "I64", ArgKind::F64 => "F64", ArgKind::H... + | ^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_arg_types` + +warning: value assigned to `enc_owned` is never read + --> src/runtime/plugin_loader_v2.rs:728:29 + | +728 | let mut enc_owned: Option> = None; + | ^^^^^^^^^ + | + = help: maybe it is overwritten before being read? + +warning: variable does not need to be mutable + --> src/runtime/plugin_loader_v2.rs:1091:13 + | +1091 | let mut cand_a = dir.join(Path::new(&stem).with_extension(cur_ext)); + | ----^^^^^^ + | | + | help: remove this `mut` + +warning: unused variable: `idx` + --> src/runtime/plugin_loader_v2.rs:1210:18 + | +1210 | for (idx, a) in _args.iter().enumerate() { + | ^^^ help: if this is intentional, prefix it with an underscore: `_idx` + +warning: value assigned to `enc_owned` is never read + --> src/runtime/plugin_loader_v2.rs:1213:25 + | +1213 | let mut enc_owned: Option> = None; + | ^^^^^^^^^ + | + = help: maybe it is overwritten before being read? + +For more information about this error, try `rustc --explain E0599`. +warning: `nyash-rust` (lib) generated 80 warnings +error: could not compile `nyash-rust` (lib) due to 1 previous error; 80 warnings emitted diff --git a/logs/archive/errs.txt b/logs/archive/errs.txt new file mode 100644 index 00000000..79dd1191 --- /dev/null +++ b/logs/archive/errs.txt @@ -0,0 +1,15 @@ + Compiling cranelift-codegen v0.103.0 + Compiling cranelift-module v0.103.0 + Compiling cranelift-native v0.103.0 + Compiling cranelift-frontend v0.103.0 + Compiling cranelift-jit v0.103.0 + Compiling cranelift-object v0.103.0 + Compiling nyash-rust v0.1.0 (/mnt/c/git/nyash-project/nyash) +error[E0599]: no method named `finalize_definitions` found for struct `ObjectModule` in the current scope + --> src/jit/lower/builder/object.rs:79:29 + | +79 | let _ = self.module.finalize_definitions(); + | ^^^^^^^^^^^^^^^^^^^^ method not found in `ObjectModule` + +For more information about this error, try `rustc --explain E0599`. +error: could not compile `nyash-rust` (lib) due to 1 previous error diff --git a/logs/archive/mir_math_sqrt.txt b/logs/archive/mir_math_sqrt.txt new file mode 100644 index 00000000..e69de29b diff --git a/logs/archive/mir_min.txt b/logs/archive/mir_min.txt new file mode 100644 index 00000000..6eaf0b7c --- /dev/null +++ b/logs/archive/mir_min.txt @@ -0,0 +1,29 @@ +[PluginLoaderV2] nyash_plugin_init rc=0 for libnyash_map_plugin +[PluginLoaderV2] nyash_plugin_init rc=0 for libnyash_integer_plugin +[FileBox] Plugin initialized +[PluginLoaderV2] nyash_plugin_init rc=0 for libnyash_filebox_plugin +[PluginLoaderV2] nyash_plugin_init rc=0 for libnyash_python_plugin +[PluginLoaderV2] nyash_plugin_init rc=0 for libnyash_array_plugin +[ConsoleBox] Plugin initialized +[PluginLoaderV2] nyash_plugin_init rc=0 for libnyash_console_plugin +Net plugin: LOG_ON=false, LOG_PATH=net_plugin.log +[PluginLoaderV2] nyash_plugin_init rc=0 for libnyash_net_plugin +[PluginLoaderV2] nyash_plugin_init rc=0 for libnyash_math_plugin +[PluginLoaderV2] nyash_plugin_init rc=0 for libnyash_counter_plugin +[PluginLoaderV2] nyash_plugin_init rc=0 for libnyash_string_plugin +🚀 MIR Output for examples/aot_py_eval_env_min.nyash: +; MIR Module: main + +define i64 @main() { +bb0: + 0: safepoint + 1: %2 = new PyRuntimeBox() + 2: plugin_invoke %2.birth() + 3: %3 = plugin_invoke %2.eval() + 4: %4 = const 0 + 5: %5 = new IntegerBox(%4) + 6: plugin_invoke %5.birth(%4) + 7: ret %5 +} + + diff --git a/src/jit/lower/builder.rs b/src/jit/lower/builder.rs index d7b9b57d..4cfddc6a 100644 --- a/src/jit/lower/builder.rs +++ b/src/jit/lower/builder.rs @@ -130,82 +130,13 @@ mod object; #[cfg(feature = "cranelift-jit")] pub use object::ObjectBuilder; -// TLS: 単一関数あたり1つの FunctionBuilder を保持(jit-direct 専用) +// TLS utilities moved to a separate module #[cfg(feature = "cranelift-jit")] -mod clif_tls { - use super::*; - thread_local! { - pub static FB: std::cell::RefCell> = std::cell::RefCell::new(None); - } - pub struct TlsCtx { - pub ctx: Box, - pub fbc: Box, - fb: *mut cranelift_frontend::FunctionBuilder<'static>, - } - impl TlsCtx { - pub fn new() -> Self { - Self { ctx: Box::new(cranelift_codegen::Context::new()), fbc: Box::new(cranelift_frontend::FunctionBuilderContext::new()), fb: core::ptr::null_mut() } - } - pub unsafe fn create(&mut self) { - let func_ptr: *mut cranelift_codegen::ir::Function = &mut self.ctx.func; - let fbc_ptr: *mut cranelift_frontend::FunctionBuilderContext = &mut *self.fbc; - let fb = Box::new(cranelift_frontend::FunctionBuilder::new(&mut *func_ptr, &mut *fbc_ptr)); - self.fb = Box::into_raw(fb); - } - pub fn with(&mut self, f: impl FnOnce(&mut cranelift_frontend::FunctionBuilder<'static>) -> R) -> R { - unsafe { f(&mut *self.fb) } - } - pub unsafe fn finalize_drop(&mut self) { - if !self.fb.is_null() { - let fb = Box::from_raw(self.fb); - fb.finalize(); - self.fb = core::ptr::null_mut(); - } - } - } -} - -// Small TLS helpers to call imported functions via the single FunctionBuilder +mod tls; #[cfg(feature = "cranelift-jit")] -fn tls_call_import_ret( - module: &mut cranelift_jit::JITModule, - func_id: cranelift_module::FuncId, - args: &[cranelift_codegen::ir::Value], - has_ret: bool, -) -> Option { - clif_tls::FB.with(|cell| { - let mut opt = cell.borrow_mut(); - let tls = opt.as_mut().expect("FunctionBuilder TLS not initialized"); - tls.with(|fb| { - let fref = module.declare_func_in_func(func_id, fb.func); - let call_inst = fb.ins().call(fref, args); - if has_ret { fb.inst_results(call_inst).get(0).copied() } else { None } - }) - }) -} - +pub(crate) use tls::clif_tls; #[cfg(feature = "cranelift-jit")] -fn tls_call_import_with_iconsts( - module: &mut cranelift_jit::JITModule, - func_id: cranelift_module::FuncId, - iconsts: &[i64], - tail_args: &[cranelift_codegen::ir::Value], - has_ret: bool, -) -> Option { - use cranelift_codegen::ir::types; - clif_tls::FB.with(|cell| { - let mut opt = cell.borrow_mut(); - let tls = opt.as_mut().expect("FunctionBuilder TLS not initialized"); - tls.with(|fb| { - let mut all_args: Vec = Vec::new(); - for &c in iconsts { all_args.push(fb.ins().iconst(types::I64, c)); } - all_args.extend_from_slice(tail_args); - let fref = module.declare_func_in_func(func_id, fb.func); - let call_inst = fb.ins().call(fref, &all_args); - if has_ret { fb.inst_results(call_inst).get(0).copied() } else { None } - }) - }) -} +use tls::{tls_call_import_ret, tls_call_import_with_iconsts}; #[cfg(feature = "cranelift-jit")] use self::rt_shims::{nyash_host_stub0, nyash_jit_dbg_i64, nyash_jit_block_enter, nyash_plugin_invoke3_i64, nyash_plugin_invoke3_f64, nyash_plugin_invoke_name_getattr_i64, nyash_plugin_invoke_name_call_i64}; diff --git a/src/jit/lower/builder/tls.rs b/src/jit/lower/builder/tls.rs new file mode 100644 index 00000000..336c93b1 --- /dev/null +++ b/src/jit/lower/builder/tls.rs @@ -0,0 +1,78 @@ +#![cfg(feature = "cranelift-jit")] + +use cranelift_module::Module; +use cranelift_codegen::ir::InstBuilder; + +// TLS: 単一関数あたり1つの FunctionBuilder を保持(jit-direct 専用) +pub(crate) mod clif_tls { + use super::*; + thread_local! { + pub static FB: std::cell::RefCell> = std::cell::RefCell::new(None); + } + pub struct TlsCtx { + pub ctx: Box, + pub fbc: Box, + pub(crate) fb: *mut cranelift_frontend::FunctionBuilder<'static>, + } + impl TlsCtx { + pub fn new() -> Self { + Self { ctx: Box::new(cranelift_codegen::Context::new()), fbc: Box::new(cranelift_frontend::FunctionBuilderContext::new()), fb: core::ptr::null_mut() } + } + pub unsafe fn create(&mut self) { + let func_ptr: *mut cranelift_codegen::ir::Function = &mut self.ctx.func; + let fbc_ptr: *mut cranelift_frontend::FunctionBuilderContext = &mut *self.fbc; + let fb = Box::new(cranelift_frontend::FunctionBuilder::new(&mut *func_ptr, &mut *fbc_ptr)); + self.fb = Box::into_raw(fb); + } + pub fn with(&mut self, f: impl FnOnce(&mut cranelift_frontend::FunctionBuilder<'static>) -> R) -> R { + unsafe { f(&mut *self.fb) } + } + pub unsafe fn finalize_drop(&mut self) { + if !self.fb.is_null() { + let fb = Box::from_raw(self.fb); + fb.finalize(); + self.fb = core::ptr::null_mut(); + } + } + } +} + +// Small TLS helpers to call imported functions via the single FunctionBuilder +pub(crate) fn tls_call_import_ret( + module: &mut cranelift_jit::JITModule, + func_id: cranelift_module::FuncId, + args: &[cranelift_codegen::ir::Value], + has_ret: bool, +) -> Option { + clif_tls::FB.with(|cell| { + let mut opt = cell.borrow_mut(); + let tls = opt.as_mut().expect("FunctionBuilder TLS not initialized"); + tls.with(|fb| { + let fref = module.declare_func_in_func(func_id, fb.func); + let call_inst = fb.ins().call(fref, args); + if has_ret { fb.inst_results(call_inst).get(0).copied() } else { None } + }) + }) +} + +pub(crate) fn tls_call_import_with_iconsts( + module: &mut cranelift_jit::JITModule, + func_id: cranelift_module::FuncId, + iconsts: &[i64], + tail_args: &[cranelift_codegen::ir::Value], + has_ret: bool, +) -> Option { + use cranelift_codegen::ir::types; + clif_tls::FB.with(|cell| { + let mut opt = cell.borrow_mut(); + let tls = opt.as_mut().expect("FunctionBuilder TLS not initialized"); + tls.with(|fb| { + let mut all_args: Vec = Vec::new(); + for &c in iconsts { all_args.push(fb.ins().iconst(types::I64, c)); } + all_args.extend_from_slice(tail_args); + let fref = module.declare_func_in_func(func_id, fb.func); + let call_inst = fb.ins().call(fref, &all_args); + if has_ret { fb.inst_results(call_inst).get(0).copied() } else { None } + }) + }) +} diff --git a/string_len_app b/string_len_app deleted file mode 100644 index fca8dcd4..00000000 Binary files a/string_len_app and /dev/null differ diff --git a/build_clean_aot.bat b/tools/windows/llvm-build-attempts/build_clean_aot.bat similarity index 100% rename from build_clean_aot.bat rename to tools/windows/llvm-build-attempts/build_clean_aot.bat diff --git a/build_llvm_clean.bat b/tools/windows/llvm-build-attempts/build_llvm_clean.bat similarity index 100% rename from build_llvm_clean.bat rename to tools/windows/llvm-build-attempts/build_llvm_clean.bat diff --git a/build_llvm_simple.bat b/tools/windows/llvm-build-attempts/build_llvm_simple.bat similarity index 100% rename from build_llvm_simple.bat rename to tools/windows/llvm-build-attempts/build_llvm_simple.bat diff --git a/build_llvm_windows.bat b/tools/windows/llvm-build-attempts/build_llvm_windows.bat similarity index 100% rename from build_llvm_windows.bat rename to tools/windows/llvm-build-attempts/build_llvm_windows.bat diff --git a/build_nyash_exe.bat b/tools/windows/llvm-build-attempts/build_nyash_exe.bat similarity index 100% rename from build_nyash_exe.bat rename to tools/windows/llvm-build-attempts/build_nyash_exe.bat diff --git a/build_win_aot.bat b/tools/windows/llvm-build-attempts/build_win_aot.bat similarity index 100% rename from build_win_aot.bat rename to tools/windows/llvm-build-attempts/build_win_aot.bat diff --git a/build_win_env_and_build.bat b/tools/windows/llvm-build-attempts/build_win_env_and_build.bat similarity index 100% rename from build_win_env_and_build.bat rename to tools/windows/llvm-build-attempts/build_win_env_and_build.bat diff --git a/build_win_llvm.bat b/tools/windows/llvm-build-attempts/build_win_llvm.bat similarity index 100% rename from build_win_llvm.bat rename to tools/windows/llvm-build-attempts/build_win_llvm.bat diff --git a/build_windows_llvm.bat b/tools/windows/llvm-build-attempts/build_windows_llvm.bat similarity index 100% rename from build_windows_llvm.bat rename to tools/windows/llvm-build-attempts/build_windows_llvm.bat diff --git a/build_windows_with_llvm.bat b/tools/windows/llvm-build-attempts/build_windows_with_llvm.bat similarity index 100% rename from build_windows_with_llvm.bat rename to tools/windows/llvm-build-attempts/build_windows_with_llvm.bat diff --git a/build_with_existing_llvm.bat b/tools/windows/llvm-build-attempts/build_with_existing_llvm.bat similarity index 100% rename from build_with_existing_llvm.bat rename to tools/windows/llvm-build-attempts/build_with_existing_llvm.bat diff --git a/build_with_setx.bat b/tools/windows/llvm-build-attempts/build_with_setx.bat similarity index 100% rename from build_with_setx.bat rename to tools/windows/llvm-build-attempts/build_with_setx.bat diff --git a/check_build.bat b/tools/windows/llvm-build-attempts/check_build.bat similarity index 100% rename from check_build.bat rename to tools/windows/llvm-build-attempts/check_build.bat diff --git a/check_llvm_env.bat b/tools/windows/llvm-build-attempts/check_llvm_env.bat similarity index 100% rename from check_llvm_env.bat rename to tools/windows/llvm-build-attempts/check_llvm_env.bat diff --git a/create_dummy_ffi.bat b/tools/windows/llvm-build-attempts/create_dummy_ffi.bat similarity index 100% rename from create_dummy_ffi.bat rename to tools/windows/llvm-build-attempts/create_dummy_ffi.bat diff --git a/install_libffi.bat b/tools/windows/llvm-build-attempts/install_libffi.bat similarity index 100% rename from install_libffi.bat rename to tools/windows/llvm-build-attempts/install_libffi.bat diff --git a/install_llvm_and_build.bat b/tools/windows/llvm-build-attempts/install_llvm_and_build.bat similarity index 100% rename from install_llvm_and_build.bat rename to tools/windows/llvm-build-attempts/install_llvm_and_build.bat diff --git a/install_vcpkg_llvm.bat b/tools/windows/llvm-build-attempts/install_vcpkg_llvm.bat similarity index 100% rename from install_vcpkg_llvm.bat rename to tools/windows/llvm-build-attempts/install_vcpkg_llvm.bat diff --git a/run_build_aot.bat b/tools/windows/llvm-build-attempts/run_build_aot.bat similarity index 100% rename from run_build_aot.bat rename to tools/windows/llvm-build-attempts/run_build_aot.bat diff --git a/set_env_and_build.bat b/tools/windows/llvm-build-attempts/set_env_and_build.bat similarity index 100% rename from set_env_and_build.bat rename to tools/windows/llvm-build-attempts/set_env_and_build.bat diff --git a/set_system_env.bat b/tools/windows/llvm-build-attempts/set_system_env.bat similarity index 100% rename from set_system_env.bat rename to tools/windows/llvm-build-attempts/set_system_env.bat