ref: 69823fb059b309c0d78b819ea331489c206b83b3
parent: 518175c179216ecf8a6bf9129f330cfc8997cf15
author: Ori Bernstein <ori@eigenstate.org>
date: Fri Apr 21 19:35:46 EDT 2017
Dedup conflicting use statements.
--- a/parse/use.c
+++ b/parse/use.c
@@ -24,6 +24,7 @@
/* type fixup list */
static Htab *tydeduptab; /* map from name -> type, contains all Tynames loaded ever */
+static Htab *trdeduptab; /* 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 */
@@ -796,7 +797,7 @@
static void fixtraitmappings(Stab *st)
{
size_t i;
- Trait *t;
+ Trait *t, *tr;
/*
* merge duplicate definitions.
@@ -808,10 +809,16 @@
t = htget(trmap, itop(traitfixid[i]));
if (!t)
die("Unable to find trait for id %zd\n", traitfixid[i]);
+
+ tr = htget(trdeduptab, t->name);
+ if (!tr) {
+ htput(trdeduptab, t->name, t);
+ tr = t;
+ }
if (traitfixdest[i])
- *traitfixdest[i] = t;
+ *traitfixdest[i] = tr;
if (traitfixtype[i])
- settrait(traitfixtype[i], t);
+ settrait(traitfixtype[i], tr);
}
lfree(&traitfixdest, &ntraitfixdest);
@@ -888,6 +895,8 @@
pushstab(file->file.globls);
if (!tydeduptab)
tydeduptab = mkht(tyhash, tyeq);
+ if (!trdeduptab)
+ trdeduptab = mkht(namehash, nameeq);
if (fgetc(f) != 'U')
return 0;
v = rdint(f);
@@ -962,8 +971,8 @@
break;
case 'R':
tr = traitunpickle(f);
- tr->vis = vis;
if (!tr->ishidden) {
+ tr->vis = vis;
puttrait(s, tr->name, tr);
for (i = 0; i < tr->nfuncs; i++) {
putdcl(s, tr->funcs[i]);