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

Remove lazy_static #180

Merged
merged 2 commits into from
Jan 19, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 0 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ vidyut-prakriya = { path = "./vidyut-prakriya" }
vidyut-sandhi = { path = "./vidyut-sandhi" }
csv = "1.1.6"
multimap = "0.8.3"
lazy_static = "1.4.0"
glob = "0.3.1"

[workspace.dependencies]
Expand Down
2 changes: 0 additions & 2 deletions bindings-python/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion vidyut-chandas/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ edition = "2021"

[dependencies]
console_error_panic_hook = "0.1.7"
lazy_static = "1.4.0"
serde = { version = "1.0.150", features = ["derive"] }
serde-wasm-bindgen = "0.4"
serde_derive = "1.0.193"
Expand Down
10 changes: 4 additions & 6 deletions vidyut-chandas/src/sounds.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use lazy_static::lazy_static;
use std::sync::LazyLock;

lazy_static! {
static ref HRASVA: Set = Set::from("aiufx");
static ref AC: Set = Set::from("aAiIuUfFxXeEoO");
static ref HAL: Set = Set::from("kKgGNcCjJYwWqQRtTdDnpPbBmyrlvSzshL");
}
static HRASVA: LazyLock<Set> = LazyLock::new(|| Set::from("aiufx"));
static AC: LazyLock<Set> = LazyLock::new(|| Set::from("aAiIuUfFxXeEoO"));
static HAL: LazyLock<Set> = LazyLock::new(|| Set::from("kKgGNcCjJYwWqQRtTdDnpPbBmyrlvSzshL"));

type Sound = char;

Expand Down
1 change: 0 additions & 1 deletion vidyut-cheda/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ compact_str = "0.8.1"
clap = { workspace = true }
log = { workspace = true }
env_logger = { workspace = true }
lazy_static = "1.5.0"
regex = "1.11.1"
rmp-serde = { workspace = true }
serde = {workspace = true }
9 changes: 4 additions & 5 deletions vidyut-cheda/src/normalize_text.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use lazy_static::lazy_static;
use std::sync::LazyLock;

use regex::Regex;

/// Creates a normalized version of `text` that is easier to process.
Expand All @@ -8,10 +9,8 @@ use regex::Regex;
/// 2. Delete all whitespace spans.
/// 3. Separate all remaining spans with a single " ".
pub fn normalize(text: &str) -> String {
lazy_static! {
static ref RE: Regex =
Regex::new(r"([a-zA-Z']+)|(\s+)|([^a-zA-Z']+)").expect("always defined");
}
static RE: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"([a-zA-Z']+)|(\s+)|([^a-zA-Z']+)").expect("always defined"));

let mut ret = RE
.find_iter(text)
Expand Down
22 changes: 8 additions & 14 deletions vidyut-cheda/src/sounds.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Utility functions for checking Sanskrit sounds.

use lazy_static::lazy_static;
use std::sync::LazyLock;

