• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Community
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
    • Interfacing-tools
    • Hardware-verification
    • Software-verification
      • Kestrel-books
        • Crypto-hdwallet
        • Apt
        • Error-checking
        • Fty-extensions
        • Isar
        • Kestrel-utilities
        • Set
        • C
        • Soft
        • Bv
        • Imp-language
        • Ethereum
        • Event-macros
        • Java
          • Atj
            • Atj-implementation
              • Atj-types
                • Atj-type-<=
                • Atj-function-type
                • Atj-type-to-jitype
                • Atj-type
                • Atj-function-type-of-min-input-types
                • Atj-type-top-join
                • Atj-atype
                • Atj-type-bottom-meet
                • Atj-type-bottom-<=
                • Atj-type-top-<=
                • Atj-type-top-list-join
                • Atj-type-bottom-list-<=
                • Atj-type-top-list-<=
                • Atj-type-bottom-list-meet
                • Atj-type-list-<=
                • Atj-type-to-pred
                • Atj-maybe-function-type-info
                • Atj-atype-<=
                • Atj-maybe-function-type
                • Atj-maybe-type
                • Atj-type-to-keyword
                • Atj-function-type-info
                • Atj-type-list-join
                • Atj-type-list-to-type
                • Atj-type-list-<
                • Atj-type-list-meet
                • Atj-type-from-keyword
                • Atj-function-type-of-min-input-types-aux
                • Atj-type-<
                • Atj-type-list-to-type-list-list
                • Atj-number-of-results
                • Atj-function-type-info-default
                • Atj-type-to-pred-gen-mono-thms-2
                • Atj-get-function-type-info-from-table
                • Atj-get-function-type-info
                • Atj-type-to-pred-gen-mono-thms-1
                • Atj-type-to-pred-gen-mono-thm
                • Atj-type-meet
                • Atj-type-to-type-list
                • Atj-type-list-to-jitype-list
                • Atj-type-join
                • Atj-type-of-value
                • Atj-type-list-to-keyword-list
                • Atj-type-semilattices
                • Atj-type-to-pred-gen-mono-thms
                • Atj-function-type-info->outputs
                • Atj-function-type-list->outputs
                • Atj-function-type-list->inputs
                • Atj-type-list-from-keyword-list
                • Atj-type-irrelevant
                • Atj-symbol-type-alist
                • Atj-type-list
                • Atj-function-type-list
                • Atj-type-list-list
                • Atj-maybe-type-list
                • Atj-function-type-info-table
                • *atj-function-type-info-table-name*
              • Atj-java-primitive-array-model
              • Atj-java-abstract-syntax
              • Atj-input-processing
              • Atj-java-pretty-printer
              • Atj-code-generation
              • Atj-java-primitives
              • Atj-java-primitive-arrays
              • Atj-type-macros
              • Atj-java-syntax-operations
              • Atj-fn
              • Atj-library-extensions
              • Atj-java-input-types
              • Atj-test-structures
              • Aij-notions
              • Atj-macro-definition
            • Atj-tutorial
          • Aij
          • Language
        • Riscv
        • Bitcoin
        • Zcash
        • Yul
        • ACL2-programming-language
        • Prime-fields
        • Json
        • Syntheto
        • File-io-light
        • Cryptography
        • Number-theory
        • Axe
        • Lists-light
        • Builtins
        • Solidity
        • Helpers
        • Htclient
        • Typed-lists-light
        • Arithmetic-light
      • X86isa
      • Axe
      • Execloader
    • Math
    • Testing-utilities
  • Atj-implementation

Atj-types

Types used by ATJ for code generation.

In order to make the generated Java code more efficient and idiomatic, ATJ uses types that correspond to both ACL2 predicates and Java types. These ATJ types are used only when :deep is nil and :guards is t.

For example, consider a unary ACL2 function whose guard is or implies stringp, and the corresponding Java method generated by ATJ. Since under the assumption of guard satisfaction this method will always be called with an Acl2Value that is an Acl2String, the method can use Acl2String instead of Acl2Value as the type of the argument. Furthermore, suppose that, under the guard, the ACL2 function always returns integerp. Then the Java method can use Acl2Integer instead of Acl2Value as the return type. In other words, narrower types than the one for all ACL2 values (i.e. Acl2Value) can be used for the argument and result of this Java method. This narrowing is also used to generate methods that operate on Java primitive values and primitive arrays.

