Match a source field to some target field.
(match-field init source targets ctxt) → (mv yes/no obligs rest-targets)
This is used when checking the static semantics of
initializers in product/sum constructions and updates:
each initializer in such expressions (the
Function:
(defun match-field (init source targets ctxt) (declare (xargs :guard (and (initializerp init) (typep source) (field-listp targets) (contextp ctxt)))) (let ((__function__ 'match-field)) (declare (ignorable __function__)) (b* (((when (endp targets)) (mv nil nil nil)) (target (field-fix (car targets))) ((when (not (equal (field->name target) (initializer->field init)))) (b* (((mv okp obligs rest-targets) (match-field init source (cdr targets) ctxt)) ((when (not okp)) (mv nil nil nil))) (mv t obligs (cons target rest-targets)))) ((mv okp obligs) (match-type (initializer->value init) source (field->type target) ctxt)) ((when (not okp)) (mv nil nil nil))) (mv t obligs (field-list-fix (cdr targets))))))
Theorem:
(defthm booleanp-of-match-field.yes/no (b* (((mv ?yes/no ?obligs ?rest-targets) (match-field init source targets ctxt))) (booleanp yes/no)) :rule-classes :rewrite)
Theorem:
(defthm proof-obligation-listp-of-match-field.obligs (b* (((mv ?yes/no ?obligs ?rest-targets) (match-field init source targets ctxt))) (proof-obligation-listp obligs)) :rule-classes :rewrite)
Theorem:
(defthm field-listp-of-match-field.rest-targets (b* (((mv ?yes/no ?obligs ?rest-targets) (match-field init source targets ctxt))) (field-listp rest-targets)) :rule-classes :rewrite)
Theorem:
(defthm match-field-of-initializer-fix-init (equal (match-field (initializer-fix init) source targets ctxt) (match-field init source targets ctxt)))
Theorem:
(defthm match-field-initializer-equiv-congruence-on-init (implies (initializer-equiv init init-equiv) (equal (match-field init source targets ctxt) (match-field init-equiv source targets ctxt))) :rule-classes :congruence)
Theorem:
(defthm match-field-of-type-fix-source (equal (match-field init (type-fix source) targets ctxt) (match-field init source targets ctxt)))
Theorem:
(defthm match-field-type-equiv-congruence-on-source (implies (type-equiv source source-equiv) (equal (match-field init source targets ctxt) (match-field init source-equiv targets ctxt))) :rule-classes :congruence)
Theorem:
(defthm match-field-of-field-list-fix-targets (equal (match-field init source (field-list-fix targets) ctxt) (match-field init source targets ctxt)))
Theorem:
(defthm match-field-field-list-equiv-congruence-on-targets (implies (field-list-equiv targets targets-equiv) (equal (match-field init source targets ctxt) (match-field init source targets-equiv ctxt))) :rule-classes :congruence)
Theorem:
(defthm match-field-of-context-fix-ctxt (equal (match-field init source targets (context-fix ctxt)) (match-field init source targets ctxt)))
Theorem:
(defthm match-field-context-equiv-congruence-on-ctxt (implies (context-equiv ctxt ctxt-equiv) (equal (match-field init source targets ctxt) (match-field init source targets ctxt-equiv))) :rule-classes :congruence)