Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Provisional API: This reference documents current compiler behavior. Compatibility is not yet promised.

src/cleanup/cleanup.x

Cleanup regions and the transfers that leave them.

Functions

FunctionSummary
Ast.defer_capturesWrites captured addresses in the order capture selection established.
Compiler.lower_cleanupLowers the cleanup regions and transfers of the completed top-level node; other nodes pass through.
Compiler.lower_defer_regionReturns the region that runs finalizer when body leaves.
Compiler.rewrite_defer_listReturns stmts with each defer statement and the statements after it replaced by one region; a list without defer returns unchanged.
Compiler.static_value_is_runtimeReports whether the static initializer value has to run at runtime, because it calls, allocates, or reads an object other than a function name.

Ast

Ast.defer_captures

List Ast.defer_captures(List environment, List records)

Writes captured addresses in the order capture selection established.

Source: src/cleanup/defer.x:17

Compiler

Compiler.lower_cleanup

List Compiler.lower_cleanup(Compiler c, List node)

Lowers the cleanup regions and transfers of the completed top-level node; other nodes pass through. Unit normalization calls this at function completion. Expressions cannot contain an unlifted function, so no second unit-tree traversal is needed.

Source: src/cleanup/transfers.x:64

Compiler.lower_defer_region

List Compiler.lower_defer_region(Compiler c, List body, List finalizer)

Returns the region that runs finalizer when body leaves. Ordinary cleanup statements take the callable chain; lexical transfers and unsupported capture types keep the landing-frame path.

Source: src/cleanup/defer.x:55

Compiler.rewrite_defer_list

List Compiler.rewrite_defer_list(Compiler c, List stmts)

Returns stmts with each defer statement and the statements after it replaced by one region; a list without defer returns unchanged.

Source: src/cleanup/defer.x:31

Compiler.static_value_is_runtime

int Compiler.static_value_is_runtime(Compiler c, List value, Map runtime)

Reports whether the static initializer value has to run at runtime, because it calls, allocates, or reads an object other than a function name. runtime holds the function-local statics already known to run that way, or is NULL at file scope.

Source: src/cleanup/statics.x:120

Design notes

A cleanup region is a defer body, a region of a landing form such as a try body or catch arm, or the rest of a block after a static local whose initializer runs at runtime. Normalization turns each defer statement into a region. When a function is complete, each try takes the landing form its component answers, and one walk places each region’s exits on every transfer that leaves it, rejects a jump into a region, and keeps the locals a sigsetjmp landing reads either volatile or escaped.