mirror of
https://github.com/nushell/nushell.git
synced 2026-11-26 03:25:39 +08:00
## Description This follows #18808, #18813, #18967, #19351, #19462 and #19638. Since #19638, commands run only from compiled code. The keyword commands that read the parser's extra data for a call, and `explain`, still evaluated parser expressions with the AST evaluator. This PR moves both off it, deletes the evaluator, and removes the last parser `Expression` from IR. Each phase is its own commit, and the last commit fixes review findings in 6a and 6b. - **Typed parser info (6a).** `Instruction::PushParserInfo` carried a parser `Expression` that `source`, `source-env` and `run` evaluated to get back a block id or a path. It now carries a `ParserInfo` value that the compiler builds once. `source-env` also uses the path the parser found, instead of looking the file up again when it runs. - **`explain` runs no code (5a).** A literal, a constant or a bare variable still shows its value. Any other argument shows its source text and the type the parser gave it. - **AST evaluator deleted (5b).** `eval_expression` and its helpers are gone, 383 of `eval.rs`'s 847 lines. Const evaluation is the only `Eval` implementation left. - **Match guards on the arm (6b).** The guard moves from `MatchPattern`, which every nested pattern carried, to a new `MatchArm { pattern, guard, body }`. Capture discovery, `$in` handling and highlighting all skipped guards before. They visit them now. ## User-facing changes (Release notes) - `explain` no longer evaluates arguments. A literal, a constant or a bare variable shows its value, and anything else shows its source text, so `$r.a` shows `$r.a` instead of `1`. Arguments that used to show an empty name or an error show their source. - `view ir` shows parser info as values such as `block(305)` or `import "assert" ["equal"]` instead of a debug dump. `view ir --json` and `ast --json` change shape for parser info and match arms. - A closure whose match guard reads an outside variable now captures it. `$in` works in a guard, and as a bare `=> $in` arm body inside a closure. All of these used to fail with `Variable not found`. - A match guard inside a closure can no longer read a `mut` variable from outside it, the same rule an `if` condition there already follows. Scripts that did this break. Copy the value into a `let` first. - The REPL and `nu-highlight` color match guards. - `source-env` sets `$env.FILE_PWD` and `$env.CURRENT_FILE` from the file the parser read. They no longer contain `..`, and a `cd` before `source-env` no longer changes them. ## Additional notes