• 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
          • Syntax-for-tools
          • Atc
            • Atc-implementation
              • Atc-abstract-syntax
              • Atc-pretty-printer
              • Atc-event-and-code-generation
                • Atc-symbolic-computation-states
                • Atc-symbolic-execution-rules
                • Atc-gen-ext-declon-lists
                • Atc-function-and-loop-generation
                • Atc-statement-generation
                  • Stmt-gin
                  • Atc-gen-term-type-formula
                  • Atc-gen-stmt
                  • Stmt-gout
                  • Atc-gen-expr
                  • Atc-gen-block-item-var-asg
                  • Atc-gen-return-stmt
                  • Atc-gen-mbt-block-items
                  • Atc-gen-if/ifelse-stmt
                  • Atc-gen-cfun-call-stmt
                  • Atc-gen-block-item-struct-scalar-asg
                  • Atc-gen-block-item-struct-array-asg
                  • Atc-gen-block-item-list-append
                  • Atc-gen-block-item-integer-asg
                  • Atc-gen-block-item-declon
                  • Atc-gen-block-item-array-asg
                  • Atc-gen-loop-stmt
                  • Atc-gen-block-item-list-cons
                  • Atc-uterm-to-components
                  • Atc-gen-block-item-stmt
                  • Lstmt-gin
                  • Atc-gen-block-item-list-one
                  • Atc-gen-block-item-var-decl
                  • Atc-gen-block-item-asg
                  • Atc-gen-call-result-and-endstate
                  • Lstmt-gout
                  • Atc-ensure-formals-not-lost
                    • Atc-gen-block-item-list-none
                    • Atc-var-assignablep
                    • Atc-gen-uterm-result-and-type-formula
                    • Atc-remove-extobj-args
                    • Atc-affecting-term-for-let-p
                    • Atc-vars-assignablep
                    • Atc-make-lets-of-uterms
                    • Atc-symbolp-list
                    • Atc-make-mv-nth-terms
                    • Atc-make-mv-lets-of-uterms
                    • Atc-update-var-term-alist
                    • Irr-stmt-gout
                    • Irr-lstmt-gout
                  • Atc-gen-fileset
                  • Atc-gen-everything
                  • Atc-gen-obj-declon
                  • Atc-gen-fileset-event
                  • Atc-tag-tables
                  • Atc-expression-generation
                  • Atc-generation-contexts
                  • Atc-gen-wf-thm
                  • Term-checkers-atc
                  • Atc-variable-tables
                  • Term-checkers-common
                  • Atc-gen-init-fun-env-thm
                  • Atc-gen-appconds
                  • Read-write-variables
                  • Atc-gen-thm-assert-events
                  • Test*
                  • Atc-gen-prog-const
                  • Atc-gen-expr-bool
                  • Atc-theorem-generation
                  • Atc-tag-generation
                  • Atc-gen-expr-pure
                  • Atc-function-tables
                  • Atc-object-tables
                • Fty-pseudo-term-utilities
                • Atc-term-recognizers
                • Atc-input-processing
                • Atc-shallow-embedding
                • Atc-process-inputs-and-gen-everything
                • Atc-table
                • Atc-fn
                • Atc-pretty-printing-options
                • Atc-types
                • Atc-macro-definition
              • Atc-tutorial
            • Language
            • Representation
            • Transformation-tools
            • Insertion-sort
            • Pack
          • Bv
          • Imp-language
          • Event-macros
          • Java
          • 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
    • Atc-statement-generation

    Atc-ensure-formals-not-lost

    Ensure that no affected formals are lost.

    Signature
    (atc-ensure-formals-not-lost bind-affect 
                                 fn-affect fn-typed-formals fn wrld) 
     
      → 
    erp
    Arguments
    bind-affect — Guard (symbol-listp bind-affect).
    fn-affect — Guard (symbol-listp fn-affect).
    fn-typed-formals — Guard (atc-symbol-varinfo-alistp fn-typed-formals).
    fn — Guard (symbolp fn).
    wrld — Guard (plist-worldp wrld).

    If the body of a non-recursive function fn includes an mv-lets or a let that affects a formal of fn of pointer or array type, or a formal of integer type that represents an external object, that formal must be among the variables affected by fn. If the body of a recursive function fn includes an mv-lets or a let that affects a formal of fn of any type, that formal must be among the variables affected by fn. In other words, no modification of formals must be ``lost''. The case of formals of pointer or array types is clear, because it means that objects in the heap are affected. The case of formals of integer type that represent external objects is also clear, as that object is globally accessible. The case of formals of non-pointer non-array types applies to recursive functions because they represent loops, which may affect local variables in the function where they appear.

    This ACL2 function ensures that no formals are lost in the sense above. The parameter bind-affect consists of the variable affected by the mv-let or let. The parameter fn-affect consists of the variables purported to be affected by fn. We go through the elements of bind-affect and check each one against the formals of fn, taking into account the information about the formals and whether fn is recursive.

    Definitions and Theorems

    Function: atc-ensure-formals-not-lost

    (defun atc-ensure-formals-not-lost
           (bind-affect fn-affect fn-typed-formals fn wrld)
     (declare
         (xargs :guard (and (symbol-listp bind-affect)
                            (symbol-listp fn-affect)
                            (atc-symbol-varinfo-alistp fn-typed-formals)
                            (symbolp fn)
                            (plist-worldp wrld))))
     (let ((__function__ 'atc-ensure-formals-not-lost))
      (declare (ignorable __function__))
      (b*
       (((reterr))
        ((when (endp bind-affect)) (retok))
        (var (car bind-affect))
        (info (cdr (assoc-eq var fn-typed-formals)))
        ((when (and info
                    (or (irecursivep+ fn wrld)
                        (type-case (atc-var-info->type info)
                                   :pointer)
                        (type-case (atc-var-info->type info)
                                   :array)
                        (atc-var-info->externalp info))
                    (not (member-eq var fn-affect))))
         (reterr
          (msg
           "When generating C code for the function ~x0, ~
                   the formal parameter ~x1 is being affected ~
                   in an MV-LET or LET term, ~
                   but it is not being returned by ~x0."
           fn var))))
       (atc-ensure-formals-not-lost
            (cdr bind-affect)
            fn-affect fn-typed-formals fn wrld))))