shithub: mc

Download patch

ref: 3e51d386096b13c255d6aec4406f85548e9e7d63
parent: c70655587600ffeb4c5821e2008bd2b97bb7698a
author: Ori Bernstein <[email protected]>
date: Fri Jan 31 10:56:23 EST 2014

Nomenclature change: cstr -> trait

    We're calling these things traits now, although they really are
    just constraints over types.

--- a/parse/cstr.def
+++ /dev/null
@@ -1,8 +1,0 @@
-/* Definitions of built in constraints */
-Tc(Tcnum, "tcnum")   /* arith ops */
-Tc(Tcint, "tcint")   /* behaves like an int, defaults to int as fallback */
-Tc(Tcfloat, "tcfloat")   /* behaves like a float, defaults to float as fallback */
-Tc(Tctest, "tctest")  /* if condition */
-Tc(Tcidx, "tcidx")   /* indexable */
-Tc(Tcslice, "tcslice") /* sliceable */
-Tc(Ncstr, "")
--- a/parse/gram.y
+++ b/parse/gram.y
@@ -23,7 +23,7 @@
 static Op binop(int toktype);
 static Node *mkpseudodecl(Type *t);
 static void installucons(Stab *st, Type *t);
-static void constrainwith(Type *t, char *str);
+static void addtrait(Type *t, char *str);
 
 %}
 
@@ -313,7 +313,7 @@
         ;
 
 traitdef: Ttrait Tident generictype Tasn traitbody Tendblk
-            {$$ = mktrait($1->line, mkname($2->line, $2->str), $5.nl, $5.nn, NULL, 0);}
+            {$$ = mktraitdef($1->line, mkname($2->line, $2->str), $5.nl, $5.nn, NULL, 0);}
         ;
 
 traitbody
@@ -367,12 +367,12 @@
             {$$ = mktyparam($1->line, $1->str);}
         | Ttyparam Twith name
             {$$ = mktyparam($1->line, $1->str);
-             constrainwith($$, $3->name.name);}
+             addtrait($$, $3->name.name);}
         | Ttyparam Twith Toparen typaramlist Tcparen
             {size_t i;
              $$ = mktyparam($1->line, $1->str);
              for (i = 0; i < $4.nn; i++)
-                constrainwith($$, $4.nl[i]->name.name);}
+                addtrait($$, $4.nl[i]->name.name);}
         ;
 
 typaramlist
@@ -808,13 +808,13 @@
 
 %%
 
