Skip to main content

text_from_bytes

Function text_from_bytes 

Source
pub fn text_from_bytes(bytes: &LogosSeq<i64>) -> String
Expand description

Rebuild a Text from a Seq of Int of UTF-8 bytes (the text_from_bytes builtin, AOT — the exact inverse of text_bytes).

★ INVALID BYTES ARE A FAILURE, NOT A SUBSTITUTION. This used to fall back to from_utf8_lossy, justified by a premise written in this very comment: “inputs originate from text_bytes, so the bytes are always valid UTF-8”. Our own stdlib falsifies it — fromHex (encoding.lg) decodes arbitrary hex and hands the result straight in, so fromHex("ff") arrives here with byte 255.

The consequence was three answers to one question: the tree-walker and the VM raised text_from_bytes(): invalid UTF-8, this returned U+FFFD, and the wasm lowering checked nothing at all. A panic is what the AOT tier means by “the reference tier errored” — readBytes already answers that way — so the tiers now agree.

A premise asserted in a doc comment is enforced by nothing, and the caller that violates it is usually in a different file from the one that states it.