Files
texrra-engine/docs/NATIVE_JOB_IO.md
T

178 lines
11 KiB
Markdown

# Native job time and file streams — 2026-10-31
2026-11-03 更新:[W3-S3 原生在线分页与实际 shipout](NATIVE_PAGES.md) 已接通真正
延迟 whatsit:原始盒/段落/数学主列表保存、复制/分盒/拆盒/丢弃及实际出页时的
递归执行;write使用真实mode=0、晚展开、参数token双写和字节编码。8真实文件
作业及4页PDF/174词/真实aux对照通过;完整1343/0、CLI39、全部原/新增门禁通过。
复杂数学field内的延迟I/O仍明确失败,须先保留语义数学盒。完整阶段仍执行中,
kernel654:3 tracingstats、完整入口pdfoutput、fmt=false。下方为历史切片范围。
2026-11-02 最新:完整工作区 **1266 / 0**、CLI28,见 [P2-M1进度](P2_M1_PROGRESS.md)。
主源和流已改为保存/读取实际原字节,按 [独立输入profile](NATIVE_INPUT_PROFILE.md)
消费,真实 UTF-8 文件名与 read/readline/aux 的字节散列验收通过;非法 UTF-8
标量输入不丢失实际读取踪迹。格式仍未启动,kernel529、完整入口pdfoutput。
以下为较早切片记录,旧边界/计数不替代最新状态。
Subsequent box/list diagnostic acceptance (2026-11-01): [native inspection](NATIVE_BOX_DIAGNOSTICS.md)
consumes actual showboxbreadth/showboxdepth and original nodes/settings in real
log/terminal output. Full workspace: 1200 passed / 0 failed; 152 exact recursive
lists, 24 paragraph lists, 24 byte-printer cases, 17 CLI tests and five-show/
19-word PDF gate pass. Unchanged LaTeX stops at errorcontextlines (526:1), full
startup false. Compound math/glue inspection and full interaction remain open.
Earlier counts/boundaries below are historical; no font/template fidelity claim.
Subsequent font-slot acceptance (2026-11-01): [native font diagnostics](NATIVE_FONT_DIAGNOSTICS.md)
now consumes tracinglostchars/tracingonline using actual TFM/Type1 slots, with
real font predicates, log/terminal delivery and fatal PDF protection. Full
workspace: 1187 passed / 0 failed; prior slice gates remain green. Unchanged
LaTeX now stops at defaultskewchar (522:1), so earlier boundaries/counts on
this page are historical. Full format startup remains false.
Subsequent update: [native boxes/vpack](NATIVE_BOXES.md) is implemented. This
page records the earlier job/I/O slice. TeX shipout syntax and deferred whatsits
inside boxes still require integration; unsupported boxed deferred I/O errors.
This slice implements actual job parameters and host file streams in the owned
Route-D executor. It does not use v1, the transitional string frontend, patched
format sources, fake timestamps or successful no-op file operations.
Original job/I/O slice acceptance: **1147 passed / 0 failed**; release, fmt/diff
and the existing math D gate pass. Complete LaTeX format startup remains open.
The later [quantity slice](NATIVE_QUANTITIES.md) passes **1153 tests** and moves
the current format boundary to **491:1, missing pretolerance**. Earlier counts
and the 326 boundary below describe this file's original job/I/O checkpoint.
## Ownership and time
- execution/job.rs defines JobTime, JobParameter, logical IoState and typed
OutputNode/OutputOperation. state.rs saves/restores time/day/month/year with
normal local/global/globaldefs semantics and records parameter reads.
- src/native_job.rs captures chrono::Local::now once before execution. The
parameters are minutes since local midnight and the corresponding calendar
date from that same instant. They are not reevaluated on every query.
- Library callers provide State::with_job_time explicitly. Without a timestamp
or explicit assignment, reading a job parameter errors; no default zero or
fixed build date is supplied. Tests inject declared timestamps independently
of the real-clock CLI test. A new job must refresh the host snapshot when
reusing an execution environment.
- The executor never shells out for clock values or invokes a TeX process.
Chrono was already locked locally; only the CLI adds a direct dependency.
## Input streams
SourceProvider owns real input/output handles indexed by TeX stream number.
The CLI uses independent BufReader<File> handles for input and File handles for
output. Input is read at each read operation, rather than fabricated from the
source preprocessor or replaced with a fixed file-exists result.
- openin/closein/read/ifeof and the explicit e-TeX profile's readline operate on
streams 0..15. Missing files close the stream; other host failures propagate.
- A successfully opened empty file is initially just-open, not EOF. Reading the
final physical line leaves the stream open. The next attempted read discovers
EOF, closes the handle and supplies TeX's virtual final empty line.
- read tokenizes physical CR/LF/CRLF lines with current catcodes/endlinechar,
balances braces across lines, preserves tokens without expansion, and defines
its target macro with normal prefix/globaldefs scoping. A premature right
brace discards the remainder of that line; an unclosed group at EOF errors.
- readline preserves raw characters with Other/Space categories, trims physical
trailing ASCII spaces, and appends the active endlinechar as a raw token. It
does not interpret comments, braces or superscript escapes.
- Closed/invalid-stream reads require terminal input in TeX. The native batch
host reports an unavailable terminal read instead of returning invented data.
- Stream source identities, actual read text, token byte spans, lookups including
misses, and stream/parameter read keys are retained for audit. This is not
sufficient dependency versioning for an incremental cache.
## Immediate and deferred output
openout/write/closeout construct native typed whatsits; immediate executes the
supported output operation now. Filenames are scanned now, while write bodies
retain their original tokens until the operation executes. A preceding immediate
ignores a non-output command and returns it to normal execution, as TeX does.
- A real openout creates/truncates its file, write appends through that stream's
handle, and closeout closes it. Failures propagate with source diagnostics.
Already executed I/O persists when a later command errors, as real I/O does.
- write16 and other positive out-of-range streams go to terminal plus job log;
negative streams go only to the log. Unopened file streams also use the
terminal/log destination. The CLI writes an actual log alongside the requested
PDF, including diagnostics emitted before a later execution error.
- Message events remain available to pure library event consumers. The CLI
observes them live, preserving their order relative to writes. It does not
replay messages a second time at the end. Diagnostic line wrapping is not a
complete TeX terminal-printer implementation.
- Internal meaning/detokenize/string conversion retains character codes. File
and diagnostic printing converts ASCII control characters to TeX notation
(for example a raw carriage return becomes ^^M), unless newlinechar selects
that code as a physical line break. write then appends its final newline.
- meaning reports actual supported native meanings, including macros, flags,
parameter delimiters, character-given values and register aliases. It is not
a fixed macro-prefix string added for the LaTeX directory test.
Executor::shipout_io executes only the OutputNodes actually shipped, in traversal
order, using the state at shipout. Copying/replaying nodes and omitting discarded
nodes do not trigger premature expansion or output. A real pdfTeX box/shipout
probe independently confirms late expansion and discarded-box behavior.
**Native TeX modes, boxes and shipout syntax are not implemented by this slice.**
The strict paragraph/demo CLI rejects pending deferred nodes; it neither drops
them silently nor flushes them at EOF. Wiring these whatsits into native lists,
box copying/discarding, output routines and page shipout remains required.
IoState serializes logical stream metadata, not OS handles. Continuations with
open streams require the same live host. JSON state is not a portable job image,
native fmt, arbitrary input checkpoint or permission to reuse side effects.
## Host lookup and output policy
Input/input-stream lookup shares one resolver: working directory, then current
source directory, with an optional .tex suffix. Output is relative to the job
working directory, with .tex for an absent extension. Quoted filenames with
spaces work. Full Kpathsea/TEXMF closure resolution remains future work.
The CLI rejects stream output onto its source, requested PDF, log or already
loaded input source. It does not overwrite the requested PDF after execution
or lowering failure. Normal auxiliaries may already have been written; jobs
are not transactions. File streams currently require UTF-8 text, not arbitrary
8-bit TeX input/output conformance.
## Independent evidence and real format boundary
- Seven job/core tests cover clock validation and scopes, source/dependency
records, EOF, read/readline categories, continuation, diagnostics, errors,
delayed expansion and selected/discarded shipout nodes.
- The token/meaning/parameter suite has **72 real pdfTeX INITEX cases**.
- **12 real native CLI/pdfTeX filesystem cases compare output bytes**, including
empty/missing files, multiline reads, raw readline, CR/LF/CRLF, protection,
newlinechar, quoted filenames, truncation and scoped time parameters.
- Additional CLI tests compare job time with the real host clock before/after
execution, distinguish terminal/log output, verify message ordering, propagate
I/O failures, preserve existing PDFs and reject unshipped output.
The unchanged pinned latex.ltx writes texsys.aux with its real job date/time,
reads it back with read, compares today successfully and prints the source's
own “./texsys.aux found” diagnostic. It advances from the previous time blocker
at **168:8** to **326:1, missing mathchardef**. The source hash is unchanged and
format_boot_passed remains false. The probe runs in a temporary working directory
and includes the actual auxiliary/log contents in its JSON report.
The subsequent quantity slice implements mathchardef meanings, real inputlineno,
dimension/glue/mu register semantics and ifdim. Next: scoped paragraph parameters
and real native list consumers, code tables, quantity expressions, fonts/
magnification, full mode/list/shipout integration and format/font closure.
Font/NFSS and full-template fidelity remain open.
~~~sh
cargo test --workspace --offline -- --test-threads=1
cargo test -p texrra-tex-core --offline --test execution_job -- --nocapture
cargo test --offline --test native_job_io -- --nocapture
python3 scripts/probe-native-format.py --binary target/release/texrra \
--texmf /usr/share/texlive/texmf-dist \
--json /tmp/texrra-native-job/format-probe-final.json
~~~
Run examples/native-bootstrap/job.tex in a scratch working directory with
native --initex --etex. Current release evidence is under /tmp/texrra-native-job/:
job.pdf/txt/log, job-time.aux, format-probe-final.json, arxiv-regression.pdf and
math-regression.json. Verification logs are under /tmp/texrra-job-*.log.