Browse the docs

silk.core.compilation.

Build choices of the current compilation, such as safety, threading, and artifact kind, for use in static evaluation.

When to use#

Use Compilation to select code for the build request, for example with static if. Use Compilation.safety to select checked or unchecked library code, and Compilation.threading to select single-thread or multi-thread code. Use silk.core.target for facts about the machine, such as the architecture and the pointer width.

Details#

Each value comes from the compilation profile, which is fixed before specialization. The values describe logical requests. They do not find SDKs, load runtime packages, or change the ownership rules. Each operation in this module is static, so the selection adds no runtime cost.

Examples#

Select code for the safety policy#

silk
import silk.core.compilation { Compilation, Safety }

fn boundsChecked() -> bool {
  static if Compilation.safety() == Safety.Checked {
    return true
  }
  return false
}

pub fn main() -> i32 {
  let checked = boundsChecked()
  return 0
}

Import as Compilation with import silk.core.compilation { Compilation }.

Public declarations: 13.

Libc#

silk
pub enum Libc

The C library that the build requests.

Details#

Read the selected value with Compilation.libc.

None#

silk
None

No C library. The program uses only Silk code and direct system calls.

System#

silk
System

The C library of the platform, such as the libc of macOS.

Gnu#

silk
Gnu

The GNU C library (glibc).

Artifact#

silk
pub enum Artifact

The kind of output file that the build requests.

Details#

Read the selected value with Compilation.artifact.

Executable#

silk
Executable

A program that the operating system can start.

LoadableModule#

silk
LoadableModule

A module that a host program loads at runtime, such as a shared library or a WebAssembly module.

StaticArchive#

silk
StaticArchive

A static library archive for a later link step.

Object#

silk
Object

One relocatable object file.

silk
pub enum Link

The link mode that the build requests.

Details#

Read the selected value with Compilation.link.

Static#

silk
Static

Static linking. The artifact includes its dependencies.

Dynamic#

silk
Dynamic

Dynamic linking. The artifact loads shared libraries at startup.

CodeModel#

silk
pub enum CodeModel

The code model that the build requests.

Details#

Read the selected value with Compilation.codeModel.

Small#

silk
Small

The small code model. Code and static data must be in a limited address range.

Large#

silk
Large

The large code model. Code and static data can be at any address.

Relocation#

silk
pub enum Relocation

The relocation model that the build requests.

Details#

Read the selected value with Compilation.relocation.

Static#

silk
Static

Code for a fixed load address.

Pic#

silk
Pic

Position-independent code, which can load at any address.

Optimization#

silk
pub enum Optimization

The optimization level that the build requests.

Details#

Read the selected value with Compilation.optimization.

None#

silk
None

No optimization.

Speed#

silk
Speed

Optimization for speed.

Size#

silk
Size

Optimization for code size.

Safety#

silk
pub enum Safety

The library safety policy that the build requests.

Details#

Read the selected value with Compilation.safety.

Checked#

silk
Checked

The library does its runtime checks.

Unchecked#

silk
Unchecked

Library code can omit runtime checks. The caller is responsible for valid inputs.

Threading#

silk
pub enum Threading

The library threading policy that the build requests.

Details#

Read the selected value with Compilation.threading.

Single#

silk
Single

The program has one thread. The library can use code without synchronization.

Multi#

silk
Multi

The program can have more than one thread. The library uses synchronized code.

Unwind#

silk
pub enum Unwind

The unwind mode that the build requests.

Details#

Read the selected value with Compilation.unwind.

None#

silk
None

No unwind tables.

Native#

silk
Native

Unwind tables for the native platform.

Selection#

silk
pub union Selection

An entry or runtime request: the platform default, none, or a named symbol or package.

Details#

Compilation.entry and Compilation.runtime return this type. A name is a logical identity, not a file path.

Default#

silk
Default

The default of the platform.

None#

silk
None

No entry point or no runtime.

Named#

silk
Named

A named symbol or package.

Field name#

silk
pub name: string<'static>

The logical name of the symbol or package.

Sanitizer#

silk
pub enum Sanitizer

A sanitizer that a build can request.

Details#

Test a sanitizer with Compilation.hasSanitizer. A build can request more than one sanitizer.

Address#

silk
Address

Address checks for instrumented memory operations.

Thread#

silk
Thread

Data-race checks for instrumented concurrent operations.

Undefined#

silk
Undefined

Checks for instrumented undefined behavior.

debug#

silk
pub const debug: bool

true if the build requests debug information.

Compilation#

silk
pub struct Compilation

The owner type of the compilation queries. It has no fields and is never constructed.

Details#

Each operation is static. Use it in a static if, a static fn, or a const initializer.

Implementation Compilation#

silk
impl Compilation

Associated function libc#

silk
pub static fn libc() -> Libc

Returns the C library that the build requests.

Associated function artifact#

silk
pub static fn artifact() -> Artifact

Returns the kind of output file that the build requests.

silk
pub static fn link() -> Link

Returns the link mode that the build requests.

Associated function codeModel#

silk
pub static fn codeModel() -> CodeModel

Returns the code model that the build requests.

Associated function relocation#

silk
pub static fn relocation() -> Relocation

Returns the relocation model that the build requests.

Associated function optimization#

silk
pub static fn optimization() -> Optimization

Returns the optimization level that the build requests.

Associated function safety#

silk
pub static fn safety() -> Safety

Returns the library safety policy that the build requests.

When to use#

Use safety to select between checked and unchecked library code, for example to omit bounds checks in an unchecked build.

Associated function threading#

silk
pub static fn threading() -> Threading

Returns the library threading policy that the build requests.

When to use#

Use threading to select between code with and without synchronization.

Associated function unwind#

silk
pub static fn unwind() -> Unwind

Returns the unwind mode that the build requests.

Associated function entry#

silk
pub static fn entry() -> Selection

Returns the entry point request of the build.

Details#

The result is a logical request. This function does not find a startup symbol.

Associated function runtime#

silk
pub static fn runtime() -> Selection

Returns the runtime request of the build.

Details#

The result is a logical request. This function does not load a runtime package.

Associated function hasSanitizer#

silk
pub static fn hasSanitizer(value: Sanitizer) -> bool

Returns true if the build requests the sanitizer value.

Category: Core.

Profiles: aarch64-apple-darwin, aarch64-unknown-linux-gnu, aarch64-unknown-linux-gnu-no-libc, x86_64-unknown-linux-gnu, x86_64-unknown-linux-gnu-no-libc, wasm32-unknown-unknown, wasm32-wasip1, wasm32-wasip2.

View the source of this page