0052. Path is erased platform bytes
- Status: Accepted
- Date: 2026-10-31
- Plan: M6.4
- Review: Strings, bytes and paths in
docs/design-review.md
Context
POSIX filenames need not be UTF-8. CLI tools need to preserve their exact bytes, while distinguishing paths from text and handling display explicitly.
Decision
path is a checked nominal type erased to bytes in
IR. path(x) accepts str or bytes without runtime
conversion; to_bytes() returns the bytes, and
to_str() validates UTF-8 into option
a.join(b)replacesafor absoluteb; emptyayieldsb; otherwise strip trailing base slashes and insert one/between them, including an empty argument. Absolute replacement preserves the argument bytes verbatim.parent()strips trailing slashes and the last component:/agives/,a/b/givesa, anda,/, and empty have no parent.file_name()returns the last component, except/, empty,.and..yield none.extension()returns the suffix after its last dot unless that dot is first or absent.components()returns nonempty pieces with/as a leading component for absolute paths; it does not normalize.or...is_absolute()tests the POSIX root.display()replaces each maximal invalid UTF-8 subpart with U+FFFD, matching Rust'sfrom_utf8_lossy.
Paths are not printable or interpolatable directly (E0852), and
+ is E0853; join and display make those operations
explicit. Windows path representation is deferred to M15.1.
Parent, file name and extension return
option<path>; components returns
vec<path>, so invalid UTF-8 remains
representable in every operation. The three optional view
intrinsics use an internal len == usize::MAX
sentinel, tested by PathPresent before wrapping the
option; it never reaches a user payload. They retain the input
lifetime. Join/display allocate fresh bytes; components allocates
a fresh vector of views. No new IR type or interpreter value is
needed.
Alternatives considered
- UTF-8 strings as paths: cannot preserve arbitrary POSIX names.
- Implicit str-to-path conversion: hides boundaries and weakens type checking.
- Normalize
..during construction or joining: changes textual identity and can change filesystem meaning in the presence of symlinks.
Consequences
The two backends share byte equality and view lifetimes. Lossy decoding requires matching malformed-sequence tests in C and Rust; filesystem and process APIs can accept paths without assuming UTF-8. Windows needs a later platform decision.