Skip to content

Commit 47d8542

Browse files
authored
Merge pull request #2019 from andrew-johnson-4/more-misc-optimizations-fdkslrfewl
More misc optimizations fdkslrfewl
2 parents 3a48ff7 + 66cd08b commit 47d8542

23 files changed

+3634
-3814
lines changed

BOOTSTRAP/cli.c

Lines changed: 3554 additions & 3747 deletions
Large diffs are not rendered by default.

Makefile

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,8 @@ LSTSFLAGS = MALLOC_CHECK_=3
77
# recursion is used fairly heavily
88
# recommendation: ulimit -s unlimited
99

10-
dev: install-bootstrap
11-
lm --v23 SRC/index.lsts
12-
#lm --v23 --showallocgen tests/promises/lm-typecheck/tc-misc-2.lsts
13-
gcc tmp.c
14-
./a.out --v23 SRC/index.lsts
10+
dev: install-production
11+
lm --v23 --showalloc SRC/index.lsts > out.txt
1512

1613
build: compile-production
1714
time env $(LSTSFLAGS) ./production --v23 --c -o deploy1.c SRC/index.lsts

PLUGINS/BACKEND/C/std-c-compile-global.lsts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ let std-c-force-import-clib(lib: CString): Nil = (
66
);
77

88
let std-c-finish-forced-imports(): S = (
9-
(if std-c-force-imports.has(c"stdlib.h") then SAtom(c"#include <stdlib.h>\n") else SNil()) +
10-
(if std-c-force-imports.has(c"stdio.h") then SAtom(c"#include <stdio.h>\n") else SNil()) +
11-
(if std-c-force-imports.has(c"regex.h") then SAtom(c"#include <regex.h>\n") else SNil()) +
12-
(if std-c-force-imports.has(c"string.h") then SAtom(c"#include <string.h>\n") else SNil()) +
9+
(if std-c-force-imports.has-key(c"stdlib.h") then SAtom(c"#include <stdlib.h>\n") else SNil()) +
10+
(if std-c-force-imports.has-key(c"stdio.h") then SAtom(c"#include <stdio.h>\n") else SNil()) +
11+
(if std-c-force-imports.has-key(c"regex.h") then SAtom(c"#include <regex.h>\n") else SNil()) +
12+
(if std-c-force-imports.has-key(c"string.h") then SAtom(c"#include <string.h>\n") else SNil()) +
1313
(SAtom(c"#include <malloc.h>\n")) +
1414
(SAtom(c"#include <unistd.h>\n"))
1515
);

