shithub: mc

Download patch

ref: e7ebda38777e5251b3479c3fdced4cb108f252e4
parent: 8a53929e91acf351a11ec717c726833b2c703be1
author: Ori Bernstein <ori@eigenstate.org>
date: Sun Jan 14 08:25:47 EST 2018

Fix serializing trait specs in usefiles.

--- a/lib/iter/bld.sub
+++ b/lib/iter/bld.sub
@@ -9,3 +9,9 @@
 	lib ../sys:sys
 	lib ../std:std
 ;;
+
+testdeps =
+	../testr:testr
+	../sys:sys
+	../std:std
+;;
--- a/parse/export.c
+++ b/parse/export.c
@@ -71,11 +71,15 @@
 {
 	size_t i;
 
-	if (t->vis != Visintern)
+	if (!t || t->vis != Visintern)
 		return;
 	t->vis = Vishidden;
 	for (i = 0; i < t->nsub; i++)
 		tagtype(st, t->sub[i], ingeneric, hidelocal);
+	for (i = 0; i < t->nspec; i++) {
+		tagtype(st, t->spec[i]->param, ingeneric, hidelocal);
+		tagtype(st, t->spec[i]->aux, ingeneric, hidelocal);
+	}
 	switch (t->type) {
 	case Tystruct:
 		for (i = 0; i < t->nmemb; i++)
@@ -259,7 +263,6 @@
 	free(k);
 
 	/* tag the traits */
-	tr = NULL;
 	for (i = 0; i < ntraittab; i++) {
 		tr = traittab[i];
 		if (tr->vis != Visexport)
@@ -266,9 +269,12 @@
 			continue;
 		if (hidelocal && tr->ishidden)
 			tr->vis = Vishidden;
+		tagtype(st, tr->param, 0, hidelocal);
 		tr->param->vis = tr->vis;
-		for (j = 0; j < tr->naux; j++)
+		for (j = 0; j < tr->naux; j++) {
+			tagtype(st, tr->aux[j], 0, hidelocal);
 			tr->aux[j]->vis = tr->vis;
+		}
 		for (j = 0; j < tr->nproto; j++) {
 			tr->proto[j]->decl.vis = tr->vis;
 			tagnode(st, tr->proto[j], 0, hidelocal);
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -1,4 +1,4 @@
-#define Abiversion 14
+#define Abiversion 15
 
 typedef struct Srcloc Srcloc;
 typedef struct Tysubst Tysubst;
--- a/parse/use.c
+++ b/parse/use.c
@@ -218,7 +218,7 @@
 static void
 typickle(FILE *fd, Type *ty)
 {
-	size_t i;
+	size_t i, j;
 
 	if (!ty) {
 		die("trying to pickle null type\n");
@@ -226,6 +226,16 @@
 	}
 	wrbyte(fd, ty->type);
 	wrbyte(fd, ty->vis);
+	wrint(fd, ty->nspec);
+	for (i = 0; i < ty->nspec; i++) {
+		wrint(fd, ty->spec[i]->ntrait);
+		for (j = 0; j < ty->spec[i]->ntrait; j++)
+			pickle(fd, ty->spec[i]->trait[j]);
+		wrtype(fd, ty->spec[i]->param);
+		wrbool(fd, ty->spec[i]->aux != NULL);
+		if (ty->spec[i]->aux)
+			wrtype(fd, ty->spec[i]->aux);
+	}
 	wrint(fd, ty->nsub);
 	switch (ty->type) {
 	case Tyunres:
@@ -350,7 +360,7 @@
 static Type *
 tyunpickle(FILE *fd)
 {
-	size_t i, n;
+	size_t i, j, n;
 	Type *ty;
 	Ty t;
 
@@ -359,6 +369,19 @@
 	ty->isimport = 1;
 	if (rdbyte(fd) == Vishidden)
 		ty->ishidden = 1;
+	ty->nspec = rdint(fd);
+	ty->spec = malloc(ty->nspec * sizeof(Traitspec*));
+	for (i = 0; i < ty->nspec; i++) {
+		ty->spec[i] = zalloc(sizeof(Traitspec));
+		n = rdint(fd);
+		ty->spec[i]->ntrait = n;
+		ty->spec[i]->trait = malloc(n * sizeof(Node*));
+		for (j = 0; j < ty->spec[i]->ntrait; j++)
+			ty->spec[i]->trait[j] = unpickle(fd);
+		rdtype(fd, &ty->spec[i]->param);
+		if (rdbool(fd))
+			rdtype(fd, &ty->spec[i]->aux);
+	}
 	ty->nsub = rdint(fd);
 	if (ty->nsub > 0)
 		ty->sub = zalloc(ty->nsub * sizeof(Type *));