Repository navigation
reduce ast footprint, increase ir footprint - phase 0 - #18808
Merged
Merged
Conversation
fdncred
added a commit
that referenced
this pull request
Oct 28, 2026
…e 3) (#19351) ## 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 #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) - `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. ## 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. | ```diff -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: ```rust 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 #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.
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
Step 0 on a multi step process of decreasing ast and increasing ir.
User-facing changes (Release notes)
Additional notes