• 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
          • Syntax-for-tools
          • Atc
            • Atc-implementation
              • Atc-abstract-syntax
              • Atc-pretty-printer
              • Atc-event-and-code-generation
              • Fty-pseudo-term-utilities
              • Atc-term-recognizers
              • Atc-input-processing
              • Atc-shallow-embedding
                • Defstruct
                  • Defstruct-implementation
                    • Defstruct-info
                    • Defstruct-gen-recognizer
                    • Defstruct-gen-integer-member-ops
                    • Defstruct-gen-constructor
                    • Defstruct-gen-array-member-ops
                    • Defstruct-gen-recognizer-conjuncts
                    • Defstruct-member-info
                    • Defstruct-member-info-list->memtype-list
                    • Defstruct-process-members
                    • Defstruct-gen-fixer
                      • Defstruct-gen-member-ops
                      • Defstruct-process-inputs
                      • Defstruct-gen-fixing-term
                      • Defstruct-info-option
                      • Defstruct-gen-everything
                      • Defstruct-gen-all-member-ops
                      • Defstruct-gen-recognizer-all-conjuncts
                      • Defstruct-info->writer-element-list
                      • Defstruct-info->reader-element-list
                      • Defstruct-gen-fixtype
                      • Defstruct-info->writer-list
                      • Defstruct-info->reader-list
                      • Defstruct-fn
                      • Defstruct-table-record-event
                      • Defstruct-table-lookup
                      • Irr-defstruct-info
                      • Defstruct-info->writer-element-list-aux
                      • Defstruct-info->reader-element-list-aux
                      • Defstruct-info->writer-list-aux
                      • Defstruct-info->reader-list-aux
                      • Defstruct-member-info-list
                      • Defstruct-table-definition
                      • *defstruct-table*
                      • Defstruct-macro-implementtion
                  • Defobject
                  • Atc-let-designations
                  • Pointer-types
                  • Atc-conditional-expressions
                • 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
    • Defstruct-implementation

    Defstruct-gen-fixer

    Generate the fixer of the structures defined by the defstruct.

    Signature
    (defstruct-gen-fixer struct-tag-fix 
                         struct-tag-p tag memtypes flexiblep) 
     
      → 
    (mv event fixer-recognizer-thm)
    Arguments
    struct-tag-fix — Guard (symbolp struct-tag-fix).
    struct-tag-p — Guard (symbolp struct-tag-p).
    tag — Guard (symbolp tag).
    memtypes — Guard (member-type-listp memtypes).
    flexiblep — Guard (booleanp flexiblep).
    Returns
    event — Type (pseudo-event-formp event).
    fixer-recognizer-thm — Type (symbolp fixer-recognizer-thm).

    As the fixing value, we pick a structure with the right tag, the right member names, zero integer values of appropriate types for the integer members, and arrays of zeros of appropriate types and appropriate lengths for the integer array mmbers.

    We also return the name of the theorem that rewrites the fixer away when the recognizer holds.

    Definitions and Theorems

    Function: defstruct-gen-fixer-aux

    (defun defstruct-gen-fixer-aux (memtypes)
     (declare (xargs :guard (member-type-listp memtypes)))
     (let ((__function__ 'defstruct-gen-fixer-aux))
      (declare (ignorable __function__))
      (b* (((when (endp memtypes)) nil)
           ((member-type member) (car memtypes))
           (val (defstruct-gen-fixing-term member.type))
           (term (cons 'make-member-value
                       (cons ':name
                             (cons (cons 'quote (cons member.name 'nil))
                                   (cons ':value (cons val 'nil))))))
           (terms (defstruct-gen-fixer-aux (cdr memtypes))))
        (cons term terms))))

    Theorem: true-listp-of-defstruct-gen-fixer-aux

    (defthm true-listp-of-defstruct-gen-fixer-aux
      (b* ((terms (defstruct-gen-fixer-aux memtypes)))
        (true-listp terms))
      :rule-classes :rewrite)

    Function: defstruct-gen-fixer

    (defun defstruct-gen-fixer
           (struct-tag-fix struct-tag-p tag memtypes flexiblep)
     (declare (xargs :guard (and (symbolp struct-tag-fix)
                                 (symbolp struct-tag-p)
                                 (symbolp tag)
                                 (member-type-listp memtypes)
                                 (booleanp flexiblep))))
     (let ((__function__ 'defstruct-gen-fixer))
      (declare (ignorable __function__))
      (b*
       ((event-theory
         (cons
          '(:e cons)
          (cons
           '(:e ident)
           (cons
            '(:e repeat)
            (cons
             '(:e member-value)
             (cons
              '(:e value-array)
              (cons
               '(:e value-struct)
               (cons
                (cons ':e (cons struct-tag-p 'nil))
                (cons
                 '(:e type-uchar)
                 (cons
                  '(:e type-ushort)
                  (cons
                   '(:e type-uint)
                   (cons
                    '(:e type-ulong)
                    (cons
                     '(:e type-ullong)
                     (cons
                      '(:e type-schar)
                      (cons
                       '(:e type-sshort)
                       (cons
                        '(:e type-sint)
                        (cons
                         '(:e type-slong)
                         (cons
                          '(:e type-sllong)
                          (cons
                           '(:e uchar-from-integer)
                           (cons
                            '(:e ushort-from-integer)
                            (cons
                             '(:e uint-from-integer)
                             (cons
                              '(:e ulong-from-integer)
                              (cons
                               '(:e ullong-from-integer)
                               (cons
                                '(:e schar-from-integer)
                                (cons
                                 '(:e sshort-from-integer)
                                 (cons
                                  '(:e sint-from-integer)
                                  (cons
                                   '(:e slong-from-integer)
                                   (cons
                                    '(:e sllong-from-integer)
                                    (cons
                                     '(:t value-struct)
                                     (cons
                                      (cons ':t
                                            (cons struct-tag-p 'nil))
                                      'nil))))))))))))))))))))))))))))))
        (event
         (cons
          'encapsulate
          (cons
           'nil
           (cons
            (cons
                'local
                (cons (cons 'in-theory
                            (cons (cons 'quote (cons event-theory 'nil))
                                  'nil))
                      'nil))
            (cons
             (cons
              'std::deffixer
              (cons
               struct-tag-fix
               (cons
                ':pred
                (cons
                 struct-tag-p
                 (cons
                  ':param
                  (cons
                   'x
                   (cons
                    ':body-fix
                    (cons
                     (cons
                      'make-value-struct
                      (cons
                       ':tag
                       (cons
                        (cons 'ident
                              (cons (symbol-name tag) 'nil))
                        (cons
                         ':members
                         (cons (cons 'list
                                     (defstruct-gen-fixer-aux memtypes))
                               (cons ':flexiblep
                                     (cons flexiblep 'nil)))))))
                     'nil))))))))
             'nil)))))
        (thm (packn-pos (list struct-tag-fix '-when-
                              struct-tag-p)
                        struct-tag-fix)))
       (mv event thm))))

    Theorem: pseudo-event-formp-of-defstruct-gen-fixer.event

    (defthm pseudo-event-formp-of-defstruct-gen-fixer.event
      (b* (((mv acl2::?event ?fixer-recognizer-thm)
            (defstruct-gen-fixer struct-tag-fix
                                 struct-tag-p tag memtypes flexiblep)))
        (pseudo-event-formp event))
      :rule-classes :rewrite)

    Theorem: symbolp-of-defstruct-gen-fixer.fixer-recognizer-thm

    (defthm symbolp-of-defstruct-gen-fixer.fixer-recognizer-thm
      (b* (((mv acl2::?event ?fixer-recognizer-thm)
            (defstruct-gen-fixer struct-tag-fix
                                 struct-tag-p tag memtypes flexiblep)))
        (symbolp fixer-recognizer-thm))
      :rule-classes :rewrite)