package libsail

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module Libsail.Constant_foldSource

Sourcemodule StringMap : sig ... end
Sourceval optimize_constant_fold : bool ref
Sourceval is_too_large : Value.value -> bool
Sourceval safe_primops : (Value.value list -> Value.value) StringMap.t
Sourceval opt_fold_to_unit : string list ref

We can specify a list of identifiers that we want to remove from the final AST here. This is useful for removing tracing features in optimized builds, e.g. for booting an OS as fast as possible.

Basically we just do this by mapping

f(x, y, z) -> ()

when f is in the list of identifiers to be mapped to unit. The advantage of doing it like this is if x, y, and z are computationally expensive then we remove them also. String concatenation is very expensive at runtime so this is something we really want when cutting out tracing features. Obviously it's important that they don't have any meaningful side effects, and that f does actually have type unit.

Sourceval fold_to_unit : Ast_util.IdSet.elt -> bool
Sourceval is_constant : Type_check.tannot Ast.exp -> bool
Sourceval is_constant_fexp : Type_check.tannot Ast.fexp -> bool

This rewriting pass looks for function applications (E_app) expressions where every argument is a literal. It passes these expressions to the OCaml interpreter in interpreter.ml, and reconstructs the values returned back into expressions which are then re-typechecked and re-inserted back into the AST.

We don't use the effect system to decide if expressions are safe to evaluate, because this ignores I/O, and would force us to ignore functions that maybe throw exceptions internally but as called are totally safe. Instead any exceptions during evaluation are caught, and the original expression is kept. Some causes of this could be:

  • Function tries to read/write register.
  • Calls an unsafe primop.
  • Throws an exception that isn't caught.
Sourceval no_fixed : fixed
Sourceval rw_exp : fixed -> string -> (unit -> 'a) -> (unit -> 'b) -> Interpreter.state -> Type_check.tannot Ast.exp -> Type_check.tannot Ast.exp
Sourceval rewrite_constant_function_calls' : fixed -> string -> Type_check.typed_ast -> Type_check.typed_ast
Sourceval rewrite_constant_function_calls : fixed -> string -> Type_check.typed_ast -> Type_check.typed_ast
Sourcetype to_constant =
  1. | Register of Ast.id * Ast.typ * Type_check.tannot Ast.exp
  2. | Register_field of Ast.id * Ast.id * Ast.typ * Type_check.tannot Ast.exp
OCaml

Innovation. Community. Security.