Skip to content

Commit 9430936

Browse files
authored
Merge pull request #1868 from folkertdev/gen-arm-remove-lazy-static
`stdarch-gen-arm`: remove `lazy_static`, use `LazyLock` instead
2 parents 017a657 + f0c7fcf commit 9430936

File tree

6 files changed

+21
-31
lines changed

6 files changed

+21
-31
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/stdarch-gen-arm/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ edition = "2024"
1313

1414
[dependencies]
1515
itertools = "0.14.0"
16-
lazy_static = "1.4.0"
1716
proc-macro2 = "1.0"
1817
quote = "1.0"
1918
regex = "1.5"

crates/stdarch-gen-arm/src/expression.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use itertools::Itertools;
2-
use lazy_static::lazy_static;
32
use proc_macro2::{Literal, Punct, Spacing, TokenStream};
43
use quote::{ToTokens, TokenStreamExt, format_ident, quote};
54
use regex::Regex;
65
use serde::de::{self, MapAccess, Visitor};
76
use serde::{Deserialize, Deserializer, Serialize};
87
use std::fmt;
98
use std::str::FromStr;
9+
use std::sync::LazyLock;
1010

1111
use crate::intrinsic::Intrinsic;
1212
use crate::wildstring::WildStringPart;
@@ -374,10 +374,8 @@ impl FromStr for Expression {
374374
type Err = String;
375375

376376
fn from_str(s: &str) -> Result<Self, Self::Err> {
377-
lazy_static! {
378-
static ref MACRO_RE: Regex =
379-
Regex::new(r"^(?P<name>[\w\d_]+)!\((?P<ex>.*?)\);?$").unwrap();
380-
}
377+
static MACRO_RE: LazyLock<Regex> =
378+
LazyLock::new(|| Regex::new(r"^(?P<name>[\w\d_]+)!\((?P<ex>.*?)\);?$").unwrap());
381379

382380
if s == "SvUndef" {
383381
Ok(Expression::SvUndef)

crates/stdarch-gen-arm/src/load_store_tests.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::fs::File;
22
use std::io::Write;
33
use std::path::PathBuf;
44
use std::str::FromStr;
5+
use std::sync::LazyLock;
56

67
use crate::format_code;
78
use crate::input::InputType;
@@ -10,7 +11,6 @@ use crate::typekinds::BaseType;
1011
use crate::typekinds::{ToRepr, TypeKind};
1112

1213
use itertools::Itertools;
13-
use lazy_static::lazy_static;
1414
use proc_macro2::TokenStream;
1515
use quote::{format_ident, quote};
1616

@@ -639,8 +639,8 @@ impl LdIntrCharacteristics {
639639
}
640640
}
641641

642-
lazy_static! {
643-
static ref PREAMBLE: String = format!(
642+
static PREAMBLE: LazyLock<String> = LazyLock::new(|| {
643+
format!(
644644
r#"#![allow(unused)]
645645
646646
use super::*;
@@ -801,13 +801,11 @@ fn assert_vector_matches_u64(vector: svuint64_t, expected: svuint64_t) {{
801801
assert!(!svptest_any(defined, cmp))
802802
}}
803803
"#
804-
);
805-
}
804+
)
805+
});
806806

807-
lazy_static! {
808-
static ref MANUAL_TESTS: String = format!(
809-
"#[simd_test(enable = \"sve\")]
810-
unsafe fn test_ffr() {{
807+
const MANUAL_TESTS: &str = "#[simd_test(enable = \"sve\")]
808+
unsafe fn test_ffr() {
811809
svsetffr();
812810
let ffr = svrdffr();
813811
assert_vector_matches_u8(svdup_n_u8_z(ffr, 1), svindex_u8(1, 0));
@@ -816,7 +814,5 @@ unsafe fn test_ffr() {{
816814
svwrffr(pred);
817815
let ffr = svrdffr_z(svptrue_b8());
818816
assert_vector_matches_u8(svdup_n_u8_z(ffr, 1), svdup_n_u8_z(pred, 1));
819-
}}
820-
"
821-
);
822817
}
818+
";

crates/stdarch-gen-arm/src/typekinds.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
use lazy_static::lazy_static;
21
use proc_macro2::TokenStream;
32
use quote::{ToTokens, TokenStreamExt, quote};
43
use regex::Regex;
54
use serde_with::{DeserializeFromStr, SerializeDisplay};
65
use std::fmt;
76
use std::str::FromStr;
7+
use std::sync::LazyLock;
88

99
use crate::context;
1010
use crate::expression::{Expression, FnCall};
@@ -496,9 +496,9 @@ impl FromStr for VectorType {
496496
type Err = String;
497497

498498
fn from_str(s: &str) -> Result<Self, Self::Err> {
499-
lazy_static! {
500-
static ref RE: Regex = Regex::new(r"^(?:(?:sv(?P<sv_ty>(?:uint|int|bool|float)(?:\d+)?))|(?:(?P<ty>(?:uint|int|bool|poly|float)(?:\d+)?)x(?P<lanes>(?:\d+)?)))(?:x(?P<tuple_size>2|3|4))?_t$").unwrap();
501-
}
499+
static RE: LazyLock<Regex> = LazyLock::new(|| {
500+
Regex::new(r"^(?:(?:sv(?P<sv_ty>(?:uint|int|bool|float)(?:\d+)?))|(?:(?P<ty>(?:uint|int|bool|poly|float)(?:\d+)?)x(?P<lanes>(?:\d+)?)))(?:x(?P<tuple_size>2|3|4))?_t$").unwrap()
501+
});
502502

503503
if let Some(c) = RE.captures(s) {
504504
let (base_type, lanes) = Self::sanitise_lanes(
@@ -698,9 +698,8 @@ impl FromStr for BaseType {
698698
type Err = String;
699699

700700
fn from_str(s: &str) -> Result<Self, Self::Err> {
701-
lazy_static! {
702-
static ref RE: Regex = Regex::new(r"^(?P<kind>[a-zA-Z]+)(?P<size>\d+)?(_t)?$").unwrap();
703-
}
701+
static RE: LazyLock<Regex> =
702+
LazyLock::new(|| Regex::new(r"^(?P<kind>[a-zA-Z]+)(?P<size>\d+)?(_t)?$").unwrap());
704703

705704
if let Some(c) = RE.captures(s) {
706705
let kind = c["kind"].parse()?;

crates/stdarch-gen-arm/src/wildcards.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
use lazy_static::lazy_static;
21
use regex::Regex;
32
use serde_with::{DeserializeFromStr, SerializeDisplay};
4-
use std::fmt;
53
use std::str::FromStr;
4+
use std::{fmt, sync::LazyLock};
65

76
use crate::{
87
fn_suffix::SuffixKind,
@@ -66,9 +65,9 @@ impl FromStr for Wildcard {
6665
type Err = String;
6766

6867
fn from_str(s: &str) -> Result<Self, Self::Err> {
69-
lazy_static! {
70-
static ref RE: Regex = Regex::new(r"^(?P<wildcard>\w+?)(?:_x(?P<tuple_size>[2-4]))?(?:\[(?P<index>\d+)\])?(?:\.(?P<modifiers>\w+))?(?:\s+as\s+(?P<scale_to>.*?))?$").unwrap();
71-
}
68+
static RE: LazyLock<Regex> = LazyLock::new(|| {
69+
Regex::new(r"^(?P<wildcard>\w+?)(?:_x(?P<tuple_size>[2-4]))?(?:\[(?P<index>\d+)\])?(?:\.(?P<modifiers>\w+))?(?:\s+as\s+(?P<scale_to>.*?))?$").unwrap()
70+
});
7271

7372
if let Some(c) = RE.captures(s) {
7473
let wildcard_name = &c["wildcard"];

0 commit comments

Comments
 (0)