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/regions.x

Values that can outlive the region that allocated them.

Functions

FunctionSummary
Compiler.check_regionsWarns about values that can outlive the region that allocated them.

Compiler

Compiler.check_regions

void Compiler.check_regions(Compiler c, List ast)

Warns about values that can outlive the region that allocated them. ast must be the bound and typed top-level unit, before transform lowering rewrites its defer and region forms. The call adds warnings to c and does not change ast.

Source: src/regions.x:802

Design notes

A region is a $scope() block, a Scope.retain and Scope.release pair, a $scope(&slot) push, a String.pool_retain bracket, an $auto local, or a Scope local that Scope.destroy ends. The pass reads the typed forms the parser produced, before the transform driver rewrites them, so a region is still the call that opens it and the defer beside it that closes it. It warns when a value born in a region reaches storage that outlives the region, when a region is opened without its close in the same block, and when a local is read after it was freed.

A function’s summary is two facts: whether it returns fresh storage, and where each parameter is sunk. The unit’s functions reach a fixpoint over their summaries. A call into another unit has a summary only through the runtime table, so a unit’s warnings do not depend on which units were translated before it.

The warnings name departures from the lexical pattern. Raw C stores, pointer arithmetic, callbacks, and storage the runtime did not allocate stay outside them.