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:
Binary file not shown.
@ -6,7 +6,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
use super::vm::{VMValue, VMError};
|
use super::vm::{VMValue, VMError};
|
||||||
use crate::mir::{BasicBlockId, ValueId, MirInstruction};
|
use crate::mir::{BasicBlockId, ValueId};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
/// Phi nodeの実行ヘルパー
|
/// Phi nodeの実行ヘルパー
|
||||||
@ -45,7 +45,7 @@ impl PhiHandler {
|
|||||||
/// Phi命令を実行
|
/// Phi命令を実行
|
||||||
pub fn execute_phi(
|
pub fn execute_phi(
|
||||||
&mut self,
|
&mut self,
|
||||||
dst: ValueId,
|
_dst: ValueId,
|
||||||
inputs: &[(BasicBlockId, ValueId)],
|
inputs: &[(BasicBlockId, ValueId)],
|
||||||
get_value_fn: impl Fn(ValueId) -> Result<VMValue, VMError>,
|
get_value_fn: impl Fn(ValueId) -> Result<VMValue, VMError>,
|
||||||
) -> Result<VMValue, VMError> {
|
) -> Result<VMValue, VMError> {
|
||||||
|
|||||||
@ -2,8 +2,6 @@
|
|||||||
mod plugin_impl {
|
mod plugin_impl {
|
||||||
|
|
||||||
use crate::bid::{BidError, BidResult, LoadedPlugin};
|
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 crate::box_trait::{NyashBox, StringBox, BoolBox, BoxCore, BoxBase};
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
use crate::bid::{BidError, BidResult, NyashHostVtable, NyashPluginInfo, PluginHandle, PLUGIN_ABI_SYMBOL, PLUGIN_INIT_SYMBOL, PLUGIN_INVOKE_SYMBOL, PLUGIN_SHUTDOWN_SYMBOL};
|
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")))]
|
#[cfg(all(feature = "plugins", not(target_arch = "wasm32")))]
|
||||||
use libloading::{Library, Symbol};
|
use libloading::{Library, Symbol};
|
||||||
use std::ffi::c_void;
|
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
/// Loaded plugin with FFI entry points and metadata
|
/// Loaded plugin with FFI entry points and metadata
|
||||||
|
|||||||
@ -145,7 +145,9 @@ pub struct PluginMetadata {
|
|||||||
pub state: PluginState,
|
pub state: PluginState,
|
||||||
|
|
||||||
// Keep CStrings alive for C interop
|
// Keep CStrings alive for C interop
|
||||||
|
#[allow(dead_code)]
|
||||||
type_name_holder: Option<CString>,
|
type_name_holder: Option<CString>,
|
||||||
|
#[allow(dead_code)]
|
||||||
method_holders: Vec<(NyashMethodInfo, CString)>,
|
method_holders: Vec<(NyashMethodInfo, CString)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
use super::{BidError, BidResult, NyashHostVtable, NyashPluginInfo};
|
use super::{BidError, BidResult, NyashHostVtable, NyashPluginInfo};
|
||||||
use std::os::raw::c_char;
|
|
||||||
|
|
||||||
/// Plugin API function signatures for C FFI
|
/// 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
|
where
|
||||||
F: Fn(usize) -> *mut std::os::raw::c_void + 'static,
|
F: Fn(usize) -> *mut std::os::raw::c_void + 'static,
|
||||||
{
|
{
|
||||||
@ -173,14 +172,14 @@ impl HostVtableBuilder {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_free<F>(mut self, f: F) -> Self
|
pub fn with_free<F>(self, _f: F) -> Self
|
||||||
where
|
where
|
||||||
F: Fn(*mut std::os::raw::c_void) + 'static,
|
F: Fn(*mut std::os::raw::c_void) + 'static,
|
||||||
{
|
{
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_log<F>(mut self, f: F) -> Self
|
pub fn with_log<F>(self, _f: F) -> Self
|
||||||
where
|
where
|
||||||
F: Fn(&str) + 'static,
|
F: Fn(&str) + 'static,
|
||||||
{
|
{
|
||||||
|
|||||||
@ -4,13 +4,11 @@
|
|||||||
//! Everything is Box philosophy applied to file operations!
|
//! Everything is Box philosophy applied to file operations!
|
||||||
|
|
||||||
use crate::bid::{BidHandle, BoxTypeId};
|
use crate::bid::{BidHandle, BoxTypeId};
|
||||||
use crate::bid::{NyashPluginInfo, NyashMethodInfo, NyashHostVtable};
|
use once_cell::sync::Lazy;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::fs::{File, OpenOptions};
|
use std::fs::{File, OpenOptions};
|
||||||
use std::io::{Read, Write, Seek, SeekFrom};
|
use std::io::{Read, Write};
|
||||||
use std::os::raw::{c_char, c_void};
|
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use std::ffi::{CStr, CString};
|
|
||||||
|
|
||||||
/// FileBox handle management
|
/// FileBox handle management
|
||||||
pub struct FileBoxRegistry {
|
pub struct FileBoxRegistry {
|
||||||
@ -21,12 +19,14 @@ pub struct FileBoxRegistry {
|
|||||||
/// State of an open file
|
/// State of an open file
|
||||||
struct FileBoxState {
|
struct FileBoxState {
|
||||||
file: File,
|
file: File,
|
||||||
|
#[allow(dead_code)]
|
||||||
path: String,
|
path: String,
|
||||||
|
#[allow(dead_code)]
|
||||||
mode: FileMode,
|
mode: FileMode,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
enum FileMode {
|
pub enum FileMode {
|
||||||
Read,
|
Read,
|
||||||
Write,
|
Write,
|
||||||
Append,
|
Append,
|
||||||
@ -94,16 +94,12 @@ impl FileBoxRegistry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Global registry instance
|
/// 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
|
/// Get or create the global registry
|
||||||
fn get_registry() -> Arc<Mutex<FileBoxRegistry>> {
|
fn get_registry() -> Arc<Mutex<FileBoxRegistry>> {
|
||||||
unsafe {
|
FILEBOX_REGISTRY.clone()
|
||||||
if FILEBOX_REGISTRY.is_none() {
|
|
||||||
FILEBOX_REGISTRY = Some(Arc::new(Mutex::new(FileBoxRegistry::new())));
|
|
||||||
}
|
|
||||||
FILEBOX_REGISTRY.as_ref().unwrap().clone()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// FileBox plugin interface for Nyash
|
/// FileBox plugin interface for Nyash
|
||||||
|
|||||||
@ -1,5 +1,3 @@
|
|||||||
use super::Usize;
|
|
||||||
|
|
||||||
/// BID-1 Type System (ChatGPT Enhanced Edition)
|
/// BID-1 Type System (ChatGPT Enhanced Edition)
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub enum BidType {
|
pub enum BidType {
|
||||||
|
|||||||
@ -50,7 +50,7 @@ impl BoxFactory for PluginBoxFactory {
|
|||||||
|
|
||||||
fn is_available(&self) -> bool {
|
fn is_available(&self) -> bool {
|
||||||
// Check if any plugins are loaded
|
// 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
|
// TODO: Add method to check if registry has any providers
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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 {
|
match &self.inner_content {
|
||||||
Some(_) => Ok(()), // ビルトイン・プラグインは初期化済み
|
Some(_) => Ok(()), // ビルトイン・プラグインは初期化済み
|
||||||
None => {
|
None => {
|
||||||
@ -286,7 +286,7 @@ impl InstanceBox {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// fields_ngから取得して変換を試みる
|
// 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 変換(簡易実装)
|
// NyashValue -> SharedNyashBox 変換(簡易実装)
|
||||||
// TODO: 適切な変換実装
|
// TODO: 適切な変換実装
|
||||||
None
|
None
|
||||||
|
|||||||
@ -225,6 +225,7 @@ pub struct NyashInterpreter {
|
|||||||
pub(super) stdlib: Option<BuiltinStdlib>,
|
pub(super) stdlib: Option<BuiltinStdlib>,
|
||||||
|
|
||||||
/// 共有ランタイム(Boxレジストリ等)
|
/// 共有ランタイム(Boxレジストリ等)
|
||||||
|
#[allow(dead_code)]
|
||||||
pub(super) runtime: NyashRuntime,
|
pub(super) runtime: NyashRuntime,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1127,7 +1127,7 @@ impl NyashInterpreter {
|
|||||||
// 🔥 Phase 8.8: pack透明化システム - ビルトインBox判定
|
// 🔥 Phase 8.8: pack透明化システム - ビルトインBox判定
|
||||||
use crate::box_trait::is_builtin_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も追加判定
|
// GUI機能が有効な場合はEguiBoxも追加判定
|
||||||
#[cfg(all(feature = "gui", not(target_arch = "wasm32")))]
|
#[cfg(all(feature = "gui", not(target_arch = "wasm32")))]
|
||||||
|
|||||||
@ -92,7 +92,7 @@ impl MirBuilder {
|
|||||||
effects: EffectMask::READ.add(Effect::ReadHeap), // conservative
|
effects: EffectMask::READ.add(Effect::ReadHeap), // conservative
|
||||||
};
|
};
|
||||||
let entry = self.block_gen.next();
|
let entry = self.block_gen.next();
|
||||||
let mut function = MirFunction::new(signature, entry);
|
let function = MirFunction::new(signature, entry);
|
||||||
|
|
||||||
// Save current builder state
|
// Save current builder state
|
||||||
let saved_function = self.current_function.take();
|
let saved_function = self.current_function.take();
|
||||||
|
|||||||
@ -6,11 +6,11 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
MirInstruction, BasicBlock, BasicBlockId, MirFunction, ValueId,
|
MirInstruction, BasicBlockId, ValueId,
|
||||||
ConstValue, CompareOp, BasicBlockIdGenerator, ValueIdGenerator, EffectMask
|
ConstValue
|
||||||
};
|
};
|
||||||
use crate::ast::ASTNode;
|
use crate::ast::ASTNode;
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::HashMap;
|
||||||
|
|
||||||
/// 不完全なPhi nodeの情報
|
/// 不完全なPhi nodeの情報
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
@ -32,6 +32,7 @@ pub struct LoopBuilder<'a> {
|
|||||||
incomplete_phis: HashMap<BasicBlockId, Vec<IncompletePhi>>,
|
incomplete_phis: HashMap<BasicBlockId, Vec<IncompletePhi>>,
|
||||||
|
|
||||||
/// ブロックごとの変数マップ(スコープ管理)
|
/// ブロックごとの変数マップ(スコープ管理)
|
||||||
|
#[allow(dead_code)]
|
||||||
block_var_maps: HashMap<BasicBlockId, HashMap<String, ValueId>>,
|
block_var_maps: HashMap<BasicBlockId, HashMap<String, ValueId>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,11 +60,11 @@ impl<'a> LoopBuilder<'a> {
|
|||||||
|
|
||||||
// 2. Preheader -> Header へのジャンプ
|
// 2. Preheader -> Header へのジャンプ
|
||||||
self.emit_jump(header_id)?;
|
self.emit_jump(header_id)?;
|
||||||
self.add_predecessor(header_id, preheader_id);
|
let _ = self.add_predecessor(header_id, preheader_id);
|
||||||
|
|
||||||
// 3. Headerブロックの準備(unsealed状態)
|
// 3. Headerブロックの準備(unsealed状態)
|
||||||
self.set_current_block(header_id)?;
|
self.set_current_block(header_id)?;
|
||||||
self.mark_block_unsealed(header_id);
|
let _ = self.mark_block_unsealed(header_id);
|
||||||
|
|
||||||
// 4. ループ変数のPhi nodeを準備
|
// 4. ループ変数のPhi nodeを準備
|
||||||
// ここでは、ループ内で変更される可能性のある変数を事前に検出するか、
|
// ここでは、ループ内で変更される可能性のある変数を事前に検出するか、
|
||||||
@ -75,8 +76,8 @@ impl<'a> LoopBuilder<'a> {
|
|||||||
|
|
||||||
// 6. 条件分岐
|
// 6. 条件分岐
|
||||||
self.emit_branch(condition_value, body_id, after_loop_id)?;
|
self.emit_branch(condition_value, body_id, after_loop_id)?;
|
||||||
self.add_predecessor(body_id, header_id);
|
let _ = self.add_predecessor(body_id, header_id);
|
||||||
self.add_predecessor(after_loop_id, header_id);
|
let _ = self.add_predecessor(after_loop_id, header_id);
|
||||||
|
|
||||||
// 7. ループボディの構築
|
// 7. ループボディの構築
|
||||||
self.set_current_block(body_id)?;
|
self.set_current_block(body_id)?;
|
||||||
@ -90,7 +91,7 @@ impl<'a> LoopBuilder<'a> {
|
|||||||
// 8. Latchブロック(ボディの最後)からHeaderへ戻る
|
// 8. Latchブロック(ボディの最後)からHeaderへ戻る
|
||||||
let latch_id = self.current_block()?;
|
let latch_id = self.current_block()?;
|
||||||
self.emit_jump(header_id)?;
|
self.emit_jump(header_id)?;
|
||||||
self.add_predecessor(header_id, latch_id);
|
let _ = self.add_predecessor(header_id, latch_id);
|
||||||
|
|
||||||
// 9. Headerブロックをシール(全predecessors確定)
|
// 9. Headerブロックをシール(全predecessors確定)
|
||||||
self.seal_block(header_id, latch_id)?;
|
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なので、特に何もしない
|
// ブロックはデフォルトでunsealedなので、特に何もしない
|
||||||
// (既にBasicBlock::newでsealed: falseに初期化されている)
|
// (既にBasicBlock::newでsealed: falseに初期化されている)
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -270,7 +271,7 @@ impl<'a> LoopBuilder<'a> {
|
|||||||
self.parent_builder.variable_map.insert(name, value);
|
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: 本来はブロックごとの変数マップを管理すべき
|
// TODO: 本来はブロックごとの変数マップを管理すべき
|
||||||
self.parent_builder.variable_map.get(name).copied()
|
self.parent_builder.variable_map.get(name).copied()
|
||||||
|
|||||||
@ -19,8 +19,7 @@ use nyash_rust::runtime::NyashRuntime;
|
|||||||
use nyash_rust::interpreter::SharedState;
|
use nyash_rust::interpreter::SharedState;
|
||||||
use nyash_rust::box_factory::user_defined::UserDefinedBoxFactory;
|
use nyash_rust::box_factory::user_defined::UserDefinedBoxFactory;
|
||||||
use nyash_rust::core::model::BoxDeclaration as CoreBoxDecl;
|
use nyash_rust::core::model::BoxDeclaration as CoreBoxDecl;
|
||||||
use std::sync::{Arc, RwLock};
|
use std::sync::Arc;
|
||||||
use std::collections::HashMap;
|
|
||||||
|
|
||||||
#[cfg(feature = "wasm-backend")]
|
#[cfg(feature = "wasm-backend")]
|
||||||
use nyash_rust::backend::{wasm::WasmBackend, aot::AotBackend};
|
use nyash_rust::backend::{wasm::WasmBackend, aot::AotBackend};
|
||||||
@ -289,7 +288,7 @@ impl NyashRunner {
|
|||||||
|
|
||||||
// Dump MIR if requested
|
// Dump MIR if requested
|
||||||
if self.config.dump_mir {
|
if self.config.dump_mir {
|
||||||
let mut printer = if self.config.mir_verbose {
|
let printer = if self.config.mir_verbose {
|
||||||
MirPrinter::verbose()
|
MirPrinter::verbose()
|
||||||
} else {
|
} else {
|
||||||
MirPrinter::new()
|
MirPrinter::new()
|
||||||
|
|||||||
@ -7,7 +7,7 @@
|
|||||||
#[cfg(all(feature = "plugins", not(target_arch = "wasm32")))]
|
#[cfg(all(feature = "plugins", not(target_arch = "wasm32")))]
|
||||||
mod enabled {
|
mod enabled {
|
||||||
use crate::bid::{BidResult, BidError};
|
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 crate::config::nyash_toml_v2::{NyashConfigV2, LibraryDefinition};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::sync::{Arc, RwLock};
|
use std::sync::{Arc, RwLock};
|
||||||
@ -21,9 +21,11 @@ mod enabled {
|
|||||||
_lib: Arc<libloading::Library>,
|
_lib: Arc<libloading::Library>,
|
||||||
|
|
||||||
/// Box types provided by this plugin
|
/// Box types provided by this plugin
|
||||||
|
#[allow(dead_code)]
|
||||||
box_types: Vec<String>,
|
box_types: Vec<String>,
|
||||||
|
|
||||||
/// Optional init function
|
/// Optional init function
|
||||||
|
#[allow(dead_code)]
|
||||||
init_fn: Option<unsafe extern "C" fn() -> i32>,
|
init_fn: Option<unsafe extern "C" fn() -> i32>,
|
||||||
|
|
||||||
/// Required invoke function
|
/// Required invoke function
|
||||||
@ -521,7 +523,7 @@ impl PluginBoxV2 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Create a Box instance
|
/// 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);
|
eprintln!("🔍 create_box called for: {}", box_type);
|
||||||
|
|
||||||
let config = self.config.as_ref()
|
let config = self.config.as_ref()
|
||||||
|
|||||||
Reference in New Issue
Block a user