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.

source
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.

source
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.

source
Finch.simplifyFunction

simplify(ctx, node)

simplify the program node using the rules in ctx

source

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.get_bindingFunction
get_binding(ctx, var)

Get the binding of a variable in the context.

source
get_binding(ctx, var, val)

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

source

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.

source
Finch.JuliaContextType
JuliaContext

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

source
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.

source
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.

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

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

source
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.

source

AbstractCompiler

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

Finch.get_resultFunction
get_result(ctx)

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

source