On this page

0052. Path is erased platform bytes

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. Equality compares exact bytes. Path methods are selected before erasure, so bytes methods do not leak onto path. The constructor and extraction form the first M6.4 increment; operations below form its second increment. POSIX semantics are textual, never I/O:

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

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.