• 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-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-gen-everything
                • Atj-name-translation
                • Atj-gen-test-cunit
                • Atj-gen-test-class
                • Atj-gen-main-file
                • Atj-post-translation
                  • Atj-post-translation-remove-array-write-calls
                    • Atj-remove-array-write-call-returns-in-jstatems+jblocks
                    • Atj-remove-array-write-call-in-asg
                    • Atj-remove-array-write-call-asgs-in-jstatems+jblocks
                    • Atj-remove-array-write-call-return
                    • Atj-remove-array-write-calls
                    • Atj-ensure-no-array-write-calls
                    • *atj-primarray-write-method-names*
                  • Atj-post-translation-cache-const-methods
                  • Atj-post-translation-tailrec-elimination
                  • Atj-post-translation-fold-returns
                  • Atj-post-translate-body
                  • Atj-post-translation-lift-loop-tests
                  • Atj-post-translation-simplify-conds
                  • Atj-post-translate-jcbody-elements
                  • Atj-post-translation-remove-continue
                • 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
        • 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-post-translation

Atj-post-translation-remove-array-write-calls

Post-translation step: remove calls of the array writing methods.

ATJ's ACL2-to-Java translation turns calls of the ACL2 functions that model array writes into calls of corresponding Java methods that make destructive writes. This keeps the translation simple, also because the array writing methods return the (modified) array, thus maintaining a functional programming style.

However, in idiomatic Java, an array write should be an assignment, whose returned value is normally discarded by turning the assignment into a statement via an ending semicolon. The goal of this post-translation step is to suitably replace calls of the array writing methods (along with some surrounding code) into assignment expression statements. This is essentially ``inlining'' these method calls.

For now we make the following transformations in this post-translation step:

  • We turn assignment expression statements of the form

    a = <array-write-method>(a, i, x);

    into assignment expressions statements of the form

    a[i] = x;

    ATJ's ACL2-to-Java translation produces statements of the first kind, when translating terms of the form

    (let (... (a (<array-write-function> a i x)) ...) ...)

    Since the array writing method makes the assignment, the second kind of assignment is equivalent to the first one. The first one just ends up assigning (the modified) a to itself. Here `modified' refers to the content of the array, not the immutable reference that is actually in a.

    Because of the single-threaded array analysis, the Java variable a on the left-hand side should be the same as the first argument of the method call (when this is a variable at all), because the single-threadedness should ensure that array variables can be reused.

  • We turn return statements of the form

    return <array-write-method>(a, i, x);

    (where a is a variable) into two-statement blocks of the form

    a[i] = x;
    return a;

    ATJ's ACL2-to-Java translation produces statements of the first kind, when a function ends its execution with a call of the form (<array-write-function> a i x). The array write method destructively updates the array and returns it. Thus, we can ``inline'' the method call here.

The two cases above are not the only kind of occurrences of the array writing methods in the Java code produced by ATJ's ACL2-to-Java translation. Other kinds of occurrences will be handled in the future.

Subtopics

Atj-remove-array-write-call-returns-in-jstatems+jblocks
Replace return statements of array write method calls with assignments to the array components and return statements of the updated arrays.
Atj-remove-array-write-call-in-asg
Replace an assignment of an array write method call with the corresponding assignment to the array component.
Atj-remove-array-write-call-asgs-in-jstatems+jblocks
Replace assignments of array write method calls with the corresponding assignments to the array components.
Atj-remove-array-write-call-return
Replace a return statement of an array write method call with an assignment to the array component followed by a return statement of the updated array.
Atj-remove-array-write-calls
Remove array write method calls from a block.
Atj-ensure-no-array-write-calls
Ensure that there are no calls of array write methods in a block.
*atj-primarray-write-method-names*
List of names of the methods to write to Java primitive arrays.