Repository navigation
Run commands found by id through one IR call path (AST migration phase 3) - #19351
Merged
Merged
Conversation
No command has opted into `requires_ast_for_arguments` since nushell#18813, so the compiler never kept argument AST and every `IrBlock.ast` entry was `None`. Remove the opt-in, `IrAstRef`, `IrBlock.ast`, the `ast` field of `engine::Argument`, `ir::Call::positional_ast`, `engine::Call::positional_nth`, and the inventory test that guarded the empty opt-in list. `let` and `mut` compile through `compile_let`, so `Let::run` only runs for an indirect call such as a plugin's `call_decl`. It now returns an error like `unlet` does instead of walking argument AST that is never there.
`eval_ir_call` runs an `ir::Call` whose arguments are on the stack the way compiled code does: the input is type checked, record spreads become flags, and a custom command binds its parameters and runs its block. The VM's call instruction now shares that code (`eval_call_frame`). Callers that looked a command up by name worked around the private VM path, and two of them broke on custom commands: - `http`'s `from <ext>` converter called `Command::run`, so a `def "from ext"` failed with "can't run custom command with 'run', use block_id". - `save` ran a custom `to <ext>` block without binding its parameters, so a flag or a default was "Variable not found". - a plugin's `call_decl` on a custom command failed like `http` (nushell#16974). - `open` went through the AST `eval_call`. All four use `eval_ir_call` now. Converters and `call_decl` also get the input type check and argument normalization that compiled calls get. `ir::Call::leave` on a call without arguments truncated the whole argument stack, because such a call never sets `args_base`; it is a no-op now. Closes nushell#16974
…ll::new `help` (`nu-highlight`, `table` for input/output types and example results, `ansi` for configured colors), `tutor`, `print`, the DAP `print`, `clip copy` and table rendering for an external's stdin built AST calls. They build `ir::Call`s now. The ones in nu-engine and nu-command run through `eval_ir_call`, so a command found by name may be a custom command. `engine::Call::new` made an empty AST call with a placeholder decl id, and it was the last producer of `CallImpl::AstBox`. Callers build an empty IR call with the command's id instead: `ir::Call::build(decl_id, span).finish()`.
Sha1rholder
reviewed
Nov 23, 2026
fdncred
added a commit
that referenced
this pull request
Nov 23, 2026
## Description This is phase 4 of the AST to IR call migration, after #18808, #18813, #18967, #19351 and #19462. Commands now run only from compiled IR, so `engine::Call` loses its AST variants and the code that handled them goes too. Plain `cal` was the last runtime code that built an `ast::Call`, to run `table --index false`. It now runs `table` through `eval_ir_call`, as `help` does. The rest is deletion: `CallImpl::AstRef`/`AstBox`, `eval_call`, `eval_external`, `impl CallExt for ast::Call`, and the AST branches in `get`, `run`, `run-internal`, known externals and plugin calls. The AST evaluator stays, because `explain` and the parser info of `source`, `source-env` and `run` still use it. Its call arms now return an error, which fixes two `explain` bugs. `explain` evaluates every argument, and a keyword's argument can be a call. For `else if` that call is `if`, whose `run` panics. For `alias x = cmd` it ran `cmd`. Both now show an error value. An argument that holds a subexpression, like `(1 + 2)`, now shows its source text and parsed type instead of an internal debug dump. `explain` doesn't run it, because that would run its commands. The AST `has_flag` was the only check that a builtin's switch got a bool. The parser rejects `ls --all=5`, but `ls --all=$x` with `$x` typed `any` and set to `5` counted as set. Builtins, const calls and custom commands now give the error `%$cmd` already gave. A builtin checks when it reads the switch, so one that never reads it still ignores a bad value. ## User-facing changes (Release notes) - `explain` no longer crashes on `else if`, and no longer runs the command an `alias` points to. - `explain` shows an argument with a subexpression, like `(1 + 2)`, as its source text and parsed type. - Breaking change: a switch given a value that isn't a bool, as in `ls --all=$x` with `$x` set to `5`, is an error. It used to count as set. ## Additional notes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This continues the AST → IR call migration (#18808, #18813, #18967). One commit per step:
requires_ast_for_argumentssince reduce ast dependency for ir calls - phase 1 #18813, so everyIrBlock.astentry wasNone. The opt-in,IrAstRef,IrBlock.ast, theastfield ofengine::Argumentandengine::Call::positional_nthare gone.Let::run, which only an indirect call can reach, now returns an error likeunlet's.nu_engine::eval_ir_callruns anir::Callthe way compiled code does: input type check, argument normalization, and parameter binding for a custom command. The VM's call instruction shares the same code.open,http,save,%(...)and a plugin'scall_decluse it, which fixes custom commands in three of them.help(nu-highlight,table,ansi),tutor,print, the DAPprint,clip copyand table rendering for an external's stdin build IR calls.tutorhighlights throughhelp'snu_highlight_string, so a snippet it can't highlight shows as plain text instead of disappearing.engine::Call::newis deleted.CallImpl::to_ownedstill turns anAstRefinto anAstBox; phase 4 removes both variants.User-facing changes (Release notes)
save,%(...)and plugincall_declcheck input and arguments like a direct callRunning a command by id now takes the same path as a compiled call, so
save,%($cmd),http,openand a plugin'scall_declcheck input types and bind arguments the way a direct call does.Breaking changes
savechecks a customto <ext>converter's input type. A converter whose signature doesn't cover the data now errors instead of running. Built-intocommands reject the same inputs as before, but withInput type not supportedinstead of their own message.openandhttpare unchanged, since they hand converters an untyped byte stream.savekeeps a customto <ext>converter's$envchanges inside it unless it isdef --env, the same as... | to <ext>.%($cmd)checks its input and arguments as a direct call does. Spreading a list into a command without a rest parameter is an error instead of being silently dropped.call_declchecks the input type, including empty input.'a' | example call-decl uniqnow errors withInput type not supported, andexample call-decl 'str join'withPipeline empty.view ir --jsonno longer has anastfield inir_block. It was alwaysnull.Additions
httpcommands can convert a response with a customfrom <ext>command, asopenalready could.savebinds the flags and defaults of a customto <ext>command.call_declcan call a custom command.Embedders and out-of-tree
Commandimplementationsengine::Call::new,Command::requires_ast_for_arguments,engine::Call::positional_nthand theastfields on calls and arguments are gone. Build anir::Callwithir::Call::buildand run it withnu_engine::eval_ir_call; the PR description has the full migration table. Plugins implementingPluginCommandare not affected.Breaking changes
Scripts
savechecks a customto <ext>converter's input type, as a direct call does. A converter whose signature doesn't cover the data now errors instead of running. Built-intocommands are unaffected: inputs they already rejected now fail withInput type not supportedinstead of the converter's own message.openandhttphand converters an untyped byte stream, which any input type accepts, so they don't change.savekeeps a customto <ext>converter's$envchanges inside it unless it isdef --env, the same as... | to <ext>.%($cmd)checks its input and arguments as a direct call does. Spreading a list into a command without a rest parameter is an error instead of being ignored.view ir --jsonno longer has anastfield inir_block. It was alwaysnull.def "to foo" []: int -> string { "int" }; [1 2] | save out.foo; open --raw out.foointInput type not supported(only int input data is supported, input typelist<int>)def "to foo" [] { $env.FOO = 1; "x" }; [1] | save out.foo; $env.FOO? | describeintnothingdef --env "to foo" [] { $env.FOO = 1; "x" }; [1] | save out.foo; $env.FOO? | describeintintlet cmd = 'length'; let args = [1]; [1 2] | %($cmd) ...$args2(the spread is dropped)Cannot spread a list into this command(length ...$argsis a parse error)view ir --json {|| 1 } | from json | get ir_block | columns[instructions, spans, data, ast, comments, register_count, file_count][instructions, spans, data, comments, register_count, file_count]Plugins
call_declchecks the input type, including empty input, as a direct call does. A call that the command's signature doesn't allow now errors, the same as when the call is written in a script.nu_plugin_example)'a' | example call-decl uniq[a]Input type not supported(only list<any> input data is supported)example call-decl 'str join'""Pipeline emptyThe
IrBlockreturned by theget_block_irengine call no longer has anastfield. Nushell only loads plugins built for the same minor version, so a plugin never reads the old format from a newer engine.Rust API (embedders and out-of-tree
Commandimplementations)Plugins implement
PluginCommandand are not affected.engine::Call::newir::Calland run it withnu_engine::eval_ir_call(example below).Command::requires_ast_for_argumentsengine::Call::positional_nth,ir::Call::positional_ast,engine::Argument::ast_expressionCallExt(req,opt,rest). On a compiled call these always returnedNone.astfield ofengine::Argument::{Positional, Spread, Named}ir::IrAstRef,IrBlock.astWith arguments, add them to the builder and call
leaveafterwards:Unlike
decl.run,eval_ir_callalso runs custom commands, checks the input type and normalizes the arguments. Code that can't depend onnu-enginecan still pass&(&call).into()todecl.run.ir::Call::leaveon a call without arguments now does nothing. It used to clear the whole argument stack, including the caller's arguments.Additional notes
nu_engine::eval_ir_call, which returns an error unless the call's arguments are the last ones on the stack, and madenu_engine::nu_highlight_stringpublic.CallImpl::AstRef/AstBoxand the AST evaluator's call path.