ERR/E4.1 (slice 1): log + is_comptime + process.exit/assert (+ noreturn codegen)
Stdlib slice of Phase E4, plus the noreturn codegen fix that enables it. noreturn codegen (the enabling bug): E1.4c made `noreturn` type-system-only; this is its first backend consumer and it crashed LLVM verification. Fixed: - lower.zig: a `-> noreturn` body lowers as statements ending in `unreachable` (ensureTerminator emits unreachable; the two body-lowering sites no longer treat the last expr as a `ret`). - emit_llvm.zig: a `void`/`noreturn` call result stays unnamed (direct + foreign call sites) — LLVM rejects a named void value. - finishCatchHandler: a `noreturn` value-carrying catch body (which is not an IR terminator) closes the handler with `unreachable` instead of feeding a bad value into the merge phi. Shared by lowerCatch + lowerCatchOverChain. is_comptime(): new nullary `.is_comptime` IR op (inst/print/interp/emit_llvm) — interp evaluates true, emit_llvm emits constant false, so `if is_comptime()` dead-codes out of compiled binaries. Recognized by name in tryLowerReflectionCall + inferExprType (no std.sx decl, which would emit a spurious `declare @is_comptime` into every module). library/modules/log.sx: warn/info/debug/err — interpolate like print, write `LEVEL: <msg>` to stderr. (`error` is reserved → the level is `log.err`.) process.exit(code) -> noreturn + assert(cond, msg) in process.sx. `exit` is POSIX `_exit(2)` (immediate, no cleanup; sx print is unbuffered so nothing is lost), bound to "_exit" which also avoids a link-level clash with the sx `exit` function's own name. examples 248 (exit 0), 249 (exit 42), 250 (exit 1). #caller_location, the comptime-exit diagnostic flush, and trace.print_interpreter_frames deferred to E4.1b.
This commit is contained in:
@@ -85,6 +85,12 @@ pub const Op = union(enum) {
|
||||
const_string: StringId,
|
||||
const_null,
|
||||
const_undef, // `---` undefined initializer
|
||||
/// ERR E4.1 — `is_comptime()` builtin. The SAME lowered IR is run by both
|
||||
/// the comptime interpreter and the compiled backend, so this can't fold at
|
||||
/// lower time: the interp evaluates it to `true`, emit_llvm emits constant
|
||||
/// `false`. Lets stdlib (`process.exit`, `assert`) take a comptime-only
|
||||
/// diagnostic branch that dead-codes out of compiled binaries.
|
||||
is_comptime,
|
||||
/// Comptime-only Type value. Carried as a `Value.type_tag(TypeId)`
|
||||
/// in the interpreter. NEVER emitted to LLVM — types are erased
|
||||
/// after lowering. `emit_llvm` bails loudly if it sees one,
|
||||
|
||||
Reference in New Issue
Block a user