Skip to content

fix5 parsetime2: complete-command posix freeze, emulated-external stand-down, lexed time operands (#1544/#1545/#1548) - #1558

Merged
caomengxuan666 merged 3 commits into
masterfrom
fix5/slice-parsetime2
Oct 25, 2026
Merged

caomengxuan666 merged 3 commits into
masterfrom
fix5/slice-parsetime2

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Fixes #1544
Fixes #1545
Fixes #1548

第五波 parsetime2 簇集成片:三条 time/posix 判定族分歧,一 issue 一 commit(基线 master 23d9f6a8 之上按序拣入,零冲突;compound_exec.rs / shift_echo_builtins.rs 自动合并,语义共存经相邻回归面复核)。

#1544 — feeder 按行翻转解析模式(fd1dbe10)

根因(两层):上层是 GroupScanFeeder 在每个逻辑行 pass 后立即把行内的 posix 翻转应用到解析模式,包括一个尚未闭合的 complete_command 的中间行;GNU 在执行前读完整个 complete_command(parse.y read_command),单元内的 set 不能翻转该单元自身后续行。但只修 feeder 不够:{} 组在批处理层折叠为单个 Keyword token,组体由 parser 以硬编码 false 种子 + 逐行翻转重 lex,bug 在下一层复活。

修法(两通道、一不变量):① feeder 翻转停放 deferred_posix,只在单元边界(awaiting_bodies 空且 token_level_needs_more() 为假)落地;② Token 新增 posix_gate(折叠 pass 的模式快照,与 extglob_gate 同点打标),feeder 加 posix_locked,新增锁定入口 tokenize_locked_body*,七个 folded-brace 重 lex 站点统一改走锁定入口、种子取 fold token 的 gate。未碰 continuation.rs。#1520 回归文件中原 #[ignore] 钉已激活转正。

#1545 — time 计时管道在坏 PATH 下吞后段失败(94be1c9d)

立案定性修正:后段并非「没跑/状态被丢」——后段实际在进程内被模拟执行。rubash 对外部命令有大量进程内模拟(pipeline stage 的 head/cat/sed/grep/wc/tr、文件型 builtin、uname/arch/stty、sleep/dirname/basename 快路径、comsub 捷径),每个准入门都只判 path_is_unset(#1126):PATH 已设但不可解析时,GNU findcmd.c search_for_command 失败(127 + 诊断),模拟层却照跑一个不存在的二进制。计时机械本身无恙。

修法:新 helper Executor::emulated_external_stands_down(name)(path_is_unset || command_path(name).is_none()),准入面统一放宽到 16 处——含回归钉实测后才暴露的第 16 处:并行管道快路径在 find_user_command 未命中时为 yes/head/wc 捏造 <rubash-internal-*> 伪路径的回退(time -p cat f | wc -c 的 wc 正是这样跑起来的)。两处诊断文案开关(#1145)故意未动。

#1548 — time '-p' 引号操作数被当选项(18358ef6)

根因:六处以上手写前缀消费循环在去引号后的词值上匹配 -p/--/! 且任意交错重复消费;GNU 在词法层按原始拼写裁决(parse.y special_case_tokens + timespec:-p 仅紧跟 TIME 为 TIMEOPT、-- 仅紧跟 TIME/TIMEOPT 为 TIMEIGN、各至多一、序固定、TIMEIGN 亦置 posix 格式)。引号/转义形原始文本永不匹配 → 是被计时命令的命令名。

修法:在 parse_loop.rs 落一份共享状态机 TimePrefixWindow(token 版 + word 版扫描器),统一六类站点:parser 构造器/折叠器、两个分类器、executor 构造与回退(time_prefix_parts 改收节点;shift_echo 的「任意位置 -p 决定格式」any() 一并改正)、alias_reparse 三处、comsub 计时捷径、support.rs 向后扫描。词级 raw 门与 #1520 期 time_option_precedes 同口径。最强钉:PATH 里真有名为 -p 的可执行文件时,time '-p' 真跑它。

验证账本(集成树实跑,门控配方,回归在净化环境下运行)

  • cargo build --locked rc=0;三 commit 各自可独立构建(前两 commit cargo check --locked 均 rc=0)。
  • lib 全量 732 过 / 1 败 / 1 ignored:唯一失败为基线许可的 root 环境项 ownership_unary_operators_check_existing_file;732 = master 基线 730 + 本片 2 条新 lexer 单测钉,不回退。lexer 单测 98/0。
  • 定向回归:issue1520 文件 18/0/0([bug] feeder 行粒度模式翻转:未闭合复合命令内 set 翻转影响同组 time 判定(GNU 按 complete_command) #1544 激活钉在内)、issue1544 15/0、issue1545 12/0 + 1 ignore 保持(sv_path 钉,见残余)、issue1548 12/0。
  • 相邻共存面:watchers 三文件 issue1528 4/4、issue1531 1/1、issue1533 3/3;issue1363 21/21、issue1364 12/12。
  • 头牌形态对拍(脚本入口,GNU 5.3.20 vs 集成二进制):多行组、镜像 --posix 组、if 体、函数体、闭合行 }; time、time '-p' 引号名、计时管道坏 PATH,七形态逐字一致(仅 argv[0] 前缀与计时数字抖动)。
  • 246 差分 244 PASS,失败集恰为 {gl08, ms10} ⊆ 基线稳定集(results JSON 头双二进制路径与 mtime 已核新鲜)。
  • fmt:全部改动文件 head_diffs=0,无新增漂移;改动文件 CR 全 0。

残余(均已另行跟踪,不在本片范围)

…er in-unit posix flips (#1544)

GNU reads one complete_command in full before executing any of it
(parse.y read_command; evalstring.c parse_and_execute), so a
`set -o/+o posix` inside the unit cannot change the mode the rest of
the unit is read under. The batch feeder applied the flip at the
logical line that carried the `set`, re-lexing the unit's later lines
under the flipped mode: `{\nset -o posix\ntime -p true\n}` reported
`time: command not found` in every entry (file, -c, stdin, eval),
and the --posix mirror flipped the other way.

Two channels, one invariant:

- Feeder (src/lexer/mod.rs): the per-line flip is parked in
  `deferred_posix` and lands only at a commit that leaves no unit
  open (`apply_deferred_posix_at_unit_boundary`: no heredoc body
  outstanding, token_level_needs_more false — the keyword-stack /
  join summary). This covers token-stream bodies (if/while/subshell/
  function bodies, &&-continued lists) and the mode later units are
  read under.

- Folded bodies: a brace group folds into ONE keyword token, so its
  body is re-lexed by the parser — under a hard-coded non-posix seed
  with per-line flips live, resurrecting the bug one level down.
  Tokens now carry `posix_gate`, the pass mode stamped next to
  `extglob_gate` (scanner.rs/word.rs), and every folded-brace body
  re-lex (brace group, function/for/select/arithmetic-for/coproc
  bodies, the innermost-compound region) goes through the new locked
  entries (`tokenize_locked_body*`): seeded with the fold token's
  gate, flips parked for the whole call can never land.

Activates the #[ignore] pin in the #1520 regression file
(issue1520_group_spanning_lines_parsed_before_execution). Regression
tests: tests/issue1544_feeder_complete_command_posix_regressions.rs
(15 pins: filed group form x 4 entries, if/while/case-arm/subshell/
function/nested bodies, `}; time` on the closing line, next-unit
flip lands with exactly one diagnostic, --posix mirror, in-group
heredoc) plus two lexer unit tests (gate stamping, locked re-lex).
…esolve (#1545)

`PATH=/nonexistent; time -p true | cat` printed the timing and
exited 0: the `cat` stage never spawned — rubash EMULATES external
programs in-process (pipeline-stage arms for head/cat/sed/grep/wc/tr,
the file-builtin family, uname/arch/stty, sleep/dirname/basename fast
paths, comsub cat/tty shortcuts, and the parallel path's
internal-program stand-in for yes/head/wc), and every admission gate
tested only `path_is_unset` (rubash#1126). Under a SET but
unresolvable PATH, GNU's search_for_command (findcmd.c:348-427)
fails with 127 + `cat: command not found` while the emulations kept
running a program that does not exist — existence depended on the
invocation shape. (The timed machinery itself was sound: not-found
and builtin stages already reported 127/1 with timing.)

One invariant, applied at all 16 admission sites: a new helper
`Executor::emulated_external_stands_down(name)` (lookup_paths.rs) =
PATH unset OR the repo's GNU resolution model (command_path: hash,
then the unset/empty-PATH dot rule, then find_user_command) resolves
nothing. Sites: pipeline stage arms and the timed "sleep" arm and
the parallel path's internal-program fallback (pipeline_exec.rs),
the file-builtin early return (external_file_builtins.rs), sleep
(command_dispatch_primary.rs), dirname/basename/uname/arch/stty
(command_dispatch_late.rs, command_no_alias_late.rs), the comsub
cat/tty shortcuts (command_substitution_pipelines.rs,
command_substitution.rs). Deliberately untouched: the two remaining
path_is_unset uses (external_inner.rs, pipeline_stages.rs) — a
diagnostic-wording switch (rubash#1145), already GNU-correct.

Regression tests:
tests/issue1545_timed_pipeline_unresolvable_stage_regressions.rs —
12 pins (filed form, bare time, negation, first-stage failure with
both stages reporting, group/function forms, controls, unset-PATH
wording, untimed pipeline, timed single command, standalone
cat/sleep/uname, comsub capture) + 1 #[ignore] pin for the hashed-
name sub-case: GNU flushes the whole command hash on ANY PATH
assignment (variables.c sv_path -> phash_flush), which rubash does
not model yet — the pin carries the GNU expectation.
…d '-p' is a command name (#1548)

`time '-p' true` ran `true` under the POSIX report format and
exited 0: every hand-rolled time-prefix consumer matched `-p`/`--`/
`!` against the DECODED word value and consumed them in any order,
any number of times. GNU decides these tokens in the lexer
(parse.y special_case_tokens): `-p` is TIMEOPT only when the
immediately preceding token was TIME, `--` is TIMEIGN only after
TIME or TIMEOPT, both compared against the token's RAW spelling —
a quoted or escaped spelling ('-p', "-p", \-p, -'p') never matches
and is the timed command's name — and the timespec grammar admits
at most one of each, in that order, with TIMEIGN also selecting
the POSIX report format (TIME TIMEIGN -> CMD_TIME_POSIX).
Oracle-verified corollaries: `time -p -p x` and `time -- -p x`
fail 127 on the second dash word, `time ! -p x` treats `-p` as the
(negated) command, a quoted '!' is a command name, and an
executable actually named `-p` on PATH runs under `time '-p'`.

One shared state machine (TimePrefixWindow +
scan_time_prefix_tokens / scan_time_prefix_words in parse_loop.rs,
re-exported via crate::parser): the raw gate is
`token.raw == token.value` for tokens, and the aligned
word_metadata raw for parsed commands — the same raw discipline as
the #1520-era time_option_precedes. Sites unified: the parser's
compound constructor and simple-command fold, both prefix
classifiers (parse_loop, coproc), the executor constructors and
fallbacks (pipeline_exec time_pipeline_prefix, compound_exec
time_prefix_parts — now node-based, shift_echo
execute_time_command_node, whose report format previously came
from a `-p` ANYWHERE after the head), the alias-reparse trio and
the comsub timed shortcut (window order only — their words are
already decoded), and parser/support.rs's backward brace scan.
Nothing here touches the #1520 verdict layer: in posix mode a
quoted dash word keeps `time` reserved (its raw first character is
the quote), and the operand scan then makes it the timed command.

Regression tests:
tests/issue1548_time_quoted_option_operand_regressions.rs — 12
pins (filed form with default format, double-quoted/escaped/
partial-quoted spellings, plain -p control, second -p in both
spellings, the TIMEIGN window + format, dash word after `!`,
quoted '!', lone `time '-p'`, a real executable named `-p` runs,
pipeline PIPESTATUS / group / function forms, posix mode + eval +
stdin entries, quoted ordinary command name).
@caomengxuan666
caomengxuan666 merged commit 0b3c16f into master Oct 25, 2026
7 of 10 checks passed
@caomengxuan666
caomengxuan666 deleted the fix5/slice-parsetime2 branch October 30, 2026 01:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant