Intrinsic Constants

Alongside the constants you declare, the compiler exposes a set of intrinsic values through the build context. Each is a field of an intrinsic — #source, #build, #target, #compiler, or #config — that you import from the standard Rux package and read with .. Because every one is fixed at compile time, it can initialize an ordinary const or serve as a default argument, at no run-time cost.

import Core::{ #source, #build };

Print(#source.file);   // e.g. "Main.rux"
Print(#source.line);   // the line number of this call

Common Compile-Time Values

ValueTypeExpands to
#source.fileSlice<char8>Current source file name
#source.lineuintCurrent line number
#source.columnuintCurrent column number
#source.functionSlice<char8>Enclosing function name
#source.moduleSlice<char8>Enclosing module path
#build.dateSlice<char8>Date the program was compiled
#build.timeSlice<char8>Time the program was compiled

See Build Context for the complete set, including #target, #compiler, and #config.

These replace the earlier standalone #file, #line, #date, and #time constants, which are now fields of #source and #build.

Substitution at the Point of Use

A build-context value expands where it is written. #source.line on line 40 evaluates to 40; #source.function inside func Parse evaluates to "Parse". The value is a plain literal by the time the program runs.

Build Stamps

Because #build.date and #build.time are constant expressions, they can initialize a regular const — a convenient way to embed a build stamp:

import Core::{ #build };

const BuildDate: Slice<char8> = #build.date;
const BuildTime: Slice<char8> = #build.time;

Source Location as a Default Argument

When a #source field is the default value of a parameter, it expands at the call site, so a function learns where it was called from without the caller passing anything — the pattern behind Assert and Panic. See Source Location as a Default Argument for the full example.

See Also

  • Build Context — every compiler-provided value in one place
  • Intrinsics — how these values are declared and imported
  • Constants — declaring your own compile-time constants