Skip to content

Commit cbf2633

Browse files
committed
improve names
1 parent 76e89ae commit cbf2633

10 files changed

Lines changed: 56 additions & 58 deletions

File tree

crates/anodized-core/src/instrument.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,24 @@ pub mod loops;
1010
pub mod traits;
1111

1212
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
13-
pub enum Config {
13+
pub enum Mode {
1414
/// Make no changes to the code.
1515
ChangeNothing,
1616
/// Inject code to enable compile-time and/or runtime checks.
17-
InjectChecks(CheckConfig),
17+
InjectChecks(CheckSettings),
1818
/// Embed spec elements as new items without changing existing code.
1919
EmbedSpecs,
2020
}
2121

2222
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
23-
pub struct CheckConfig {
23+
pub struct CheckSettings {
2424
pub does_print: bool,
2525
pub does_panic: bool,
2626
}
2727

28-
impl Config {
28+
impl Mode {
2929
pub fn changes_anything(&self) -> bool {
30-
!matches!(self, Self::ChangeNothing)
30+
!matches!(self, Mode::ChangeNothing)
3131
}
3232

3333
pub fn instrument_item_fn(&self, spec: Spec, mut item_fn: ItemFn) -> Result<TokenStream> {
@@ -99,12 +99,12 @@ impl Config {
9999
}
100100

101101
#[cfg(test)]
102-
impl Config {
103-
pub(crate) const DEFAULT: Self = Self::InjectChecks(CheckConfig::DEFAULT);
102+
impl Mode {
103+
pub(crate) const DEFAULT: Self = Mode::InjectChecks(CheckSettings::DEFAULT);
104104
}
105105

106106
#[cfg(test)]
107-
impl CheckConfig {
107+
impl CheckSettings {
108108
pub(crate) const DEFAULT: Self = Self {
109109
does_print: false,
110110
does_panic: false,

crates/anodized-core/src/instrument/data.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ use proc_macro2::TokenStream;
66
use quote::ToTokens;
77
use syn::{ItemEnum, ItemImpl, ItemStruct, Result, parse_quote};
88

9-
use crate::{DataSpec, instrument::Config};
9+
use crate::{DataSpec, instrument::Mode};
1010

11-
impl Config {
11+
impl Mode {
1212
pub fn instrument_item_struct(
1313
&self,
1414
spec: DataSpec,
@@ -47,7 +47,7 @@ impl Config {
4747

4848
item_enum.to_tokens(&mut tokens);
4949

50-
if let Self::EmbedSpecs = self {
50+
if let Mode::EmbedSpecs = self {
5151
let spec_impl: ItemImpl = parse_quote! {
5252
#[doc(hidden)]
5353
#[allow(warnings)]

crates/anodized-core/src/instrument/data_tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{DataSpec, instrument::Config, test_util::assert_tokens_eq};
1+
use crate::{DataSpec, instrument::Mode, test_util::assert_tokens_eq};
22

33
use proc_macro2::TokenStream;
44
use syn::{ItemEnum, ItemStruct, parse_quote};
@@ -46,7 +46,7 @@ fn embed_spec_item_struct() {
4646
}
4747
};
4848

49-
let observed = Config::EmbedSpecs
49+
let observed = Mode::EmbedSpecs
5050
.instrument_item_struct(struct_spec, item_struct)
5151
.unwrap();
5252
assert_tokens_eq(&observed, &expected);
@@ -98,7 +98,7 @@ fn embed_spec_item_enum() {
9898
}
9999
};
100100

101-
let observed = Config::EmbedSpecs
101+
let observed = Mode::EmbedSpecs
102102
.instrument_item_enum(struct_spec, item_enum)
103103
.unwrap();
104104
assert_tokens_eq(&observed, &expected);

crates/anodized-core/src/instrument/fns.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ use syn::{
1212

1313
use crate::{
1414
Capture, PostCondition, PreCondition, Spec,
15-
instrument::{CheckConfig, Config},
15+
instrument::{CheckSettings, Mode},
1616
qualifiers::FnQualifiers,
1717
};
1818

19-
impl Config {
19+
impl Mode {
2020
pub fn instrument_fn(&self, spec: &Spec, sig: &Signature, body: &mut Block) -> syn::Result<()> {
2121
self.instrument_loops_in_fn_body(body)?;
2222

23-
let Self::InjectChecks(check_config) = self else {
23+
let Mode::InjectChecks(check_config) = self else {
2424
return Ok(());
2525
};
2626

@@ -212,7 +212,7 @@ impl Config {
212212
}
213213
}
214214

215-
impl CheckConfig {
215+
impl CheckSettings {
216216
fn instrument_fn_body(
217217
&self,
218218
spec: &Spec,

crates/anodized-core/src/instrument/fns_tests.rs

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ fn embed_spec_item_fn() {
7373
}
7474
};
7575

76-
let observed = Config::EmbedSpecs
76+
let observed = Mode::EmbedSpecs
7777
.instrument_item_fn(fn_spec, item_fn)
7878
.unwrap();
7979
assert_tokens_eq(&observed, &expected);
@@ -121,9 +121,7 @@ fn default_instrument_item_fn() {
121121
}
122122
};
123123

124-
let observed = Config::DEFAULT
125-
.instrument_item_fn(fn_spec, item_fn)
126-
.unwrap();
124+
let observed = Mode::DEFAULT.instrument_item_fn(fn_spec, item_fn).unwrap();
127125
assert_tokens_eq(&observed, &expected);
128126
}
129127

@@ -170,7 +168,7 @@ fn simple_requires() {
170168
}
171169
};
172170

173-
let observed = CheckConfig::PRINT_AND_PANIC
171+
let observed = CheckSettings::PRINT_AND_PANIC
174172
.instrument_fn_body(&spec, &body, is_async, &ret_type)
175173
.unwrap();
176174
assert_tokens_eq(&observed, &expected);
@@ -185,7 +183,7 @@ fn requires_disable_runtime_checks() {
185183
let ret_type = make_return_type();
186184
let is_async = false;
187185

188-
let observed = CheckConfig::DEFAULT
186+
let observed = CheckSettings::DEFAULT
189187
.instrument_fn_body(&spec, &body, is_async, &ret_type)
190188
.unwrap();
191189
let expected: Block = parse_quote! {
@@ -238,7 +236,7 @@ fn requires_no_panic_runtime() {
238236
}
239237
};
240238

241-
let observed = CheckConfig::PRINT
239+
let observed = CheckSettings::PRINT
242240
.instrument_fn_body(&spec, &body, is_async, &ret_type)
243241
.unwrap();
244242
assert_tokens_eq(&observed, &expected);
@@ -276,7 +274,7 @@ fn simple_maintains() {
276274
}
277275
};
278276

279-
let observed = CheckConfig::PRINT_AND_PANIC
277+
let observed = CheckSettings::PRINT_AND_PANIC
280278
.instrument_fn_body(&spec, &body, is_async, &ret_type)
281279
.unwrap();
282280
assert_tokens_eq(&observed, &expected);
@@ -313,7 +311,7 @@ fn simple_ensures() {
313311
}
314312
};
315313

316-
let observed = CheckConfig::PRINT_AND_PANIC
314+
let observed = CheckSettings::PRINT_AND_PANIC
317315
.instrument_fn_body(&spec, &body, is_async, &ret_type)
318316
.unwrap();
319317
assert_tokens_eq(&observed, &expected);
@@ -354,7 +352,7 @@ fn simple_requires_and_maintains() {
354352
}
355353
};
356354

357-
let observed = CheckConfig::PRINT_AND_PANIC
355+
let observed = CheckSettings::PRINT_AND_PANIC
358356
.instrument_fn_body(&spec, &body, is_async, &ret_type)
359357
.unwrap();
360358
assert_tokens_eq(&observed, &expected);
@@ -393,7 +391,7 @@ fn simple_requires_and_ensures() {
393391
}
394392
};
395393

396-
let observed = CheckConfig::PRINT_AND_PANIC
394+
let observed = CheckSettings::PRINT_AND_PANIC
397395
.instrument_fn_body(&spec, &body, is_async, &ret_type)
398396
.unwrap();
399397
assert_tokens_eq(&observed, &expected);
@@ -434,7 +432,7 @@ fn simple_maintains_and_ensures() {
434432
}
435433
};
436434

437-
let observed = CheckConfig::PRINT_AND_PANIC
435+
let observed = CheckSettings::PRINT_AND_PANIC
438436
.instrument_fn_body(&spec, &body, is_async, &ret_type)
439437
.unwrap();
440438
assert_tokens_eq(&observed, &expected);
@@ -478,7 +476,7 @@ fn simple_requires_maintains_and_ensures() {
478476
}
479477
};
480478

481-
let observed = CheckConfig::PRINT_AND_PANIC
479+
let observed = CheckSettings::PRINT_AND_PANIC
482480
.instrument_fn_body(&spec, &body, is_async, &ret_type)
483481
.unwrap();
484482
assert_tokens_eq(&observed, &expected);
@@ -522,7 +520,7 @@ fn simple_async_requires_maintains_and_ensures() {
522520
}
523521
};
524522

525-
let observed = CheckConfig::PRINT_AND_PANIC
523+
let observed = CheckSettings::PRINT_AND_PANIC
526524
.instrument_fn_body(&spec, &body, is_async, &ret_type)
527525
.unwrap();
528526
assert_tokens_eq(&observed, &expected);
@@ -574,7 +572,7 @@ fn multiple_conditions_in_clauses() {
574572
}
575573
};
576574

577-
let observed = CheckConfig::PRINT_AND_PANIC
575+
let observed = CheckSettings::PRINT_AND_PANIC
578576
.instrument_fn_body(&spec, &body, is_async, &ret_type)
579577
.unwrap();
580578
assert_tokens_eq(&observed, &expected);
@@ -612,7 +610,7 @@ fn binds_parameter() {
612610
}
613611
};
614612

615-
let observed = CheckConfig::PRINT_AND_PANIC
613+
let observed = CheckSettings::PRINT_AND_PANIC
616614
.instrument_fn_body(&spec, &body, is_async, &ret_type)
617615
.unwrap();
618616
assert_tokens_eq(&observed, &expected);
@@ -660,7 +658,7 @@ fn ensures_with_mixed_conditions() {
660658
}
661659
};
662660

663-
let observed = CheckConfig::PRINT_AND_PANIC
661+
let observed = CheckSettings::PRINT_AND_PANIC
664662
.instrument_fn_body(&spec, &body, is_async, &ret_type)
665663
.unwrap();
666664
assert_tokens_eq(&observed, &expected);
@@ -708,7 +706,7 @@ fn cfg_attributes() {
708706
}
709707
};
710708

711-
let observed = CheckConfig::PRINT_AND_PANIC
709+
let observed = CheckSettings::PRINT_AND_PANIC
712710
.instrument_fn_body(&spec, &body, is_async, &ret_type)
713711
.unwrap();
714712
assert_tokens_eq(&observed, &expected);
@@ -762,7 +760,7 @@ fn cfg_on_single_and_list_conditions() {
762760
}
763761
};
764762

765-
let observed = CheckConfig::PRINT_AND_PANIC
763+
let observed = CheckSettings::PRINT_AND_PANIC
766764
.instrument_fn_body(&spec, &body, is_async, &ret_type)
767765
.unwrap();
768766
assert_tokens_eq(&observed, &expected);
@@ -830,7 +828,7 @@ fn complex_mixed_conditions() {
830828
}
831829
};
832830

833-
let observed = CheckConfig::PRINT_AND_PANIC
831+
let observed = CheckSettings::PRINT_AND_PANIC
834832
.instrument_fn_body(&spec, &body, is_async, &ret_type)
835833
.unwrap();
836834
assert_tokens_eq(&observed, &expected);
@@ -878,7 +876,7 @@ fn captures() {
878876
}
879877
};
880878

881-
let observed = CheckConfig::PRINT_AND_PANIC
879+
let observed = CheckSettings::PRINT_AND_PANIC
882880
.instrument_fn_body(&spec, &body, is_async, &ret_type)
883881
.unwrap();
884882
assert_tokens_eq(&observed, &expected);

crates/anodized-core/src/instrument/loops.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ use syn::{
1111

1212
use crate::{
1313
LoopSpec,
14-
instrument::{Config, find_spec_attr},
14+
instrument::{Mode, find_spec_attr},
1515
};
1616

17-
impl Config {
17+
impl Mode {
1818
pub fn instrument_loops_in_fn_body(&self, body: &mut Block) -> Result<()> {
1919
let mut visitor = LoopSpecVisitor::new(self);
2020
visitor.visit_block_mut(body);
@@ -68,12 +68,12 @@ impl Config {
6868
}
6969

7070
struct LoopSpecVisitor<'a> {
71-
config: &'a Config,
71+
config: &'a Mode,
7272
errors: Option<Error>,
7373
}
7474

7575
impl<'a> LoopSpecVisitor<'a> {
76-
fn new(config: &'a Config) -> Self {
76+
fn new(config: &'a Mode) -> Self {
7777
Self {
7878
config,
7979
errors: None,

crates/anodized-core/src/instrument/loops_tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use proc_macro2::TokenStream;
22
use syn::{ExprForLoop, ExprWhile, parse_quote};
33

4-
use crate::{LoopSpec, instrument::Config, test_util::assert_tokens_eq};
4+
use crate::{LoopSpec, instrument::Mode, test_util::assert_tokens_eq};
55

66
#[test]
77
fn embed_spec_expr_while() {
@@ -33,7 +33,7 @@ fn embed_spec_expr_while() {
3333
}
3434
};
3535

36-
Config::EmbedSpecs.instrument_expr_while(while_spec, &mut expr_while);
36+
Mode::EmbedSpecs.instrument_expr_while(while_spec, &mut expr_while);
3737
let observed = expr_while;
3838

3939
assert_tokens_eq(&observed, &expected);
@@ -65,7 +65,7 @@ fn embed_spec_expr_for() {
6565
}
6666
};
6767

68-
Config::EmbedSpecs.instrument_expr_for_loop(for_spec, &mut expr_for_loop);
68+
Mode::EmbedSpecs.instrument_expr_for_loop(for_spec, &mut expr_for_loop);
6969
let observed = expr_for_loop;
7070

7171
assert_tokens_eq(&observed, &expected);

crates/anodized-core/src/instrument/traits.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ use syn::{
1010

1111
use crate::{
1212
DataSpec, Spec,
13-
instrument::{Config, find_spec_attr, make_item_error},
13+
instrument::{Mode, find_spec_attr, make_item_error},
1414
};
1515

16-
impl Config {
16+
impl Mode {
1717
/// Expand trait items by mangling each method and adding a wrapper default impl.
1818
///
1919
/// Mangling a function involves the following:
@@ -111,7 +111,7 @@ impl Config {
111111
self.instrument_loops_in_fn_body(default_body)?;
112112
}
113113

114-
if let Self::InjectChecks(_) = self {
114+
if let Mode::InjectChecks(_) = self {
115115
let mangled_ident = mangle_ident(&func.sig.ident);
116116

117117
let mut mangled_fn = func.clone();
@@ -260,7 +260,7 @@ Instead, ensure that both the trait and the impl fn have a `#[spec]` annotation.
260260
new_items.push(ImplItem::Const(spec_qualifiers_const));
261261
}
262262

263-
if let Self::InjectChecks(_) = self {
263+
if let Mode::InjectChecks(_) = self {
264264
self.instrument_fn(&fn_spec, &func.sig, &mut func.block)?;
265265

266266
// Add a compile-time check to the body.

0 commit comments

Comments
 (0)