In general, establishing the narrower input and output types for a Java method generated from an ACL2 function may involve arbitrarily hard theorem proving: (i) proving that the guard implies that the inputs of the ACL2 function satisfy the ACL2 predicates corresponding to the input types, and (ii) proving that the guard implies that the outputs of the ACL2 function satisfy the ACL2 predicates corresponding to the output types; the number of outputs of an ACL2 function is greater than 1 if the function returns an mv value; otherwise the number of outputs is 1. Since we do not want ATJ to attempt any theorem proving, we provide a macro atj-main-function-type to perform those theorem proving tasks under user control and to record the input and output types of ACL2 functions in a table, and we have ATJ look up types in this table. Note that these types are different from ACL2's built-in types used for typeset reasoning, ACL2's tau system types, and our ACL2 model of Java types.

With a table of the types of the involved ACL2 functions in hand (the table being constructed via calls of atj-main-function-type), ATJ performs a type analysis of the ACL2 terms in function bodies before translating them to Java; this analysis is part of ATJ's pre-translation steps. Generally speaking, ATJ compares the type inferred for an actual argument of a function (this type is inferred by analyzing terms recursively) with the type of the corresponding formal argument of the function (this type is retrieved from the table of function types): if they differ, ATJ inserts code to convert from the former to the latter, unless the former is a subtype of (including equal to) the latter in Java. The conversion may be a type cast, e.g. to convert from Acl2Value to Acl2String; the cast is guaranteed to succeed, assuming that the ACL2 guards are verified. The conversion may also be a change in representation in other cases.

The ATJ type information stored in the table determines/specifies the input and output types of the Java methods generated for the corresponding ACL2 functions. In general, there may be different possible choices of types for certain ACL2 functions: different choices will lead to different Java code. For instance, if a function's guard implies that an argument satisfies integerp, that function's argument can be assigned a type corresponding to Acl2Integer, or a type corresponding to Acl2Rational. The types of these Java methods are part of the ``API'' that the generated Java code provides to external Java code.

In some cases, ACL2 functions return outputs of narrower types when given inputs of narrower types. Prime examples are the arithmetic operations binary-+, binary-*, and unary--. All of their input and output types are the type corresponding to ACL2-numberp, based on their guards: this can be recorded via atj-main-function-type. Based on these types, the corresponding Java methods will take and return Acl2Number values. Now, consider a unary function f that takes integers (i.e. it has a recorded input type corresponding to integerp), and a term (f (binary-+ <i> <j>)), where <i> and <j> are integer-valued terms. When this term is translated to Java, a cast (from Acl2Number) to Acl2Integer will be inserted around the call of the method corresponding to binary-+, in order to fit the Acl2Integer type of the argument of the method corresponding to f.

However, due to well-known closure properties, binary-+, like binary-+ and unary--, maps rationalp inputs to rationalp outputs, and integerp inputs to integerp outputs. This means that we could generate three overloaded methods for each such ACL2 function: one with Acl2Number argument and result types (as above), one with Acl2Rational argument and result types, and one with Acl2Integer argument and result types. This will make the cast in the example above unnecessary: since the Java expressions that translate <i> and <j> statically have type Acl2Integer, the Java compiler will pick the most specific overloaded method, which returns Acl2Integer.

This is not limited to primitive arithmetic operations. Any ACL2 function may have the property of returning outputs of narrower types when given inputs of narrower types. Even if the output types are not narrower, the internal computations may be more efficient on narrower inputs, e.g. the cast in the example above can be avoided when that call of f is part of some function g that may not even return numbers (e.g. it may return booleans).

