shithub: mc

Download patch

ref: aca3c17e5de2b8ef3e728d6c356acabd168c5e95
parent: a1774754e1da0397cc2cf567ca2ce6e79ae57bf7
author: Ori Bernstein <[email protected]>
date: Fri Jul 20 12:54:21 EDT 2012

Improve commenting

--- a/parse/infer.c
+++ b/parse/infer.c
@@ -100,7 +100,8 @@
     return t;
 }
 
-static int tyoccurs(Inferstate *st, Type *t, Type *sub)
+/* prevents types that directly contain themselves. */
+static int tyinfinite(Inferstate *st, Type *t, Type *sub)
 {
     size_t i;
 
@@ -116,12 +117,12 @@
     switch (sub->type) {
         case Tystruct:
             for (i = 0; i < sub->nmemb; i++)
-                if (tyoccurs(st, t, decltype(sub->sdecls[i])))
+                if (tyinfinite(st, t, decltype(sub->sdecls[i])))
                     return 1;
             break;
         case Tyunion:
             for (i = 0; i < t->nmemb; i++) {
-                if (sub->udecls[i]->etype && tyoccurs(st, t, sub->udecls[i]->etype))
+                if (sub->udecls[i]->etype && tyinfinite(st, t, sub->udecls[i]->etype))
                     return 1;
             }
             break;
@@ -131,7 +132,7 @@
             return 0;
         default:
             for (i = 0; i < sub->nsub; i++)
-                if (tyoccurs(st, t, sub->sub[i]))
+                if (tyinfinite(st, t, sub->sub[i]))
                     return 1;
             break;
     }
@@ -170,7 +171,7 @@
         bsunion(t->cstrs, base->cstrs);
     else
         t->cstrs = bsdup(base->cstrs);
-    if (tyoccurs(st, t, NULL))
+    if (tyinfinite(st, t, NULL))
         fatal(t->line, "Type %s includes itself", tystr(t));
 }
 
@@ -328,6 +329,8 @@
     return (a->type == Tyvar && a->nsub > 0) || a->type == Tyarray || a->type == Tyslice;
 }
 
+/* prevents types that contain themselves in the unification;
+ * eg @a U (@a -> foo) */
 static int occurs(Type *a, Type *b)
 {
     size_t i;
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -92,14 +92,17 @@
     Ty type;
     int tid;
     int line;
+
     int resolved;     /* Have we resolved the subtypes? Prevents infinite recursion. */
     int fixed;        /* Have we fixed the subtypes? Prevents infinite recursion. */
+
     Bitset *cstrs;    /* the type constraints matched on this type */
-    Node **cstrlist;  /* The names of the constraints on the type. Used to resolve/fill the bitset */
+    Node **cstrlist;  /* The names of the constraints on the type. Used to fill the bitset */
     size_t ncstrlist; /* The length of the constraint list above */
+
+    Type **sub;       /* sub-types; shared by all composite types */
     size_t nsub;      /* For compound types */
     size_t nmemb;     /* for aggregate types (struct, union) */
-    Type **sub;       /* sub-types; shared by all composite types */
     union {
         Node *aname;   /* Tyalias: alias name */
         Node *name;    /* Tyname: unresolved name */