• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Community
    • Proof-automation
    • Macro-libraries
    • ACL2
    • Interfacing-tools
    • Hardware-verification
    • Software-verification
      • Kestrel-books
        • Crypto-hdwallet
        • Apt
        • Error-checking
        • Fty-extensions
        • Isar
        • Kestrel-utilities
        • Set
        • Soft
        • C
        • Bv
        • Imp-language
        • Event-macros
        • Java
          • Atj
            • Atj-implementation
              • Atj-types
              • Atj-java-primitive-array-model
              • Atj-java-abstract-syntax
              • Atj-input-processing
              • Atj-java-pretty-printer
              • Atj-code-generation
                • Atj-gen-test-method
                • Atj-shallow-code-generation
                • Atj-common-code-generation
                • Atj-shallow-quoted-constant-generation
                • Atj-pre-translation
                  • Atj-pre-translation-array-analysis
                  • Atj-pre-translation-type-annotation
                  • Atj-pre-translation-var-reuse
                    • Atj-mark-term
                    • Atj-vars-in-jexpr
                    • Atj-mark-lambda-formals
                    • Atj-mark-formals+body
                    • Atj-unmark-vars
                    • Atj-unmark-var
                    • Atj-mark-vars-new
                    • Atj-mark-var-new
                    • Atj-mark-var-old
                  • Atj-pre-translate
                  • Atj-pre-translation-multiple-values
                  • Atj-pre-translation-no-aij-types-analysis
                  • Atj-pre-translation-var-renaming
                  • Atj-pre-translation-remove-return-last
                  • Atj-pre-translation-disjunctions
                  • Atj-pre-translation-trivial-vars
                  • Atj-pre-translation-conjunctions
                  • Atj-pre-translation-unused-vars
                  • Atj-pre-translation-remove-dead-if-branches
                • Atj-gen-everything
                • Atj-name-translation
                • Atj-gen-test-cunit
                • Atj-gen-test-class
                • Atj-gen-main-file
                • Atj-post-translation
                • Atj-deep-code-generation
                • Atj-gen-test-methods
                • Atj-gen-test-file
                • Atj-gen-env-file
                • Atj-gen-output-subdir
              • 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
        • Bitcoin
        • Ethereum
        • Yul
        • Zcash
        • ACL2-programming-language
        • Prime-fields
        • Json
        • Syntheto
        • File-io-light
        • Cryptography
        • Number-theory
        • Lists-light
        • Axe
        • Builtins
        • Solidity
        • Helpers
        • Htclient
        • Typed-lists-light
        • Arithmetic-light
      • X86isa
      • Axe
      • Execloader
    • Math
    • Testing-utilities
  • Atj-pre-translation

Atj-pre-translation-var-reuse

Pre-translation step performed by ATJ: marking of reusable lambda-bound variables.

Consider a function body of the form

(let ((x ...))
  (let ((x ...))
    (f x)))

The second x bound by let ``overwrites'' the first one completely, because in the rest of the term (namely, (f x)) only the second one is referenced, not the first one.

In contrast, consider a function body of the form

(let ((x ...))
  (f (let ((x ...)) (f x)) (g x)))

Here, the second x bound by let ``overwrites'' the second one only partially, namely in (f x), but other parts of the rest of the term, namely (g x), reference the first one.

When we translate ACL2 to Java, let-bound variables become Java local variables. In the first example above, provided that the two x variables have the same type, the Java code can use the same local variable for both: for the first binding, the Java code declares and initializes the variable; for the second binding, the Java code assigns to the variable, destructively updating it, which is safe because the old value is no longer needed. However, in the second example above, there have to be two distinct Java local variables, say x1 and x2, corresponding to the two bound variables: both are declared and initialized, none can be safely destructively updated.

This pre-translation step analyzes terms to find out which lambda-bound (i.e. let-bound) variables can be reused and destructively updated. The lambda-bound variables are marked as either `new' or `old': the first marking means that the variable must be a new Java local variable that is declared and initilized; the second marking means that the variable can be an old Java local variable that is destructively assigned. These markings provide ``instructions'' to the ACL2-to-Java translation.

In the first example above the markings would be

(let (([n]x ...))
  (let (([o]x ...))
    (f [o]x)))

while in the second example above the markings would be

(let (([n]x ...))
  (f (let (([n]x ...)) (f [n]x)) (g [n]x)))

Note that, as we mark the lambda-bound variables, we must mark in the same way the occurrences in the lambda bodies, to maintain the well-formedness of the ACL2 terms.

This pre-translation step must be performed after the type annotation step, so that types are kept into account: a variable can be reused only if it has the same type in both lambda formal parameters. Since the type annotation step adds types to variable names, by comparing names for equality we also compare their types for equality. If two variables have different types, they also have different names (since the name includes the type).

After this translation step, the variable renaming step takes care of renaming apart ACL2 variables with the same name that are both marked as `new'.

Subtopics

Atj-mark-term
Mark the variables in a term as `new' or `old'.
Atj-vars-in-jexpr
Variables that will occur in the Java expression generated from an ACL2 term.
Atj-mark-lambda-formals
Atj-mark-formals+body
Mark all the variables in the formal parameters and body of an ACL2 function definition as `new' or `old'
Atj-unmark-vars
Lift atj-unmark-var to lists.
Atj-unmark-var
Decompose a marked variable into its marking and its unmarked name.
Atj-mark-vars-new
Lift atj-mark-var-new to lists.
Atj-mark-var-new
Mark a variable as `new'.
Atj-mark-var-old
Mark a variable as `old'.