Thus, we provide another macro, atj-other-function-type, to record additional input and output types for ACL2 functions. ATJ makes use of these additional types to generate multiple overloaded methods for single ACL2 functions. In general, via these two macros, each ACL2 function may have more than one input/output type associated with it (where an input/output type is a full function type, consisting of zero or more input types and one or more output types): (i) a primary (`main') input/output type, provable from the guards as described above; and (ii) zero or more secondary (`other') input/output types. The secondary input types are narrower than the primary ones, but do not have to be provable from the guard; what must be proved, via a theorem generated by atj-other-function-type, is that the guard and the input types imply the output type.

The atj-main-function-type and atj-other-function-type actually attempt to verify the theorems only if the function is in logic mode (whether it is guard-verified or not). If the function is in program mode, there is no attempt to verify theorems (as it is impossible to do so with program-mode functions), and the macros succeed. This should be no more troubling than running program-mode or guard-unverified code.

The above is just an overview of the use of types by ATJ. More details are in the documentation of their implementation and of the code generation functions that use them.

Subtopics

Atj-type-<=
Partial order over all the ATJ types.
Atj-function-type
Fixtype of ATJ function types.
Atj-type-to-jitype
Java input type denoted by an ATJ type.
Atj-type
Fixtype of all the ATJ types.
Atj-function-type-of-min-input-types
Function type with the minimum input types.
Atj-type-top-join
Least upper bound of two ATJ types or nils, with respect to the partial order atj-type-top-<=.
Atj-atype
Fixtype of the ATJ types that denote built-in ACL2 types.
Atj-type-bottom-meet
Greatest lower bound of two ATJ types or nils, with respect to the partial order atj-type-bottom-<=.
Atj-type-bottom-<=
Extension of atj-type-<= to include nil as bottom.
Atj-type-top-<=
Extension of atj-type-<= to include nil as top.
Atj-type-top-list-join
Lift atj-type-top-join to lists.
Atj-type-bottom-list-<=
Lift atj-type-bottom-<= to lists.
Atj-type-top-list-<=
Lift atj-type-top-<= to lists.
Atj-type-bottom-list-meet
Lift atj-type-bottom-meet to lists.
Atj-type-list-<=
Lift atj-type-<= to lists.
Atj-type-to-pred
ACL2 predicate denoted by an ATJ type.
Atj-maybe-function-type-info
Fixtype of ATJ function type information and nil.
Atj-atype-<=
Partial order over the ATJ types that denote built-in ACL2 types.
Atj-maybe-function-type
Fixtype of ATJ function types and nil.
Atj-maybe-type
Fixtype of ATJ types and nil.
Atj-type-to-keyword
Map each ATJ type to a distinct keyword.
Atj-function-type-info
Fixtype of ATJ function type information.
Atj-type-list-join
Lift atj-type-join to lists.
Atj-type-list-to-type
Ensure that a non-empty list of types is a singleton, and return its only element.
Atj-type-list-<
Irreflexive kernel (i.e. strict version) of atj-type-list-<=.
Atj-type-list-meet
Lift atj-type-meet to lists.
Atj-type-from-keyword
Map keywords back to ATJ types.
Atj-function-type-of-min-input-types-aux
Atj-type-<
Irreflexive kernel (i.e. strict version) of atj-type-<=.
Atj-type-list-to-type-list-list
Lift atj-type-to-type-list to lists.
Atj-number-of-results
Number of results returned by a function.
Atj-function-type-info-default
Default ATJ function type information for a function.
Atj-type-to-pred-gen-mono-thms-2
Atj-get-function-type-info-from-table
Retrieve the ATJ function type information of the specified function from the table.
Atj-get-function-type-info
Obtain the ATJ function type information of the specified function.
Atj-type-to-pred-gen-mono-thms-1
Atj-type-to-pred-gen-mono-thm
Atj-type-meet
Greatest lower bound of two ATJ types.
Atj-type-to-type-list
Turn a single ATJ type into a singleton list of it.
Atj-type-list-to-jitype-list
Lift atj-type-to-jitype to lists.
Atj-type-join
Least upper bound of two ATJ types.
Atj-type-of-value
ATJ type of an ACL2 value.
Atj-type-list-to-keyword-list
Lift atj-type-to-keyword to lists.
Atj-type-semilattices
The two semilattices consisting of ATJ types and nil.
Atj-type-to-pred-gen-mono-thms
Atj-function-type-info->outputs
Return the list of all the output type lists in a function's type information.
Atj-function-type-list->outputs
Lift atj-function-type->outputs to lists.
Atj-function-type-list->inputs
Lift atj-function-type->inputs to lists.
Atj-type-list-from-keyword-list
Lift atj-type-from-keyword to lists.
Atj-type-irrelevant
An irrelevant ATJ type, usable as dummy return value with hard errors.
Atj-symbol-type-alist
Fixtype of alists from symbols to ATJ types.
Atj-type-list
Fixtype of lists of ATJ types.
Atj-function-type-list
Fixtype of lists of ATJ function types.
Atj-type-list-list
Fixtype of lists of lists of ATJ types.
Atj-maybe-type-list
Fixtype of lists of ATJ types and nil.
Atj-function-type-info-table
Table that associates ATJ types to ACL2 functions.
*atj-function-type-info-table-name*
Name of the table that associates ATJ types to ACL2 functions.