-static void constrainwith(Type *t, char *str)
+static void addtrait(Type *t, char *str)
 {
     size_t i;
 
-    for (i = 0; i < ncstrs; i++) {
-        if (!strcmp(cstrtab[i]->name, str)) {
-            setcstr(t, cstrtab[i]);
+    for (i = 0; i < ntraits; i++) {
+        if (!strcmp(traittab[i]->name, str)) {
+            settrait(t, traittab[i]);
             return;
         }
     }
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -280,10 +280,10 @@
         t->sub[i] = tf(st, t->sub[i]);
     base = tybase(t);
     /* no-ops if base == t */
-    if (t->cstrs)
-        bsunion(t->cstrs, base->cstrs);
+    if (t->traits)
+        bsunion(t->traits, base->traits);
     else
-        t->cstrs = bsdup(base->cstrs);
+        t->traits = bsdup(base->traits);
     if (tyinfinite(st, t, NULL))
         fatal(t->line, "Type %s includes itself", tystr(t));
     st->ingeneric--;
@@ -516,44 +516,44 @@
  * type variables, the constraint is added to the required
  * constraint list. Otherwise, the type is checked to see
  * if it has the required constraint */
-static void constrain(Inferstate *st, Node *ctx, Type *a, Cstr *c)
+static void constrain(Inferstate *st, Node *ctx, Type *a, Trait *c)
 {
     if (a->type == Tyvar) {
-        if (!a->cstrs)
-            a->cstrs = mkbs();
-        setcstr(a, c);
-    } else if (!a->cstrs || !bshas(a->cstrs, c->cid)) {
+        if (!a->traits)
+            a->traits = mkbs();
+        settrait(a, c);
+    } else if (!a->traits || !bshas(a->traits, c->cid)) {
         fatal(ctx->line, "%s needs %s near %s", tystr(a), c->name, ctxstr(st, ctx));
     }
 }
 
 /* does b satisfy all the constraints of a? */
-static int cstrcheck(Type *a, Type *b)
+static int traitcheck(Type *a, Type *b)
 {
-    /* a has no cstrs to satisfy */
-    if (!a->cstrs)
+    /* a has no traits to satisfy */
+    if (!a->traits)
         return 1;
-    /* b satisfies no cstrs; only valid if a requires none */
-    if (!b->cstrs)
-        return bscount(a->cstrs) == 0;
-    /* if a->cstrs is a subset of b->cstrs, all of
+    /* b satisfies no traits; only valid if a requires none */
+    if (!b->traits)
+        return bscount(a->traits) == 0;
+    /* if a->traits is a subset of b->traits, all of
      * a's constraints are satisfied by b. */
-    return bsissubset(a->cstrs, b->cstrs);
+    return bsissubset(a->traits, b->traits);
 }
 
 /* Merges the constraints on types */
-static void mergecstrs(Inferstate *st, Node *ctx, Type *a, Type *b)
+static void mergetraits(Inferstate *st, Node *ctx, Type *a, Type *b)
 {
     if (b->type == Tyvar) {
-        /* make sure that if a = b, both have same cstrs */
-        if (a->cstrs && b->cstrs)
-            bsunion(b->cstrs, a->cstrs);
-        else if (a->cstrs)
-            b->cstrs = bsdup(a->cstrs);
-        else if (b->cstrs)
-            a->cstrs = bsdup(b->cstrs);
+        /* make sure that if a = b, both have same traits */
+        if (a->traits && b->traits)
+            bsunion(b->traits, a->traits);
+        else if (a->traits)
+            b->traits = bsdup(a->traits);
+        else if (b->traits)
+            a->traits = bsdup(b->traits);
     } else {
-        if (!cstrcheck(a, b)) {
+        if (!traitcheck(a, b)) {
             /* FIXME: say WHICH constraints we're missing */
             fatal(ctx->line, "%s missing constraints for %s near %s", tystr(b), tystr(a), ctxstr(st, ctx));
         }
@@ -691,7 +691,7 @@
     } else if (a->type != Tyvar) {
         typeerror(st, a, b, ctx, NULL);
     }
-    mergecstrs(st, ctx, a, b);
+    mergetraits(st, ctx, a, b);
     membunify(st, ctx, a, b);
 
     /* if we have delayed types for a tyvar, transfer it over. */
@@ -1081,7 +1081,7 @@
         case Oneg:      /* -@a -> @a */
             infersub(st, n, ret, sawret, &isconst);
             t = type(st, args[0]);
-            constrain(st, n, type(st, args[0]), cstrtab[Tcnum]);
+            constrain(st, n, type(st, args[0]), traittab[Tcnum]);
             isconst = args[0]->expr.isconst;
             for (i = 1; i < nargs; i++) {
                 isconst = isconst && args[i]->expr.isconst;
@@ -1113,8 +1113,8 @@
         case Obsreq:    /* @a >>= @a -> @a */
             infersub(st, n, ret, sawret, &isconst);
             t = type(st, args[0]);
-            constrain(st, n, type(st, args[0]), cstrtab[Tcnum]);
-            constrain(st, n, type(st, args[0]), cstrtab[Tcint]);
+            constrain(st, n, type(st, args[0]), traittab[Tcnum]);
+            constrain(st, n, type(st, args[0]), traittab[Tcint]);
             isconst = args[0]->expr.isconst;
             for (i = 1; i < nargs; i++) {
                 isconst = isconst && args[i]->expr.isconst;
@@ -1164,7 +1164,7 @@
             infersub(st, n, ret, sawret, &isconst);
             t = mktyidxhack(n->line, mktyvar(n->line));
             unify(st, n, type(st, args[0]), t);
-            constrain(st, n, type(st, args[1]), cstrtab[Tcint]);
+            constrain(st, n, type(st, args[1]), traittab[Tcint]);
             settype(st, n, t->sub[0]);
             break;
         case Oslice:    /* @a[@b::tcint,@b::tcint] -> @a[,] */
@@ -1171,8 +1171,8 @@
             infersub(st, n, ret, sawret, &isconst);
             t = mktyidxhack(n->line, mktyvar(n->line));
             unify(st, n, type(st, args[0]), t);
-            constrain(st, n, type(st, args[1]), cstrtab[Tcint]);
-            constrain(st, n, type(st, args[2]), cstrtab[Tcint]);
+            constrain(st, n, type(st, args[1]), traittab[Tcint]);
+            constrain(st, n, type(st, args[2]), traittab[Tcint]);
             settype(st, n, mktyslice(n->line, t->sub[0]));
             break;
 
@@ -1369,7 +1369,7 @@
             infernode(st, n->ifstmt.cond, NULL, sawret);
             infernode(st, n->ifstmt.iftrue, ret, sawret);
             infernode(st, n->ifstmt.iffalse, ret, sawret);
-            constrain(st, n, type(st, n->ifstmt.cond), cstrtab[Tctest]);
+            constrain(st, n, type(st, n->ifstmt.cond), traittab[Tctest]);
             break;
         case Nloopstmt:
             infernode(st, n->loopstmt.init, ret, sawret);
@@ -1376,7 +1376,7 @@
             infernode(st, n->loopstmt.cond, NULL, sawret);
             infernode(st, n->loopstmt.step, ret, sawret);
             infernode(st, n->loopstmt.body, ret, sawret);
-            constrain(st, n, type(st, n->loopstmt.cond), cstrtab[Tctest]);
+            constrain(st, n, type(st, n->loopstmt.cond), traittab[Tctest]);
             break;
         case Niterstmt:
             bound = NULL;
@@ -1389,7 +1389,7 @@
             infernode(st, n->iterstmt.body, ret, sawret);
 
             t = mktyidxhack(n->line, mktyvar(n->line));
-            constrain(st, n, type(st, n->iterstmt.seq), cstrtab[Tcidx]);
+            constrain(st, n, type(st, n->iterstmt.seq), traittab[Tcidx]);
             unify(st, n, type(st, n->iterstmt.seq), t);
             unify(st, n, type(st, n->iterstmt.elt), t->sub[0]);
             break;
@@ -1458,9 +1458,9 @@
             fatal(ctx->line, "Type %s not compatible with %s near %s\n", tystr(t), tystr(delayed), ctxstr(st, ctx));
     }
     if (t->type == Tyvar) {
-        if (hascstr(t, cstrtab[Tcint]) && cstrcheck(t, tyint))
+        if (hastrait(t, traittab[Tcint]) && traitcheck(t, tyint))
             return tyint;
-        if (hascstr(t, cstrtab[Tcfloat]) && cstrcheck(t, tyflt))
+        if (hastrait(t, traittab[Tcfloat]) && traitcheck(t, tyflt))
             return tyflt;
     } else if (!t->fixed) {
         t->fixed = 1;
@@ -1513,9 +1513,9 @@
     /* all array-like types have a fake "len" member that we emulate */
     if (t->type == Tyslice || t->type == Tyarray) {
         if (!strcmp(namestr(memb), "len")) {
-            constrain(st, n, type(st, n), cstrtab[Tcnum]);
-            constrain(st, n, type(st, n), cstrtab[Tcint]);
-            constrain(st, n, type(st, n), cstrtab[Tctest]);
+            constrain(st, n, type(st, n), traittab[Tcnum]);
+            constrain(st, n, type(st, n), traittab[Tcint]);
+            constrain(st, n, type(st, n), traittab[Tctest]);
             found = 1;
         }
         /* otherwise, we search aggregate types for the member, and unify
--- a/parse/node.c
+++ b/parse/node.c
@@ -183,7 +183,7 @@
     return n;
 }
 
-Node *mktrait(int line, Node *name, Node **funcs, size_t nfuncs, Node **membs, size_t nmembs)
+Node *mktraitdef(int line, Node *name, Node **funcs, size_t nfuncs, Node **membs, size_t nmembs)
 {
     Node *n;
 
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -15,7 +15,7 @@
 typedef struct Stab Stab;
 
 typedef struct Type Type;
-typedef struct Cstr Cstr;
+typedef struct Trait Trait;
 
 typedef enum {
 #define O(op, pure) op,
@@ -45,7 +45,7 @@
 
 typedef enum {
 #define Tc(c, n) c,
-#include "cstr.def"
+#include "trait.def"
 #undef Tc
 } Tc;
 
@@ -111,9 +111,9 @@
     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 fill the bitset */
-    size_t ncstrlist;   /* The length of the constraint list above */
+    Bitset *traits;      /* the type constraints matched on this type */
+    Node **traitlist;    /* The names of the constraints on the type. Used to fill the bitset */
+    size_t ntraitlist;   /* The length of the constraint list above */
 
     int  issynth;       /* Tyname: whether this is synthesized or not */
     int  ishidden;      /* Tyname: whether this is hidden or not */
@@ -145,7 +145,7 @@
     Type *etype;        /* type for the element */
 };
 
-struct Cstr {
+struct Trait {
     int cid;    /* unique id */
     char *name;
     Node **memb;        /* type must have these members */
@@ -296,8 +296,8 @@
 extern Type **tytab;    /* type -> type map used by inference. size maintained by type creation code */
 extern Type **types;
 extern size_t ntypes;
-extern Cstr **cstrtab;  /* int -> cstr map */
-extern size_t ncstrs;
+extern Trait **traittab;  /* int -> trait map */
+extern size_t ntraits;
 extern Node **decls;    /* decl id -> decl map */
 extern size_t ndecls;
 extern size_t maxnid;      /* the maximum node id generated so far */
@@ -362,7 +362,7 @@
 
 void putns(Stab *st, Stab *scope);
 void puttype(Stab *st, Node *n, Type *ty);
-void putcstr(Stab *st, Node *n, Cstr *cstr);
+void puttrait(Stab *st, Node *n, Trait *trait);
 void updatetype(Stab *st, Node *n, Type *t);
 void putdcl(Stab *st, Node *dcl);
 void forcedcl(Stab *st, Node *dcl);
@@ -373,7 +373,7 @@
 Node *getdcl(Stab *st, Node *n);
 Type *gettype_l(Stab *st, Node *n);
 Type *gettype(Stab *st, Node *n);
-Cstr *getcstr(Stab *st, Node *n);
+Trait *gettrait(Stab *st, Node *n);
 Ucon *getucon(Stab *st, Node *n);
 
 Stab *curstab(void);
@@ -397,7 +397,7 @@
 Type *mktyfunc(int line, Node **args, size_t nargs, Type *ret);
 Type *mktystruct(int line, Node **decls, size_t ndecls);
 Type *mktyunion(int line, Ucon **decls, size_t ndecls);
-Cstr *mkcstr(int line, char *name, Node **memb, size_t nmemb, Node **funcs, size_t nfuncs);
+Trait *mktrait(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   istyfloat(Type *t);
@@ -406,14 +406,15 @@
 
 /* type manipulation */
 Type *tybase(Type *t);
-int hascstr(Type *t, Cstr *c);
-int cstreq(Type *t, Cstr **cstrs, size_t len);
-int setcstr(Type *t, Cstr *c);
 char *tyfmt(char *buf, size_t len, Type *t);
-int cstrfmt(char *buf, size_t len, Type *t);
-char *cstrstr(Type *t);
 char *tystr(Type *t);
 
+int hastrait(Type *t, Trait *c);
+int settrait(Type *t, Trait *c);
+int traiteq(Type *t, Trait **traits, size_t len);
+int traitfmt(char *buf, size_t len, Type *t);
+char *traitstr(Type *t);
+
 /* node creation */
 Node *mknode(int line, Ntype nt);
 Node *mkfile(char *name);
@@ -428,7 +429,7 @@
 Node *mkmatchstmt(int line, Node *val, Node **matches, size_t nmatches);
 Node *mkmatch(int line, Node *pat, Node *body);
 Node *mkblock(int line, Stab *scope);
-Node *mktrait(int line, Node *name, Node **funcs, size_t nfuncs, Node **membs, size_t nmembs);
+Node *mktraitdef(int line, Node *name, Node **funcs, size_t nfuncs, Node **membs, size_t nmembs);
 Node *mkintlit(int line, uvlong val);
 Node *mkidxinit(int line, Node *idx, Node *init);
 
--- a/parse/specialize.c
+++ b/parse/specialize.c
@@ -13,13 +13,13 @@
 
 static Node *specializenode(Node *n, Htab *tsmap);
 
-void addcstrs(Type *t, Bitset *cstrs)
+void addtraits(Type *t, Bitset *traits)
 {
     size_t b;
 
-    if (cstrs)
-        for (b = 0; bsiter(cstrs, &b); b++)
-            setcstr(t, cstrtab[b]);
+    if (traits)
+        for (b = 0; bsiter(traits, &b); b++)
+            settrait(t, traittab[b]);
 }
 
 /*
@@ -42,7 +42,7 @@
     switch (t->type) {
         case Typaram:
             ret = mktyvar(t->line);
-            addcstrs(ret, t->cstrs);
+            addtraits(ret, t->traits);
             htput(tsmap, t, ret);
             break;
         case Tyname:
@@ -57,7 +57,7 @@
                     if (subst[i]->type != Typaram || hthas(tsmap, subst[i]))
                         continue;
                     tmp = mktyvar(subst[i]->line);
-                    addcstrs(tmp, subst[i]->cstrs);
+                    addtraits(tmp, subst[i]->traits);
                     htput(tsmap, subst[i], tmp);
                 }
                 ret = mktyname(t->line, t->name, t->param, t->nparam, tyspecialize(t->sub[0], tsmap));
--- a/parse/stab.c
+++ b/parse/stab.c
@@ -14,7 +14,7 @@
 
 /* Allows us to look up types/cstrs by name nodes */
 typedef struct Tydefn Tydefn;
-typedef struct Cstrdefn Cstrdefn;
+typedef struct Traitdefn Traitdefn;
 struct Tydefn {
     int line;
     Node *name;
@@ -21,10 +21,10 @@
     Type *type;
 };
 
-struct Cstrdefn {
+struct Traitdefn {
     int line;
     Node *name;
-    Cstr *cstr;
+    Trait *cstr;
 };
 
 #define Maxstabdepth 128
@@ -140,9 +140,9 @@
     return NULL;
 }
 
-Cstr *getcstr(Stab *st, Node *n)
+Trait *getcstr(Stab *st, Node *n)
 {
-    Cstrdefn *c;
+    Traitdefn *c;
 
     do {
         if ((c = htget(st->ty, n)))
@@ -220,9 +220,9 @@
     htput(st->uc, uc->name, uc);
 }
 
-void putcstr(Stab *st, Node *n, Cstr *c)
+void putcstr(Stab *st, Node *n, Trait *c)
 {
-    Cstrdefn *cd;
+    Traitdefn *cd;
 
     if (gettype(st, n))
         fatal(n->line, "Type %s already defined", namestr(n));
--- /dev/null
+++ b/parse/trait.def
@@ -1,0 +1,8 @@
+/* Definitions of built in constraints */
+Tc(Tcnum, "tcnum")   /* arith ops */
+Tc(Tcint, "tcint")   /* behaves like an int, defaults to int as fallback */
+Tc(Tcfloat, "tcfloat")   /* behaves like a float, defaults to float as fallback */
+Tc(Tctest, "tctest")  /* if condition */
+Tc(Tcidx, "tcidx")   /* indexable */
+Tc(Tcslice, "tcslice") /* sliceable */
+Tc(Ncstr, "")
--- a/parse/type.c
+++ b/parse/type.c
@@ -20,11 +20,11 @@
 Type **tytab = NULL;
 Type **types = NULL;
 size_t ntypes;
-Cstr **cstrtab;
-size_t ncstrs;
+Trait **traittab;
+size_t ntraits;
 
 /* Built in type constraints */
-static Cstr *tycstrs[Ntypes + 1][4];
+static Trait *traits[Ntypes + 1][4];
 
 Type *mktype(int line, Ty ty)
 {
@@ -42,8 +42,8 @@
     if (ty <= Tyvalist) /* the last builtin atomic type */
         t->vis = Visbuiltin;
 
-    for(i = 0; tycstrs[ty][i]; i++)
-        setcstr(t, tycstrs[ty][i]);
+    for(i = 0; traits[ty][i]; i++)
+        settrait(t, traits[ty][i]);
 
     return t;
 }
@@ -60,9 +60,9 @@
     r->resolved = 0; /* re-resolving doesn't hurt */
     r->fixed = 0; /* re-resolving doesn't hurt */
 
-    r->cstrs = bsdup(t->cstrs);
-    r->cstrlist = memdup(t->cstrlist, t->ncstrlist * sizeof(Node*));
-    r->ncstrlist = t->ncstrlist;
+    r->traits = bsdup(t->traits);
+    r->traitlist = memdup(t->traitlist, t->ntraitlist * sizeof(Node*));
+    r->ntraitlist = t->ntraitlist;
 
     r->arg = memdup(t->arg, t->narg * sizeof(Type*));
     r->narg = t->narg;
@@ -94,26 +94,26 @@
     int i;
 
     t = mktyvar(line);
-    for (i = 0; tycstrs[like][i]; i++)
-        setcstr(t, tycstrs[like][i]);
+    for (i = 0; traits[like][i]; i++)
+        settrait(t, traits[like][i]);
     return t;
 }
 
 /* steals memb, funcs */
-Cstr *mkcstr(int line, char *name, Node **memb, size_t nmemb, Node **funcs, size_t nfuncs)
+Trait *mktrait(int line, char *name, Node **memb, size_t nmemb, Node **funcs, size_t nfuncs)
 {
-    Cstr *c;
+    Trait *c;
 
-    c = zalloc(sizeof(Cstr));
+    c = zalloc(sizeof(Trait));
     c->name = strdup(name);
     c->memb = memb;
     c->nmemb = nmemb;
     c->funcs = funcs;
     c->nfuncs = nfuncs;
-    c->cid = ncstrs++;
+    c->cid = ntraits++;
 
-    cstrtab = xrealloc(cstrtab, ncstrs*sizeof(Cstr*));
-    cstrtab[c->cid] = c;
+    traittab = xrealloc(traittab, ntraits*sizeof(Trait*));
+    traittab[c->cid] = c;
     return c;
 }
 
@@ -153,7 +153,7 @@
     t = mktype(line, Tyname);
     t->name = name;
     t->nsub = 1;
-    t->cstrs = bsdup(base->cstrs);
+    t->traits = bsdup(base->traits);
     t->sub = xalloc(sizeof(Type*));
     t->sub[0] = base;
     t->param = param;
@@ -333,20 +333,20 @@
     return len - (end - p);
 }
 
-int setcstr(Type *t, Cstr *c)
+int settrait(Type *t, Trait *c)
 {
-    if (!t->cstrs)
-        t->cstrs = mkbs();
-    bsput(t->cstrs, c->cid);
+    if (!t->traits)
+        t->traits = mkbs();
+    bsput(t->traits, c->cid);
     return 1;
 }
 
-int hascstr(Type *t, Cstr *c)
+int hastrait(Type *t, Trait *c)
 {
-    return t->cstrs && bshas(t->cstrs, c->cid);
+    return t->traits && bshas(t->traits, c->cid);
 }
 
-int cstrfmt(char *buf, size_t len, Type *t)
+int traitfmt(char *buf, size_t len, Type *t)
 {
     size_t i;
     char *p;
@@ -353,7 +353,7 @@
     char *end;
     char *sep;
 
-    if (!t->cstrs || !bscount(t->cstrs))
+    if (!t->traits || !bscount(t->traits))
         return 0;
 
     p = buf;
@@ -361,9 +361,9 @@
 
     p += snprintf(p, end - p, " :: ");
     sep = "";
-    for (i = 0; i < ncstrs; i++) {
-        if (bshas(t->cstrs, i)) {
-            p += snprintf(p, end - p, "%s%s", sep, cstrtab[i]->name);
+    for (i = 0; i < ntraits; i++) {
+        if (bshas(t->traits, i)) {
+            p += snprintf(p, end - p, "%s%s", sep, traittab[i]->name);
             sep = ",";
         }
     }
@@ -536,7 +536,7 @@
 
     /* we only show constraints on non-builtin typaram */
     if (t->type == Tyvar || t->type == Typaram)
-        p += cstrfmt(p, end - p, t);
+        p += traitfmt(p, end - p, t);
 
     return p - buf;
 }
@@ -547,10 +547,10 @@
     return buf;
 }
 
-char *cstrstr(Type *t)
+char *traitstr(Type *t)
 {
     char buf[1024];
-    cstrfmt(buf, 1024, t);
+    traitfmt(buf, 1024, t);
     return strdup(buf);
 }
 
@@ -631,55 +631,55 @@
     Type *ty;
 
 #define Tc(c, n) \
-    mkcstr(-1, n, NULL, 0, NULL, 0);
-#include "cstr.def"
+    mktrait(-1, n, NULL, 0, NULL, 0);
+#include "trait.def"
 #undef Tc
 
     /* bool :: tctest */
-    tycstrs[Tybool][0] = cstrtab[Tctest];
+    traits[Tybool][0] = traittab[Tctest];
 
-    tycstrs[Tychar][0] = cstrtab[Tcnum];
-    tycstrs[Tychar][1] = cstrtab[Tcint];
-    tycstrs[Tychar][2] = cstrtab[Tctest];
+    traits[Tychar][0] = traittab[Tcnum];
+    traits[Tychar][1] = traittab[Tcint];
+    traits[Tychar][2] = traittab[Tctest];
 
-    tycstrs[Tybyte][0] = cstrtab[Tcnum];
-    tycstrs[Tybyte][1] = cstrtab[Tcint];
-    tycstrs[Tybyte][2] = cstrtab[Tctest];
+    traits[Tybyte][0] = traittab[Tcnum];
+    traits[Tybyte][1] = traittab[Tcint];
+    traits[Tybyte][2] = traittab[Tctest];
 
     /* <integer types> :: tcnum, tcint, tctest */
     for (i = Tyint8; i < Tyfloat32; i++) {
-        tycstrs[i][0] = cstrtab[Tcnum];
-        tycstrs[i][1] = cstrtab[Tcint];
-        tycstrs[i][2] = cstrtab[Tctest];
+        traits[i][0] = traittab[Tcnum];
+        traits[i][1] = traittab[Tcint];
+        traits[i][2] = traittab[Tctest];
     }
 
     /* <floats> :: tcnum */
-    tycstrs[Tyfloat32][0] = cstrtab[Tcnum];
-    tycstrs[Tyfloat32][1] = cstrtab[Tcfloat];
-    tycstrs[Tyfloat64][0] = cstrtab[Tcnum];
-    tycstrs[Tyfloat64][1] = cstrtab[Tcfloat];
+    traits[Tyfloat32][0] = traittab[Tcnum];
+    traits[Tyfloat32][1] = traittab[Tcfloat];
+    traits[Tyfloat64][0] = traittab[Tcnum];
+    traits[Tyfloat64][1] = traittab[Tcfloat];
 
     /* @a* :: tctest[0] = tcslice */
-    tycstrs[Typtr][0] = cstrtab[Tctest];
-    tycstrs[Typtr][1] = cstrtab[Tcslice];
+    traits[Typtr][0] = traittab[Tctest];
+    traits[Typtr][1] = traittab[Tcslice];
 
     /* @a[,] :: tctest[0] = tcslice[0] = tcidx */
-    tycstrs[Tyslice][0] = cstrtab[Tctest];
-    tycstrs[Tyslice][1] = cstrtab[Tcslice];
-    tycstrs[Tyslice][2] = cstrtab[Tcidx];
+    traits[Tyslice][0] = traittab[Tctest];
+    traits[Tyslice][1] = traittab[Tcslice];
+    traits[Tyslice][2] = traittab[Tcidx];
 
     /* array :: tcidx, tcslice */
-    tycstrs[Tyarray][0] = cstrtab[Tcidx];
-    tycstrs[Tyarray][1] = cstrtab[Tcslice];
+    traits[Tyarray][0] = traittab[Tcidx];
+    traits[Tyarray][1] = traittab[Tcslice];
 
     /* ptr :: tcslice, tctest */
-    tycstrs[Typtr][0] = cstrtab[Tcidx];
-    tycstrs[Typtr][1] = cstrtab[Tctest];
+    traits[Typtr][0] = traittab[Tcidx];
+    traits[Typtr][1] = traittab[Tctest];
 
     /* slice :: tcidx, tcslice, tctest */
-    tycstrs[Tyslice][0] = cstrtab[Tcidx];
-    tycstrs[Tyslice][1] = cstrtab[Tcslice];
-    tycstrs[Tyslice][1] = cstrtab[Tctest];
+    traits[Tyslice][0] = traittab[Tcidx];
+    traits[Tyslice][1] = traittab[Tcslice];
+    traits[Tyslice][1] = traittab[Tctest];
 
 /* Definining and registering the types has to go after we define the
  * constraints, otherwise they will have no constraints set on them. */
--- a/parse/use.c
+++ b/parse/use.c
@@ -187,14 +187,14 @@
     wrbyte(fd, ty->type);
     wrbyte(fd, ty->vis);
     /* tid is generated; don't write */
-    /* FIXME: since we only support hardcoded cstrs, we just write
-     * out the set of them. we should write out the cstr list as
+    /* FIXME: since we only support hardcoded traits, we just write
+     * out the set of them. we should write out the trait list as
      * well */
-    if (!ty->cstrs) {
+    if (!ty->traits) {
         wrint(fd, 0);
     } else {
-        wrint(fd, bscount(ty->cstrs));
-        for (i = 0; bsiter(ty->cstrs, &i); i++)
+        wrint(fd, bscount(ty->traits));
+        for (i = 0; bsiter(ty->traits, &i); i++)
             wrint(fd, i);
     }
     wrint(fd, ty->nsub);
@@ -286,10 +286,10 @@
     /* tid is generated; don't write */
     n = rdint(fd);
     if (n > 0) {
-        ty->cstrs = mkbs();
+        ty->traits = mkbs();
         for (i = 0; i < n; i++) {
             v = rdint(fd);
-            setcstr(ty, cstrtab[v]);
+            settrait(ty, traittab[v]);
         }
     }
     ty->nsub = rdint(fd);