Skip to content

Commit 21d289a

Browse files
committed
Fix builds.
1 parent 6fbd4fc commit 21d289a

File tree

10 files changed

+45
-35
lines changed

10 files changed

+45
-35
lines changed

src/api/compile.rs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Module that defines the public compilation API of [`Engine`].
22
33
use crate::parser::{ParseResult, ParseState};
4-
use crate::{Engine, OptimizationLevel, Scope, AST};
4+
use crate::{Engine, Scope, AST};
55
#[cfg(feature = "no_std")]
66
use std::prelude::v1::*;
77

@@ -200,28 +200,37 @@ impl Engine {
200200
scope: &Scope,
201201
scripts: impl AsRef<[S]>,
202202
) -> ParseResult<AST> {
203-
self.compile_scripts_with_scope_raw(Some(scope), scripts, self.optimization_level)
203+
self.compile_scripts_with_scope_raw(
204+
Some(scope),
205+
scripts,
206+
#[cfg(not(feature = "no_optimize"))]
207+
self.optimization_level,
208+
)
204209
}
205210
/// Join a list of strings and compile into an [`AST`] using own scope at a specific optimization level.
206211
///
207212
/// ## Constants Propagation
208213
///
209-
/// If not [`OptimizationLevel::None`], constants defined within the scope are propagated
214+
/// If not [`OptimizationLevel::None`][`crate::OptimizationLevel::None`], constants defined within the scope are propagated
210215
/// throughout the script _including_ functions. This allows functions to be optimized based on
211216
/// dynamic global constants.
212217
#[inline]
213218
pub(crate) fn compile_scripts_with_scope_raw<S: AsRef<str>>(
214219
&self,
215220
scope: Option<&Scope>,
216221
scripts: impl AsRef<[S]>,
217-
optimization_level: OptimizationLevel,
222+
#[cfg(not(feature = "no_optimize"))] optimization_level: crate::OptimizationLevel,
218223
) -> ParseResult<AST> {
219224
let (stream, tc) = self.lex(scripts.as_ref());
220225

221226
let input = &mut stream.peekable();
222227
let lib = &mut <_>::default();
223228
let state = ParseState::new(scope, input, tc.clone(), lib);
224-
let mut _ast = self.parse(state, optimization_level)?;
229+
let mut _ast = self.parse(
230+
state,
231+
#[cfg(not(feature = "no_optimize"))]
232+
optimization_level,
233+
)?;
225234
#[cfg(feature = "metadata")]
226235
{
227236
let global_comments = &tc.borrow().global_comments;
@@ -296,6 +305,11 @@ impl Engine {
296305
let lib = &mut <_>::default();
297306
let state = ParseState::new(Some(scope), input, t, lib);
298307

299-
self.parse_global_expr(state, |_| {}, self.optimization_level)
308+
self.parse_global_expr(
309+
state,
310+
|_| {},
311+
#[cfg(not(feature = "no_optimize"))]
312+
self.optimization_level,
313+
)
300314
}
301315
}

src/api/eval.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,12 @@ impl Engine {
6565
scope: &mut Scope,
6666
script: &str,
6767
) -> RhaiResultOf<T> {
68-
let ast =
69-
self.compile_scripts_with_scope_raw(Some(scope), [script], self.optimization_level)?;
68+
let ast = self.compile_scripts_with_scope_raw(
69+
Some(scope),
70+
[script],
71+
#[cfg(not(feature = "no_optimize"))]
72+
self.optimization_level,
73+
)?;
7074
self.eval_ast_with_scope(scope, &ast)
7175
}
7276
/// Evaluate a string containing an expression, returning the result value or an error.
@@ -125,8 +129,6 @@ impl Engine {
125129
|_| {},
126130
#[cfg(not(feature = "no_optimize"))]
127131
crate::OptimizationLevel::None,
128-
#[cfg(feature = "no_optimize")]
129-
<_>::default(),
130132
)?
131133
};
132134

src/api/formatting.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,6 @@ impl Engine {
272272
state,
273273
#[cfg(not(feature = "no_optimize"))]
274274
crate::OptimizationLevel::None,
275-
#[cfg(feature = "no_optimize")]
276-
(),
277275
)?;
278276

279277
let guard = tc.borrow();

src/api/json.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,6 @@ impl Engine {
125125
|s| s.flags |= ParseSettingFlags::DISALLOW_UNQUOTED_MAP_PROPERTIES,
126126
#[cfg(not(feature = "no_optimize"))]
127127
crate::OptimizationLevel::None,
128-
#[cfg(feature = "no_optimize")]
129-
<_>::default(),
130128
)?
131129
};
132130

src/api/run.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ impl Engine {
6363
let lib = &mut <_>::default();
6464
let state = ParseState::new(Some(scope), input, tc, lib);
6565

66-
self.parse(state, self.optimization_level)?
66+
self.parse(
67+
state,
68+
#[cfg(not(feature = "no_optimize"))]
69+
self.optimization_level,
70+
)?
6771
};
6872
self.run_ast_with_scope(scope, &ast)
6973
}

src/ast/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ pub use stmt::{
2727
/// _(internals)_ Empty placeholder for a script-defined function.
2828
/// Exported under the `internals` feature only.
2929
#[cfg(feature = "no_function")]
30+
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, Default)]
3031
pub struct ScriptFuncDef;

