• 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
          • 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-gen-cfun-correct-thm
                  • Atc-typed-formals
                  • Atc-gen-outer-bindings-and-hyps
                  • Atc-gen-fundef
                  • Atc-gen-exec-stmt-while-for-loop
                  • Atc-gen-context-preamble
                  • Atc-gen-pop-frame-thm
                  • Atc-gen-loop-correct-thm
                  • Atc-gen-init-scope-thms
                  • Atc-gen-fun-correct-thm
                  • Atc-gen-fn-result-thm
                  • Atc-gen-loop-body-correct-thm
                  • Atc-gen-loop
                  • Atc-gen-loop-test-correct-thm
                  • Atc-check-guard-conjunct
                  • Atc-find-affected
                    • Atc-gen-cfun-final-compustate
                    • Atc-gen-init-inscope-auto
                    • Atc-gen-init-inscope-static
                    • Atc-gen-push-init-thm
                    • Atc-gen-loop-measure-fn
                    • Atc-gen-fun-endstate
                    • Atc-gen-loop-termination-thm
                    • Atc-gen-formal-thm
                    • Atc-gen-loop-final-compustate
                    • Atc-gen-loop-measure-thm
                    • Atc-gen-object-disjoint-hyps
                    • Atc-loop-body-term-subst
                    • Atc-gen-omap-update-formals
                    • Atc-gen-loop-tthm-formula
                    • Atc-gen-init-inscope
                    • Atc-gen-fn-def*
                    • Atc-gen-param-declon-list
                    • Atc-formal-affectablep
                    • Atc-gen-cfun-fun-env-thm
                    • Atc-gen-add-var-formals
                    • Atc-gen-cfun-fun-env-thm-name
                    • Atc-gen-fn-guard
                    • Atc-filter-exec-fun-args
                    • Atc-gen-context-preamble-aux-aux
                    • Atc-typed-formals-to-extobjs
                    • Atc-formal-affectable-listp
                  • Atc-statement-generation
                  • 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-function-and-loop-generation

    Atc-find-affected

    Find the variables affected by a term.

    Signature
    (atc-find-affected fn term typed-formals prec-fns wrld) 
      → 
    (mv erp affected)
    Arguments
    fn — Guard (symbolp fn).
    term — Guard (pseudo-termp term).
    typed-formals — Guard (atc-symbol-varinfo-alistp typed-formals).
    prec-fns — Guard (atc-symbol-fninfo-alistp prec-fns).
    wrld — Guard (plist-worldp wrld).
    Returns
    affected — Type (symbol-listp affected), given (atc-symbol-varinfo-alistp typed-formals).

    This is used on the body of each non-recursive target function fn, in order to determine the variables affected by it, according to the nomenclature in the user documentation. We visit the leaves of the term according to the if and let structure, and ensure that they all have the same form, which must be one of the following forms:

    • A call of a (recursive or non-recursive) target function fn0 that precedes fn in the list of targets. In this case, term affects the same variables as fn0. We use atc-check-cfun-call and atc-check-loop-call to check if the term is a call of a target function and to retrieve that function's affected variables: we pass nil as the variable-term alist, because it does not change the returned affected variables, which is the only thing we care about here, ignoring all the other results.
    • A formal parameter var of fn that either has pointer or array type or refers to an external object. In this case, term affects the list of variables (var).
    • A term ret that is not a call of fn0 as above and is not a formal parameter of fn that either has pointer or array type or refers to an external object. In this case, term affects no variables.
    • A term (mv var1 ... varn) where each vari is a formal parameter of the function that either has pointer or array type or refers to an external object. In this case, term affects the list of variables (var1 ... varn).
    • A term (mv ret var1 ... varn) where each vari is a formal parameter of the function that either has pointer or array type or refers to an external object, and ret is not. In this case, term affects the list of variables (var1 ... varn).

    In checking that the terms at the leaves have the same form, we allow ret to vary, but the other parts must coincide.

    When we encounter ifs with mbt tests, we recursively process the `then' branch, skipping the `else' branch. This is because only the `then' branch represents C code.

    Definitions and Theorems

    Function: atc-find-affected

    (defun atc-find-affected (fn term typed-formals prec-fns wrld)
     (declare
          (xargs :guard (and (symbolp fn)
                             (pseudo-termp term)
                             (atc-symbol-varinfo-alistp typed-formals)
                             (atc-symbol-fninfo-alistp prec-fns)
                             (plist-worldp wrld))))
     (let ((__function__ 'atc-find-affected))
      (declare (ignorable __function__))
      (b*
       (((reterr) nil)
        ((mv okp test then else)
         (fty-check-if-call term))
        ((when okp)
         (b* (((mv mbtp &) (check-mbt-call test))
              ((when mbtp)
               (atc-find-affected fn then typed-formals prec-fns wrld))
              ((erp then-affected)
               (atc-find-affected fn then typed-formals prec-fns wrld))
              ((erp else-affected)
               (atc-find-affected fn else typed-formals prec-fns wrld)))
          (if (equal then-affected else-affected)
              (retok then-affected)
           (reterr
            (msg
             "When generating code for function ~x0, ~
                       an IF branch affects variables ~x1, ~
                       while the other branch affects variables ~x2: ~
                       this is disallowed."
             fn then-affected else-affected)))))
        ((mv okp & body &)
         (fty-check-lambda-call term))
        ((when okp)
         (atc-find-affected fn body typed-formals prec-fns wrld))
        ((erp okp & & & & affected & & &)
         (atc-check-cfun-call term nil prec-fns wrld))
        ((when okp) (retok affected))
        ((mv okp & & & affected & &)
         (atc-check-loop-call term nil prec-fns))
        ((when okp) (retok affected))
        ((when (pseudo-term-case term :var))
         (b* ((var (pseudo-term-var->name term)))
           (if (atc-formal-affectablep var typed-formals)
               (retok (list var))
             (retok nil))))
        ((mv okp terms)
         (fty-check-list-call term))
        ((when okp)
         (cond
          ((and (symbol-listp terms)
                (atc-formal-affectable-listp terms typed-formals))
           (retok terms))
          ((and (symbol-listp (cdr terms))
                (atc-formal-affectable-listp (cdr terms)
                                             typed-formals))
           (retok (cdr terms)))
          (t
           (reterr
            (msg
             "When generating code for function ~x0, ~
                            a term ~x1 was encountered that ~
                            returns multiple values but they, ~
                            or at least all of them except the first one, ~
                            are not all formal parameters of ~x0 ~
                            of pointer or array type."
             fn term))))))
       (retok nil))))

    Theorem: symbol-listp-of-atc-find-affected.affected

    (defthm symbol-listp-of-atc-find-affected.affected
     (implies
         (atc-symbol-varinfo-alistp typed-formals)
         (b* (((mv acl2::?erp ?affected)
               (atc-find-affected fn term typed-formals prec-fns wrld)))
           (symbol-listp affected)))
     :rule-classes :rewrite)