Skip to content

Commit 07e6a0e

Browse files
authored
Merge pull request #2023 from andrew-johnson-4/more-misc-optimizations-flwemfewl
More misc optimizations flwemfewl
2 parents 9ca1504 + cd9fa8a commit 07e6a0e

File tree

10 files changed

+3584
-3408
lines changed

10 files changed

+3584
-3408
lines changed

BOOTSTRAP/cli.c

Lines changed: 3446 additions & 3306 deletions
Large diffs are not rendered by default.

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ LSTSFLAGS = MALLOC_CHECK_=3
88
# recommendation: ulimit -s unlimited
99

1010
dev: install-production
11-
lm --v23 --showalloc SRC/index.lsts > out.txt
11+
#lm --showalloc SRC/unit-tctx-core.lsts > out.txt
12+
#lm --showalloc SRC/unit-prop-core.lsts > out.txt
13+
#lm --showalloc SRC/unit-ascript-core.lsts > out.txt
14+
lm --showalloc --v23 SRC/index.lsts > out.txt
1215

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

PLUGINS/BACKEND/C/compile-program-ordered.lsts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
let compile-program-ordered(global-ctx: FContext, program: AST): Nil = (
33
for vector g in program.unroll-seq { match g {
44
Glb{ key=key, val=val } => (
5+
config-hot-path = key.key == c"std-bind-term";
56
if not(typeof-term(def-to-sym(g)).is-open)
67
or not(typeof-term(val).is-open) then {
78
std-c-compile-global(global-ctx, key.key, val);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,8 @@ let std-c-compile-expr(ctx: FContext, t: AST, is-stmt: Bool): Fragment = (
309309
};
310310
if is-stmt and non-zero(f.get(c"expression")) then f = f.set(c"expression", f.get(c"expression") + SAtom(c";"));
311311
f.context = close(ctx);
312-
f.type = typeof-term(t); f
312+
f.type = typeof-term(t);
313+
f
313314
);
314315

315316

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ let std-c-compile-global(ctx: FContext, k: CString, term: AST): Nil = (
186186
} else {
187187
text = SAtom(k) + SAtom(c" = ") + inner-expr.get(c"expression") + SAtom(c";\n");
188188
assemble-global-initializer-section = assemble-global-initializer-section + text;
189-
}
189+
};
190190
);
191191
}
192192
);

SRC/ast-constructor.lsts

