Skip to content

Run commands found by id through one IR call path (AST migration phase 3) - #19351

Merged
fdncred merged 4 commits into
nushell:mainfrom
fdncred:reduce_ast_phase_3
Oct 28, 2026
Merged

fdncred merged 4 commits into
nushell:mainfrom
fdncred:reduce_ast_phase_3

Conversation

@fdncred

@fdncred fdncred commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Description

This continues the AST → IR call migration (#18808, #18813, #18967). One commit per step:

  1. Drop argument AST retention. No command has opted into requires_ast_for_arguments since reduce ast dependency for ir calls - phase 1 #18813, so every IrBlock.ast entry was None. The opt-in, IrAstRef, IrBlock.ast, the ast field of engine::Argument and engine::Call::positional_nth are gone. Let::run, which only an indirect call can reach, now returns an error like unlet's.
  2. One IR path for running a command by id. nu_engine::eval_ir_call runs an ir::Call the 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's call_decl use it, which fixes custom commands in three of them.
  3. Display call sites. help (nu-highlight, table, ansi), tutor, print, the DAP print, clip copy and table rendering for an external's stdin build IR calls. tutor highlights through help's nu_highlight_string, so a snippet it can't highlight shows as plain text instead of disappearing. engine::Call::new is deleted. CallImpl::to_owned still turns an AstRef into an AstBox; phase 4 removes both variants.

User-facing changes (Release notes)

save, %(...) and plugin call_decl check input and arguments like a direct call

Running a command by id now takes the same path as a compiled call, so save, %($cmd), http, open and a plugin's call_decl check input types and bind arguments the way a direct call does.

Breaking changes

  • save checks a custom to <ext> converter's input type. A converter whose signature doesn't cover the data now errors instead of running. Built-in to commands reject the same inputs as before, but with Input type not supported instead of their own message. open and http are unchanged, since they hand converters an untyped byte stream.
  • save keeps a custom to <ext> converter's $env changes inside it unless it is def --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.
  • A plugin's call_decl checks the input type, including empty input. 'a' | example call-decl uniq now errors with Input type not supported, and example call-decl 'str join' with Pipeline empty.
  • view ir --json no longer has an ast field in ir_block. It was always null.

Additions

  • http commands can convert a response with a custom from <ext> command, as open already could.
  • save binds the flags and defaults of a custom to <ext> command.
  • A plugin's call_decl can call a custom command.

Embedders and out-of-tree Command implementations

engine::Call::new, Command::requires_ast_for_arguments, engine::Call::positional_nth and the ast fields on calls and arguments are gone. Build an ir::Call with ir::Call::build and run it with nu_engine::eval_ir_call; the PR description has the full migration table. Plugins implementing PluginCommand are not affected.

Breaking changes

Scripts

  • save checks a custom to <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-in to commands are unaffected: inputs they already rejected now fail with Input type not supported instead of the converter's own message. open and http hand converters an untyped byte stream, which any input type accepts, so they don't change.
  • save keeps a custom to <ext> converter's $env changes inside it unless it is def --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 --json no longer has an ast field in ir_block. It was always null.
Command main branch
def "to foo" []: int -> string { "int" }; [1 2] | save out.foo; open --raw out.foo int Input type not supported (only int input data is supported, input type list<int>)
def "to foo" [] { $env.FOO = 1; "x" }; [1] | save out.foo; $env.FOO? | describe int nothing
def --env "to foo" [] { $env.FOO = 1; "x" }; [1] | save out.foo; $env.FOO? | describe int int
let cmd = 'length'; let args = [1]; [1 2] | %($cmd) ...$args 2 (the spread is dropped) Cannot spread a list into this command (length ...$args is 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_decl checks 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.

Command (with nu_plugin_example) main branch
'a' | example call-decl uniq [a] Input type not supported (only list<any> input data is supported)
example call-decl 'str join' "" Pipeline empty

The IrBlock returned by the get_block_ir engine call no longer has an ast field. 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 Command implementations)

Plugins implement PluginCommand and are not affected.

Removed Instead
engine::Call::new Build an ir::Call and run it with nu_engine::eval_ir_call (example below).
Command::requires_ast_for_arguments Delete the override. No command has needed it since #18813.
engine::Call::positional_nth, ir::Call::positional_ast, engine::Argument::ast_expression Read argument values with CallExt (req, opt, rest). On a compiled call these always returned None.
The ast field of engine::Argument::{Positional, Spread, Named} Drop it from patterns and struct literals.
ir::IrAstRef, IrBlock.ast Nothing.
-let call = engine::Call::new(span);
-decl.run(engine_state, stack, &call, input)
+let call = ir::Call::build(decl_id, span).finish();
+nu_engine::eval_ir_call(engine_state, stack, &call, input)

With arguments, add them to the builder and call leave afterwards:

let mut builder = ir::Call::build(decl_id, span);
builder.add_named(stack, "width", "", span, Value::int(80, span));
let call = builder.finish();
let result = nu_engine::eval_ir_call(engine_state, stack, &call, input);
call.leave(stack);

Unlike decl.run, eval_ir_call also runs custom commands, checks the input type and normalizes the arguments. Code that can't depend on nu-engine can still pass &(&call).into() to decl.run.

ir::Call::leave on a call without arguments now does nothing. It used to clear the whole argument stack, including the caller's arguments.

Additional notes

  • Closes Cannot call custom commands from plugin #16974.
  • Added nu_engine::eval_ir_call, which returns an error unless the call's arguments are the last ones on the stack, and made nu_engine::nu_highlight_string public.
  • Next: phase 4 deletes CallImpl::AstRef/AstBox and the AST evaluator's call path.

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()`.
@github-actions github-actions Bot added A:parser Issues related to parsing A:plugins This issue is about plugins labels Oct 26, 2026
@fdncred fdncred added notes:breaking-changes Noted in Breaking Changes section and removed A:parser Issues related to parsing A:plugins This issue is about plugins labels Oct 26, 2026
@fdncred
fdncred merged commit 85fba6f into nushell:main Oct 28, 2026
12 checks passed
@fdncred
fdncred deleted the reduce_ast_phase_3 branch October 28, 2026 11:40
@fdncred fdncred added the notes:ready Indicates Ready for Release notes label Oct 28, 2026
@github-actions github-actions Bot added this to the v0.117.0 milestone Oct 28, 2026

@Sha1rholder Sha1rholder Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

notes:breaking-changes Noted in Breaking Changes section notes:ready Indicates Ready for Release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot call custom commands from plugin

2 participants