commit d7d4b1c
shrub
·
2026-11-23 20:27:19 +0000 UTC
parent f8b22a6
stop generic function from losing borrowing information
1 files changed,
+17,
-3
M
type.c
M
type.c
+17,
-3
1@@ -26,6 +26,16 @@ occurs(struct type *m, struct type *t) {
2 return 0;
3 }
4
5+static int
6+borrowed(struct type *t) {
7+ while(t) {
8+ if(t->borrow)
9+ return 1;
10+ t = t->kind == YMETA ? t->link : nil;
11+ }
12+ return 0;
13+}
14+
15 int
16 unify(struct type *a, struct type *b) {
17 struct type *x;
18@@ -57,7 +67,7 @@ unify(struct type *a, struct type *b) {
19 if(!unify(x, y))
20 return 0;
21 /* a function that borrows a param isn't the same as one that takes it */
22- if(a->kind == YFN && deref(x)->borrow != deref(y)->borrow)
23+ if(a->kind == YFN && borrowed(x) != borrowed(y))
24 return 0;
25 }
26 return (!x && !y);
27@@ -217,8 +227,12 @@ subst(struct type *t, struct param *from, struct type *to) {
28 switch(t->kind) {
29 case YVAR:
30 for(p = from, b = to; p && b; p = p->next, b = b->next)
31- if(p->binding == t->binding)
32- return tydup(b);
33+ if(p->binding == t->binding) {
34+ a = tydup(b);
35+ if(t->borrow)
36+ a->borrow = 1;
37+ return a;
38+ }
39 return mktype(YVAR, t->binding);
40 case YMETA:
41 return tydup(t);