From c457d29f0665e6e68e792921209246bc22bab443 Mon Sep 17 00:00:00 2001 From: Ryo Yamashita Date: Sat, 10 Aug 2024 19:15:58 +0900 Subject: [PATCH 1/5] =?UTF-8?q?`once=5Fcell::sync::Lazy`=20=E2=86=92=20`st?= =?UTF-8?q?d::sync::LazyLock`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.lock | 5 ----- crates/downloader/Cargo.toml | 1 - crates/downloader/src/main.rs | 19 +++++++++---------- crates/test_util/Cargo.toml | 1 - crates/test_util/src/lib.rs | 4 ++-- crates/voicevox_core/Cargo.toml | 1 - .../src/engine/acoustic_feature_extractor.rs | 6 +++--- .../voicevox_core/src/engine/kana_parser.rs | 11 +++++++---- .../voicevox_core/src/infer/domains/talk.rs | 6 +++--- crates/voicevox_core/src/metas.rs | 7 ++++--- .../src/user_dict/part_of_speech_data.rs | 6 +++--- crates/voicevox_core/src/user_dict/word.rs | 16 +++++++++------- crates/voicevox_core/src/voice_model.rs | 5 +++-- crates/voicevox_core_c_api/Cargo.toml | 1 - .../src/compatible_engine.rs | 15 +++++++-------- crates/voicevox_core_c_api/src/drop_check.rs | 2 +- .../voicevox_core_c_api/tests/e2e/log_mask.rs | 5 +++-- .../tests/e2e/snapshots.rs | 2 +- .../tests/e2e/testcases/compatible_engine.rs | 4 ++-- ...ble_engine_load_model_before_initialize.rs | 5 ++--- .../tests/e2e/testcases/global_info.rs | 5 ++--- .../tests/e2e/testcases/simple_tts.rs | 5 ++--- .../testcases/synthesizer_new_output_json.rs | 4 ++-- .../e2e/testcases/tts_via_audio_query.rs | 5 ++--- .../tests/e2e/testcases/user_dict_load.rs | 8 ++++---- .../e2e/testcases/user_dict_manipulate.rs | 7 ++++--- crates/voicevox_core_java_api/Cargo.toml | 1 - 27 files changed, 75 insertions(+), 82 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9fdf8f695..3da1581da 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1062,7 +1062,6 @@ dependencies = [ "indicatif", "itertools 0.10.5", "octocrab", - "once_cell", "parse-display", "rayon", "reqwest", @@ -3782,7 +3781,6 @@ dependencies = [ "fs-err", "indoc", "libloading 0.7.3", - "once_cell", "reqwest", "serde", "serde_json", @@ -4250,7 +4248,6 @@ dependencies = [ "itertools 0.10.5", "jlabel", "ndarray", - "once_cell", "open_jtalk", "ouroboros", "pretty_assertions", @@ -4301,7 +4298,6 @@ dependencies = [ "libtest-mimic", "ndarray", "ndarray-stats", - "once_cell", "process_path", "ref-cast", "regex", @@ -4330,7 +4326,6 @@ dependencies = [ "duplicate", "easy-ext", "jni", - "once_cell", "pretty_assertions", "rstest", "serde_json", diff --git a/crates/downloader/Cargo.toml b/crates/downloader/Cargo.toml index c60afd3b6..427a1854d 100644 --- a/crates/downloader/Cargo.toml +++ b/crates/downloader/Cargo.toml @@ -19,7 +19,6 @@ futures-util.workspace = true indicatif.workspace = true itertools.workspace = true octocrab = { workspace = true, default-features = false, features = ["rustls-tls", "stream"] } -once_cell.workspace = true parse-display.workspace = true rayon.workspace = true reqwest = { workspace = true, default-features = false, features = ["rustls-tls", "stream"] } diff --git a/crates/downloader/src/main.rs b/crates/downloader/src/main.rs index 0432ea0a9..6ece6d054 100644 --- a/crates/downloader/src/main.rs +++ b/crates/downloader/src/main.rs @@ -5,7 +5,7 @@ use std::{ future::Future, io::{self, Cursor, Read}, path::{Path, PathBuf}, - sync::Arc, + sync::{Arc, LazyLock}, time::Duration, }; @@ -24,7 +24,6 @@ use octocrab::{ }, Octocrab, }; -use once_cell::sync::Lazy; use rayon::iter::{IntoParallelIterator as _, ParallelIterator as _}; use strum::{Display, IntoStaticStr}; use tokio::task::{JoinError, JoinSet}; @@ -43,7 +42,7 @@ const DEFAULT_CORE_REPO: &str = "VOICEVOX/voicevox_core"; const DEFAULT_ONNXRUNTIME_BUILDER_REPO: &str = "VOICEVOX/onnxruntime-builder"; const DEFAULT_ADDITIONAL_LIBRARIES_REPO: &str = "VOICEVOX/voicevox_additional_libraries"; -static OPEN_JTALK_DIC_URL: Lazy = Lazy::new(|| { +static OPEN_JTALK_DIC_URL: LazyLock = LazyLock::new(|| { "https://jaist.dl.sourceforge.net/project/open-jtalk/Dictionary/open_jtalk_dic-1.11/open_jtalk_dic_utf_8-1.11.tar.gz" .parse() .unwrap() @@ -449,8 +448,8 @@ fn find_onnxruntime( ) -> anyhow::Result { macro_rules! selector { ($expr:expr $(,)?) => {{ - static SELECTOR: Lazy = - Lazy::new(|| scraper::Selector::parse($expr).expect("should be valid")); + static SELECTOR: LazyLock = + LazyLock::new(|| scraper::Selector::parse($expr).expect("should be valid")); &SELECTOR }}; } @@ -595,8 +594,8 @@ fn add_progress_bar( const INTERVAL: Duration = Duration::from_millis(100); - static PROGRESS_STYLE: Lazy = - Lazy::new(|| ProgressStyle::with_template("{prefix}").unwrap()); + static PROGRESS_STYLE: LazyLock = + LazyLock::new(|| ProgressStyle::with_template("{prefix}").unwrap()); } async fn download_and_extract( @@ -614,15 +613,15 @@ async fn download_and_extract( let files = &read_archive(archive, archive_kind, pb.clone()).await?; return extract(files, stripping, output, pb).await; - static PROGRESS_STYLE1: Lazy = Lazy::new(|| { + static PROGRESS_STYLE1: LazyLock = LazyLock::new(|| { ProgressStyle::with_template( "{prefix:55} {bytes:>11} {bytes_per_sec:>13} {elapsed_precise} {bar} {percent:>3}%", ) .unwrap() }); - static PROGRESS_STYLE2: Lazy = - Lazy::new(|| ProgressStyle::with_template("{prefix:55} {spinner} {msg}").unwrap()); + static PROGRESS_STYLE2: LazyLock = + LazyLock::new(|| ProgressStyle::with_template("{prefix:55} {spinner} {msg}").unwrap()); async fn with_style( pb: ProgressBar, diff --git a/crates/test_util/Cargo.toml b/crates/test_util/Cargo.toml index fe0c2f6dd..329d5f603 100644 --- a/crates/test_util/Cargo.toml +++ b/crates/test_util/Cargo.toml @@ -4,7 +4,6 @@ edition.workspace = true [dependencies] libloading.workspace = true -once_cell.workspace = true serde = { workspace = true, features = ["derive"] } serde_json.workspace = true diff --git a/crates/test_util/src/lib.rs b/crates/test_util/src/lib.rs index 6473e438e..740cfb415 100644 --- a/crates/test_util/src/lib.rs +++ b/crates/test_util/src/lib.rs @@ -17,7 +17,7 @@ pub mod c_api { pub const VV_MODELS_ROOT_DIR: &str = super::VV_MODELS_ROOT_DIR; } -use once_cell::sync::Lazy; +use std::sync::LazyLock; pub use self::typing::{ DecodeExampleData, DurationExampleData, ExampleData, IntonationExampleData, @@ -36,6 +36,6 @@ const EXAMPLE_DATA_JSON: &str = include_str!(concat!( "/data/example_data.json" )); -pub static EXAMPLE_DATA: Lazy = Lazy::new(|| { +pub static EXAMPLE_DATA: LazyLock = LazyLock::new(|| { serde_json::from_str(EXAMPLE_DATA_JSON).expect("failed to parse example_data.json") }); diff --git a/crates/voicevox_core/Cargo.toml b/crates/voicevox_core/Cargo.toml index c9ed52725..8cb2b1cfc 100644 --- a/crates/voicevox_core/Cargo.toml +++ b/crates/voicevox_core/Cargo.toml @@ -32,7 +32,6 @@ indexmap = { workspace = true, features = ["serde"] } itertools.workspace = true jlabel.workspace = true ndarray.workspace = true -once_cell.workspace = true open_jtalk.workspace = true ouroboros.workspace = true rayon.workspace = true diff --git a/crates/voicevox_core/src/engine/acoustic_feature_extractor.rs b/crates/voicevox_core/src/engine/acoustic_feature_extractor.rs index 5ee7ea540..e78833cf5 100644 --- a/crates/voicevox_core/src/engine/acoustic_feature_extractor.rs +++ b/crates/voicevox_core/src/engine/acoustic_feature_extractor.rs @@ -1,7 +1,7 @@ +use std::{collections::HashMap, sync::LazyLock}; + use derive_getters::Getters; use derive_new::new; -use once_cell::sync::Lazy; -use std::collections::HashMap; #[rustfmt::skip] const PHONEME_LIST: &[&str] = &[ @@ -52,7 +52,7 @@ const PHONEME_LIST: &[&str] = &[ "z", ]; -static PHONEME_MAP: Lazy> = Lazy::new(|| { +static PHONEME_MAP: LazyLock> = LazyLock::new(|| { let mut m = HashMap::new(); for (i, s) in PHONEME_LIST.iter().enumerate() { m.insert(*s, i as i64); diff --git a/crates/voicevox_core/src/engine/kana_parser.rs b/crates/voicevox_core/src/engine/kana_parser.rs index 9397376f6..67aa276cb 100644 --- a/crates/voicevox_core/src/engine/kana_parser.rs +++ b/crates/voicevox_core/src/engine/kana_parser.rs @@ -1,7 +1,10 @@ -use crate::engine::model::{AccentPhrase, Mora}; -use crate::engine::mora_list::MORA_LIST_MINIMUM; -use once_cell::sync::Lazy; use std::collections::HashMap; +use std::sync::LazyLock; + +use crate::engine::{ + model::{AccentPhrase, Mora}, + mora_list::MORA_LIST_MINIMUM, +}; const UNVOICE_SYMBOL: char = '_'; const ACCENT_SYMBOL: char = '\''; @@ -16,7 +19,7 @@ pub(crate) struct KanaParseError(String); type KanaParseResult = std::result::Result; -static TEXT2MORA_WITH_UNVOICE: Lazy> = Lazy::new(|| { +static TEXT2MORA_WITH_UNVOICE: LazyLock> = LazyLock::new(|| { let mut text2mora_with_unvoice = HashMap::new(); for [text, consonant, vowel] in MORA_LIST_MINIMUM { let consonant = if !consonant.is_empty() { diff --git a/crates/voicevox_core/src/infer/domains/talk.rs b/crates/voicevox_core/src/infer/domains/talk.rs index e0716fa50..b2470c124 100644 --- a/crates/voicevox_core/src/infer/domains/talk.rs +++ b/crates/voicevox_core/src/infer/domains/talk.rs @@ -1,9 +1,8 @@ -use std::collections::BTreeSet; +use std::{collections::BTreeSet, sync::LazyLock}; use enum_map::Enum; use macros::{InferenceInputSignature, InferenceOperation, InferenceOutputSignature}; use ndarray::{Array0, Array1, Array2}; -use once_cell::sync::Lazy; use crate::StyleType; @@ -17,7 +16,8 @@ impl InferenceDomain for TalkDomain { type Operation = TalkOperation; fn style_types() -> &'static BTreeSet { - static STYLE_TYPES: Lazy> = Lazy::new(|| [StyleType::Talk].into()); + static STYLE_TYPES: LazyLock> = + LazyLock::new(|| [StyleType::Talk].into()); &STYLE_TYPES } } diff --git a/crates/voicevox_core/src/metas.rs b/crates/voicevox_core/src/metas.rs index 1fb4a7f9d..97c3922c7 100644 --- a/crates/voicevox_core/src/metas.rs +++ b/crates/voicevox_core/src/metas.rs @@ -209,12 +209,13 @@ pub enum StyleType { #[cfg(test)] mod tests { - use once_cell::sync::Lazy; + use std::sync::LazyLock; + use serde_json::json; #[test] fn merge_works() -> anyhow::Result<()> { - static INPUT: Lazy = Lazy::new(|| { + static INPUT: LazyLock = LazyLock::new(|| { json!([ { "name": "B", @@ -267,7 +268,7 @@ mod tests { ]) }); - static EXPECTED: Lazy = Lazy::new(|| { + static EXPECTED: LazyLock = LazyLock::new(|| { json!([ { "name": "A", diff --git a/crates/voicevox_core/src/user_dict/part_of_speech_data.rs b/crates/voicevox_core/src/user_dict/part_of_speech_data.rs index b7bc95440..908885c65 100644 --- a/crates/voicevox_core/src/user_dict/part_of_speech_data.rs +++ b/crates/voicevox_core/src/user_dict/part_of_speech_data.rs @@ -1,5 +1,5 @@ -use once_cell::sync::Lazy; use std::collections::HashMap; +use std::sync::LazyLock; use crate::UserDictWordType; @@ -30,8 +30,8 @@ pub(super) struct PartOfSpeechDetail { } // 元データ: https://github.com/VOICEVOX/voicevox_engine/blob/master/voicevox_engine/part_of_speech_data.py -pub(super) static PART_OF_SPEECH_DETAIL: Lazy> = - Lazy::new(|| { +pub(super) static PART_OF_SPEECH_DETAIL: LazyLock> = + LazyLock::new(|| { HashMap::from_iter([ ( UserDictWordType::ProperNoun, diff --git a/crates/voicevox_core/src/user_dict/word.rs b/crates/voicevox_core/src/user_dict/word.rs index f6bbc182f..0a42f1da5 100644 --- a/crates/voicevox_core/src/user_dict/word.rs +++ b/crates/voicevox_core/src/user_dict/word.rs @@ -1,3 +1,8 @@ +use std::{ops::RangeToInclusive, sync::LazyLock}; + +use regex::Regex; +use serde::{de::Error as _, Deserialize, Serialize}; + use crate::{ error::ErrorRepr, result::Result, @@ -5,10 +10,6 @@ use crate::{ priority2cost, MAX_PRIORITY, MIN_PRIORITY, PART_OF_SPEECH_DETAIL, }, }; -use once_cell::sync::Lazy; -use regex::Regex; -use serde::{de::Error as _, Deserialize, Serialize}; -use std::ops::RangeToInclusive; /// ユーザー辞書の単語。 #[derive(Clone, Debug, Serialize)] @@ -77,8 +78,9 @@ impl InvalidWordError { type InvalidWordResult = std::result::Result; -static PRONUNCIATION_REGEX: Lazy = Lazy::new(|| Regex::new(r"^[ァ-ヴー]+$").unwrap()); -static MORA_REGEX: Lazy = Lazy::new(|| { +static PRONUNCIATION_REGEX: LazyLock = + LazyLock::new(|| Regex::new(r"^[ァ-ヴー]+$").unwrap()); +static MORA_REGEX: LazyLock = LazyLock::new(|| { Regex::new(concat!( "(?:", "[イ][ェ]|[ヴ][ャュョ]|[トド][ゥ]|[テデ][ィャュョ]|[デ][ェ]|[クグ][ヮ]|", // rule_others @@ -89,7 +91,7 @@ static MORA_REGEX: Lazy = Lazy::new(|| { )) .unwrap() }); -static SPACE_REGEX: Lazy = Lazy::new(|| Regex::new(r"\p{Z}").unwrap()); +static SPACE_REGEX: LazyLock = LazyLock::new(|| Regex::new(r"\p{Z}").unwrap()); impl Default for UserDictWord { fn default() -> Self { diff --git a/crates/voicevox_core/src/voice_model.rs b/crates/voicevox_core/src/voice_model.rs index 027747ab7..48477256c 100644 --- a/crates/voicevox_core/src/voice_model.rs +++ b/crates/voicevox_core/src/voice_model.rs @@ -454,7 +454,8 @@ pub(crate) mod tokio { #[cfg(test)] mod tests { - use once_cell::sync::Lazy; + use std::sync::LazyLock; + use rstest::{fixture, rstest}; use serde_json::json; @@ -501,7 +502,7 @@ mod tests { assert_eq!(expected, actual); } - static TALK_MANIFEST: Lazy = Lazy::new(|| TalkManifest { + static TALK_MANIFEST: LazyLock = LazyLock::new(|| TalkManifest { predict_duration_filename: "".to_owned(), predict_intonation_filename: "".to_owned(), decode_filename: "".to_owned(), diff --git a/crates/voicevox_core_c_api/Cargo.toml b/crates/voicevox_core_c_api/Cargo.toml index 1b86521d1..996367a5f 100644 --- a/crates/voicevox_core_c_api/Cargo.toml +++ b/crates/voicevox_core_c_api/Cargo.toml @@ -29,7 +29,6 @@ easy-ext.workspace = true futures.workspace = true itertools.workspace = true libc.workspace = true -once_cell.workspace = true process_path.workspace = true ref-cast.workspace = true serde_json = { workspace = true, features = ["preserve_order"] } diff --git a/crates/voicevox_core_c_api/src/compatible_engine.rs b/crates/voicevox_core_c_api/src/compatible_engine.rs index 70fa83710..68b836f2f 100644 --- a/crates/voicevox_core_c_api/src/compatible_engine.rs +++ b/crates/voicevox_core_c_api/src/compatible_engine.rs @@ -2,12 +2,11 @@ use std::{ collections::BTreeMap, env, ffi::{c_char, CString}, - sync::{Mutex, MutexGuard}, + sync::{LazyLock, Mutex, MutexGuard}, }; use libc::c_int; -use once_cell::sync::Lazy; use voicevox_core::{StyleId, VoiceModelId, __internal::interop::PerformInference as _}; use crate::{helpers::display_error, init_logger_once}; @@ -24,9 +23,9 @@ macro_rules! ensure_initialized { }; } -static ERROR_MESSAGE: Lazy> = Lazy::new(|| Mutex::new(String::new())); +static ERROR_MESSAGE: LazyLock> = LazyLock::new(|| Mutex::new(String::new())); -static ONNXRUNTIME: Lazy<&'static voicevox_core::blocking::Onnxruntime> = Lazy::new(|| { +static ONNXRUNTIME: LazyLock<&'static voicevox_core::blocking::Onnxruntime> = LazyLock::new(|| { voicevox_core::blocking::Onnxruntime::load_once() .exec() .unwrap_or_else(|err| { @@ -42,7 +41,7 @@ struct VoiceModelSet { model_map: BTreeMap, } -static VOICE_MODEL_SET: Lazy = Lazy::new(|| { +static VOICE_MODEL_SET: LazyLock = LazyLock::new(|| { let all_vvms = get_all_models(); let model_map: BTreeMap<_, _> = all_vvms.iter().map(|vvm| (vvm.id(), vvm.clone())).collect(); let metas = voicevox_core::__internal::interop::merge_metas( @@ -99,8 +98,8 @@ fn voice_model_set() -> &'static VoiceModelSet { &VOICE_MODEL_SET } -static SYNTHESIZER: Lazy>>> = - Lazy::new(|| Mutex::new(None)); +static SYNTHESIZER: LazyLock>>> = + LazyLock::new(|| Mutex::new(None)); fn lock_synthesizer() -> MutexGuard<'static, Option>> { SYNTHESIZER.lock().unwrap() @@ -203,7 +202,7 @@ pub extern "C" fn supported_devices() -> *const c_char { init_logger_once(); return SUPPORTED_DEVICES.as_ptr(); - static SUPPORTED_DEVICES: Lazy = Lazy::new(|| { + static SUPPORTED_DEVICES: LazyLock = LazyLock::new(|| { CString::new( ONNXRUNTIME .supported_devices() diff --git a/crates/voicevox_core_c_api/src/drop_check.rs b/crates/voicevox_core_c_api/src/drop_check.rs index 36acec570..09b94c284 100644 --- a/crates/voicevox_core_c_api/src/drop_check.rs +++ b/crates/voicevox_core_c_api/src/drop_check.rs @@ -13,7 +13,7 @@ use std::{ /// `CString`は`Box`と同様Cの世界でもポインタ一つで実体を表すことができるため、こちら側 /// で管理すべきものは本来無い。しかしながら本クレートが提供するAPIには「解放不要」な文字列を返すも /// のが含まれている。ユーザーが誤ってそのような文字列を解放するのは未定義動作 (undefined behavior) -/// であるため、綺麗にSEGVするとも限らない。`once_cell::sync::Lazy`由来の文字列の場合、最悪解放が成 +/// であるため、綺麗にSEGVするとも限らない。`std::sync::LazyLock`由来の文字列の場合、最悪解放が成 /// 功してしまう。 /// /// この構造体はCの世界から帰ってきた`*mut c_char`を`CString`としてdropする際、それが本当にこちら側 diff --git a/crates/voicevox_core_c_api/tests/e2e/log_mask.rs b/crates/voicevox_core_c_api/tests/e2e/log_mask.rs index 93114976e..4e6d26482 100644 --- a/crates/voicevox_core_c_api/tests/e2e/log_mask.rs +++ b/crates/voicevox_core_c_api/tests/e2e/log_mask.rs @@ -1,11 +1,12 @@ -use once_cell::sync::Lazy; +use std::sync::LazyLock; + use regex::{Regex, Replacer}; use crate::assert_cdylib::Utf8Output; macro_rules! static_regex { ($regex:expr $(,)?) => {{ - static REGEX: Lazy = Lazy::new(|| $regex.parse().unwrap()); + static REGEX: LazyLock = LazyLock::new(|| $regex.parse().unwrap()); ®EX }}; } diff --git a/crates/voicevox_core_c_api/tests/e2e/snapshots.rs b/crates/voicevox_core_c_api/tests/e2e/snapshots.rs index 249bc5f09..c4c181603 100644 --- a/crates/voicevox_core_c_api/tests/e2e/snapshots.rs +++ b/crates/voicevox_core_c_api/tests/e2e/snapshots.rs @@ -10,7 +10,7 @@ macro_rules! section { $section_name: T, } - ::once_cell::sync::Lazy::new(|| { + ::std::sync::LazyLock::new(|| { let Snapshots { $section_name } = ::toml::from_str(crate::snapshots::SNAPSHOTS_TOML).unwrap(); $section_name diff --git a/crates/voicevox_core_c_api/tests/e2e/testcases/compatible_engine.rs b/crates/voicevox_core_c_api/tests/e2e/testcases/compatible_engine.rs index 79b1d5dc8..e69ad68fd 100644 --- a/crates/voicevox_core_c_api/tests/e2e/testcases/compatible_engine.rs +++ b/crates/voicevox_core_c_api/tests/e2e/testcases/compatible_engine.rs @@ -1,10 +1,10 @@ // エンジンを起動してyukarin_s・yukarin_sa・decodeの推論を行う use std::ffi::CStr; +use std::sync::LazyLock; use assert_cmd::assert::AssertResult; use libloading::Library; -use once_cell::sync::Lazy; use serde::{Deserialize, Serialize}; use voicevox_core::SupportedDevices; @@ -106,7 +106,7 @@ impl assert_cdylib::TestCase for TestCase { } } -static SNAPSHOTS: Lazy = snapshots::section!(compatible_engine); +static SNAPSHOTS: LazyLock = snapshots::section!(compatible_engine); #[derive(Deserialize)] struct Snapshots { diff --git a/crates/voicevox_core_c_api/tests/e2e/testcases/compatible_engine_load_model_before_initialize.rs b/crates/voicevox_core_c_api/tests/e2e/testcases/compatible_engine_load_model_before_initialize.rs index 18482f0de..7b709a83d 100644 --- a/crates/voicevox_core_c_api/tests/e2e/testcases/compatible_engine_load_model_before_initialize.rs +++ b/crates/voicevox_core_c_api/tests/e2e/testcases/compatible_engine_load_model_before_initialize.rs @@ -1,10 +1,9 @@ // initialize前にモデルを読み込むとエラーになるテスト -use std::ffi::CStr; +use std::{ffi::CStr, sync::LazyLock}; use assert_cmd::assert::AssertResult; use libloading::Library; -use once_cell::sync::Lazy; use serde::{Deserialize, Serialize}; use test_util::c_api::CApi; @@ -43,7 +42,7 @@ impl assert_cdylib::TestCase for TestCase { } } -static SNAPSHOTS: Lazy = +static SNAPSHOTS: LazyLock = snapshots::section!(compatible_engine_load_model_before_initialize); #[derive(Deserialize)] diff --git a/crates/voicevox_core_c_api/tests/e2e/testcases/global_info.rs b/crates/voicevox_core_c_api/tests/e2e/testcases/global_info.rs index d2a8fc7e7..e3303db4f 100644 --- a/crates/voicevox_core_c_api/tests/e2e/testcases/global_info.rs +++ b/crates/voicevox_core_c_api/tests/e2e/testcases/global_info.rs @@ -1,8 +1,7 @@ -use std::{collections::HashMap, ffi::CStr, mem::MaybeUninit, str}; +use std::{collections::HashMap, ffi::CStr, mem::MaybeUninit, str, sync::LazyLock}; use assert_cmd::assert::AssertResult; use libloading::Library; -use once_cell::sync::Lazy; use serde::{Deserialize, Serialize}; use serde_with::{serde_as, DisplayFromStr}; use test_util::c_api::{self, CApi, VoicevoxResultCode}; @@ -99,7 +98,7 @@ impl assert_cdylib::TestCase for TestCase { } } -static SNAPSHOTS: Lazy = snapshots::section!(global_info); +static SNAPSHOTS: LazyLock = snapshots::section!(global_info); #[serde_as] #[derive(Deserialize)] diff --git a/crates/voicevox_core_c_api/tests/e2e/testcases/simple_tts.rs b/crates/voicevox_core_c_api/tests/e2e/testcases/simple_tts.rs index 4635b0271..a4381f74d 100644 --- a/crates/voicevox_core_c_api/tests/e2e/testcases/simple_tts.rs +++ b/crates/voicevox_core_c_api/tests/e2e/testcases/simple_tts.rs @@ -1,8 +1,7 @@ -use std::{collections::HashMap, ffi::CString, mem::MaybeUninit}; +use std::{collections::HashMap, ffi::CString, mem::MaybeUninit, sync::LazyLock}; use assert_cmd::assert::AssertResult; use libloading::Library; -use once_cell::sync::Lazy; use serde::{Deserialize, Serialize}; use test_util::{ c_api::{self, CApi, VoicevoxInitializeOptions, VoicevoxResultCode}, @@ -115,7 +114,7 @@ impl assert_cdylib::TestCase for TestCase { } } -static SNAPSHOTS: Lazy = snapshots::section!(simple_tts); +static SNAPSHOTS: LazyLock = snapshots::section!(simple_tts); #[derive(Deserialize)] struct Snapshots { diff --git a/crates/voicevox_core_c_api/tests/e2e/testcases/synthesizer_new_output_json.rs b/crates/voicevox_core_c_api/tests/e2e/testcases/synthesizer_new_output_json.rs index 8a2fd1951..9ac8f4b35 100644 --- a/crates/voicevox_core_c_api/tests/e2e/testcases/synthesizer_new_output_json.rs +++ b/crates/voicevox_core_c_api/tests/e2e/testcases/synthesizer_new_output_json.rs @@ -1,11 +1,11 @@ use std::{ ffi::{CStr, CString}, mem::MaybeUninit, + sync::LazyLock, }; use assert_cmd::assert::AssertResult; use libloading::Library; -use once_cell::sync::Lazy; use serde::{Deserialize, Serialize}; use test_util::{ @@ -104,7 +104,7 @@ impl assert_cdylib::TestCase for TestCase { } } -static SNAPSHOTS: Lazy = snapshots::section!(synthesizer_new_output_json); +static SNAPSHOTS: LazyLock = snapshots::section!(synthesizer_new_output_json); #[derive(Deserialize)] struct Snapshots { diff --git a/crates/voicevox_core_c_api/tests/e2e/testcases/tts_via_audio_query.rs b/crates/voicevox_core_c_api/tests/e2e/testcases/tts_via_audio_query.rs index 728f21339..0f2ff5fc8 100644 --- a/crates/voicevox_core_c_api/tests/e2e/testcases/tts_via_audio_query.rs +++ b/crates/voicevox_core_c_api/tests/e2e/testcases/tts_via_audio_query.rs @@ -1,8 +1,7 @@ -use std::{collections::HashMap, ffi::CString, mem::MaybeUninit}; +use std::{collections::HashMap, ffi::CString, mem::MaybeUninit, sync::LazyLock}; use assert_cmd::assert::AssertResult; use libloading::Library; -use once_cell::sync::Lazy; use serde::{Deserialize, Serialize}; use test_util::{ c_api::{self, CApi, VoicevoxInitializeOptions, VoicevoxResultCode}, @@ -127,7 +126,7 @@ impl assert_cdylib::TestCase for TestCase { } } -static SNAPSHOTS: Lazy = snapshots::section!(tts_via_audio_query); +static SNAPSHOTS: LazyLock = snapshots::section!(tts_via_audio_query); #[derive(Deserialize)] struct Snapshots { diff --git a/crates/voicevox_core_c_api/tests/e2e/testcases/user_dict_load.rs b/crates/voicevox_core_c_api/tests/e2e/testcases/user_dict_load.rs index 646c5647b..64e062251 100644 --- a/crates/voicevox_core_c_api/tests/e2e/testcases/user_dict_load.rs +++ b/crates/voicevox_core_c_api/tests/e2e/testcases/user_dict_load.rs @@ -1,16 +1,16 @@ // ユーザー辞書の登録によって読みが変化することを確認するテスト。 // 辞書ロード前後でAudioQueryのkanaが変化するかどうかで確認する。 -use assert_cmd::assert::AssertResult; -use once_cell::sync::Lazy; use std::ffi::{CStr, CString}; use std::mem::MaybeUninit; -use test_util::OPEN_JTALK_DIC_DIR; +use std::sync::LazyLock; +use assert_cmd::assert::AssertResult; use cstr::cstr; use libloading::Library; use serde::{Deserialize, Serialize}; use test_util::c_api::{self, CApi, VoicevoxInitializeOptions, VoicevoxResultCode}; +use test_util::OPEN_JTALK_DIC_DIR; use crate::{ assert_cdylib::{self, case, Utf8Output}, @@ -144,7 +144,7 @@ impl assert_cdylib::TestCase for TestCase { } } -static SNAPSHOTS: Lazy = snapshots::section!(user_dict); +static SNAPSHOTS: LazyLock = snapshots::section!(user_dict); #[derive(Deserialize)] struct Snapshots { diff --git a/crates/voicevox_core_c_api/tests/e2e/testcases/user_dict_manipulate.rs b/crates/voicevox_core_c_api/tests/e2e/testcases/user_dict_manipulate.rs index bec0d61b5..d3c37f127 100644 --- a/crates/voicevox_core_c_api/tests/e2e/testcases/user_dict_manipulate.rs +++ b/crates/voicevox_core_c_api/tests/e2e/testcases/user_dict_manipulate.rs @@ -1,11 +1,12 @@ // ユーザー辞書の操作をテストする。 -use assert_cmd::assert::AssertResult; -use once_cell::sync::Lazy; use std::{ ffi::{CStr, CString}, mem::MaybeUninit, + sync::LazyLock, }; + +use assert_cmd::assert::AssertResult; use tempfile::NamedTempFile; use uuid::Uuid; @@ -149,7 +150,7 @@ impl assert_cdylib::TestCase for TestCase { } } -static SNAPSHOTS: Lazy = snapshots::section!(user_dict_manipulate); +static SNAPSHOTS: LazyLock = snapshots::section!(user_dict_manipulate); #[derive(Deserialize)] struct Snapshots { diff --git a/crates/voicevox_core_java_api/Cargo.toml b/crates/voicevox_core_java_api/Cargo.toml index ec4e2d616..aed67c058 100644 --- a/crates/voicevox_core_java_api/Cargo.toml +++ b/crates/voicevox_core_java_api/Cargo.toml @@ -14,7 +14,6 @@ derive_more.workspace = true duplicate.workspace = true easy-ext.workspace = true jni.workspace = true -once_cell.workspace = true pretty_assertions = "1.3.0" rstest.workspace = true serde_json = { workspace = true, features = ["preserve_order"] } From c1956755b5d12f8a57a77edfc9a84d318b721e22 Mon Sep 17 00:00:00 2001 From: Ryo Yamashita Date: Sun, 11 Aug 2024 00:05:17 +0900 Subject: [PATCH 2/5] =?UTF-8?q?`NonNull`=E3=81=AB=E7=9B=B4=E6=8E=A5?= =?UTF-8?q?=E7=94=9F=E3=81=88=E3=81=9F=E3=83=A1=E3=82=BD=E3=83=83=E3=83=89?= =?UTF-8?q?=E3=82=92=E4=BD=BF=E3=81=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/voicevox_core_c_api/src/lib.rs | 25 ++++++------------- crates/voicevox_core_c_api/src/slice_owner.rs | 4 +-- 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/crates/voicevox_core_c_api/src/lib.rs b/crates/voicevox_core_c_api/src/lib.rs index 6f157bf6b..f35179807 100644 --- a/crates/voicevox_core_c_api/src/lib.rs +++ b/crates/voicevox_core_c_api/src/lib.rs @@ -218,7 +218,7 @@ pub unsafe extern "C" fn voicevox_onnxruntime_load_once( let instance = VoicevoxOnnxruntime::load_once(filename)?; unsafe { // SAFETY: ユーザーに要求している条件で十分 - out_onnxruntime.as_ptr().write_unaligned(instance); + out_onnxruntime.write_unaligned(instance); } Ok(()) })()) @@ -249,7 +249,7 @@ pub unsafe extern "C" fn voicevox_onnxruntime_init_once( let instance = VoicevoxOnnxruntime::init_once()?; unsafe { // SAFETY: ユーザーに要求している条件で十分 - out_onnxruntime.as_ptr().write_unaligned(instance); + out_onnxruntime.write_unaligned(instance); } Ok(()) })()) @@ -303,7 +303,7 @@ pub unsafe extern "C" fn voicevox_open_jtalk_rc_new( into_result_code_with_error((|| { let open_jtalk_dic_dir = ensure_utf8(CStr::from_ptr(open_jtalk_dic_dir))?; let open_jtalk = OpenJtalkRc::new(open_jtalk_dic_dir)?.into(); - out_open_jtalk.as_ptr().write_unaligned(open_jtalk); + out_open_jtalk.write_unaligned(open_jtalk); Ok(()) })()) } @@ -434,7 +434,7 @@ pub unsafe extern "C" fn voicevox_voice_model_new_from_path( into_result_code_with_error((|| { let path = ensure_utf8(CStr::from_ptr(path))?; let model = VoicevoxVoiceModel::from_path(path)?.into(); - out_model.as_ptr().write_unaligned(model); + out_model.write_unaligned(model); Ok(()) })()) } @@ -518,7 +518,7 @@ pub unsafe extern "C" fn voicevox_synthesizer_new( let options = options.into(); let synthesizer = VoicevoxSynthesizer::new(onnxruntime, open_jtalk, &options)?.into(); - out_synthesizer.as_ptr().write_unaligned(synthesizer); + out_synthesizer.write_unaligned(synthesizer); Ok(()) })()) } @@ -681,7 +681,7 @@ pub unsafe extern "C" fn voicevox_onnxruntime_create_supported_devices_json( into_result_code_with_error((|| { let supported_devices = CString::new(onnxruntime.0.supported_devices()?.to_json().to_string()).unwrap(); - output_supported_devices_json.as_ptr().write_unaligned( + output_supported_devices_json.write_unaligned( C_STRING_DROP_CHECKER .whitelist(supported_devices) .into_raw(), @@ -733,7 +733,6 @@ pub unsafe extern "C" fn voicevox_synthesizer_create_audio_query_from_kana( let audio_query = CString::new(audio_query_model_to_json(&audio_query)) .expect("should not contain '\\0'"); output_audio_query_json - .as_ptr() .write_unaligned(C_STRING_DROP_CHECKER.whitelist(audio_query).into_raw()); Ok(()) })()) @@ -782,7 +781,6 @@ pub unsafe extern "C" fn voicevox_synthesizer_create_audio_query( let audio_query = CString::new(audio_query_model_to_json(&audio_query)) .expect("should not contain '\\0'"); output_audio_query_json - .as_ptr() .write_unaligned(C_STRING_DROP_CHECKER.whitelist(audio_query).into_raw()); Ok(()) })()) @@ -830,7 +828,6 @@ pub unsafe extern "C" fn voicevox_synthesizer_create_accent_phrases_from_kana( let accent_phrases = CString::new(accent_phrases_to_json(&accent_phrases)) .expect("should not contain '\\0'"); output_accent_phrases_json - .as_ptr() .write_unaligned(C_STRING_DROP_CHECKER.whitelist(accent_phrases).into_raw()); Ok(()) })()) @@ -877,7 +874,6 @@ pub unsafe extern "C" fn voicevox_synthesizer_create_accent_phrases( let accent_phrases = CString::new(accent_phrases_to_json(&accent_phrases)) .expect("should not contain '\\0'"); output_accent_phrases_json - .as_ptr() .write_unaligned(C_STRING_DROP_CHECKER.whitelist(accent_phrases).into_raw()); Ok(()) })()) @@ -917,7 +913,6 @@ pub unsafe extern "C" fn voicevox_synthesizer_replace_mora_data( let accent_phrases = CString::new(accent_phrases_to_json(&accent_phrases)) .expect("should not contain '\\0'"); output_accent_phrases_json - .as_ptr() .write_unaligned(C_STRING_DROP_CHECKER.whitelist(accent_phrases).into_raw()); Ok(()) })()) @@ -957,7 +952,6 @@ pub unsafe extern "C" fn voicevox_synthesizer_replace_phoneme_length( let accent_phrases = CString::new(accent_phrases_to_json(&accent_phrases)) .expect("should not contain '\\0'"); output_accent_phrases_json - .as_ptr() .write_unaligned(C_STRING_DROP_CHECKER.whitelist(accent_phrases).into_raw()); Ok(()) })()) @@ -997,7 +991,6 @@ pub unsafe extern "C" fn voicevox_synthesizer_replace_mora_pitch( let accent_phrases = CString::new(accent_phrases_to_json(&accent_phrases)) .expect("should not contain '\\0'"); output_accent_phrases_json - .as_ptr() .write_unaligned(C_STRING_DROP_CHECKER.whitelist(accent_phrases).into_raw()); Ok(()) })()) @@ -1347,7 +1340,7 @@ pub unsafe extern "C" fn voicevox_user_dict_add_word( into_result_code_with_error((|| { let word = word.read_unaligned().try_into_word()?; let uuid = user_dict.dict.add_word(word)?; - output_word_uuid.as_ptr().write_unaligned(uuid.into_bytes()); + output_word_uuid.write_unaligned(uuid.into_bytes()); Ok(()) })()) @@ -1425,9 +1418,7 @@ pub unsafe extern "C" fn voicevox_user_dict_to_json( init_logger_once(); let json = user_dict.dict.to_json(); let json = CString::new(json).expect("\\0を含まない文字列であることが保証されている"); - output_json - .as_ptr() - .write_unaligned(C_STRING_DROP_CHECKER.whitelist(json).into_raw()); + output_json.write_unaligned(C_STRING_DROP_CHECKER.whitelist(json).into_raw()); VoicevoxResultCode::VOICEVOX_RESULT_OK } diff --git a/crates/voicevox_core_c_api/src/slice_owner.rs b/crates/voicevox_core_c_api/src/slice_owner.rs index fa75add52..239847cb7 100644 --- a/crates/voicevox_core_c_api/src/slice_owner.rs +++ b/crates/voicevox_core_c_api/src/slice_owner.rs @@ -55,8 +55,8 @@ impl SliceOwner { ); } - out_ptr.as_ptr().write_unaligned(ptr); - out_len.as_ptr().write_unaligned(len); + out_ptr.write_unaligned(ptr); + out_len.write_unaligned(len); } /// `own_and_lend`でC API利用者に貸し出したポインタに対応する`Box<[u8]>`をデストラクトする。 From 21c23a5e247dcd0d832b586dc64ecf177a8dab8d Mon Sep 17 00:00:00 2001 From: Ryo Yamashita Date: Sun, 11 Aug 2024 00:45:05 +0900 Subject: [PATCH 3/5] `<[[T; N]]>::as_flattened` --- .../src/engine/acoustic_feature_extractor.rs | 4 ++-- crates/voicevox_core/src/synthesizer.rs | 9 +++------ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/crates/voicevox_core/src/engine/acoustic_feature_extractor.rs b/crates/voicevox_core/src/engine/acoustic_feature_extractor.rs index e78833cf5..a75770dd9 100644 --- a/crates/voicevox_core/src/engine/acoustic_feature_extractor.rs +++ b/crates/voicevox_core/src/engine/acoustic_feature_extractor.rs @@ -70,8 +70,8 @@ pub(crate) struct OjtPhoneme { } impl OjtPhoneme { - pub(crate) fn num_phoneme() -> usize { - PHONEME_MAP.len() + pub(crate) const fn num_phoneme() -> usize { + PHONEME_LIST.len() // == PHONEME_MAP.len() } fn space_phoneme() -> String { diff --git a/crates/voicevox_core/src/synthesizer.rs b/crates/voicevox_core/src/synthesizer.rs index adae7c4b5..cfc330469 100644 --- a/crates/voicevox_core/src/synthesizer.rs +++ b/crates/voicevox_core/src/synthesizer.rs @@ -318,7 +318,7 @@ pub(crate) mod blocking { let (_, _, vowel_indexes) = split_mora(&phoneme_data_list); - let mut phoneme: Vec> = Vec::new(); + let mut phoneme = Vec::new(); let mut f0: Vec = Vec::new(); { const RATE: f32 = 24000. / 256.; @@ -335,7 +335,7 @@ pub(crate) mod blocking { let phoneme_id = phoneme_data_list[i].phoneme_id(); for _ in 0..phoneme_length { - let mut phonemes_vec = vec![0.; OjtPhoneme::num_phoneme()]; + let mut phonemes_vec = [0.; OjtPhoneme::num_phoneme()]; phonemes_vec[phoneme_id as usize] = 1.; phoneme.push(phonemes_vec) } @@ -352,14 +352,11 @@ pub(crate) mod blocking { } } - // 2次元のvectorを1次元に変換し、アドレスを連続させる - let flatten_phoneme = phoneme.into_iter().flatten().collect::>(); - let wave = &self.decode( f0.len(), OjtPhoneme::num_phoneme(), &f0, - &flatten_phoneme, + phoneme.as_flattened(), style_id, )?; return Ok(to_wav(wave, audio_query)); From c437aaa3cf74e2d861f2cd5c2e0453298517aa2c Mon Sep 17 00:00:00 2001 From: Ryo Yamashita Date: Sun, 11 Aug 2024 23:26:38 +0900 Subject: [PATCH 4/5] =?UTF-8?q?`if`=E3=81=A8`match`=E3=81=A7=E3=81=AE?= =?UTF-8?q?=E3=83=A9=E3=82=A4=E3=83=95=E3=82=BF=E3=82=A4=E3=83=A0=E5=BB=B6?= =?UTF-8?q?=E9=95=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/voicevox_core/src/infer/session_set.rs | 4 ++-- crates/voicevox_core/src/synthesizer.rs | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/voicevox_core/src/infer/session_set.rs b/crates/voicevox_core/src/infer/session_set.rs index 95f081bac..20419ce2c 100644 --- a/crates/voicevox_core/src/infer/session_set.rs +++ b/crates/voicevox_core/src/infer/session_set.rs @@ -61,8 +61,8 @@ impl InferenceSessionSet { .iter() .map(|ParamInfo { name, dt, ndim }| { let brackets = match *ndim { - Some(ndim) => "[]".repeat(ndim), - None => "[]...".to_owned(), + Some(ndim) => &"[]".repeat(ndim), + None => "[]...", }; format!("{name}: {dt}{brackets}") }) diff --git a/crates/voicevox_core/src/synthesizer.rs b/crates/voicevox_core/src/synthesizer.rs index cfc330469..8dcbf848a 100644 --- a/crates/voicevox_core/src/synthesizer.rs +++ b/crates/voicevox_core/src/synthesizer.rs @@ -265,12 +265,12 @@ pub(crate) mod blocking { } = audio_query; let accent_phrases = if options.enable_interrogative_upspeak { - adjust_interrogative_accent_phrases(accent_phrases) + &adjust_interrogative_accent_phrases(accent_phrases) } else { - accent_phrases.clone() + accent_phrases }; - let (flatten_moras, phoneme_data_list) = initial_process(&accent_phrases); + let (flatten_moras, phoneme_data_list) = initial_process(accent_phrases); let mut phoneme_length_list = vec![*pre_phoneme_length]; let mut f0_list = vec![0.]; From 3da1871e984e7c549e4409a5d792621af6274371 Mon Sep 17 00:00:00 2001 From: Ryo Yamashita Date: Sun, 11 Aug 2024 23:42:12 +0900 Subject: [PATCH 5/5] `associated_type_bounds` --- crates/voicevox_core/src/infer/session_set.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/voicevox_core/src/infer/session_set.rs b/crates/voicevox_core/src/infer/session_set.rs index 20419ce2c..ad85e93ac 100644 --- a/crates/voicevox_core/src/infer/session_set.rs +++ b/crates/voicevox_core/src/infer/session_set.rs @@ -74,8 +74,7 @@ impl InferenceSessionSet { impl InferenceSessionSet { pub(crate) fn get(&self) -> InferenceSessionCell where - I: InferenceInputSignature, - I::Signature: InferenceSignature, + I: InferenceInputSignature>, { InferenceSessionCell { inner: self.0[I::Signature::OPERATION].clone(),