• 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-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-check-liftable-loop-test
                    • Atj-check-single-return-with-expr
                    • Atj-lift-loop-test
                  • 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-lift-loop-tests

Post-translation step: lifting to loop tests.

The tail recursion elimination step produces method bodies of the form while (true) { ... }. When the body of the while is an if one of whose branches is a return, then it is possible to lift the if tests to the loop test, moving the return after the loop.

More precisely, if the method body has the form

while (true) {
    if (<test>) {
        return <expr>;
    } else {
        ...
    }
}

it can be turned into

while (!<test>) {
    ...
}
return <expr>;

Simillarly, if the method body has the form

while (true) {
    if (<test>) {
        ....
    } else {
        return <expr>;
    }
}

it can be turned into

while (<test>) {
    ...
}
return <expr>;

This post-translation step performs these transformations, which produce more idiomatic looping code. It should be possible to extend the scope of this post-translation step, e.g. to cases in which the return is preceded by some statements.

Subtopics

Atj-check-liftable-loop-test
Check if a Java block is a while (true) ... loop with an if body whose test can be lifted to the loop.
Atj-check-single-return-with-expr
Check if a Java block consists of a single return with an expression.
Atj-lift-loop-test
Lift an if test to the enclosing loop.