Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rust 1.77の新機能を導入する #771

Merged
merged 3 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ chrono = { version = "0.4.26", default-features = false }
clap = "4.0.10"
color-eyre = "0.6.2"
colorchoice = "1.0.0"
cstr = "0.2.11"
cstr = "0.2.11" # https://github.com/dtolnay/syn/issues/1502
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

このコメントが解消される条件をメモっておかないてあげると、他の人も意図がわかって良さげな気がしました!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

多分dtolnay氏か誰かが腰を上げればスムーズに解決しそうなissueなので、長々と文脈を書かないでいいかなと思いました。cstrがどういうライブラリなのかを考えればリンク先のissueのタイトルで大体はわかるようになっていると思います。

Copy link
Member Author

@qryxip qryxip Apr 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

多分dtolnay氏か誰かが腰を上げればスムーズに解決しそうなissue

そう言ってるうちに実装されましたね。あとはクレートとしてのリリースがなされればc"…"への置き換えができるはず。
dtolnay/syn#1622

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

derive-getters = "0.2.0"
derive-new = "0.5.9"
derive_more = "0.99.17"
Expand Down
102 changes: 0 additions & 102 deletions crates/voicevox_core/src/engine/full_context_label.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,108 +177,6 @@ pub fn mora_to_text(consonant: Option<&str>, vowel: &str) -> String {
engine::mora2text(&mora_text).to_string()
}

// FIXME: Rust 1.77の新機能導入と共にこれを消す
#[allow(unused_imports)]
mod chunk_by {
// Implementations in this module were copied from
// [Rust](https://github.com/rust-lang/rust/blob/746a58d4359786e4aebb372a30829706fa5a968f/library/core/src/slice/iter.rs).

// MIT License Notice

// Permission is hereby granted, free of charge, to any
// person obtaining a copy of this software and associated
// documentation files (the "Software"), to deal in the
// Software without restriction, including without
// limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of
// the Software, and to permit persons to whom the Software
// is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice
// shall be included in all copies or substantial portions
// of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
// ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
// SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.

pub struct ChunkBy<'a, T, P> {
slice: &'a [T],
predicate: P,
}
impl<'a, T, P> ChunkBy<'a, T, P> {
pub(super) fn new(slice: &'a [T], predicate: P) -> Self {
ChunkBy { slice, predicate }
}
}
impl<'a, T, P> Iterator for ChunkBy<'a, T, P>
where
P: FnMut(&T, &T) -> bool,
{
type Item = &'a [T];

#[inline]
fn next(&mut self) -> Option<Self::Item> {
if self.slice.is_empty() {
None
} else {
let mut len = 1;
let mut iter = self.slice.windows(2);
while let Some([l, r]) = iter.next() {
if (self.predicate)(l, r) {
len += 1
} else {
break;
}
}
let (head, tail) = self.slice.split_at(len);
self.slice = tail;
Some(head)
}
}

#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
if self.slice.is_empty() {
(0, Some(0))
} else {
(1, Some(self.slice.len()))
}
}
}

#[easy_ext::ext(TChunkBy)]
impl<T> [T] {
pub fn chunk_by<F>(&self, pred: F) -> ChunkBy<'_, T, F>
where
F: FnMut(&T, &T) -> bool,
{
ChunkBy::new(self, pred)
}
}

#[cfg(test)]
mod tests {
use super::TChunkBy;

#[test]
fn chunk_by() {
let mut split = [0, 0, 1, 1, 1, -5].chunk_by(|a, b| a == b);
assert_eq!(split.next(), Some([0, 0].as_slice()));
assert_eq!(split.next(), Some([1, 1, 1].as_slice()));
assert_eq!(split.next(), Some([-5].as_slice()));
assert_eq!(split.next(), None);
}
}
}

#[cfg(test)]
mod tests {
use rstest_reuse::*;
Expand Down
1 change: 0 additions & 1 deletion crates/voicevox_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ mod infer;
mod macros;
mod manifest;
mod metas;
mod numerics;
mod result;
mod synthesizer;
mod task;
Expand Down
17 changes: 0 additions & 17 deletions crates/voicevox_core/src/numerics.rs

This file was deleted.

5 changes: 2 additions & 3 deletions crates/voicevox_core/src/synthesizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ pub(crate) mod blocking {
status::Status,
InferenceSessionOptions,
},
numerics::F32Ext as _,
text_analyzer::{KanaAnalyzer, OpenJTalkAnalyzer, TextAnalyzer},
AccentPhraseModel, AudioQueryModel, FullcontextExtractor, Result, StyleId,
SupportedDevices, SynthesisOptions, VoiceModelId, VoiceModelMeta,
Expand Down Expand Up @@ -302,8 +301,8 @@ pub(crate) mod blocking {
// VOICEVOX ENGINEと挙動を合わせるため、四捨五入ではなく偶数丸めをする
//
// https://github.com/VOICEVOX/voicevox_engine/issues/552
let phoneme_length = ((*phoneme_length * RATE).round_ties_even_() / speed_scale)
.round_ties_even_() as usize;
let phoneme_length = ((*phoneme_length * RATE).round_ties_even() / speed_scale)
.round_ties_even() as usize;
let phoneme_id = phoneme_data_list[i].phoneme_id();

for _ in 0..phoneme_length {
Expand Down
Loading