fix: Replace static mut with Lazy for thread safety in FileBoxRegistry

- Eliminate static_mut_refs warnings by using once_cell::sync::Lazy
- Make FileMode enum public to fix private_interfaces warning
- Reduce warnings from 6 to 3
- Prepare for Rust 2024 edition compatibility
This commit is contained in:
Moe Charm
2025-08-21 12:14:33 +09:00
parent 11c8672252
commit 4f360e0fbb
16 changed files with 38 additions and 43 deletions

Binary file not shown.

View File

@ -6,7 +6,7 @@
*/
use super::vm::{VMValue, VMError};
use crate::mir::{BasicBlockId, ValueId, MirInstruction};
use crate::mir::{BasicBlockId, ValueId};
use std::collections::HashMap;
/// Phi nodeの実行ヘルパー
@ -45,7 +45,7 @@ impl PhiHandler {
/// Phi命令を実行
pub fn execute_phi(
&mut self,
dst: ValueId,
_dst: ValueId,
inputs: &[(BasicBlockId, ValueId)],
get_value_fn: impl Fn(ValueId) -> Result<VMValue, VMError>,
) -> Result<VMValue, VMError> {

View File

@ -2,8 +2,6 @@
mod plugin_impl {
use crate::bid::{BidError, BidResult, LoadedPlugin};
use crate::bid::tlv::{TlvEncoder, TlvDecoder};
use crate::bid::types::BidTag;
use crate::box_trait::{NyashBox, StringBox, BoolBox, BoxCore, BoxBase};
use std::any::Any;
use std::fmt;

View File

@ -1,7 +1,6 @@
use crate::bid::{BidError, BidResult, NyashHostVtable, NyashPluginInfo, PluginHandle, PLUGIN_ABI_SYMBOL, PLUGIN_INIT_SYMBOL, PLUGIN_INVOKE_SYMBOL, PLUGIN_SHUTDOWN_SYMBOL};
#[cfg(all(feature = "plugins", not(target_arch = "wasm32")))]
use libloading::{Library, Symbol};
use std::ffi::c_void;
use std::path::{Path, PathBuf};
/// Loaded plugin with FFI entry points and metadata

View File

@ -145,7 +145,9 @@ pub struct PluginMetadata {
pub state: PluginState,
// Keep CStrings alive for C interop
#[allow(dead_code)]
type_name_holder: Option<CString>,
#[allow(dead_code)]
method_holders: Vec<(NyashMethodInfo, CString)>,
}

View File

@ -1,5 +1,4 @@
use super::{BidError, BidResult, NyashHostVtable, NyashPluginInfo};
use std::os::raw::c_char;
/// Plugin API function signatures for C FFI
///
@ -164,7 +163,7 @@ impl HostVtableBuilder {
}
}
pub fn with_alloc<F>(mut self, f: F) -> Self
pub fn with_alloc<F>(self, _f: F) -> Self
where
F: Fn(usize) -> *mut std::os::raw::c_void + 'static,
{
@ -173,14 +172,14 @@ impl HostVtableBuilder {
self
}
pub fn with_free<F>(mut self, f: F) -> Self
pub fn with_free<F>(self, _f: F) -> Self
where
F: Fn(*mut std::os::raw::c_void) + 'static,
{
self
}
pub fn with_log<F>(mut self, f: F) -> Self
pub fn with_log<F>(self, _f: F) -> Self
where
F: Fn(&str) + 'static,
{

View File

@ -4,13 +4,11 @@
//! Everything is Box philosophy applied to file operations!
use crate::bid::{BidHandle, BoxTypeId};
use crate::bid::{NyashPluginInfo, NyashMethodInfo, NyashHostVtable};
use once_cell::sync::Lazy;
use std::collections::HashMap;
use std::fs::{File, OpenOptions};
use std::io::{Read, Write, Seek, SeekFrom};
use std::os::raw::{c_char, c_void};
use std::io::{Read, Write};
use std::sync::{Arc, Mutex};
use std::ffi::{CStr, CString};
/// FileBox handle management
pub struct FileBoxRegistry {
@ -21,12 +19,14 @@ pub struct FileBoxRegistry {
/// State of an open file
struct FileBoxState {
file: File,
#[allow(dead_code)]
path: String,
#[allow(dead_code)]
mode: FileMode,
}
#[derive(Debug, Clone, Copy)]
enum FileMode {
pub enum FileMode {
Read,
Write,
Append,
@ -94,16 +94,12 @@ impl FileBoxRegistry {
}
/// Global registry instance
static mut FILEBOX_REGISTRY: Option<Arc<Mutex<FileBoxRegistry>>> = None;
static FILEBOX_REGISTRY: Lazy<Arc<Mutex<FileBoxRegistry>>> =
Lazy::new(|| Arc::new(Mutex::new(FileBoxRegistry::new())));
/// Get or create the global registry
fn get_registry() -> Arc<Mutex<FileBoxRegistry>> {
unsafe {
if FILEBOX_REGISTRY.is_none() {
FILEBOX_REGISTRY = Some(Arc::new(Mutex::new(FileBoxRegistry::new())));
}
FILEBOX_REGISTRY.as_ref().unwrap().clone()
}
FILEBOX_REGISTRY.clone()
}
/// FileBox plugin interface for Nyash

View File

@ -1,5 +1,3 @@
use super::Usize;
/// BID-1 Type System (ChatGPT Enhanced Edition)
#[derive(Clone, Debug, PartialEq)]
pub enum BidType {

View File

@ -50,7 +50,7 @@ impl BoxFactory for PluginBoxFactory {
fn is_available(&self) -> bool {
// Check if any plugins are loaded
let registry = get_global_registry();
let _registry = get_global_registry();
// TODO: Add method to check if registry has any providers
true
}

View File

@ -144,7 +144,7 @@ impl InstanceBox {
}
/// 🎯 統一初期化処理
pub fn init(&mut self, args: &[Box<dyn NyashBox>]) -> Result<(), String> {
pub fn init(&mut self, _args: &[Box<dyn NyashBox>]) -> Result<(), String> {
match &self.inner_content {
Some(_) => Ok(()), // ビルトイン・プラグインは初期化済み
None => {
@ -286,7 +286,7 @@ impl InstanceBox {
}
// fields_ngから取得して変換を試みる
if let Some(nyash_value) = self.fields_ng.lock().unwrap().get(field_name) {
if let Some(_nyash_value) = self.fields_ng.lock().unwrap().get(field_name) {
// NyashValue -> SharedNyashBox 変換(簡易実装)
// TODO: 適切な変換実装
None

View File

@ -225,6 +225,7 @@ pub struct NyashInterpreter {
pub(super) stdlib: Option<BuiltinStdlib>,
/// 共有ランタイムBoxレジストリ等
#[allow(dead_code)]
pub(super) runtime: NyashRuntime,
}

View File

@ -1127,7 +1127,7 @@ impl NyashInterpreter {
// 🔥 Phase 8.8: pack透明化システム - ビルトインBox判定
use crate::box_trait::is_builtin_box;
let mut is_builtin = is_builtin_box(parent_name);
let is_builtin = is_builtin_box(parent_name);
// GUI機能が有効な場合はEguiBoxも追加判定
#[cfg(all(feature = "gui", not(target_arch = "wasm32")))]

View File

@ -92,7 +92,7 @@ impl MirBuilder {
effects: EffectMask::READ.add(Effect::ReadHeap), // conservative
};
let entry = self.block_gen.next();
let mut function = MirFunction::new(signature, entry);
let function = MirFunction::new(signature, entry);
// Save current builder state
let saved_function = self.current_function.take();

View File

@ -6,11 +6,11 @@
*/
use super::{
MirInstruction, BasicBlock, BasicBlockId, MirFunction, ValueId,
ConstValue, CompareOp, BasicBlockIdGenerator, ValueIdGenerator, EffectMask
MirInstruction, BasicBlockId, ValueId,
ConstValue
};
use crate::ast::ASTNode;
use std::collections::{HashMap, HashSet};
use std::collections::HashMap;
/// 不完全なPhi nodeの情報
#[derive(Debug, Clone)]
@ -32,6 +32,7 @@ pub struct LoopBuilder<'a> {
incomplete_phis: HashMap<BasicBlockId, Vec<IncompletePhi>>,
/// ブロックごとの変数マップ(スコープ管理)
#[allow(dead_code)]
block_var_maps: HashMap<BasicBlockId, HashMap<String, ValueId>>,
}
@ -59,11 +60,11 @@ impl<'a> LoopBuilder<'a> {
// 2. Preheader -> Header へのジャンプ
self.emit_jump(header_id)?;
self.add_predecessor(header_id, preheader_id);
let _ = self.add_predecessor(header_id, preheader_id);
// 3. Headerブロックの準備unsealed状態
self.set_current_block(header_id)?;
self.mark_block_unsealed(header_id);
let _ = self.mark_block_unsealed(header_id);
// 4. ループ変数のPhi nodeを準備
// ここでは、ループ内で変更される可能性のある変数を事前に検出するか、
@ -75,8 +76,8 @@ impl<'a> LoopBuilder<'a> {
// 6. 条件分岐
self.emit_branch(condition_value, body_id, after_loop_id)?;
self.add_predecessor(body_id, header_id);
self.add_predecessor(after_loop_id, header_id);
let _ = self.add_predecessor(body_id, header_id);
let _ = self.add_predecessor(after_loop_id, header_id);
// 7. ループボディの構築
self.set_current_block(body_id)?;
@ -90,7 +91,7 @@ impl<'a> LoopBuilder<'a> {
// 8. Latchブロックボディの最後からHeaderへ戻る
let latch_id = self.current_block()?;
self.emit_jump(header_id)?;
self.add_predecessor(header_id, latch_id);
let _ = self.add_predecessor(header_id, latch_id);
// 9. Headerブロックをシール全predecessors確定
self.seal_block(header_id, latch_id)?;
@ -243,7 +244,7 @@ impl<'a> LoopBuilder<'a> {
}
}
fn mark_block_unsealed(&mut self, block_id: BasicBlockId) -> Result<(), String> {
fn mark_block_unsealed(&mut self, _block_id: BasicBlockId) -> Result<(), String> {
// ブロックはデフォルトでunsealedなので、特に何もしない
// 既にBasicBlock::newでsealed: falseに初期化されている
Ok(())
@ -270,7 +271,7 @@ impl<'a> LoopBuilder<'a> {
self.parent_builder.variable_map.insert(name, value);
}
fn get_variable_at_block(&self, name: &str, block_id: BasicBlockId) -> Option<ValueId> {
fn get_variable_at_block(&self, name: &str, _block_id: BasicBlockId) -> Option<ValueId> {
// 簡易実装:現在の変数マップから取得
// TODO: 本来はブロックごとの変数マップを管理すべき
self.parent_builder.variable_map.get(name).copied()

View File

@ -19,8 +19,7 @@ use nyash_rust::runtime::NyashRuntime;
use nyash_rust::interpreter::SharedState;
use nyash_rust::box_factory::user_defined::UserDefinedBoxFactory;
use nyash_rust::core::model::BoxDeclaration as CoreBoxDecl;
use std::sync::{Arc, RwLock};
use std::collections::HashMap;
use std::sync::Arc;
#[cfg(feature = "wasm-backend")]
use nyash_rust::backend::{wasm::WasmBackend, aot::AotBackend};
@ -289,7 +288,7 @@ impl NyashRunner {
// Dump MIR if requested
if self.config.dump_mir {
let mut printer = if self.config.mir_verbose {
let printer = if self.config.mir_verbose {
MirPrinter::verbose()
} else {
MirPrinter::new()

View File

@ -7,7 +7,7 @@
#[cfg(all(feature = "plugins", not(target_arch = "wasm32")))]
mod enabled {
use crate::bid::{BidResult, BidError};
use crate::box_trait::{NyashBox, BoxCore, BoxBase, StringBox, IntegerBox, BoolBox};
use crate::box_trait::{NyashBox, BoxCore, StringBox, IntegerBox};
use crate::config::nyash_toml_v2::{NyashConfigV2, LibraryDefinition};
use std::collections::HashMap;
use std::sync::{Arc, RwLock};
@ -21,9 +21,11 @@ mod enabled {
_lib: Arc<libloading::Library>,
/// Box types provided by this plugin
#[allow(dead_code)]
box_types: Vec<String>,
/// Optional init function
#[allow(dead_code)]
init_fn: Option<unsafe extern "C" fn() -> i32>,
/// Required invoke function
@ -521,7 +523,7 @@ impl PluginBoxV2 {
}
/// Create a Box instance
pub fn create_box(&self, box_type: &str, args: &[Box<dyn NyashBox>]) -> BidResult<Box<dyn NyashBox>> {
pub fn create_box(&self, box_type: &str, _args: &[Box<dyn NyashBox>]) -> BidResult<Box<dyn NyashBox>> {
eprintln!("🔍 create_box called for: {}", box_type);
let config = self.config.as_ref()