/// A set of Sanskrit sounds.
///
Expand Down Expand Up @@ -42,20 +42,16 @@ impl Default for SoundSet {
/// - other punctuation characters (|, ||, numbers)
/// - characters or symbols from non-SLP1 encodings
pub fn is_sanskrit(c: char) -> bool {
lazy_static! {
static ref CHARS: SoundSet =
SoundSet::from("aAiIuUfFxXeEoOMHkKgGNcCjJYwWqQRtTdDnpPbBmyrlvSzshL'");
}
static CHARS: LazyLock<SoundSet> =
LazyLock::new(|| SoundSet::from("aAiIuUfFxXeEoOMHkKgGNcCjJYwWqQRtTdDnpPbBmyrlvSzshL'"));
CHARS.contains(c)
}

/// Returns whether the given sound is a vowel.
///
/// `ac` is the Paninian name for the Sanskrit vowels.
pub fn is_ac(c: char) -> bool {
lazy_static! {
static ref AC: SoundSet = SoundSet::from("aAiIuUfFxXeEoO");
}
static AC: LazyLock<SoundSet> = LazyLock::new(|| SoundSet::from("aAiIuUfFxXeEoO"));
AC.contains(c)
}

Expand All @@ -64,18 +60,16 @@ pub fn is_ac(c: char) -> bool {
/// `hal` is the Paninian name for the Sanskrit consonants.
#[allow(unused)]
pub fn is_hal(c: char) -> bool {
lazy_static! {
static ref HAL: SoundSet = SoundSet::from("kKgGNcCjJYwWqQRtTdDnpPbBmyrlvSzshL");
}
static HAL: LazyLock<SoundSet> =
LazyLock::new(|| SoundSet::from("kKgGNcCjJYwWqQRtTdDnpPbBmyrlvSzshL"));
HAL.contains(c)
}

/// Returns whether the given sound is voiced.
#[allow(unused)]
pub fn is_ghosha(c: char) -> bool {
lazy_static! {
static ref GHOSHA: SoundSet = SoundSet::from("aAiIuUfFxXeEoOgGNjJYqQRdDnbBmyrlvh");
}
static GHOSHA: LazyLock<SoundSet> =
LazyLock::new(|| SoundSet::from("aAiIuUfFxXeEoOgGNjJYqQRdDnbBmyrlvh"));
GHOSHA.contains(c)
}

Expand Down
21 changes: 0 additions & 21 deletions vidyut-prakriya/ARCHITECTURE.md
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know what the usual style is, but I like having two blank spaces before heading so that sections are clear. Can you revert the changes to this file?

Copy link
Contributor Author

@vbasky vbasky Jan 16, 2025

Choose a reason for hiding this comment

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

image

This is the VSCode Extension that I use for Markdown Lint. The extension has well written rules that a markdown should validate against. The cleanup that I did was based on the extension's recommendation

image

This is how it offers suggestions to make markdown compliant. But you are right. The change here is unrelated to what this PR is inteded for. I should revert this change, will do.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ our system.
This document assumes some familiarity with basic Rust concepts like structs,
enums, closures, and lifetimes.


Goals and values
----------------

Expand Down Expand Up @@ -40,7 +39,6 @@ than wait for perfect clarity. Fortunately, we have found that as the program
has grown and matured, we have become more and more able to remove hacks and
solve problems in a more fundamental way.


Core data types
---------------

Expand All @@ -66,21 +64,18 @@ In addition to these three types, we recommend exploring the types in the
part of its API. Our hope is that callers can lean on Rust's type system to
define meaningful requests and receive correct derivations.


Core modules
------------

We start our description here with the high-level `vyakarana` module then work
our way into specific implementation details.


### `vyakarana`

This defines the public API. Given certain input conditions, the method here
return all `Prakriya`s compatible with those conditions. `vyakarana` is a thin
wrapper over the `ashtadhyayi` module, which we describe below.


### `args`

This defines the argument types that `Vyakarana` accepts. The types here follow
Expand All @@ -89,8 +84,6 @@ Paninian categories as closely as possible, so we have types like `Dhatu`,
arguments are well formed. For example, a `Krdanta` must have a `Dhatu` and a
`Krt`.



### `ashtadhyayi`

This defines the core rules of the Ashtadhayi. Given the input constraints
Expand Down Expand Up @@ -118,7 +111,6 @@ their own modules. Some examples:
- `unadipatha`, which defines the rules of the Unadipatha. These rules enter
the Ashtadhyayi through rule 3.3.1 (*uṇādayo bahulam*)


### `prakriya`, `terms`, and `tags`

These define the `Prakriya` and `Term` types, as well as some useful secondary
Expand All @@ -130,21 +122,18 @@ variety of ad-hoc flags.

Since `Term` and `Tag` are not stable, we do not expose them in our public API.


### `prakriya_stack`

This module defines utilities for exploring different paths of optional rules.
The core type here is `PrakriyaStack`, which manages a stack of rule paths.
(`RulePathStack` might be a clearer name, but it doesn't quite roll off the
tongue!)


### `sounds`

This defines various functions for testing and modifying Sanskrit sounds. The
core data structure here is `Set`, which stores sounds in a simple array.


Code style
----------

Expand All @@ -165,7 +154,6 @@ the logic of each rule more obvious. Here, `p` is a `Prakriya`, `i` is the
index of some `Term` within the `Prakriya`, and `|t| ...` is a closure (inline
function) that accepts a `Term`.


### Closures

`run_at`, like many of the methods on `Prakriya`, accepts a closure.
Expand All @@ -188,7 +176,6 @@ for `p.terms[i]`. `Prakriya` also defines many methods for working with
indices, such as `find_first_where`, `find_last_where`, `find_next_where`,
and so on.


### Naming conventions

Since we have so many rules to write, we use short variable names for common
Expand All @@ -203,7 +190,6 @@ concepts. Some examples:
[rust-borrow]: https://users.rust-lang.org/t/newbie-mut-with-nested-structs/84755
[rust-q]: https://doc.rust-lang.org/rust-by-example/std/result/question_mark.html


Control flow
------------

Expand All @@ -226,7 +212,6 @@ directly encodes a critical principle of the grammar.
The sections below extend the example above and illustrate the various kinds of
control flow we use, ordered from least to most complex.


### Rule sequences

The control flow in the example above is appropriate for simple sequences of
Expand All @@ -241,7 +226,6 @@ if condition_2 {
}
```


### Simple rule blocking

A natural extension is to use `if`-`else` chains to enforce that only one rule
Expand All @@ -257,7 +241,6 @@ if condition_1 {
}
```


### Falling through

If a rule is optional, we might wish to "fall through" and consider other
Expand All @@ -277,7 +260,6 @@ if condition_2 {

Here, `rule_2` is accessible even if we reject `rule_1`.


### Simple locking

If we fall through in a simple way, we could end up running both `rule_1` and
Expand All @@ -300,7 +282,6 @@ if done {
}
```


### Extended locking

Sometimes, we might wish to implement rule locking over a very large section of
Expand Down Expand Up @@ -345,12 +326,10 @@ If we use the new `do_something_1` and `do_something_2` methods here,
the original `Prakriya` struct, we can access it through `lp.p`. Once the
lifetime of `lp` has ended, we can continue using `p` as before.


### Context-aware locking

Suppose we wish to derive a *taddhitānta* that uses a specific
taddhita-pratyaya only if available in a specific meaning context. In this
case, we can extend the `LockingPrakriya` pattern above to record other useful
metadata, such as the meaning condition we wish to derive (if any). For
examples of this pattern, see `KrtPrakriya` and `TaddhitaPrakriya`.

1 change: 0 additions & 1 deletion vidyut-prakriya/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions vidyut-prakriya/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ rust-version = "1.68"

[dependencies]
enumset = { version = "1.1.3", features = ["serde"] }
lazy_static = "1.4.0"
rustc-hash = { workspace = true }
serde = { version = "1.0.150", features = ["derive"] }
wasm-bindgen = { version = "0.2", features = ["serde-serialize"]}
wasm-bindgen = { version = "0.2", features = ["serde-serialize"] }
serde-wasm-bindgen = "0.4"
console_error_panic_hook = "0.1.7"

Expand Down
7 changes: 3 additions & 4 deletions vidyut-prakriya/src/angasya/abhyasasya.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ abhyasasya
Runs rules that modify the abhyāsa.
*/

use std::sync::LazyLock;

use crate::args::Agama as A;
use crate::args::Agama;
use crate::args::Aupadeshika;
Expand All @@ -23,7 +25,6 @@ use crate::dhatu_gana as gana;
use crate::it_samjna;
use crate::sounds as al;
use crate::sounds::{map, s, Map, Set, AC, HAL};
use lazy_static::lazy_static;

const AA: Set = s(&["a"]);
const ANUNASIKA: Set = s(&["Yam"]);
Expand All @@ -33,9 +34,7 @@ const KHAY: Set = s(&["Kay"]);
const F_HAL: Set = s(&["f hal"]);
const PU_YAN_J: Set = s(&["pu~", "yaR", "j"]);

lazy_static! {
static ref KUH_CU: Map = map("ku~ h", "cu~");
}
static KUH_CU: LazyLock<Map> = LazyLock::new(|| map("ku~ h", "cu~"));

/// Simplifies the abhyasa per 7.4.60.
fn try_haladi(text: &str) -> TermString {
Expand Down
6 changes: 2 additions & 4 deletions vidyut-prakriya/src/krt/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,13 @@ use crate::krt::utils::KrtPrakriya;
use crate::sounds::{s, Set, AC, HAL, IK};
use crate::stem_gana::TYAD_ADI;
use crate::Rule::Varttika;
use lazy_static::lazy_static;
use std::sync::LazyLock;

const II: Set = s(&["i"]);
const UU: Set = s(&["u"]);
const PU: Set = s(&["pu~"]);

lazy_static! {
static ref EMPTY_TERM: Term = Term::make_text("");
}
static EMPTY_TERM: LazyLock<Term> = LazyLock::new(|| Term::make_text(""));

/// Tries to add various pratyayas that are just "a."
fn try_add_various_pratyayas(kp: &mut KrtPrakriya) {
Expand Down
Loading
Loading