Lines changed: 72 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ let .is-var-or-ascripted-var(t: AST): Bool = (
5050
let .with-implies(term: AST, implies: Vector<Type>): AST = (
5151
match term {
5252
Typedef{} => (
53-
let location = (term as Tag::Typedef).location;
54-
let lhs-type = (term as Tag::Typedef).lhs-type;
55-
let implements = (term as Tag::Typedef).implements;
56-
let size = (term as Tag::Typedef).size;
57-
let alias = (term as Tag::Typedef).alias;
58-
let opaque-alias = (term as Tag::Typedef).opaque-alias;
59-
let cases = (term as Tag::Typedef).cases;
60-
let misc-type = (term as Tag::Typedef).misc-type;
61-
let implied-phi = (term as Tag::Typedef).implied-phi;
53+
let location = open((term as Tag::Typedef).td).location;
54+
let lhs-type = open((term as Tag::Typedef).td).lhs-type;
55+
let implements = open((term as Tag::Typedef).td).implements;
56+
let size = open((term as Tag::Typedef).td).size;
57+
let alias = open((term as Tag::Typedef).td).alias;
58+
let opaque-alias = open((term as Tag::Typedef).td).opaque-alias;
59+
let cases = open((term as Tag::Typedef).td).cases;
60+
let misc-type = open((term as Tag::Typedef).td).misc-type;
61+
let implied-phi = open((term as Tag::Typedef).td).implied-phi;
6262
Typedef( location, lhs-type, implies, implements, size, alias, opaque-alias, cases, misc-type, implied-phi );
6363
);
6464
_ => term;
@@ -67,15 +67,15 @@ let .with-implies(term: AST, implies: Vector<Type>): AST = (
6767
let .with-implements(term: AST, implements: Vector<Type>): AST = (
6868
match term {
6969
Typedef{} => (
70-
let location = (term as Tag::Typedef).location;
71-
let lhs-type = (term as Tag::Typedef).lhs-type;
72-
let implies = (term as Tag::Typedef).implies;
73-
let size = (term as Tag::Typedef).size;
74-
let alias = (term as Tag::Typedef).alias;
75-
let opaque-alias = (term as Tag::Typedef).opaque-alias;
76-
let cases = (term as Tag::Typedef).cases;
77-
let misc-type = (term as Tag::Typedef).misc-type;
78-
let implied-phi = (term as Tag::Typedef).implied-phi;
70+
let location = open((term as Tag::Typedef).td).location;
71+
let lhs-type = open((term as Tag::Typedef).td).lhs-type;
72+
let implies = open((term as Tag::Typedef).td).implies;
73+
let size = open((term as Tag::Typedef).td).size;
74+
let alias = open((term as Tag::Typedef).td).alias;
75+
let opaque-alias = open((term as Tag::Typedef).td).opaque-alias;
76+
let cases = open((term as Tag::Typedef).td).cases;
77+
let misc-type = open((term as Tag::Typedef).td).misc-type;
78+
let implied-phi = open((term as Tag::Typedef).td).implied-phi;
7979
Typedef( location, lhs-type, implies, implements, size, alias, opaque-alias, cases, misc-type, implied-phi );
8080
);
8181
_ => term;
@@ -84,15 +84,15 @@ let .with-implements(term: AST, implements: Vector<Type>): AST = (
8484
let .with-size(term: AST, size: Type): AST = (
8585
match term {
8686
Typedef{} => (
87-
let location = (term as Tag::Typedef).location;
88-
let lhs-type = (term as Tag::Typedef).lhs-type;
89-
let implies = (term as Tag::Typedef).implies;
90-
let implements = (term as Tag::Typedef).implements;
91-
let alias = (term as Tag::Typedef).alias;
92-
let opaque-alias = (term as Tag::Typedef).opaque-alias;
93-
let cases = (term as Tag::Typedef).cases;
94-
let misc-type = (term as Tag::Typedef).misc-type;
95-
let implied-phi = (term as Tag::Typedef).implied-phi;
87+
let location = open((term as Tag::Typedef).td).location;
88+
let lhs-type = open((term as Tag::Typedef).td).lhs-type;
89+
let implies = open((term as Tag::Typedef).td).implies;
90+
let implements = open((term as Tag::Typedef).td).implements;
91+
let alias = open((term as Tag::Typedef).td).alias;
92+
let opaque-alias = open((term as Tag::Typedef).td).opaque-alias;
93+
let cases = open((term as Tag::Typedef).td).cases;
94+
let misc-type = open((term as Tag::Typedef).td).misc-type;
95+
let implied-phi = open((term as Tag::Typedef).td).implied-phi;
9696
Typedef( location, lhs-type, implies, implements, size, alias, opaque-alias, cases, misc-type, implied-phi );
9797
);
9898
_ => term;
@@ -101,15 +101,15 @@ let .with-size(term: AST, size: Type): AST = (
101101
let .with-alias(term: AST, alias: Type): AST = (
102102
match term {
103103
Typedef{} => (
104-
let location = (term as Tag::Typedef).location;
105-
let lhs-type = (term as Tag::Typedef).lhs-type;
106-
let implies = (term as Tag::Typedef).implies;
107-
let implements = (term as Tag::Typedef).implements;
108-
let size = (term as Tag::Typedef).size;
109-
let opaque-alias = (term as Tag::Typedef).opaque-alias;
110-
let cases = (term as Tag::Typedef).cases;
111-
let misc-type = (term as Tag::Typedef).misc-type;
112-
let implied-phi = (term as Tag::Typedef).implied-phi;
104+
let location = open((term as Tag::Typedef).td).location;
105+
let lhs-type = open((term as Tag::Typedef).td).lhs-type;
106+
let implies = open((term as Tag::Typedef).td).implies;
107+
let implements = open((term as Tag::Typedef).td).implements;
108+
let size = open((term as Tag::Typedef).td).size;
109+
let opaque-alias = open((term as Tag::Typedef).td).opaque-alias;
110+
let cases = open((term as Tag::Typedef).td).cases;
111+
let misc-type = open((term as Tag::Typedef).td).misc-type;
112+
let implied-phi = open((term as Tag::Typedef).td).implied-phi;
113113
Typedef( location, lhs-type, implies, implements, size, alias, opaque-alias, cases, misc-type, implied-phi );
114114
);
115115
_ => term;
@@ -118,15 +118,15 @@ let .with-alias(term: AST, alias: Type): AST = (
118118
let .with-opaque-alias(term: AST, opaque-alias: Type): AST = (
119119
match term {
120120
Typedef{} => (
121-
let location = (term as Tag::Typedef).location;
122-
let lhs-type = (term as Tag::Typedef).lhs-type;
123-
let implies = (term as Tag::Typedef).implies;
124-
let implements = (term as Tag::Typedef).implements;
125-
let size = (term as Tag::Typedef).size;
126-
let alias = (term as Tag::Typedef).alias;
127-
let cases = (term as Tag::Typedef).cases;
128-
let misc-type = (term as Tag::Typedef).misc-type;
129-
let implied-phi = (term as Tag::Typedef).implied-phi;
121+
let location = open((term as Tag::Typedef).td).location;
122+
let lhs-type = open((term as Tag::Typedef).td).lhs-type;
123+
let implies = open((term as Tag::Typedef).td).implies;
124+
let implements = open((term as Tag::Typedef).td).implements;
125+
let size = open((term as Tag::Typedef).td).size;
126+
let alias = open((term as Tag::Typedef).td).alias;
127+
let cases = open((term as Tag::Typedef).td).cases;
128+
let misc-type = open((term as Tag::Typedef).td).misc-type;
129+
let implied-phi = open((term as Tag::Typedef).td).implied-phi;
130130
Typedef( location, lhs-type, implies, implements, size, alias, opaque-alias, cases, misc-type, implied-phi );
131131
);
132132
_ => term;
@@ -135,15 +135,15 @@ let .with-opaque-alias(term: AST, opaque-alias: Type): AST = (
135135
let .with-cases(term: AST, cases: Vector<(CString,Vector<(CString,Type)>)>): AST = (
136136
match term {
137137
Typedef{} => (
138-
let location = (term as Tag::Typedef).location;
139-
let lhs-type = (term as Tag::Typedef).lhs-type;
140-
let implies = (term as Tag::Typedef).implies;
141-
let implements = (term as Tag::Typedef).implements;
142-
let size = (term as Tag::Typedef).size;
143-
let alias = (term as Tag::Typedef).alias;
144-
let opaque-alias = (term as Tag::Typedef).opaque-alias;
145-
let misc-type = (term as Tag::Typedef).misc-type;
146-
let implied-phi = (term as Tag::Typedef).implied-phi;
138+
let location = open((term as Tag::Typedef).td).location;
139+
let lhs-type = open((term as Tag::Typedef).td).lhs-type;
140+
let implies = open((term as Tag::Typedef).td).implies;
141+
let implements = open((term as Tag::Typedef).td).implements;
142+
let size = open((term as Tag::Typedef).td).size;
143+
let alias = open((term as Tag::Typedef).td).alias;
144+
let opaque-alias = open((term as Tag::Typedef).td).opaque-alias;
145+
let misc-type = open((term as Tag::Typedef).td).misc-type;
146+
let implied-phi = open((term as Tag::Typedef).td).implied-phi;
147147
Typedef( location, lhs-type, implies, implements, size, alias, opaque-alias, cases, misc-type, implied-phi );
148148
);
149149
_ => term;
@@ -152,15 +152,15 @@ let .with-cases(term: AST, cases: Vector<(CString,Vector<(CString,Type)>)>): AST
152152
let .with-misc(term: AST, misc-type: Type): AST = (
153153
match term {
154154
Typedef{} => (
155-
let location = (term as Tag::Typedef).location;
156-
let lhs-type = (term as Tag::Typedef).lhs-type;
157-
let implies = (term as Tag::Typedef).implies;
158-
let implements = (term as Tag::Typedef).implements;
159-
let size = (term as Tag::Typedef).size;
160-
let alias = (term as Tag::Typedef).alias;
161-
let opaque-alias = (term as Tag::Typedef).opaque-alias;
162-
let cases = (term as Tag::Typedef).cases;
163-
let implied-phi = (term as Tag::Typedef).implied-phi;
155+
let location = open((term as Tag::Typedef).td).location;
156+
let lhs-type = open((term as Tag::Typedef).td).lhs-type;
157+
let implies = open((term as Tag::Typedef).td).implies;
158+
let implements = open((term as Tag::Typedef).td).implements;
159+
let size = open((term as Tag::Typedef).td).size;
160+
let alias = open((term as Tag::Typedef).td).alias;
161+
let opaque-alias = open((term as Tag::Typedef).td).opaque-alias;
162+
let cases = open((term as Tag::Typedef).td).cases;
163+
let implied-phi = open((term as Tag::Typedef).td).implied-phi;
164164
Typedef( location, lhs-type, implies, implements, size, alias, opaque-alias, cases, misc-type, implied-phi );
165165
);
166166
_ => term;
@@ -169,15 +169,15 @@ let .with-misc(term: AST, misc-type: Type): AST = (
169169
let .with-implied-phi(term: AST, implied-phi: Type): AST = (
170170
match term {
171171
Typedef{} => (
172-
let location = (term as Tag::Typedef).location;
173-
let lhs-type = (term as Tag::Typedef).lhs-type;
174-
let implies = (term as Tag::Typedef).implies;
175-
let implements = (term as Tag::Typedef).implements;
176-
let size = (term as Tag::Typedef).size;
177-
let alias = (term as Tag::Typedef).alias;
178-
let opaque-alias = (term as Tag::Typedef).opaque-alias;
179-
let cases = (term as Tag::Typedef).cases;
180-
let misc-type = (term as Tag::Typedef).misc-type;
172+
let location = open((term as Tag::Typedef).td).location;
173+
let lhs-type = open((term as Tag::Typedef).td).lhs-type;
174+
let implies = open((term as Tag::Typedef).td).implies;
175+
let implements = open((term as Tag::Typedef).td).implements;
176+
let size = open((term as Tag::Typedef).td).size;
177+
let alias = open((term as Tag::Typedef).td).alias;
178+
let opaque-alias = open((term as Tag::Typedef).td).opaque-alias;
179+
let cases = open((term as Tag::Typedef).td).cases;
180+
let misc-type = open((term as Tag::Typedef).td).misc-type;
181181
Typedef( location, lhs-type, implies, implements, size, alias, opaque-alias, cases, misc-type, implied-phi );
182182
);
183183
_ => term;

SRC/ast-definition.lsts

Lines changed: 50 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,28 @@
22
type SourceLocation = { filename: CString, line: U64, column: U64 };
33
type Token = { key: CString, nonce: U64, location: SourceLocation };
44

5+
# This AST row is very fat, so we move it into an indirect data
6+
# TODO: do this optimization automatically or with a simple annotation
7+
type ASTTypedef = { location: SourceLocation, lhs-type: Type, implies: Vector<Type>, implements: Vector<Type>,
8+
size: Type, alias: Type, opaque-alias: Type, cases: Vector<(CString,Vector<(CString,Type)>)>,
9+
misc-type: Type, implied-phi: Type };
10+
11+
let $"Typedef"(location: SourceLocation, lhs-type: Type, implies: Vector<Type>, implements: Vector<Type>,
12+
size: Type, alias: Type, opaque-alias: Type, cases: Vector<(CString,Vector<(CString,Type)>)>,
13+
misc-type: Type, implied-phi: Type): AST = (
14+
Typedef(close(ASTTypedef(location, lhs-type, implies, implements, size, alias, opaque-alias, cases, misc-type, implied-phi)))
15+
);
16+
17+
let .lhs-type(t: AST+Tag::Typedef): Type = open((t as Tag::Typedef).td).lhs-type;
18+
let .implies(t: AST+Tag::Typedef): Vector<Type> = open((t as Tag::Typedef).td).implies;
19+
let .implements(t: AST+Tag::Typedef): Vector<Type> = open((t as Tag::Typedef).td).implements;
20+
let .size(t: AST+Tag::Typedef): Type = open((t as Tag::Typedef).td).size;
21+
let .alias(t: AST+Tag::Typedef): Type = open((t as Tag::Typedef).td).alias;
22+
let .opaque-alias(t: AST+Tag::Typedef): Type = open((t as Tag::Typedef).td).opaque-alias;
23+
let .cases(t: AST+Tag::Typedef): Vector<(CString,Vector<(CString,Type)>)> = open((t as Tag::Typedef).td).cases;
24+
let .misc-type(t: AST+Tag::Typedef): Type = open((t as Tag::Typedef).td).misc-type;
25+
let .implied-phi(t: AST+Tag::Typedef): Type = open((t as Tag::Typedef).td).implied-phi;
26+
527
type AST zero ASTEOF implies MustRetain, MustRelease
628
= Meta { val: OwnedData<AST>[] }
729
| ASTEOF
@@ -13,12 +35,23 @@ type AST zero ASTEOF implies MustRetain, MustRelease
1335
| AType { tt: Type }
1436
| Seq { seq: Vector<AST> }
1537
| Glb { key: Token , val: OwnedData<AST>[] }
16-
| Typedef { location: SourceLocation, lhs-type: Type, implies: Vector<Type>, implements: Vector<Type>,
17-
size: Type, alias: Type, opaque-alias: Type, cases: Vector<(CString,Vector<(CString,Type)>)>,
18-
misc-type: Type, implied-phi: Type };
38+
| Typedef { td: OwnedData<ASTTypedef>[] };
1939

2040
let $"App"(left: OwnedData<AST>[], right: OwnedData<AST>[]): AST = App ( false, left, right );
2141

42+
let .retain(t: ASTTypedef): ASTTypedef = (
43+
mark-as-released(t.lhs-type.retain);
44+
mark-as-released(t.implies.retain);
45+
mark-as-released(t.implements.retain);
46+
mark-as-released(t.size.retain);
47+
mark-as-released(t.alias.retain);
48+
mark-as-released(t.opaque-alias.retain);
49+
mark-as-released(t.cases.retain);
50+
mark-as-released(t.misc-type.retain);
51+
mark-as-released(t.implied-phi.retain);
52+
t
53+
);
54+
2255
let .retain(t: AST): AST = (
2356
if t.discriminator-case-tag==(t as Tag::Meta).discriminator-case-tag {
2457
(t as Tag::Meta).val.retain;
@@ -42,19 +75,23 @@ let .retain(t: AST): AST = (
4275
(t as Tag::Glb).val.retain;
4376
};
4477
if t.discriminator-case-tag==(t as Tag::Typedef).discriminator-case-tag {
45-
mark-as-released((t as Tag::Typedef).lhs-type.retain);
46-
mark-as-released((t as Tag::Typedef).implies.retain);
47-
mark-as-released((t as Tag::Typedef).implements.retain);
48-
mark-as-released((t as Tag::Typedef).size.retain);
49-
mark-as-released((t as Tag::Typedef).alias.retain);
50-
mark-as-released((t as Tag::Typedef).opaque-alias.retain);
51-
mark-as-released((t as Tag::Typedef).cases.retain);
52-
mark-as-released((t as Tag::Typedef).misc-type.retain);
53-
mark-as-released((t as Tag::Typedef).implied-phi.retain);
78+
mark-as-released((t as Tag::Typedef).td.retain);
5479
};
5580
t
5681
);
5782

83+
let .release(t: ASTTypedef): Nil = (
84+
t.lhs-type.release;
85+
t.implies.release;
86+
t.implements.release;
87+
t.size.release;
88+
t.alias.release;
89+
t.opaque-alias.release;
90+
t.cases.release;
91+
t.misc-type.release;
92+
t.implied-phi.release;
93+
);
94+
5895
let .release(t: AST): Nil = (
5996
if t.discriminator-case-tag==(t as Tag::Meta).discriminator-case-tag {
6097
(t as Tag::Meta).val.release;
@@ -78,15 +115,7 @@ let .release(t: AST): Nil = (
78115
(t as Tag::Glb).val.release;
79116
};
80117
if t.discriminator-case-tag==(t as Tag::Typedef).discriminator-case-tag {
81-
(t as Tag::Typedef).lhs-type.release;
82-
(t as Tag::Typedef).implies.release;
83-
(t as Tag::Typedef).implements.release;
84-
(t as Tag::Typedef).size.release;
85-
(t as Tag::Typedef).alias.release;
86-
(t as Tag::Typedef).opaque-alias.release;
87-
(t as Tag::Typedef).cases.release;
88-
(t as Tag::Typedef).misc-type.release;
89-
(t as Tag::Typedef).implied-phi.release;
118+
(t as Tag::Typedef).td.release;
90119
};
91120
mark-as-released(t);
92121
);

SRC/ast-location.lsts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ let .location(term: AST): SourceLocation = (
1111
for vector s in seq { loc = loc || s.location };
1212
loc
1313
);
14-
Typedef{ location=location } => location;
14+
Typedef{ td=td } => open(td).location;
1515
_ => mk-location();
1616
}
1717
);

SRC/typecheck-var-to-def-index.lsts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11

2+
let config-hot-path = false;
3+
24
let var-to-def-index = mk-hashtable-is(type(AST), type(AST));
35

46
let var-to-def(k: AST): AST = (

lib/core/array.lsts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ let safe-alloc-semaphore = false;
5555
#);
5656

5757
let safe-alloc-impl(nb: USize, tt: Type<t>): t[] = (
58+
# TODO: wrap counter adjustments in conditional compilation
59+
safe-alloc-block-count = safe-alloc-block-count + 1;
60+
safe-alloc-block-count-monotonic = safe-alloc-block-count-monotonic + 1;
61+
safe-alloc-block-count-monotonic-history = safe-alloc-block-count-monotonic-history + 1;
62+
5863
#let tk = type(t).into(type(CString));
5964
#if tk != c"SparseOwnedData<Tuple<U64,C<\"char\">[],HashtableRowExists>>" {
6065
# alloc-type-counter = alloc-type-counter.bind(tk, alloc-type-counter.lookup(tk,0_u64) + 1);
@@ -74,11 +79,6 @@ let safe-alloc-impl(nb: USize, tt: Type<t>): t[] = (
7479

7580
mark-memory-as-safe(ptr as U8[], nb);
7681

77-
# TODO: wrap counter adjustments in conditional compilation
78-
safe-alloc-block-count = safe-alloc-block-count + 1;
79-
safe-alloc-block-count-monotonic = safe-alloc-block-count-monotonic + 1;
80-
safe-alloc-block-count-monotonic-history = safe-alloc-block-count-monotonic-history + 1;
81-
8282
ptr
8383
);
8484

0 commit comments

Comments
 (0)