Skip to content

Commit 630ea3a

Browse files
committed
very small improvement but improvement nonetheless
1 parent d9bb1fb commit 630ea3a

9 files changed

Lines changed: 3431 additions & 3421 deletions

BOOTSTRAP/cli.c

Lines changed: 3392 additions & 3388 deletions
Large diffs are not rendered by default.

PLUGINS/FRONTEND/LSTS/lsts-parse.lsts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ let lsts-parse-type-conjugate(tokens: List<Token>): Tuple<Type,List<Token>> = (
321321
tokens = tnext-rest.second;
322322
};
323323
lsts-parse-expect(c")", tokens); tokens = tail(tokens);
324-
if args.length==0 then t0(c"Nil")
324+
if args.length==0 then type-nil
325325
else if args.length==1 then head(args)
326326
else ts( c"Tuple", args );
327327
} else if lsts-parse-head(tokens)==c"?" {
@@ -1025,7 +1025,7 @@ let lsts-parse-function-signature(fname: CString, tokens: List<Token>, loc: Sour
10251025
let out = LstsFnSignature ( mk-nil(), ta, ta );
10261026

10271027
lsts-parse-expect(c"(", tokens); tokens = tail(tokens);
1028-
out.args-type = t0(c"Nil");
1028+
out.args-type = type-nil;
10291029
while non-zero(tokens) and lsts-parse-head(tokens)!=c")" {
10301030
lsts-parse-expect(c"Identifier", lsts-is-ident-head(lsts-parse-head(tokens)), tokens);
10311031
let arg-name = head(tokens); tokens = tail(tokens);
@@ -1059,7 +1059,7 @@ let lsts-parse-function-signature(fname: CString, tokens: List<Token>, loc: Sour
10591059
if fname!=c"phi" then out.return-type = phi-as-state(out.return-type);
10601060
tokens = rtype-rest.second;
10611061
} else if non-zero(out.args-type) {
1062-
out.return-type = t0(c"Nil");
1062+
out.return-type = type-nil;
10631063
};
10641064

10651065
Tuple ( out, tokens )

SRC/tctx-unify.lsts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ let unify-inner(fpt: Type, pt: Type, blame: AST): Maybe<TypeContext> = (
122122
second:rp1
123123
} => (
124124
if can-unify(lp1, rp1)
125-
then { ctx = unify-inner(lp1,rp1,blame) && unify-inner(lpr, t0(c"Nil"), blame); }
125+
then { ctx = unify-inner(lp1,rp1,blame) && unify-inner(lpr, type-nil, blame); }
126126
else { ctx = unify-inner(lpr,rp1,blame); }
127127
);
128128
Tuple{

SRC/type-can-unify.lsts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ let can-unify(fpt: Type, pt: Type): Bool = (
124124
]},
125125
second:rp1
126126
} => (
127-
if can-unify(lp1,rp1) then can-unify(lpr,t0(c"Nil")) else can-unify(lpr,rp1)
127+
if can-unify(lp1,rp1) then can-unify(lpr,type-nil) else can-unify(lpr,rp1)
128128
);
129129
Tuple{
130130
first:TGround{tag:c"...", parameters:[lp1..]},

SRC/type-constructor.lsts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,14 @@ let t2(tag: CString, p1: Type, p2: Type): Type = TGround(tag, mk-vector(type(Typ
2020
# new allocations = 0
2121
let tv(name: CString): Type = TVar(name);
2222

23-
# new allocations = 0
24-
let type-any-arrow = t2(c"Arrow", t0(c"Any"), t0(c"Any"));
23+
# new allocations = 0 (constant)
24+
let type-nil = t0(c"Nil");
25+
26+
# new allocations = 0 (constant)
27+
let type-any = t0(c"Any");
28+
29+
# new allocations = 0 (constant)
30+
let type-any-arrow = t2(c"Arrow", type-any, type-any);
2531

2632
# new allocations = 0 if either argument is ?
2733
# | 1

SRC/typecheck-infer-expr.lsts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ let std-infer-expr(tctx: Maybe<TypeContext>, term: AST, is-scoped: Bool, used: I
1818
if not(is(rhs,new-rhs)) then { rhs = new-rhs; term = mk-app(mk-abs(def,mk-nil(),misc-tt),rhs); };
1919
(tctx, let tt) = std-bind-term(tctx, lname, rhs, def, term, hint);
2020
tctx = tctx.ascript(def, tt);
21-
tctx = tctx.ascript(term, t0(c"Nil"));
21+
tctx = tctx.ascript(term, type-nil);
2222
);
2323
App{o-t=left:Var{key:c"typeof"}, r=right} => (
2424
(tctx, let new-r) = std-infer-expr(tctx, r, is-scoped, Used, ta);
@@ -63,7 +63,7 @@ let std-infer-expr(tctx: Maybe<TypeContext>, term: AST, is-scoped: Bool, used: I
6363
App{asc=left:Lit{key:c":"}, right:App{inner=left:ASTNil{},right:AType{tt=tt}}} => (
6464
tt = tt.rewrite-type-alias;
6565
add-concrete-type-instance(tt, term);
66-
tctx = tctx.ascript(inner, t0(c"Nil"));
66+
tctx = tctx.ascript(inner, type-nil);
6767
tctx = tctx.ascript(term, tt);
6868
);
6969
App{asc=left:Lit{key:c":"}, right:App{t=left,right:AType{tt=tt}}} => (
@@ -88,7 +88,7 @@ let std-infer-expr(tctx: Maybe<TypeContext>, term: AST, is-scoped: Bool, used: I
8888
let is-nullary = false;
8989
if typeof-term(t).is-arrow and not(tt.is-arrow) and non-zero(var-name-if-var-or-lit(t)) {
9090
# This case exists for nullary constructors like TAny : Type
91-
let ftype = tctx.find-callable( var-name-if-var-or-lit(t), t0(c"Nil"), term, tt ).direct-type;
91+
let ftype = tctx.find-callable( var-name-if-var-or-lit(t), type-nil, term, tt ).direct-type;
9292
tctx = tctx.ascript(term, ftype);
9393
is-nullary = true;
9494
} else if typeof-term(t) == type-any-arrow {
@@ -175,7 +175,7 @@ let std-infer-expr(tctx: Maybe<TypeContext>, term: AST, is-scoped: Bool, used: I
175175
};
176176
let lub = if typeof-term(f).is-t(c"Never",0) then typeof-term(t)
177177
else if typeof-term(t).is-t(c"Never",0) then typeof-term(f)
178-
else if typeof-term(f).is-t(c"Nil",0) or typeof-term(t).is-t(c"Nil",0) then t0(c"Nil")
178+
else if typeof-term(f).is-t(c"Nil",0) or typeof-term(t).is-t(c"Nil",0) then type-nil
179179
else { (tctx, let lub) = tctx.least-upper-bound(typeof-term(t), typeof-term(f), term); lub };
180180
tctx = tctx.ascript(term, lub);
181181
let term-phi-id = typeof-term(term).slot(c"Phi::Id",1).l1.simple-id;
@@ -189,9 +189,9 @@ let std-infer-expr(tctx: Maybe<TypeContext>, term: AST, is-scoped: Bool, used: I
189189
if non-zero(term-phi-id) and term-phi-id != f-phi-id then tctx = tctx.phi-move(typeof-term(f), f);
190190
}
191191
);
192-
ASTEOF{} => tctx = tctx.ascript(term, t0(c"Nil"));
193-
ASTNil{} => tctx = tctx.ascript(term, t0(c"Nil"));
194-
Meta{} => tctx = tctx.ascript(term, t0(c"Nil"));
192+
ASTEOF{} => tctx = tctx.ascript(term, type-nil);
193+
ASTNil{} => tctx = tctx.ascript(term, type-nil);
194+
Meta{} => tctx = tctx.ascript(term, type-nil);
195195
Typedef{} => ();
196196
AType{tt:TGround{tag:c"Type",parameters:[p1..]}} => tctx = tctx.ascript(term, t1(c"Type",p1.sanitize-phi));
197197
AType{tt=tt} => tctx = tctx.ascript(term, tt.sanitize-phi);
@@ -274,7 +274,7 @@ let std-infer-expr(tctx: Maybe<TypeContext>, term: AST, is-scoped: Bool, used: I
274274
} else if not(non-zero(typeof-term(term))) {
275275
if hint.is-t(c"HashtableEq",2) and hint.is-datatype and key3==c"HashtableEqEOF"
276276
then {
277-
(tctx, let lit-tt) = tctx.apply-callable(key3, t0(c"Nil"), term, hint);
277+
(tctx, let lit-tt) = tctx.apply-callable(key3, type-nil, term, hint);
278278
tctx = tctx.ascript(term, lit-tt);
279279
} else {
280280
tctx = tctx.ascript(term, type-any-arrow);
@@ -340,7 +340,7 @@ let std-infer-expr(tctx: Maybe<TypeContext>, term: AST, is-scoped: Bool, used: I
340340
let pre-retain-tctx = tctx;
341341
(tctx, let new-r) = std-infer-call-arg(tctx, r, var-name-if-var-or-lit(l), rr-args-hint);
342342
let ftype = tctx.find-callable( var-name-if-var-or-lit(l), typeof-term(new-r), term, direct-hint ).direct-type;
343-
if typeof-term(l) == t2(c"Arrow",t0(c"Any"),t0(c"Any")) {
343+
if typeof-term(l) == type-any-arrow {
344344
tctx = tctx.ascript(l, ftype);
345345
};
346346
if ftype.domain.is-any-arg-t(c"MustNotRetain",0) {
@@ -398,16 +398,16 @@ let std-infer-expr(tctx: Maybe<TypeContext>, term: AST, is-scoped: Bool, used: I
398398
let tmp-var = mk-var(tmp-id); ascript-force(tmp-var, typeof-term(term));
399399
tctx = tctx.bind(tmp-id, ta, typeof-term(term), tmp-def);
400400
mark-var-to-def-todo(tctx, tmp-id, ta, tmp-var);
401-
let tmp-nil = mk-nil(); ascript-force(tmp-nil, t0(c"Nil"));
402-
let declare = mk-abs(tmp-def, tmp-nil, ta); ascript-force(declare, t0(c"Nil"));
401+
let tmp-nil = mk-nil(); ascript-force(tmp-nil, type-nil);
402+
let declare = mk-abs(tmp-def, tmp-nil, ta); ascript-force(declare, type-nil);
403403
if function-type.is-t(c"MustRetainOnCall",0) and not(hint.is-t(c"MustNotRetain",0)) and not(tctx.get-or(mk-tctx()).is-blob) {
404404
(tctx, term) = maybe-retain(tctx, term);
405405
};
406-
let bind = mk-app(declare, term); ascript-force(bind, t0(c"Nil"));
406+
let bind = mk-app(declare, term); ascript-force(bind, type-nil);
407407

408408
let new-term = bind;
409409
if non-zero(prefix) {
410-
new-term = mk-cons(prefix, new-term); ascript-force(new-term, t0(c"Nil"));
410+
new-term = mk-cons(prefix, new-term); ascript-force(new-term, type-nil);
411411
};
412412
new-term = mk-cons(new-term, postfix); ascript-force(new-term, typeof-term(postfix));
413413
new-term = mk-cons(new-term, tmp-var); ascript-force(new-term, typeof-term(term));

SRC/typecheck-release-locals.lsts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ let release-locals(tctx-before: TypeContext?, tctx-after: TypeContext?, term: AS
2424
let rhs = term;
2525
let def = mk-var(return-id);
2626
if not(return-type.is-t(c"Nil",0)) and not(return-type.is-t(c"Never",0)) {
27-
term = mk-app( mk-abs(def, mk-nil(), ta), term ); tctx-after = tctx-after.ascript(term, t0(c"Nil"));
27+
term = mk-app( mk-abs(def, mk-nil(), ta), term ); tctx-after = tctx-after.ascript(term, type-nil);
2828
(tctx-after, let binding-type) = std-bind-term(tctx-after, return-id, rhs, def, term, hint);
2929
tctx-after = tctx-after.ascript(def, binding-type);
3030
};
@@ -35,7 +35,7 @@ let release-locals(tctx-before: TypeContext?, tctx-after: TypeContext?, term: AS
3535
mk-app(mk-var(c"destroy"),mk-var(nd.key-or-zero))
3636
);
3737
(tctx-after, do-release) = std-infer-expr(tctx-after, do-release, false, Used, ta);
38-
term = mk-cons(term, do-release); tctx-after = tctx-after.ascript(term, t0(c"Nil"));
38+
term = mk-cons(term, do-release); tctx-after = tctx-after.ascript(term, type-nil);
3939
};
4040
let return-term = if not(return-type.is-t(c"Nil",0)) and not(return-type.is-t(c"Never",0))
4141
then mk-var(return-id)

SRC/typecheck-std-maybe-release-after-call.lsts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ let std-release-after-call(tctx: TypeContext?, function-type: Type, param-types:
4747
let tmp-var2 = mk-var(tmp-id1); ascript-force(tmp-var2, args-type);
4848
tctx = tctx.bind(tmp-id1, ta, args-type, tmp-def);
4949
mark-var-to-def-todo(tctx, tmp-id1, ta, tmp-var2);
50-
let tmp-nil = mk-nil(); ascript-force(tmp-nil, t0(c"Nil"));
51-
let declare = mk-abs(tmp-def, tmp-nil, ta); ascript-force(declare, t0(c"Nil"));
52-
let bind = mk-app(declare, args); ascript-force(bind, t0(c"Nil"));
50+
let tmp-nil = mk-nil(); ascript-force(tmp-nil, type-nil);
51+
let declare = mk-abs(tmp-def, tmp-nil, ta); ascript-force(declare, type-nil);
52+
let bind = mk-app(declare, args); ascript-force(bind, type-nil);
5353

5454
if non-zero(prefix)
55-
then (prefix = mk-cons( prefix, bind ); ascript-force(prefix, t0(c"Nil"));)
55+
then (prefix = mk-cons( prefix, bind ); ascript-force(prefix, type-nil);)
5656
else prefix = bind;
5757

5858
(tmp-var2, args)
@@ -64,12 +64,12 @@ let std-release-after-call(tctx: TypeContext?, function-type: Type, param-types:
6464
tctx = tctx.bind(tmp-id2, ta, args-type, tmp-def);
6565
mark-var-to-def-todo(tctx, tmp-id2, ta, tmp-var2);
6666
mark-var-to-def-todo(tctx, tmp-id2, ta, tmp-direct);
67-
let tmp-nil = mk-nil(); ascript-force(tmp-nil, t0(c"Nil"));
68-
let declare = mk-abs(tmp-def, tmp-nil, ta); ascript-force(declare, t0(c"Nil"));
69-
let bind = mk-app(declare, args); ascript-force(bind, t0(c"Nil"));
67+
let tmp-nil = mk-nil(); ascript-force(tmp-nil, type-nil);
68+
let declare = mk-abs(tmp-def, tmp-nil, ta); ascript-force(declare, type-nil);
69+
let bind = mk-app(declare, args); ascript-force(bind, type-nil);
7070

7171
if non-zero(prefix)
72-
then (prefix = mk-cons( prefix, bind ); ascript-force(prefix, t0(c"Nil"));)
72+
then (prefix = mk-cons( prefix, bind ); ascript-force(prefix, type-nil);)
7373
else prefix = bind;
7474

7575
(tmp-var2, tmp-direct)
@@ -81,7 +81,7 @@ let std-release-after-call(tctx: TypeContext?, function-type: Type, param-types:
8181
let do-release = mk-app(release-var, tmp-release); ascript-force(do-release, release-return);
8282

8383
if non-zero(postfix)
84-
then (postfix = mk-cons( postfix, do-release ); ascript-force(postfix, t0(c"Nil"));)
84+
then (postfix = mk-cons( postfix, do-release ); ascript-force(postfix, type-nil);)
8585
else postfix = do-release;
8686
};
8787

SRC/typecheck-typeof-lhs.lsts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ let typeof-lhs(lhs: AST, idx: U64): Type = match lhs {
55
App{ left:Lit{key:c":"}, right:App{ right:AType{tt=tt} } } => tt.rewrite-type-alias.accept-interface(idx);
66
App{ ps=left, right:App{ left:Lit{key:c":"}, right:App{ right:AType{tt=tt} } } } =>
77
t2(c"Cons", typeof-lhs(ps,idx+1), tt.rewrite-type-alias.accept-interface(idx));
8-
ASTNil{} => t0(c"Nil");
9-
_ => (exit-error("typeof-lhs Unexpected LHS \{lhs}\n", lhs); t0(c"Nil"));
8+
ASTNil{} => type-nil;
9+
_ => (exit-error("typeof-lhs Unexpected LHS \{lhs}\n", lhs); type-nil);
1010
};

0 commit comments

Comments
 (0)