Compiler Internals

Finch has several compiler modules with separate interfaces.

SymbolicContexts

SymbolicContexts are used to represent the symbolic information of a program. They are used to reason about the bounds of loops and the symbolic information of the program, and are defined on an algebra

Finch.StaticHashType
StaticHash

A hash function which is static, i.e. the hashes are the same when objects are hashed in the same order. The hash is used to memoize the results of simplification and proof rules.

Finch.SymbolicContextType
SymbolicContext

A compiler context for symbolic computation, defined on an algebra.

Finch.get_algebraFunction
get_algebra(ctx)

get the algebra used in the current context

Finch.get_static_hashFunction
get_static_hash(ctx)

Return an object which can be called as a hash function. The hashes are the same when objects are hashed in the same order.

Finch.proveFunction
prove(ctx, root; verbose = false)

use the rules in ctx to attempt to prove that the program root is true. Return false if the program cannot be shown to be true.

Finch.simplifyFunction

simplify(ctx, node)

simplify the program node using the rules in ctx

ScopeContexts

ScopeContexts are used to represent the scope of a program. They are used to reason about values bound to variables and also the modes of tensor variables.

Finch.ScopeContextType
ScopeContext

A context for managing variable bindings and tensor modes.

Finch.get_bindingFunction
get_binding(ctx, var)

Get the binding of a variable in the context.

get_binding(ctx, var, val)

Get the binding of a variable in the context, or return a default value.

Finch.has_bindingFunction
has_binding(ctx, var)

Check if a variable is bound in the context.

Finch.set_binding!Function
set_binding!(ctx, var, val)

Set the binding of a variable in the context.

Finch.set_declared!Function
set_declared!(ctx, var, val)

Mark a tensor variable as declared in the context.

Finch.set_frozen!Function
set_frozen!(ctx, var, val)

Mark a tensor variable as frozen in the context.

Finch.set_thawed!Function
set_thawed!(ctx, var, val)

Mark a tensor variable as thawed in the context.

Finch.get_tensor_modeFunction
get_tensor_mode(ctx, var)

Get the mode of a tensor variable in the context.

Finch.open_scopeFunction
open_scope(f, ctx)

Call the function f(ctx_2) in a new scope ctx_2.

JuliaContexts

JuliaContexts are used to represent the execution environment of a program, including variables and tasks. They are used to generate code.

Finch.NamespaceType
Namespace

A namespace for managing variable names and aesthetic fresh variable generation.

Finch.JuliaContextType
JuliaContext

A context for compiling Julia code, managing side effects, parallelism, and variable names in the generated code of the executing environment.

Finch.push_preamble!Function
push_preamble!(ctx, thunk)

Push the thunk onto the preamble in the currently executing context. The preamble will be evaluated before the code returned by the given function in the context.

Finch.push_epilogue!Function
push_epilogue!(ctx, thunk)

Push the thunk onto the epilogue in the currently executing context. The epilogue will be evaluated after the code returned by the given function in the context.

Finch.get_taskFunction
get_task(ctx)

Get the task which will execute code in this context

Finch.freshenFunction
freshen(ctx, tags...)

Return a fresh variable in the current context named after Symbol(tags...)

Finch.containFunction
contain(f, ctx)

Call f on a subcontext of ctx and return the result. Variable bindings, preambles, and epilogues defined in the subcontext will not escape the call to contain.

AbstractCompiler

The AbstractCompiler interface requires all of the functionality of the above contexts, as well as the following two methods:

Finch.FinchCompilerType
FinchCompiler

The core compiler for Finch, lowering canonicalized Finch IR to Julia code.

Finch.get_resultFunction
get_result(ctx)

Return a variable which evaluates to the result of the program which should be returned to the user.

Finch.get_mode_flagFunction
get_mode_flag(ctx)

Return the mode flag given in @finch mode = ?.