ref: 5b7e3296ba57c446904ecd173ad9f3823a119851
parent: 8e1b57e6cb50118d28a86115520b7331cc0fdf23
author: Ori Bernstein <ori@eigenstate.org>
date: Sat Feb 27 18:42:20 EST 2016
Fix up type generation a bit.
--- a/6/gen.c
+++ b/6/gen.c
@@ -127,17 +127,19 @@
ns = "";
p = buf;
end = buf + bufsz;
+ ty = tydedup(ty);
if (ty->type == Tyname) {
if (ty->name->name.ns) {
ns = ty->name->name.ns;
sep = "$";
}
- if (ty->vis == Visexport || ty->isimport)
- p += bprintf(p, end - p, "_tydesc$%s%s%s", ns, sep, ty->name->name.name);
+ if (ty->vis != Visintern || ty->isimport)
+ p += bprintf(p, end - p, "_tydesc$%s%s%s", ns, sep, ty->name->name.name, ty->tid);
else
p += bprintf(p, end - p, "_tydesc$%s%s%s$%d", ns, sep, ty->name->name.name, ty->tid);
for (i = 0; i < ty->narg; i++)
p += tyidfmt(p, end - p, ty->arg[i]);
+ bprintf(p, end - p, "/* %zd */", ty->tid);
} else {
if (file->file.globls->name) {
ns = file->file.globls->name;
--- a/6/gengas.c
+++ b/6/gengas.c
@@ -346,17 +346,37 @@
writeasm(fd, &is, fn);
}
-void gentype(FILE *fd, Type *ty)
+static void gentype(FILE *fd, Type *ty)
{
Blob *b;
- if (ty->type == Tyvar)
+ ty = tydedup(ty);
+ if (ty->type == Tyvar || ty->isemitted)
return;
+
+ ty->isemitted = 1;
b = tydescblob(ty);
writeblob(fd, b);
blobfree(b);
}
+static void gentypes(FILE *fd)
+{
+ Type *ty;
+ size_t i;
+
+ for (i = Ntypes; i < ntypes; i++) {
+ if (!types[i]->isreflect)
+ continue;
+ ty = tydedup(types[i]);
+ if (ty->isemitted || ty->isimport)
+ continue;
+ gentype(fd, ty);
+ }
+ fprintf(fd, "\n");
+}
+
+
void genblob(FILE *fd, Node *blob, Htab *globls, Htab *strtab)
{
char *lbl;
@@ -436,14 +456,12 @@
fprintf(fd, ".text\n");
for (i = 0; i < nfn; i++)
genfunc(fd, fn[i], globls, strtab);
+ gentypes(fd);
fprintf(fd, "\n");
- for (i = 0; i < ntypes; i++)
- if (types[i]->isreflect && (!types[i]->isimport || types[i]->ishidden))
- gentype(fd, types[i]);
+ genstrings(fd, strtab);
fprintf(fd, "\n");
- genstrings(fd, strtab);
fclose(fd);
}
--- a/6/genp9.c
+++ b/6/genp9.c
@@ -402,6 +402,23 @@
writeblob(fd, b, 0, lbl);
}
+static void gentypes(FILE *fd)
+{
+ Type *ty;
+ size_t i;
+
+ for (i = Ntypes; i < ntypes; i++) {
+ if (!types[i]->isreflect)
+ continue;
+ ty = tydedup(types[i]);
+ if (ty->isemitted || ty->isimport)
+ continue;
+ gentype(fd, ty);
+ }
+ fprintf(fd, "\n");
+}
+
+
static void genblob(FILE *fd, Node *blob, Htab *globls, Htab *strtab)
{
char *lbl;
@@ -471,11 +488,11 @@
genblob(fd, blob[i], globls, strtab);
for (i = 0; i < nfn; i++)
genfunc(fd, fn[i], globls, strtab);
- for (i = 0; i < ntypes; i++)
- if (types[i]->isreflect && (!types[i]->isimport || types[i]->ishidden))
- gentype(fd, types[i]);
+ gentypes(fd);
fprintf(fd, "\n");
+
genstrings(fd, strtab);
+ fprintf(fd, "\n");
fclose(fd);
}
--- a/6/typeinfo.c
+++ b/6/typeinfo.c
@@ -114,6 +114,7 @@
if (ty->type == Tyvar)
return NULL;
+ ty = tydedup(ty);
if (ty->type == Tyname)
tt |= Tdindirect;
sz = mkblobi(Btimin, 0);
@@ -220,7 +221,7 @@
sz->ival = blobsz(sub);
lappend(&b->seq.sub, &b->seq.nsub, sz);
lappend(&b->seq.sub, &b->seq.nsub, sub);
- if (ty->vis == Visexport)
+ if (ty->vis != Visintern)
b->isglobl = 1;
} else {
b = tydescsub(ty);
--- a/mbldwrap.sh
+++ b/mbldwrap.sh
@@ -16,8 +16,8 @@
fi
if [ -f mbld/mbld ]; then
- ./mbld/mbld $@ || mbld $@ || \
+ ./mbld/mbld -S $@ || mbld -S $@ || \
(echo "Unable to run mbld $@; have you build successfully"; false)
else
- ./mbld/mbld || mbld || $BOOT
+ ./mbld/mbld -S || mbld -S || $BOOT
fi
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -371,6 +371,7 @@
int litvaleq(Node *a, Node *b);
ulong tyhash(void *t);
int tyeq(void *a, void *b);
+int tystricteq(void *a, void *b);
ulong namehash(void *t);
int nameeq(void *a, void *b);
ulong nsnamehash(void *t);
--- a/parse/specialize.c
+++ b/parse/specialize.c
@@ -114,7 +114,6 @@
ret = mktyname(t->loc, t->name, tyspecialize(t->sub[0], tsmap, delayed, trbase));
if (orig->type == Tyunres)
substpop(tsmap);
- ret->issynth = 1;
ret->arg = arg;
ret->narg = narg;
ret->traits = bsdup(t->traits);
--- a/parse/type.c
+++ b/parse/type.c
@@ -672,14 +672,16 @@
return hash;
}
-int tyeq_rec(Type *a, Type *b, Bitset *visited)
+int tyeq_rec(Type *a, Type *b, Bitset *visited, int search)
{
size_t i;
if (!a || !b)
return a == b;
- a = tysearch(a);
- b = tysearch(b);
+ if (!search) {
+ a = tysearch(a);
+ b = tysearch(b);
+ }
if (a->type != b->type)
return 0;
if (a->narg != b->narg)
@@ -712,7 +714,7 @@
for (i = 0; i < a->nmemb; i++) {
if (!nameeq(a->udecls[i]->name, b->udecls[i]->name))
return 0;
- if (!tyeq_rec(a->udecls[i]->etype, b->udecls[i]->etype, visited))
+ if (!tyeq_rec(a->udecls[i]->etype, b->udecls[i]->etype, visited, search))
return 0;
}
break;
@@ -720,7 +722,7 @@
for (i = 0; i < a->nmemb; i++) {
if (strcmp(declname(a->sdecls[i]), declname(b->sdecls[i])) != 0)
return 0;
- if (!tyeq_rec(decltype(a->sdecls[i]), decltype(b->sdecls[i]), visited))
+ if (!tyeq_rec(decltype(a->sdecls[i]), decltype(b->sdecls[i]), visited, search))
return 0;
}
break;
@@ -728,10 +730,10 @@
if (!nameeq(a->name, b->name))
return 0;
for (i = 0; i < a->narg; i++)
- if (!tyeq_rec(a->arg[i], b->arg[i], visited))
+ if (!tyeq_rec(a->arg[i], b->arg[i], visited, search))
return 0;
for (i = 0; i < a->nsub; i++)
- if (!tyeq_rec(a->sub[i], b->sub[i], visited))
+ if (!tyeq_rec(a->sub[i], b->sub[i], visited, search))
return 0;
break;
case Tyarray:
@@ -741,11 +743,24 @@
default: break;
}
for (i = 0; i < a->nsub; i++)
- if (!tyeq_rec(a->sub[i], b->sub[i], visited))
+ if (!tyeq_rec(a->sub[i], b->sub[i], visited, search))
return 0;
return 1;
}
+int tystricteq(void *a, void *b)
+{
+ Bitset *bs;
+ int eq;
+
+ if (a == b)
+ return 1;
+ bs = mkbs();
+ eq = tyeq_rec(a, b, bs, 0);
+ bsfree(bs);
+ return eq;
+}
+
int tyeq(void *a, void *b)
{
Bitset *bs;
@@ -754,7 +769,7 @@
if (a == b)
return 1;
bs = mkbs();
- eq = tyeq_rec(a, b, bs);
+ eq = tyeq_rec(a, b, bs, 1);
bsfree(bs);
return eq;
}
@@ -903,7 +918,7 @@
Type *ty;
Trait *tr;
- tydeduptab = mkht(tyhash, tyeq);
+ tydeduptab = mkht(tyhash, tystricteq);
/* this must be done after all the types are created, otherwise we will
* clobber the memoized bunch of types with the type params. */
#define Tc(c, n) \
--- a/parse/use.c
+++ b/parse/use.c
@@ -23,7 +23,7 @@
static Node *unpickle(FILE *fd);
/* type fixup list */
-static Htab *tydedup; /* map from name -> type, contains all Tynames loaded ever */
+static Htab *tydeduptab; /* map from name -> type, contains all Tynames loaded ever */
static Htab *tidmap; /* map from tid -> type */
static Htab *trmap; /* map from trait id -> trait */
static Htab *initmap; /* map from init name -> int */
@@ -744,7 +744,7 @@
static void fixtypemappings(Stab *st)
{
size_t i;
- Type *t, *old;
+ Type *t, *u, *old;
/*
* merge duplicate definitions.
@@ -761,11 +761,13 @@
for (i = 0; i < ntypefixdest; i++) {
old = *typefixdest[i];
if (old->type == Tyname || old->type == Tygeneric) {
- t = htget(tydedup, old);
+ t = htget(tydeduptab, old);
if (!t) {
t = old;
- htput(tydedup, old, old);
+ htput(tydeduptab, old, old);
}
+ u = tydedup(old);
+ assert(tyeq(t, u));
*typefixdest[i] = t;
}
}
@@ -775,7 +777,7 @@
t = htget(tidmap, itop(typefixid[i]));
if ((t->type != Tyname && t->type != Tygeneric) || t->issynth)
continue;
- old = htget(tydedup, t);
+ old = htget(tydeduptab, t);
if (old && !tyeq(t, old) && !isspecialization(t, old))
lfatal(t->loc, "Duplicate definition of type %s on %s:%d", tystr(old),
file->file.files[old->loc.file], old->loc.line);
@@ -878,8 +880,8 @@
int c;
pushstab(file->file.globls);
- if (!tydedup)
- tydedup = mkht(tyhash, tyeq);
+ if (!tydeduptab)
+ tydeduptab = mkht(tyhash, tyeq);
if (fgetc(f) != 'U')
return 0;
v = rdint(f);