Repository navigation
fix5 parsetime2: complete-command posix freeze, emulated-external stand-down, lexed time operands (#1544/#1545/#1548) - #1558
Merged
Conversation
…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).
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.
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.yread_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 已设但不可解析时,GNUfindcmd.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.yspecial_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 --lockedrc=0;三 commit 各自可独立构建(前两 commitcargo check --locked均 rc=0)。ownership_unary_operators_check_existing_file;732 = master 基线 730 + 本片 2 条新 lexer 单测钉,不回退。lexer 单测 98/0。--posix组、if 体、函数体、闭合行}; time、time '-p'引号名、计时管道坏 PATH,七形态逐字一致(仅 argv[0] 前缀与计时数字抖动)。head_diffs=0,无新增漂移;改动文件 CR 全 0。残余(均已另行跟踪,不在本片范围)
variables.c sv_path→phash_flush),rubash 不冲刷;[bug] time 计时管道后段命令失败被吞(rc 0 应为 127) #1545 回归文件中的#[ignore]钉带 GNU 期望,待 [bug] PATH 赋值未冲刷命令哈希表(GNU sv_path → phash_flush 未建模) #1551 激活。-p: command not found诊断 → [bug] 计时管道以 dash 词作首段时丢失 command not found 诊断 #1552(rc 与计时正确,机制未定位)。set的过度翻转近似;C. cat stage 诊断前缀([compat-gap] in-engine external_cat emulation silently ignores all options (-n/-A/-E lost, -Z not rejected) for bare cat and /bin/cat #415 族);D. alias/comsub 词已解码、引号保真不可恢复,本片只对齐窗口序。