src/engine.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::func::native::{
99
use crate::packages::{Package, StandardPackage};
1010
use crate::tokenizer::Token;
1111
use crate::types::StringsInterner;
12-
use crate::{Dynamic, Identifier, ImmutableString, Locked, OptimizationLevel, SharedModule};
12+
use crate::{Dynamic, Identifier, ImmutableString, Locked, SharedModule};
1313
#[cfg(feature = "no_std")]
1414
use std::prelude::v1::*;
1515
use std::{collections::BTreeSet, fmt, num::NonZeroU8};
@@ -131,7 +131,8 @@ pub struct Engine {
131131
pub(crate) def_tag: Dynamic,
132132

133133
/// Script optimization level.
134-
pub(crate) optimization_level: OptimizationLevel,
134+
#[cfg(not(feature = "no_optimize"))]
135+
pub(crate) optimization_level: crate::OptimizationLevel,
135136

136137
/// Max limits.
137138
#[cfg(not(feature = "unchecked"))]
@@ -254,9 +255,7 @@ impl Engine {
254255
def_tag: Dynamic::UNIT,
255256

256257
#[cfg(not(feature = "no_optimize"))]
257-
optimization_level: OptimizationLevel::Simple,
258-
#[cfg(feature = "no_optimize")]
259-
optimization_level: (),
258+
optimization_level: crate::OptimizationLevel::Simple,
260259

261260
#[cfg(not(feature = "unchecked"))]
262261
limits: crate::api::limits::Limits::new(),

src/func/call.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1621,8 +1621,6 @@ impl Engine {
16211621
[script],
16221622
#[cfg(not(feature = "no_optimize"))]
16231623
crate::OptimizationLevel::None,
1624-
#[cfg(feature = "no_optimize")]
1625-
<_>::default(),
16261624
)?;
16271625

16281626
// If new functions are defined within the eval string, it is an error

src/lib.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -323,10 +323,6 @@ pub use module::resolvers as module_resolvers;
323323
#[cfg(not(feature = "no_optimize"))]
324324
pub use optimizer::OptimizationLevel;
325325

326-
/// Empty placeholder for the optimization level.
327-
#[cfg(feature = "no_optimize")]
328-
struct OptimizationLevel;
329-
330326
// Expose internal data structures.
331327

332328
#[cfg(feature = "internals")]

src/parser.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ use crate::tokenizer::{
1616
use crate::types::dynamic::{AccessMode, Union};
1717
use crate::{
1818
calc_fn_hash, Dynamic, Engine, EvalAltResult, EvalContext, ExclusiveRange, FnArgsVec,
19-
ImmutableString, InclusiveRange, LexError, OptimizationLevel, ParseError, Position, Scope,
20-
Shared, SmartString, StaticVec, ThinVec, VarDefInfo, AST, PERR,
19+
ImmutableString, InclusiveRange, LexError, ParseError, Position, Scope, Shared, SmartString,
20+
StaticVec, ThinVec, VarDefInfo, AST, PERR,
2121
};
2222
use bitflags::bitflags;
2323
#[cfg(feature = "no_std")]
@@ -2156,7 +2156,7 @@ impl Engine {
21562156
(.., Expr::Variable(x, ..)) if !x.2.is_empty() => unreachable!("lhs.ns::id"),
21572157
// lhs.id
21582158
(lhs, var_expr @ Expr::Variable(..)) => {
2159-
let rhs = self.convert_expr_into_property( var_expr);
2159+
let rhs = self.convert_expr_into_property(var_expr);
21602160
Ok(Expr::Dot(BinaryExpr { lhs, rhs }.into(), op_flags, op_pos))
21612161
}
21622162
// lhs.prop
@@ -2232,7 +2232,7 @@ impl Engine {
22322232
// lhs.id.dot_rhs or lhs.id[idx_rhs]
22332233
Expr::Variable(..) | Expr::Property(..) => {
22342234
let new_binary = BinaryExpr {
2235-
lhs: self.convert_expr_into_property( x.lhs),
2235+
lhs: self.convert_expr_into_property(x.lhs),
22362236
rhs: x.rhs,
22372237
}
22382238
.into();
@@ -3796,7 +3796,7 @@ impl Engine {
37963796
&self,
37973797
mut state: ParseState,
37983798
process_settings: impl FnOnce(&mut ParseSettings),
3799-
_optimization_level: OptimizationLevel,
3799+
#[cfg(not(feature = "no_optimize"))] optimization_level: crate::OptimizationLevel,
38003800
) -> ParseResult<AST> {
38013801
let options = self.options & !LangOptions::STMT_EXPR & !LangOptions::LOOP_EXPR;
38023802

@@ -3828,14 +3828,14 @@ impl Engine {
38283828
statements,
38293829
#[cfg(not(feature = "no_function"))]
38303830
state.lib.values().cloned().collect::<Vec<_>>(),
3831-
_optimization_level,
3831+
optimization_level,
38323832
));
38333833

38343834
#[cfg(feature = "no_optimize")]
38353835
return Ok(AST::new(
38363836
statements,
38373837
#[cfg(not(feature = "no_function"))]
3838-
crate::Module::from(state.lib.into_values()),
3838+
crate::Module::from(state.lib.values().cloned()),
38393839
));
38403840
}
38413841

@@ -3906,7 +3906,7 @@ impl Engine {
39063906
pub(crate) fn parse(
39073907
&self,
39083908
mut state: ParseState,
3909-
_optimization_level: OptimizationLevel,
3909+
#[cfg(not(feature = "no_optimize"))] optimization_level: crate::OptimizationLevel,
39103910
) -> ParseResult<AST> {
39113911
let (statements, _lib) = self.parse_global_level(&mut state, |_| {})?;
39123912

@@ -3916,7 +3916,7 @@ impl Engine {
39163916
statements,
39173917
#[cfg(not(feature = "no_function"))]
39183918
_lib,
3919-
_optimization_level,
3919+
optimization_level,
39203920
));
39213921

39223922
#[cfg(feature = "no_optimize")]

0 commit comments

Comments
 (0)