remove nu/do --use-ir, add NU_USE_IR environment variable, tested at start and by do

This commit is contained in:
Devyn Cairns 2024-07-09 00:26:46 -07:00
parent 1ce2096b72
commit 1cd8279ad5
4 changed files with 29 additions and 49 deletions

View File

@ -49,12 +49,6 @@ impl Command for Do {
"catch errors as the closure runs, and return them", "catch errors as the closure runs, and return them",
Some('c'), Some('c'),
) )
// FIXME: for testing only
.switch(
"use-ir",
"use the compiled IR instead of evaluating the expression",
None,
)
.switch( .switch(
"env", "env",
"keep the environment defined inside the command", "keep the environment defined inside the command",
@ -84,7 +78,6 @@ impl Command for Do {
let ignore_program_errors = ignore_all_errors let ignore_program_errors = ignore_all_errors
|| call.has_flag(engine_state, caller_stack, "ignore-program-errors")?; || call.has_flag(engine_state, caller_stack, "ignore-program-errors")?;
let capture_errors = call.has_flag(engine_state, caller_stack, "capture-errors")?; let capture_errors = call.has_flag(engine_state, caller_stack, "capture-errors")?;
let use_ir = call.has_flag(engine_state, caller_stack, "use-ir")?;
let has_env = call.has_flag(engine_state, caller_stack, "env")?; let has_env = call.has_flag(engine_state, caller_stack, "env")?;
let mut callee_stack = caller_stack.captures_to_stack_preserve_out_dest(block.captures); let mut callee_stack = caller_stack.captures_to_stack_preserve_out_dest(block.captures);
@ -94,9 +87,7 @@ impl Command for Do {
let eval_block_with_early_return = get_eval_block_with_early_return(engine_state); let eval_block_with_early_return = get_eval_block_with_early_return(engine_state);
// Applies to all block evaluation once set true // Applies to all block evaluation once set true
if use_ir { callee_stack.use_ir = caller_stack.has_env_var(engine_state, "NU_USE_IR");
caller_stack.use_ir = true;
}
let result = eval_block_with_early_return(engine_state, &mut callee_stack, block, input); let result = eval_block_with_early_return(engine_state, &mut callee_stack, block, input);

View File

@ -297,12 +297,13 @@ pub fn nu_run_test(opts: NuOpts, commands: impl AsRef<str>, with_std: bool) -> O
.stdout(Stdio::piped()) .stdout(Stdio::piped())
.stderr(Stdio::piped()); .stderr(Stdio::piped());
// Use IR evaluator (or set $env.NU_TEST_USE_IR to always do this) // Explicitly set NU_USE_IR
if opts if let Some(use_ir) = opts.use_ir {
.use_ir if use_ir {
.unwrap_or_else(|| std::env::var("NU_TEST_USE_IR").is_ok()) command.env("NU_USE_IR", "1");
{ } else {
command.arg("--use-ir"); command.env_remove("NU_USE_IR");
}
} }
// Uncomment to debug the command being run: // Uncomment to debug the command being run:
@ -383,32 +384,24 @@ where
executable_path = crate::fs::installed_nu_path(); executable_path = crate::fs::installed_nu_path();
} }
let mut nu = setup_command(&executable_path, &target_cwd); let process = match setup_command(&executable_path, &target_cwd)
.envs(envs)
nu.envs(envs); .arg("--commands")
.arg(command)
nu.arg("--commands"); // Use plain errors to help make error text matching more consistent
nu.arg(command); .args(["--error-style", "plain"])
// Use plain errors to help make error text matching more consistent .arg("--config")
nu.args(["--error-style", "plain"]); .arg(temp_config_file)
nu.arg("--config"); .arg("--env-config")
nu.arg(temp_config_file); .arg(temp_env_config_file)
nu.arg("--env-config"); .arg("--plugin-config")
nu.arg(temp_env_config_file); .arg(temp_plugin_file)
nu.arg("--plugin-config"); .arg("--plugins")
nu.arg(temp_plugin_file); .arg(plugins_arg)
nu.arg("--plugins"); .stdout(Stdio::piped())
nu.arg(plugins_arg); .stderr(Stdio::piped())
.spawn()
// Test plugin tests with IR too, if asked to {
if std::env::var("NU_TEST_USE_IR").is_ok() {
nu.arg("--use-ir");
}
nu.stdout(Stdio::piped());
nu.stderr(Stdio::piped());
let process = match nu.spawn() {
Ok(child) => child, Ok(child) => child,
Err(why) => panic!("Can't run test {}", why), Err(why) => panic!("Can't run test {}", why),
}; };

View File

@ -107,7 +107,6 @@ pub(crate) fn parse_commandline_args(
let error_style: Option<Value> = let error_style: Option<Value> =
call.get_flag(engine_state, &mut stack, "error-style")?; call.get_flag(engine_state, &mut stack, "error-style")?;
let no_newline = call.get_named_arg("no-newline"); let no_newline = call.get_named_arg("no-newline");
let use_ir = call.has_flag(engine_state, &mut stack, "use-ir")?;
// ide flags // ide flags
let lsp = call.has_flag(engine_state, &mut stack, "lsp")?; let lsp = call.has_flag(engine_state, &mut stack, "lsp")?;
@ -252,7 +251,6 @@ pub(crate) fn parse_commandline_args(
table_mode, table_mode,
error_style, error_style,
no_newline, no_newline,
use_ir,
}); });
} }
} }
@ -294,7 +292,6 @@ pub(crate) struct NushellCliArgs {
pub(crate) ide_complete: Option<Value>, pub(crate) ide_complete: Option<Value>,
pub(crate) ide_check: Option<Value>, pub(crate) ide_check: Option<Value>,
pub(crate) ide_ast: Option<Spanned<String>>, pub(crate) ide_ast: Option<Spanned<String>>,
pub(crate) use_ir: bool,
} }
#[derive(Clone)] #[derive(Clone)]
@ -371,7 +368,6 @@ impl Command for Nu {
"start with an alternate environment config file", "start with an alternate environment config file",
None, None,
) )
.switch("use-ir", "EXPERIMENTAL: use the IR evaluation engine on launch", None)
.switch( .switch(
"lsp", "lsp",
"start nu's language server protocol", "start nu's language server protocol",

View File

@ -26,7 +26,7 @@ pub(crate) fn run_commands(
let mut stack = Stack::new(); let mut stack = Stack::new();
let start_time = std::time::Instant::now(); let start_time = std::time::Instant::now();
if parsed_nu_cli_args.use_ir { if stack.has_env_var(engine_state, "NU_USE_IR") {
stack.use_ir = true; stack.use_ir = true;
} }
@ -148,7 +148,7 @@ pub(crate) fn run_file(
trace!("run_file"); trace!("run_file");
let mut stack = Stack::new(); let mut stack = Stack::new();
if parsed_nu_cli_args.use_ir { if stack.has_env_var(engine_state, "NU_USE_IR") {
stack.use_ir = true; stack.use_ir = true;
} }
@ -262,7 +262,7 @@ pub(crate) fn run_repl(
let mut stack = Stack::new(); let mut stack = Stack::new();
let start_time = std::time::Instant::now(); let start_time = std::time::Instant::now();
if parsed_nu_cli_args.use_ir { if stack.has_env_var(engine_state, "NU_USE_IR") {
stack.use_ir = true; stack.use_ir = true;
} }