summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--6/gen.c6
-rw-r--r--6/gengas.c30
-rw-r--r--6/genp9.c23
-rw-r--r--6/typeinfo.c3
-rwxr-xr-xmbldwrap.sh4
-rw-r--r--parse/parse.h1
-rw-r--r--parse/specialize.c1
-rw-r--r--parse/type.c35
-rw-r--r--parse/use.c16
9 files changed, 87 insertions, 32 deletions
diff --git a/6/gen.c b/6/gen.c
index 25df139..aac6c0b 100644
--- a/6/gen.c
+++ b/6/gen.c
@@ -127,17 +127,19 @@ char *tydescid(char *buf, size_t bufsz, Type *ty)
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;
diff --git a/6/gengas.c b/6/gengas.c
index 7581e29..5307661 100644
--- a/6/gengas.c
+++ b/6/gengas.c
@@ -346,17 +346,37 @@ static void genfunc(FILE *fd, Func *fn, Htab *globls, Htab *strtab)
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 @@ void gengas(Node *file, char *out)
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);
}
diff --git a/6/genp9.c b/6/genp9.c
index d4c9e98..9042856 100644
--- a/6/genp9.c
+++ b/6/genp9.c
@@ -402,6 +402,23 @@ static void gentype(FILE *fd, Type *ty)
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 @@ void genp9(Node *file, char *out)
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);
}
diff --git a/6/typeinfo.c b/6/typeinfo.c
index a16982c..be34b93 100644
--- a/6/typeinfo.c
+++ b/6/typeinfo.c
@@ -114,6 +114,7 @@ Blob *tydescsub(Type *ty)
if (ty->type == Tyvar)
return NULL;
+ ty = tydedup(ty);
if (ty->type == Tyname)
tt |= Tdindirect;
sz = mkblobi(Btimin, 0);
@@ -220,7 +221,7 @@ Blob *tydescblob(Type *ty)
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);
diff --git a/mbldwrap.sh b/mbldwrap.sh
index 9d94fd1..4c68388 100755
--- a/mbldwrap.sh
+++ b/mbldwrap.sh
@@ -16,8 +16,8 @@ else
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
diff --git a/parse/parse.h b/parse/parse.h
index 2f42dd9..39bfa4f 100644
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -371,6 +371,7 @@ int liteq(Node *a, Node *b);
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);
diff --git a/parse/specialize.c b/parse/specialize.c
index 4df9729..26136ed 100644
--- a/parse/specialize.c
+++ b/parse/specialize.c
@@ -114,7 +114,6 @@ Type *tyspecialize(Type *orig, Tysubst *tsmap, Htab *delayed, Htab *trbase)
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);
diff --git a/parse/type.c b/parse/type.c
index 4cd2716..804f841 100644
--- a/parse/type.c
+++ b/parse/type.c
@@ -672,14 +672,16 @@ ulong tyhash(void *ty)
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 @@ int tyeq_rec(Type *a, Type *b, Bitset *visited)
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 @@ int tyeq_rec(Type *a, Type *b, Bitset *visited)
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 @@ int tyeq_rec(Type *a, Type *b, Bitset *visited)
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 @@ int tyeq_rec(Type *a, Type *b, Bitset *visited)
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 @@ int tyeq(void *a, void *b)
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 @@ void tyinit(Stab *st)
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) \
diff --git a/parse/use.c b/parse/use.c
index f0c154c..479f0c6 100644
--- a/parse/use.c
+++ b/parse/use.c
@@ -23,7 +23,7 @@ static void pickle(FILE *fd, Node *n);
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 int isspecialization(Type *t1, Type *t2)
static void fixtypemappings(Stab *st)
{
size_t i;
- Type *t, *old;
+ Type *t, *u, *old;
/*
* merge duplicate definitions.
@@ -761,11 +761,13 @@ static void fixtypemappings(Stab *st)
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 @@ static void fixtypemappings(Stab *st)
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 loaduse(char *path, FILE *f, Stab *st, Vis vis)
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);