shithub: mc

Download patch

ref: 0af648321d764657b71a996be5397ecdb9e7d600
parent: e68cc72862487557d50d5104e6769e8494e303e2
author: Ori Bernstein <[email protected]>
date: Wed Dec 25 11:18:03 EST 2013

remove 'isgeneric()' property from type.

    It's not useful.

--- a/parse/gram.y
+++ b/parse/gram.y
@@ -296,13 +296,9 @@
 
 tydef   : Ttype typeid Tasn type
             {$$ = $2;
-             $$.type = mktyname($2.line, mkname($2.line, $2.name), $2.params, $2.nparams, $4);
-	     if ($2.params)
-		$$.type->isgeneric = 1;}
+             $$.type = mktyname($2.line, mkname($2.line, $2.name), $2.params, $2.nparams, $4);}
         | Ttype typeid
-            {$$ = $2;
-	     if ($2.params)
-		$$.type->isgeneric = 1;}
+            {$$ = $2;}
         ;
 
 typeid  : Tident
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -200,7 +200,7 @@
 
     switch (t->type) {
         case Typaram:   return 1;
-        case Tyname:    return t->isgeneric;
+        case Tyname:    return isgeneric(t);
         case Tystruct:
             for (i = 0; i < t->nmemb; i++)
                 if (needfreshen(st, decltype(t->sdecls[i])))
@@ -317,21 +317,22 @@
 {
     Type *t;
     size_t i;
+    int is;
 
     t = tysearch(st, orig);
-    st->ingeneric += orig->isgeneric;
+    is = isgeneric(orig);
+    st->ingeneric += isgeneric(orig);
     tyresolve(st, t);
     /* If this is an instantiation of a generic type, we want the params to
      * match the instantiation */
-    if (orig->type == Tyunres && t->isgeneric) {
+    if (orig->type == Tyunres && isgeneric(t)) {
         t = tyfreshen(st, t);
         for (i = 0; i < t->narg; i++) {
             unify(st, NULL, t->arg[i], orig->arg[i]);
-            if (orig->arg[i]->type == Typaram || needfreshen(st, t->arg[i]))
-                t->isgeneric = 1;
         }
     }
-    st->ingeneric -= orig->isgeneric;
+    assert(is == isgeneric(orig));
+    st->ingeneric -= isgeneric(orig);
     return t;
 }
 
@@ -451,7 +452,7 @@
     Htab *bt;
     char *s;
 
-    if (t->type != Tyname && !t->isgeneric)
+    if (t->type != Tyname && !isgeneric(t))
         return;
     if (debugopt['u']) {
         s = tystr(t);
@@ -496,7 +497,7 @@
 
 static void tyunbind(Inferstate *st, Type *t)
 {
-    if (t->type != Tyname && !t->isgeneric)
+    if (t->type != Tyname && !isgeneric(t))
         return;
     htfree(st->tybindings[st->ntybindings - 1]);
     lpop(&st->tybindings, &st->ntybindings);
@@ -1218,7 +1219,7 @@
     Type *t;
 
     t = tf(st, decltype(n));
-    if (t->type == Tyname && t->isgeneric && !n->decl.isgeneric) {
+    if (t->type == Tyname && isgeneric(t) && !n->decl.isgeneric) {
         t = tyfreshen(st, t);
         unifyparams(st, n, t, decltype(n));
     }
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -115,7 +115,6 @@
     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 */
 
-    int  isgeneric;     /* Tyname: whether this is generic or not */
     int  issynth;       /* Tyname: whether this is synthesized or not */
     int  ishidden;      /* Tyname: whether this is hidden or not */
     Type **param;       /* Tyname: type parameters that match the type args */
@@ -376,6 +375,8 @@
 Cstr *mkcstr(int line, char *name, Node **memb, size_t nmemb, Node **funcs, size_t nfuncs);
 Type *mktylike(int line, Ty ty); /* constrains tyvar t like it was builtin ty */
 int   istysigned(Type *t);
+int   isgeneric(Type *t);
+int   hasparams(Type *t);
 
 /* type manipulation */
 Type *tybase(Type *t);
--- a/parse/specialize.c
+++ b/parse/specialize.c
@@ -13,25 +13,6 @@
 
 static Node *specializenode(Node *n, Htab *tsmap);
 
-/*
- * Checks if a type contains any type
- * parameers at all (ie, if it generic).
- */
-static int hasparams(Type *t)
-{
-    size_t i;
-
-    if (t->type == Typaram || t->isgeneric)
-        return 1;
-    for (i = 0; i < t->nsub; i++)
-        if (hasparams(t->sub[i]))
-            return 1;
-    for (i = 0; i < t->narg; i++)
-        if (hasparams(t->arg[i]))
-            return 1;
-    return 0;
-}
-
 void addcstrs(Type *t, Bitset *cstrs)
 {
     size_t b;
@@ -84,7 +65,6 @@
                 htput(tsmap, t, ret);
                 for (i = 0; i < t->nparam; i++)
                     lappend(&ret->arg, &ret->narg, tyspecialize(subst[i], tsmap));
-                ret->isgeneric = hasparams(ret);
             }
             break;
         case Tystruct:
--- a/parse/type.c
+++ b/parse/type.c
@@ -267,6 +267,40 @@
     }
 }
 
+int isgeneric(Type *t)
+{
+    size_t i;
+
+    if (t->type != Tyname && t->type != Tyunres)
+        return 0;
+    if (!t->narg)
+        return t->nparam > 0;
+    else
+        for (i = 0; i < t->narg; i++)
+            if (hasparams(t->arg[i]))
+                return 1;
+    return 0;
+}
+
+/*
+ * Checks if a type contains any type
+ * parameers at all (ie, if it generic).
+ */
+int hasparams(Type *t)
+{
+    size_t i;
+
+    if (t->type == Typaram || isgeneric(t))
+        return 1;
+    for (i = 0; i < t->nsub; i++)
+        if (hasparams(t->sub[i]))
+            return 1;
+    for (i = 0; i < t->narg; i++)
+        if (hasparams(t->arg[i]))
+            return 1;
+    return 0;
+}
+
 Type *tybase(Type *t)
 {
     assert(t != NULL);
@@ -274,6 +308,7 @@
         t = t->sub[0];
     return t;
 }
+
 
 static int namefmt(char *buf, size_t len, Node *n)
 {
--- a/parse/use.c
+++ b/parse/use.c
@@ -224,7 +224,6 @@
             break;
         case Tyname:
             pickle(ty->name, fd);
-            wrbool(fd, ty->isgeneric);
             wrbool(fd, ty->issynth);
 
             wrint(fd, ty->nparam);
@@ -321,7 +320,6 @@
             break;
         case Tyname:
             ty->name = unpickle(fd);
-            ty->isgeneric = rdbool(fd);
             ty->issynth = rdbool(fd);
 
             ty->nparam = rdint(fd);