Check if a Leo file has no struct type recursion.
We build the dependency graph of the struct types in the file, by going through the declarations that form the file. Then we attempt to topologically sort the graph. If that succeeds, the graph has no circularities and therefore there is no struct type recursion. If that fails, there is a circularity.
Function:
(defun file-struct-recursion-okp (file) (declare (xargs :guard (filep file))) (let ((__function__ 'file-struct-recursion-okp)) (declare (ignorable __function__)) (b* ((graph (topdecl-list-struct-graph (programdecl->items (file->program file)))) ((mv okp &) (depgraph::toposort graph))) okp)))
Theorem:
(defthm booleanp-of-file-struct-recursion-okp (b* ((yes/no (file-struct-recursion-okp file))) (booleanp yes/no)) :rule-classes :rewrite)
Theorem:
(defthm file-struct-recursion-okp-of-file-fix-file (equal (file-struct-recursion-okp (file-fix file)) (file-struct-recursion-okp file)))
Theorem:
(defthm file-struct-recursion-okp-file-equiv-congruence-on-file (implies (file-equiv file file-equiv) (equal (file-struct-recursion-okp file) (file-struct-recursion-okp file-equiv))) :rule-classes :congruence)