15.1 comptime
- A
comptime fnis executed only at compile time;comptime { … }is a block evaluated at compile time;constis its result. - comptime code is deterministic: the effects
io,net,db,time,randare forbidden. Exceptions arecomptime.readFile(path),comptime.embedDir(path)andcomptime.template(path)(a path inside the package; the file is tracked in the incremental build). comptime.embedDir("dir")is aList<(str, str, str, bytes, i64)>: for every file of the directory (the path below the directory with the separator/, the content type by extension from a fixed table, theETag— a quoted hash string of the content (FNV-1a 64), the gzip-compressed content, the size before compression). Files are sorted by path (reproducibility), hidden files and directories (.name) are skipped. The directory is looked up relative to the source file, then from the nearest directory withoxl.toml; a missing directory or an unreadable file is acomptime-error(D-8054; D-7883).
Implementation-defined. comptime file operations (D-8054; D-7883). Of the exceptions of this section this implementation contains only
comptime.embedDir;comptime.readFileandcomptime.templateare not implemented (optional). Embedded files are not tracked in the incremental build: the driver has no build cache yet (changing a file requires rebuilding the package).
- Types are comptime values of type
type:comptime fn sizeOf(T: type) -> usize. inline for x in comptimeIterable { … }is unrolled at compile time.
Related diagnostics
See also
Source: docs/spec/oxl-standard.en.md