Skip to content

Run commands only from compiled code (AST migration phase 4) - #19638

Merged
fdncred merged 1 commit into
nushell:mainfrom
fdncred:ast_reduce_phase4
Nov 23, 2026
Merged

fdncred merged 1 commit into
nushell:mainfrom
fdncred:ast_reduce_phase4

Conversation

@fdncred

@fdncred fdncred commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

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

Plain `cal` runs `table` through `eval_ir_call`, so nothing builds an
`ast::Call` to run anymore. Remove `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's call arms now return an error.

That fixes `explain` panicking on `else if` and running the command of
an `alias`. `explain` also shows an argument that holds a subexpression
as its source text and parsed type, without running it.

A switch given a value that isn't a bool, such as `ls --all=$x` with
`$x` typed `any`, is now an error in builtins, const calls and custom
commands, as it already was for `%$cmd` and `run`.
@github-actions github-actions Bot added A:parser Issues related to parsing A:plugins This issue is about plugins labels Nov 22, 2026
@fdncred fdncred added notes:ready Indicates Ready for Release notes notes:other Noted in "Other changes" section labels Nov 23, 2026
@fdncred
fdncred merged commit 0e0ce16 into nushell:main Nov 23, 2026
15 checks passed
@fdncred
fdncred deleted the ast_reduce_phase4 branch November 23, 2026 14:28
@github-actions github-actions Bot added this to the v0.118.0 milestone Nov 23, 2026
fdncred added a commit that referenced this pull request Nov 23, 2026
#19645)

## Description

`repl::test_engine::const_switch_rejects_a_value_that_is_not_a_bool`
fails on main (1dc849d), and so does every PR's root test job. #19638
added the test. Two PRs merged a few minutes before it changed what the
test expects, and each of the three passed CI on its own base:

- #19634 turned on `cell-path-types`, so the parser now knows `$r.a` in
`const r = {a: 5}` is an `int`. It rejects `--chars=$r.a` with a type
mismatch and never evaluates the const.
- #19635 moved errors from parse-time evaluation out of
`ParseError::LabeledError` and into the new `ParseError::ParseTimeEval`.

The test covers the check #19638 added to const evaluation, so it needs
an argument the parser can't type. It now passes `($r | get a)`. `get`
returns `any`, so the parser lets it through and the const evaluation
rejects it. The test matches the `CantConvert` inside `ParseTimeEval`,
the same way `builtin_switch_rejects_a_value_that_is_not_a_bool` matches
its error.

## User-facing changes (Release notes)
<!--
This section is used (mostly as-is) for https://www.nushell.sh/blog/

Describe how Nushell behavior changes from a user's perspective.
Do NOT describe internal Rust changes here.

Write in a release note style, for example:
- "Added support for..."
- "Fixed an issue where..."
- "Nushell now supports..."
- "Improved performance of..."

If your changes do NOT affect users (internal refactors, cleanup, etc.),
just write:
- "n/a"
- "nan"
- or similar

This tells us the change should not appear in the changelog.

Tips:
- Focus on observable behavior
- Include examples if helpful
- Keep it concise

You can:
- Write a short paragraph (will appear as a bullet point), OR
- Use headings (###) if your change needs more structure

Avoid writing things like:
- "In this PR, I refactored..."
- "This updates internal code..."

You may leave this blank until the PR is ready.
-->

## Additional notes
<!--
Optional.

Examples:
- fixes #123
- closes #456
- related #789

Anything else reviewers should know.
Remove this section if not needed.
-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A:parser Issues related to parsing A:plugins This issue is about plugins notes:other Noted in "Other changes" section notes:ready Indicates Ready for Release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant