• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Community
    • Proof-automation
    • ACL2
    • Macro-libraries
    • 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-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-make-parallel-asg
                    • Atj-elim-tailrec-in-jstatems+jblocks
                    • Atj-parallel-asg-depgraph
                    • Atj-elim-tailrec-in-return
                    • Atj-serialize-parallel-asg
                    • Atj-elim-tailrec
                      • Atj-elim-tailrec-gen-block
                    • 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
          • 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-post-translation-tailrec-elimination

    Atj-elim-tailrec

    Turn the body of a tail-recursive method into a loop.

    Signature
    (atj-elim-tailrec name params body) → new-block
    Arguments
    name — Guard (stringp name).
    params — Guard (jparam-listp params).
    body — Guard (jblockp body).
    Returns
    new-block — Type (jblockp new-block).

    This is called only on tail-recursive methods. We replace the recursive calls in the block and we surround the block with a while loop with test true; the loop is actually exited when a return is executed.

    Under suitable conditions, it should be possible to generate more idiomatic while loops, with an actual continuation test instead of true, and with base cases outside the loop. However, the current form always works for all possible tail-recursive methods.

    Because of the constant true continuation test in the while, it is unnecessary to have a dummy return after the loop. According to Java's static semantics, code after the loop is unreachable.

    Definitions and Theorems

    Function: atj-elim-tailrec

    (defun atj-elim-tailrec (name params body)
     (declare (xargs :guard (and (stringp name)
                                 (jparam-listp params)
                                 (jblockp body))))
     (let ((__function__ 'atj-elim-tailrec))
      (declare (ignorable __function__))
      (list (make-jstatem-while
                 :test (jexpr-literal-true)
                 :body (atj-elim-tailrec-in-jblock body params name)))))

    Theorem: jblockp-of-atj-elim-tailrec

    (defthm jblockp-of-atj-elim-tailrec
      (b* ((new-block (atj-elim-tailrec name params body)))
        (jblockp new-block))
      :rule-classes :rewrite)