PLUGINS/FRONTEND/C/c-ast-to-lm-ast.lsts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ let std-c-declare(t: CTerm): Nil = (
1919
))
2020
);
2121
);
22-
CIdentifier{name2=value} => (if not(std-c-declare-dedup-index.has(name2)) {
22+
CIdentifier{name2=value} => (if not(std-c-declare-dedup-index.has-key(name2)) {
2323
std-c-declare-dedup-index = std-c-declare-dedup-index.bind(name2, true);
2424
if can-unify( t1(c"C",t0(c"typedef")), return-type ) {
2525
std-c-typedef-name-index = std-c-typedef-name-index.bind(name2, true);
@@ -36,7 +36,7 @@ let std-c-declare(t: CTerm): Nil = (
3636
});
3737
CUnaryPrefix{op:"Declarator(", arg=arg} => (
3838
(let name3, let body) = std-c-sig-of-declarator(return-type, arg, ta, (None : Maybe<CTerm>)());
39-
if not(std-c-declare-dedup-index.has(name3.into(type(String)))) {
39+
if not(std-c-declare-dedup-index.has-key(name3.into(type(String)))) {
4040
std-c-declare-dedup-index = std-c-declare-dedup-index.bind(name3.into(type(String)), true);
4141
if can-unify( t1(c"C",t0(c"typedef")), return-type ) {
4242
std-c-typedef-name-index = std-c-typedef-name-index.bind(name3.into(type(String)), true);
@@ -48,7 +48,7 @@ let std-c-declare(t: CTerm): Nil = (
4848
);
4949
CBinaryOp{op:"Declarator(", arg1=arg1, arg2=arg2 } => (
5050
(let name4, let body) = std-c-sig-of-declarator(return-type, arg1, ta, Some(arg2));
51-
if not(std-c-declare-dedup-index.has(name4.into(type(String)))) {
51+
if not(std-c-declare-dedup-index.has-key(name4.into(type(String)))) {
5252
std-c-declare-dedup-index = std-c-declare-dedup-index.bind(name4.into(type(String)), true);
5353
if can-unify( t1(c"C",t0(c"typedef")), return-type ) {
5454
std-c-typedef-name-index = std-c-typedef-name-index.bind(name4.into(type(String)), true);
@@ -61,7 +61,7 @@ let std-c-declare(t: CTerm): Nil = (
6161
CBinaryOp{op:"Declarator*", ptr=arg1, arg2:CBinaryOp{op:"Declarator(", arg1=arg1, arg2=arg2 } } => (
6262
return-type = std-c-decorate-pointer(return-type, ptr);
6363
(let name5, let body) = std-c-sig-of-declarator(return-type, arg1, ta, Some(arg2));
64-
if not(std-c-declare-dedup-index.has(name5.into(type(String)))) {
64+
if not(std-c-declare-dedup-index.has-key(name5.into(type(String)))) {
6565
std-c-declare-dedup-index = std-c-declare-dedup-index.bind(name5.into(type(String)), true);
6666
if can-unify( t1(c"C",t0(c"typedef")), return-type ) {
6767
std-c-typedef-name-index = std-c-typedef-name-index.bind(name5.into(type(String)), true);
@@ -72,7 +72,7 @@ let std-c-declare(t: CTerm): Nil = (
7272
}
7373
);
7474
CBinaryOp{op:"Declarator*", ptr=arg1, arg2:CIdentifier{name6=value} } => (
75-
if not(std-c-declare-dedup-index.has(name6)) {
75+
if not(std-c-declare-dedup-index.has-key(name6)) {
7676
std-c-declare-dedup-index = std-c-declare-dedup-index.bind(name6, true);
7777
if can-unify( t1(c"C",t0(c"typedef")), return-type ) {
7878
std-c-typedef-name-index = std-c-typedef-name-index.bind(name6, true);

PLUGINS/FRONTEND/C/c-parse.lsts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ let std-c-has-class(tks: String, cls: String): Bool = (
157157
"floating" => tk == r/^[0-9]+([.][0-9]+)?([eE][0-9]+)?[fF]?/ # decimal constant
158158
or tk == r/^[0][x][0-9a-fA-F]+([.][0-9a-fA-F]+)?([eE][0-9a-fA-F]+)?([pP][0-9]+)[fF]?/; # hexadecimal constant
159159
"string" => tk == r/^[RLuU8]*["]([^"\\]|([\\].))*["]/;
160-
"enumeration" => std-c-enumeration-constant-index.has(tks);
160+
"enumeration" => std-c-enumeration-constant-index.has-key(tks);
161161
_ => tks == cls;
162162
}
163163
);
@@ -704,7 +704,7 @@ std-c-typedef-name-index = std-c-typedef-name-index.bind("__builtin_va_list", tr
704704

705705
let std-c-parse-typedef-name(tokens: List<Token>): Tuple<Maybe<CTerm>,List<Token>> = (
706706
let no = (None : Maybe<CTerm>)();
707-
if non-zero(tokens) and std-c-typedef-name-index.has(head(tokens).skey) {
707+
if non-zero(tokens) and std-c-typedef-name-index.has-key(head(tokens).skey) {
708708
Tuple( Some(CType1(head(tokens).skey)), tail(tokens) )
709709
} else Tuple( no, tokens )
710710
);

SRC/ascript-datatype-index.lsts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ let .is-datatype(tt: Type): Bool = (
1414
);
1515
_ => (
1616
let gta = tt.ground-tag-and-arity;
17-
datatype-index.has(gta)
17+
datatype-index.has-key(gta)
1818
);
1919
}
2020
);

SRC/prop-core.lsts

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -153,21 +153,17 @@ let weaken-quick-prop(original-base: Type, base: Type, pre: Type): Type = (
153153
);
154154
}
155155
};
156-
if tag.contains(c"::") {
157-
let tag-parts = tag.split(c"::").into(type(Vector<CString>));
158-
let tag-base = tag-parts[0] + c"::";
159-
let ti = 1_sz;
160-
while ti < tag-parts.length {
161-
let tag-part = tag-parts[ti];
162-
for vector row in weaken-quick-prop-index.lookup( (tag-base, parameters.length as U64), mk-vector(type((Type,Type))) ) {
163-
let lt = row.first;
164-
let rt = row.second;
165-
if can-unify(lt, original-base) then (
166-
base = remove-info(base, rt);
167-
);
168-
};
169-
tag-base = tag-base + tag-part + c"::";
170-
ti = ti + 1;
156+
if tag.has-prefix(c"Tag::") or tag.has-prefix(c"Field::") {
157+
# TODO: generalize to all :: types, temporary semantic regression
158+
let tag-base = if tag.has-prefix(c"Tag::") then c"Tag::"
159+
else if tag.has-prefix(c"Field::") then c"Field::"
160+
else c"";
161+
for vector row in weaken-quick-prop-index.lookup( (tag-base, parameters.length as U64), mk-vector(type((Type,Type))) ) {
162+
let lt = row.first;
163+
let rt = row.second;
164+
if can-unify(lt, original-base) then (
165+
base = remove-info(base, rt);
166+
);
171167
};
172168
};
173169
);
@@ -233,20 +229,15 @@ let unenrich-quick-prop(original-base: Type, base: Type, pre: Type): Type = (
233229
}
234230
};
235231
if tag.contains(c"::") {
236-
let tag-parts = tag.split(c"::").into(type(Vector<CString>));
237-
let tag-base = tag-parts[0] + c"::";
238-
let ti = 1_sz;
239-
while ti < tag-parts.length {
240-
let tag-part = tag-parts[ti];
241-
for vector row in quick-prop.lookup( (tag-base, parameters.length as U64), mk-vector(type((Type,Type))) ) {
242-
let lt = row.first;
243-
let rt = row.second;
244-
if can-unify(lt, original-base) then (
245-
base = remove-info(base, rt);
246-
);
247-
};
248-
tag-base = tag-base + tag-part + c"::";
249-
ti = ti + 1;
232+
let tag-base = if tag.has-prefix(c"Tag::") then c"Tag::"
233+
else if tag.has-prefix(c"Field::") then c"Field::"
234+
else c"";
235+
for vector row in quick-prop.lookup( (tag-base, parameters.length as U64), mk-vector(type((Type,Type))) ) {
236+
let lt = row.first;
237+
let rt = row.second;
238+
if can-unify(lt, original-base) then (
239+
base = remove-info(base, rt);
240+
);
250241
};
251242
};
252243
);

SRC/prop-is-phi-type.lsts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
let phi-type-index = {} : Hashtable<(CString,U64),Bool>;
33

44
let .is-phi-type(tt: Type): Bool = (
5-
phi-type-index.has(tt.ground-tag-and-arity)
5+
phi-type-index.has-key(tt.ground-tag-and-arity)
66
);

SRC/prop-tctx-apply.lsts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ let .apply(tctx: TypeContext?, fname: CString, ft: Type, at: Type, blame: AST, r
1818
# Assert that all equal type variables also have equal datatype
1919
let apply-type-variables = {} : Hashtable<CString,Type>;
2020
for list tr in apply-tctx.get-or-panic.tctx {
21-
if apply-type-variables.has(tr.key-or-zero) {
21+
if apply-type-variables.has-key(tr.key-or-zero) {
2222
let previous-seen-tt = apply-type-variables.lookup(tr.key-or-zero, ta).datatype;
2323
let current-seen-tt = tr.direct-type.datatype;
2424
if previous-seen-tt != current-seen-tt {

SRC/tctx-lookup.lsts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ let .lookup(tctx: TypeContext?, key: CString): TypeContextRow = tctx.get-or(mk-t
33
let .lookup(trs: List<TypeContextRow>, key: CString): TypeContextRow = (
44
let default = NullTypeContextRow;
55
let continue = true;
6-
for list tr in trs { if continue {
6+
while non-zero(trs) and continue {
7+
let tr = head(trs); trs = tail(trs);
78
if tr.key-or-zero == key {
89
default = tr;
910
continue = false;
1011
}
11-
}};
12+
};
1213
if not(non-zero(default)) {
1314
for vector tr in global-tctx.lookup(key, mk-vector(type(TypeContextRow)) ) {
1415
if tr.key-or-zero == key {
@@ -29,12 +30,13 @@ let .lookups(tctx: TypeContext?, key: CString): Vector<TypeContextRow> = tctx.ge
2930
let .lookups(trs: List<TypeContextRow>, key: CString): Vector<TypeContextRow> = (
3031
let default = mk-vector(type(TypeContextRow));
3132
let continue = true;
32-
for list tr in trs { if continue {
33+
while non-zero(trs) and continue {
34+
let tr = head(trs); trs = tail(trs);
3335
if tr.key-or-zero == key {
3436
default = default.push(tr);
3537
continue = false;
3638
}
37-
}};
39+
};
3840
if continue {
3941
for vector tr in global-tctx.lookup(key, mk-vector(type(TypeContextRow)) ) {
4042
if tr.key-or-zero == key {
@@ -49,11 +51,12 @@ let .lookup-phi(tctx: TypeContext?, key: CString): PhiContextRow = tctx.get-or(m
4951
let .lookup(trs: List<PhiContextRow>, key: CString): PhiContextRow = (
5052
let default = NullPhiContextRow;
5153
let continue = true;
52-
for list tr in trs { if continue {
54+
while non-zero(trs) and continue {
55+
let tr = head(trs); trs = tail(trs);
5356
if tr.phi-id-or-zero == key {
5457
default = tr;
5558
if not(tr.dead-on-arrival-or-zero) then continue = false;
5659
}
57-
}};
60+
};
5861
default
5962
);

0 commit comments

Comments
 (0)