Repository navigation
fix(parser): accept redirect-first coproc simple-command bodies (Refs #3267) - #3475
Conversation
…3267) GNU's simple_command is redirections + words in any order, so 'coproc >x foooo' is a legal body; rubash collected WORD tokens only and stranded the first word as an unexpected token. Consume leading and intermixed redirections onto the coproc node in the simple-body loop with the shared trailing-redirection collector. The #1652 second-word-'!' rejection now fires only while no redirection has been consumed yet: GNU takes the simple_command branch and treats '!' as a plain word once a redirection precedes it ('coproc >x foo ! bar', 'coproc foo >y ! bar' both rc 0). Regression nails: tests/issue3267_coproc_redirect_first_regressions.rs (20 cells, oracle-verified against GNU bash 5.3.20).
|
【WIN-AGENT-AUDIT】 机制核查:
腿(逐项给数字与名字):
F 点:
未跑/VOID 的腿:无(Linux head/base、Windows head 均已实跑) |
…#3267) GNU's coproc grammar (parse.y:1125-1175, simple_command element productions parse.y:532-575) reads every reserved-word spelling as a WORD once a redirection precedes the first word — verified on the 5.3.20 oracle: `!` `}` `done` `fi` `[[` `]]` `function` `coproc` `do` `esac` `in` `then` `else` `elif` and the compound starters `if` `for` `while` `until` `case` `select` all run as command names, so `coproc >x ! echo hi` reports `!: command not found` and `coproc >x { ...; }` blames the later `}` at command position, never `{`. Two mechanism fixes, no per-spelling patches: - parser: the post-redirect pre-word stop now only fires on real operator tokens (`(`, `((`-prefixed arithmetic opens, folded brace-group tokens); keyword spellings fall through to the word collector. - executor: the coproc simple body respawns through `rubash -c`, so a collected head word whose spelling is a keyword/operator at command position regains non-word status on re-parse (GNU forks the parse tree instead). The head word's raw text is now re-printed with `"` quoting when it is one of those spellings — `"`, not `'`, because the lexer folds `'!'` back into a BANG token (continuation.rs residual, captain lane). Known residuals disclosed: `{`, `coproc` and `time` head words are fold-blocked in every quoting form (same continuation.rs fold); the #1653 `time: command not found` expectations are anti-GNU (GNU keeps `time` the timespec, parse.y:1416) and stay pinned until their own ledger. Windows-only `coproc <<HD cat` Broken pipe (audit F3) is a platform residual, untouched. Pins: `{`→`}` and `if`→`then` blame flips are GNU-exact on the 5.3.20 oracle; two new cells cover the word class (`done`, `}`).
|
【WIN-AGENT-REWORK】 F 点逐条:
绕障披露: 腿:
残余声明:F3 Windows Broken pipe、continuation.rs 引用 fold 三拼写( |
… SIGPIPE (Refs #3475) (#3753) Disclosed as Windows platform debt during the #3475 coproc rework: `coproc <<HD cat` intermittently printed `case.sh: line 1: Broken pipe` when the parent exited (or retired the coproc read end via `exec {COPROC[0]}<&-`) before the child's output write landed. The fault was NOT the pipe lifetime — GNU models the coproc body as a fork, and a forked child restores every signal's startup disposition (execute_cmd.c:1670 -> trap.c:1480 reset_signal_handlers), so SIGPIPE is SIG_DFL there and a write that meets a pipe with no readers kills the child silently with status 141. rubash respawns fork-shaped bodies (async `&`, coproc, both process-substitution forms) as `rubash -c` children marked by the validated RESPawned_CHILD provenance (init.rs), but the child's EPIPE still ran the MAIN shell's write-failure path (report_io_error_routed) and printed `Broken pipe` — the #440 model, which is only correct for the main shell whose SIGPIPE stays SIG_IGN. Mechanism fix at the two seams where a child's EPIPE verdict unwinds: - report_io_error_routed (ast_exec.rs): a validated respawn child's EPIPE returns ExecuteError::BrokenPipe instead of the main-shell diagnostic; the -c driver maps that arm to exit 141, silent (script_driver.rs), matching child_process_exit_status's existing BrokenPipe arm for in-process children. - handle_external_file_builtins (external_file_builtins.rs): every emulated-external arm stands in for a forked disk child (execute_cmd.c:5522 execute_disk_command), so an EPIPE-class output error becomes exit_code 141 with no diagnostic — this is the exact path that produced the disclosed failure (`cat` replayed through write_cat_output into the dead coproc pipe). Verification (LF script files, both sides): - fail-first: 4/4 new pins red on base 0a405d8 with the disclosed `Broken pipe` diagnostic; all four green after the fix. - pins: tests/issue3475_coproc_child_broken_pipe_regressions.rs 4/4, issue3267 redirect-first pin file 22/22 (incl. the formerly racy F3 heredoc cell), issue1882/2893/440/1580/1822 neighbors all pass (#2102's one red cell reproduces identically on base). - GNU oracle: byte-for-byte match with WSL /usr/local/bin/bash 5.3.20 on the deterministic dead-pipe shapes (coproc builtin write, emulated cat write, heredoc-fed cat, group continuation) — no diagnostic, `wait` -> 0, rc 0. - lib: 1351 passed, failure set = {issue2084} = base. - fmt clean on touched files; RUSTFLAGS="-D warnings" cargo check --locked clean.
|
Platform debt converted: the Windows heredoc Reproduction (LF script files): Root cause: not the spawn pin-pass write-end lifetime, and not an early reader drop. The diagnostic came from the respawned coproc child (verified via child-PID/error-232 instrumentation): its emulated Mechanism fix (Refs #3473 FileFd retirement / #3474 sequential model untouched):
Verification: fail-first 4/4 red on base; new pin file |
根因
coproc >x foooo在 rubash 任何位置都解析失败(rc=2 syntax error),GNU bash 5.3.20 接受(rc=0)。parse_coproc_command的简单体循环只收集 WORD token;行首重定向被finish_compound_command吃掉,首词无分隔符 stranded,主循环报 unexpected token。修法
简单体循环内遇重定向 token 即用共享
collect_trailing_redirections贴到预建的CommandNode上再继续收词;{var}>x的 fd-var 前缀按 read_token_word 规则跳过;行首重定向后接复合体({/(/if…)仍 break,走原 rc=2 路径。#1652 第二词
!细化:仅当简单体内尚未消费任何重定向时才报第二词!错误。GNU 在重定向先行时取COPROC simple_command分支,!为普通词(coproc >x foo ! bar、coproc foo >y ! bar均为 rc 0)。GNU 锚点
parse.y:1125-1175:COPROC shell_command/COPROC WORD shell_command/COPROC simple_command(:1171)parse.y:532-575:重定向产生式;parse.y:5821-5843:{var}REDIR_WORD 规则probes/gnu_check.sh,工作区内未入仓)两处 oracle 纠正(初稿与 GNU 不符):
coproc NAME >x foooo里 NAME 是命令词(NAME: command not found),不是 coproc 名字——名字产生式只在 WORD 后接复合体时生效;!规则见上。本 PR 删除了什么
无删除。仅新增:
src/parser/coproc_command.rs改动(+113/−18)与 20 格回归钉tests/issue3267_coproc_redirect_first_regressions.rs(新文件)。未碰src/lexer/continuation.rs,未改docs/api-ledger.md,未引入 trust/签名/加载期校验机制。回归钉
20 格:redirect-first(minimal、spaced-target、two-words、intermixed、trailing、numbered-fd、devnull-target、heredoc、bang-is-a-word、applies-to-child、named、fd-var、bang-after-leading/intermixed-redirect、double-leading-redirect)+ 5 格 rc=2 守卫。#3209 已合 PR #3266 的预登记红格
coproc_first_reports_definition_line应随本修法转绿。UNVERIFIED-BY-CAPTAIN
未跑任何构建/测试腿:本地写墙 EDQUOT 间歇发作、box 盘满、老服务器 ssh 未恢复、X299 直连未通。待复核轮:
rustfmt --check、RUSTFLAGS="-D warnings" cargo check、hygiene 脚本、钉 stem fail-first 复跑(base 红 → 修后绿)、#3209 与 #1652 stem 复测、全量 lib 与 base 逐数对齐。Refs #3267