MCPcopy Create free account
hub / github.com/ElementsProject/elements / freezeTypes

Function freezeTypes

src/simplicity/typeInference.c:524–539  ·  view source on GitHub ↗

Create a type DAG that supports all the type annotations of the Simplicity expression, 'dag', * and the input and output types of whole expression. * * If the Simplicity DAG, 'dag', has a principal type (including constraints due to sharing of subexpressions), * and 'arrow[i]'s and 'source' and 'target' field's unification variables are bound to the principal source and target types * of sube

Source from the content-addressed store, hash-verified

522 * unification_arrow arrow[len] is a graph of bindings that satisfies the typing constraints of imposed by 'dag'.
523 */
524static simplicity_err freezeTypes(type* type_dag, dag_node* dag, unification_arrow* arrow, const size_t len) {
525 /* First entry of type_dag gets assigned to the ONE type. */
526 type_dag[0] = (type){ .kind = ONE };
527 size_t type_dag_used = 1;
528
529 for (size_t i = 0; i < len; ++i) {
530 if (!(freeze(&(dag[i].sourceType), type_dag, &type_dag_used, &(arrow[i].source)) &&
531 freeze(&(dag[i].targetType), type_dag, &type_dag_used, &(arrow[i].target)))) {
532 return SIMPLICITY_ERR_TYPE_INFERENCE_OCCURS_CHECK;
533 }
534 }
535
536 simplicity_computeTypeAnalyses(type_dag, type_dag_used);
537
538 return SIMPLICITY_NO_ERROR;
539}
540
541/* If the Simplicity DAG, 'dag', has a principal type (including constraints due to sharing of subexpressions),
542 * then allocate a well-formed type DAG containing all the types needed for all the subexpressions of 'dag',

Callers 1

Calls 2

freezeFunction · 0.85

Tested by

no test coverage detected