Repository navigation
fix: coproc time is a plain word, not the time keyword (#1653) - #1698
Merged
Merged
Conversation
GNU parse.y:1125-1175 gives coproc only `COPROC shell_command`,
`COPROC WORD shell_command` and `COPROC simple_command`; `time` is a
timespec prefix on `pipeline_command` (parse.y:1416), never a
shell_command starter. After `coproc`, `time` is therefore never the
keyword: it is the coproc NAME when a compound command follows, and
otherwise the first word of the simple-command body.
Parser (src/parser/coproc_command.rs): drop the `time` arm from
parse_coproc_compound_body and the two time branches from
is_coproc_shell_command_start (removing the now-dead
time_prefixed_compound_command_start). `coproc time echo hi | cat`
now parses as a pipeline whose first stage is an unnamed coproc of
the simple command [time, echo, hi], so the coproc lives in the
pipeline subshell and the parent never sees COPROC_PID; the
`time`-as-name cases (`coproc time { ...; }`, `coproc time for ...`)
keep working through the caller's next-token check.
Executor (src/executor/compound_exec.rs): the simple coproc body is
respawned through `rubash -c <text>`, where a bare head word `time`
would regain keyword status on re-parse (GNU forks the same parse
tree). Quote a bare head `time` (`'time'`) when rendering the child
text, so the child keeps it an ordinary command name and reports
`time: command not found` (127) like GNU's forked child. An already
quoted head keeps its own spelling.
Tests: 5 stale parser tests asserted the old named-plus-timed model
for `coproc MYC time ...` (GNU: MYC is argv[0], `MYC: command not
found`); rewritten to the pipeline/simple-word shapes. New
tests/issue1653_coproc_time.rs (10 end-to-end cases, isolated PATH
so `time` can never resolve via PATH).
Known adjacent gaps, NOT fixed here (recorded, not hidden):
- The literal no-sleep seed's child diagnostic is racy: the coproc
child is a respawned process, so its `time: command not found`
can arrive after the parent exits (with any trailing sleep/wait
it appears deterministically). Same pre-existing class as a plain
`coproc nosuchcmd` whose diagnostic lands late.
- `coproc echo hi | cat` (no time involved) spuriously prints
`Broken pipe` when the script outlives the subshell — pre-existing
coproc-pipeline EPIPE reporting, needs its own issue.
- `coproc WORD time <compound>` trailing shapes (`{ ...; }`,
`(( ... ))`, `foo() {...}`) still lack GNU's `syntax error near`
for the trailing token: after the coproc simple body, the parser
swallows the compound token instead of erroring. The #1653
direction (WORD is a command, not a name) is fixed; the
trailing-token validation is a separate coproc-parser gap.
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 #1653.
Bug
coproc time echo hi | catsetCOPROC_PIDin the parent shell; GNU leaves it unset (the coproc lives in the pipeline subshell, and its child reportstime: command not found).Root cause (GNU source)
parse.y:1125-1175gives coproc onlyCOPROC shell_command,COPROC WORD shell_commandandCOPROC simple_command(plus redirection variants).timeis a timespec prefix onpipeline_command(parse.y:1416), never ashell_commandstarter — so aftercoprocit is never the time keyword. Rubash granted it keyword status in two places, which swallowed the wholetime echo hi | catas one timed coproc body in the parent.Changes
src/parser/coproc_command.rs: removed thetimearm fromparse_coproc_compound_bodyand the two time branches fromis_coproc_shell_command_start(plus the now-deadtime_prefixed_compound_command_start).timeis now the coproc NAME when a compound command follows (via the existing next-token check —coproc time { ...; }andcoproc time for ...keep working as named coprocs) and otherwise the first word of the simple-command body, which stops at|.src/executor/compound_exec.rs: the simple coproc body is respawned throughrubash -c <text>, where a bare head wordtimewould regain keyword status on re-parse (GNU forks the same parse tree). A bare headtimeis now rendered quoted ('time') so the child keeps it an ordinary command name and reportstime: command not found(127) like GNU's forked child. Already-quoted heads keep their own spelling.coproc MYC time ...are rewritten to the GNU shapes (GNU:MYC: command not found, MYC is argv[0], not a name). Newtests/issue1653_coproc_time.rs: 10 end-to-end cases under an isolated PATH (onlycat/sleep, sotimecan never resolve via PATH).Verification
declare: COPROC_PID: not found,done); with any trailingsleep/wait, stderr matches too (time: command not found).tests/parser_coproc_tests: 31 passed.tests/issue1653_coproc_time: 10 passed. Coproc family (issue352,issue387,issue1370,issue1528) and time family (issue1369,issue1520,issue1545,issue1548,issue1611) all green.Known adjacent gaps, not fixed here
time: command not foundcan arrive after the parent exits (deterministic once the script outlives child startup). Same pre-existing class as a plaincoproc nosuchcmddiagnostic landing late.coproc echo hi | cat(notimeinvolved) spuriously printsBroken pipewhen the script outlives the subshell — pre-existing coproc-pipeline EPIPE reporting, needs its own issue.coproc WORD time <compound>trailing shapes ({ ...; },(( ... )),foo() {...}) still lack GNU'ssyntax error nearfor the trailing token: after the coproc simple body, the parser swallows the compound token instead of erroring. The [bug] coproc time CMD | CAT sets COPROC in parent; GNU leaves it unset (pipeline-of-coproc parse) #1653 direction (WORD is a command, not a name) is fixed; the trailing-token validation is a separate coproc-parser gap.