• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • 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
        • Soft
        • C
        • Bv
        • Imp-language
        • Event-macros
        • Java
        • Bitcoin
        • Ethereum
        • Yul
        • Zcash
        • ACL2-programming-language
        • Prime-fields
        • Json
        • Syntheto
          • Process-syntheto-toplevel-fn
          • Translation
          • Language
            • Static-semantics
              • Check-expression-fns
              • Subtypep
              • Match-type
              • Check-product-update-expression
              • Get-builtin-function-in/out/pre-post
              • Check-sum-update-expression
              • Check-sum-field-expression
              • Check-strict-binary-expression
              • Check-lt/le/gt/ge-expression
              • Check-eq/ne-expression
              • Check-div/rem-expression
              • Check-add/sub/mul-expression
              • Align-let-vars-values
              • Check-iff-expression
              • Check-function-definition-top/nontop
              • Check-sum-construct-expression
              • Check-rem-expression
              • Check-mul-expression
              • Check-sub-expression
              • Check-div-expression
              • Check-add-expression
              • Check-ne-expression
              • Check-lt-expression
              • Check-le-expression
              • Check-gt-expression
              • Check-ge-expression
              • Check-eq-expression
              • Check-function-specifier
              • Type-result
              • Check-product-construct-expression
              • Supremum-type
              • Check-call-expression
                • Check-product-field-expression
                • Check-function-definer
                • Make-subproof-obligations
                • Get-function-in/out/pre/post
                • Check-sum-test-expression
                • Match-field
                • Decompose-expression
                • Match-to-target
                • Check-unary-expression
                • Max-supertype
                • Match-type-list
                • Check-minus-expression
                • Check-type-definition
                • Check-not-expression
                • Check-type-product
                • Match-field-list
                • Check-type-subset
                • Check-type-definition-in-recursion
                • Align-let-vars-values-aux
                • Non-trivial-proof-obligation
                • Check-type-recursion
                • Check-function-specification
                • Check-toplevel
                • Supremum-type-list
                • Check-component-expression
                • Check-branch-list
                • Check-function-recursion
                • Check-function-definition
                • Binding
                • Check-function-header
                • Check-function-definition-list
                • Check-type-definition-list-in-recursion
                • Check-theorem
                • Check-nonstrict-binary-expression
                • Context-add-variables
                • Decompose-expression-aux
                • Check-alternative
                • Check-multi-expression
                • Check-type-sum
                • Check-type
                • Check-alternative-list
                • Context-add-condition
                • Check-type-definer
                • Check-transform
                • Check-variable
                • Check-transform-args
                • Check-toplevel-list
                • Context-add-condition-list
                • Check-if/when/unless-expression
                • Initializers-to-variable-substitution
                • Context-add-binding
                • Check-function-header-list
                • Context-add-toplevel
                • Ensure-single-type
                • Max-supertypes
                • Check-bind-expression
                • Check-type-list
                • Check-literal
                • Literal-type
                • Check-expression-list
                • Variable-context
                • Check-cond-expression
                • Check-branch
                • Args-without-defaults
                • Check-expression
                • *builtin-function-names*
                • Function-called-in
              • Abstract-syntax
              • Outcome
              • Abstract-syntax-operations
              • Outcome-list
              • Outcomes
            • Process-syntheto-toplevel
            • Shallow-embedding
          • File-io-light
          • Cryptography
          • Number-theory
          • Lists-light
          • Axe
          • Builtins
          • Solidity
          • Helpers
          • Htclient
          • Typed-lists-light
          • Arithmetic-light
        • X86isa
        • Axe
        • Execloader
      • Math
      • Testing-utilities
    • Static-semantics

    Check-call-expression

    Check if a function call is statically well-formed.

    Signature
    (check-call-expression function types args args-result expr ctxt) 
      → 
    result
    Arguments
    function — Guard (identifierp function).
    types — Guard (type-listp types).
    args — Guard (expression-listp args).
    args-result — Guard (type-resultp args-result).
    expr — Guard (expressionp expr).
    ctxt — Guard (contextp ctxt).
    Returns
    result — Type (type-resultp result).

    We check that the argument types match the function's input types. If the function has a precondition, we also generate a proof obligation saying that the arguments satisfy it. The call has the output types of the function.

    Definitions and Theorems

    Function: check-call-expression

    (defun check-call-expression
           (function types args args-result expr ctxt)
     (declare (xargs :guard (and (identifierp function)
                                 (type-listp types)
                                 (expression-listp args)
                                 (type-resultp args-result)
                                 (expressionp expr)
                                 (contextp ctxt))))
     (declare
          (xargs :guard (type-result-case args-result
                                          :err t
                                          :ok (= (len args-result.types)
                                                 (len args)))))
     (let ((__function__ 'check-call-expression))
      (declare (ignorable __function__))
      (type-result-case
       args-result
       :err (type-result-err args-result.info)
       :ok
       (b*
        (((mv err? inputs outputs precond &)
          (get-function-in/out/pre/post function types ctxt))
         ((when err?) (type-result-err err?))
         (input-types (typed-variable-list->type-list inputs))
         (output-types (typed-variable-list->type-list outputs))
         ((mv okp obligs)
          (match-type-list args
                           args-result.types input-types ctxt))
         ((when (not okp))
          (type-result-err (list :type-mismatch-call
                                 (identifier-fix function)
                                 (expression-list-fix args)
                                 args-result.types input-types)))
         (oblig?
          (if precond
           (b*
            ((input-names (typed-variable-list->name-list inputs))
             (subst
              (omap::from-lists input-names (expression-list-fix args)))
             (formula (subst-expression subst precond)))
            (non-trivial-proof-obligation
                 (context->obligation-vars ctxt)
                 (context->obligation-hyps ctxt)
                 formula expr))
           nil)))
        (make-type-result-ok
             :types output-types
             :obligations (append args-result.obligations
                                  obligs oblig?))))))

    Theorem: type-resultp-of-check-call-expression

    (defthm type-resultp-of-check-call-expression
      (b*
        ((result
              (check-call-expression function
                                     types args args-result expr ctxt)))
        (type-resultp result))
      :rule-classes :rewrite)

    Theorem: check-call-expression-of-identifier-fix-function

    (defthm check-call-expression-of-identifier-fix-function
      (equal (check-call-expression (identifier-fix function)
                                    types args args-result expr ctxt)
             (check-call-expression function
                                    types args args-result expr ctxt)))

    Theorem: check-call-expression-identifier-equiv-congruence-on-function

    (defthm
          check-call-expression-identifier-equiv-congruence-on-function
     (implies
       (identifier-equiv function function-equiv)
       (equal (check-call-expression function
                                     types args args-result expr ctxt)
              (check-call-expression function-equiv
                                     types args args-result expr ctxt)))
     :rule-classes :congruence)

    Theorem: check-call-expression-of-type-list-fix-types

    (defthm check-call-expression-of-type-list-fix-types
      (equal (check-call-expression function (type-list-fix types)
                                    args args-result expr ctxt)
             (check-call-expression function
                                    types args args-result expr ctxt)))

    Theorem: check-call-expression-type-list-equiv-congruence-on-types

    (defthm check-call-expression-type-list-equiv-congruence-on-types
     (implies
         (type-list-equiv types types-equiv)
         (equal (check-call-expression function
                                       types args args-result expr ctxt)
                (check-call-expression function types-equiv
                                       args args-result expr ctxt)))
     :rule-classes :congruence)

    Theorem: check-call-expression-of-expression-list-fix-args

    (defthm check-call-expression-of-expression-list-fix-args
      (equal (check-call-expression function
                                    types (expression-list-fix args)
                                    args-result expr ctxt)
             (check-call-expression function
                                    types args args-result expr ctxt)))

    Theorem: check-call-expression-expression-list-equiv-congruence-on-args

    (defthm
         check-call-expression-expression-list-equiv-congruence-on-args
     (implies
       (expression-list-equiv args args-equiv)
       (equal (check-call-expression function
                                     types args args-result expr ctxt)
              (check-call-expression function types
                                     args-equiv args-result expr ctxt)))
     :rule-classes :congruence)

    Theorem: check-call-expression-of-type-result-fix-args-result

    (defthm check-call-expression-of-type-result-fix-args-result
     (equal
         (check-call-expression function
                                types args (type-result-fix args-result)
                                expr ctxt)
         (check-call-expression function
                                types args args-result expr ctxt)))

    Theorem: check-call-expression-type-result-equiv-congruence-on-args-result

    (defthm
      check-call-expression-type-result-equiv-congruence-on-args-result
     (implies
       (type-result-equiv args-result args-result-equiv)
       (equal (check-call-expression function
                                     types args args-result expr ctxt)
              (check-call-expression function types
                                     args args-result-equiv expr ctxt)))
     :rule-classes :congruence)

    Theorem: check-call-expression-of-expression-fix-expr

    (defthm check-call-expression-of-expression-fix-expr
      (equal
           (check-call-expression function types
                                  args args-result (expression-fix expr)
                                  ctxt)
           (check-call-expression function
                                  types args args-result expr ctxt)))

    Theorem: check-call-expression-expression-equiv-congruence-on-expr

    (defthm check-call-expression-expression-equiv-congruence-on-expr
     (implies
       (expression-equiv expr expr-equiv)
       (equal (check-call-expression function
                                     types args args-result expr ctxt)
              (check-call-expression function types
                                     args args-result expr-equiv ctxt)))
     :rule-classes :congruence)

    Theorem: check-call-expression-of-context-fix-ctxt

    (defthm check-call-expression-of-context-fix-ctxt
      (equal (check-call-expression function types args
                                    args-result expr (context-fix ctxt))
             (check-call-expression function
                                    types args args-result expr ctxt)))

    Theorem: check-call-expression-context-equiv-congruence-on-ctxt

    (defthm check-call-expression-context-equiv-congruence-on-ctxt
     (implies
       (context-equiv ctxt ctxt-equiv)
       (equal (check-call-expression function
                                     types args args-result expr ctxt)
              (check-call-expression function types
                                     args args-result expr ctxt-equiv)))
     :rule-classes :congruence)