Skip to content

Commit 3a48ff7

Browse files
authored
Merge pull request #2018 from andrew-johnson-4/profile-optimize-type-fsdlslsl
Profile optimize type fsdlslsl
2 parents 51b7278 + 98e5cd8 commit 3a48ff7

19 files changed

Lines changed: 116 additions & 39 deletions

Makefile

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

10-
dev: install-production
11-
lm tests/promises/lm-type/can-unify.lsts
10+
dev: install-bootstrap
11+
lm --v23 SRC/index.lsts
12+
#lm --v23 --showallocgen tests/promises/lm-typecheck/tc-misc-2.lsts
1213
gcc tmp.c
13-
./a.out
14+
./a.out --v23 SRC/index.lsts
1415

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

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ let std-c-compile-call(ctx: FContext, fname: CString, return-hint-if-constructor
66
.expect("std-c-compile-call Function \{fname} was null\nArguments: \{typeof-term(args)}, Return Hint \{return-hint-if-constructor}\nAt \{args.location}\n").blame-or-zero;
77
if typeof-term(fterm).is-t(c"Blob",0) {
88
if typeof-term(fterm).is-open and fname!=c"open" and fname!=c"mov" then {
9-
for list tr in Some(mk-tctx()).lookups(fname) {
9+
for vector tr in Some(mk-tctx()).lookups(fname) {
1010
print("STD C compile call candidate \{fname} : \{tr.dt-or-zero}\n");
1111
};
1212
exit-error("STD C compile call is open \{fname} (\{typeof-term(args)})\n\{typeof-term(fterm)}\nArgs \{args}\n", args);
@@ -23,7 +23,7 @@ let std-c-compile-call(ctx: FContext, fname: CString, return-hint-if-constructor
2323
} else if typeof-term(fterm).is-t(c"Prop",0) { std-c-compile-expr(ctx, args, false)
2424
} else {
2525
if typeof-term(fterm).is-open then {
26-
for list tr in Some(mk-tctx()).lookups(fname) {
26+
for vector tr in Some(mk-tctx()).lookups(fname) {
2727
print("STD C compile call candidate \{fname} : \{tr.dt-or-zero}\n");
2828
};
2929
exit-error("STD C compile call is open \{fname} (\{typeof-term(args)})\n\{typeof-term(fterm)}\nArgs \{args}\n", args);

SRC/prop-core.lsts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11

2-
let quick-prop = {} : Hashtable<(CString,U64),List<(Type,Type)>>;
2+
let quick-prop = {} : Hashtable<(CString,U64),Vector<(Type,Type)>>;
33

44
let add-quick-prop(pre: Type, pat: Type, post: Type): Nil = (
55
let key = pre.ground-tag-and-arity;
6-
let val = quick-prop.lookup(key, ([] : List<(Type,Type)>));
7-
val = cons( (pat,post), val );
6+
let val = quick-prop.lookup(key, mk-vector(type((Type,Type))) );
7+
val = val.push( (pat,post) );
88
quick-prop = quick-prop.bind( key, val );
99
);
1010

@@ -54,7 +54,7 @@ let .enrich-strong(base: Type): Type = (
5454
let enrich-quick-prop(base: Type, pre: Type): Type = (
5555
match pre {
5656
TGround { tag=tag, parameters=parameters } => (
57-
for list row in quick-prop.lookup( pre.ground-tag-and-arity, ([] : List<(Type,Type)>) ) {
57+
for vector row in quick-prop.lookup( pre.ground-tag-and-arity, mk-vector(type((Type,Type))) ) {
5858
let lt = row.first;
5959
let rt = row.second;
6060
if base <: lt then (
@@ -68,7 +68,7 @@ let enrich-quick-prop(base: Type, pre: Type): Type = (
6868
);
6969
};
7070
if tag==c"Array" and parameters.length==2 {
71-
for list row in quick-prop.lookup( (c"Array",2_u64), ([] : List<(Type,Type)>) ) {
71+
for vector row in quick-prop.lookup( (c"Array",2_u64), mk-vector(type((Type,Type))) ) {
7272
let lt = row.first;
7373
let rt = row.second;
7474
if base <: lt then (
@@ -101,7 +101,7 @@ let enrich-quick-prop(base: Type, pre: Type): Type = (
101101
pre
102102
);
103103

104-
let weaken-quick-prop-index = {} : Hashtable<(CString,U64),List<(Type,Type)>>;
104+
let weaken-quick-prop-index = {} : Hashtable<(CString,U64),Vector<(Type,Type)>>;
105105

106106
# core implicit weakening rules
107107
add-weaken-quick-prop( t1(c"Constructor",ta), t1(c"Constructor",ta), t1(c"Constructor",ta) );
@@ -124,8 +124,8 @@ add-weaken-quick-prop( t0(c"Tag::"), ta, t0(c"Tag::") );
124124

125125
let add-weaken-quick-prop(pre: Type, pat: Type, post: Type): Nil = (
126126
let key = pre.ground-tag-and-arity;
127-
let val = weaken-quick-prop-index.lookup(key, ([] : List<(Type,Type)>));
128-
val = cons( (pat,post), val );
127+
let val = weaken-quick-prop-index.lookup(key, mk-vector(type((Type,Type))) );
128+
val = val.push( (pat,post) );
129129
weaken-quick-prop-index = weaken-quick-prop-index.bind( key, val );
130130
);
131131

@@ -137,15 +137,15 @@ let weaken-quick-prop(original-base: Type, base: Type, pre: Type): Type = (
137137
let early-base = base;
138138
match pre {
139139
TGround { tag=tag, parameters=parameters } => (
140-
for list row in weaken-quick-prop-index.lookup( pre.ground-tag-and-arity, ([] : List<(Type,Type)>) ) {
140+
for vector row in weaken-quick-prop-index.lookup( pre.ground-tag-and-arity, mk-vector(type((Type,Type))) ) {
141141
let lt = row.first;
142142
let rt = row.second;
143143
if can-unify(lt, original-base) then (
144144
base = remove-info(base, rt);
145145
);
146146
};
147147
if tag==c"Array" and parameters.length==2 {
148-
for list row in weaken-quick-prop-index.lookup( (c"Array",2_u64), ([] : List<(Type,Type)>) ) {
148+
for vector row in weaken-quick-prop-index.lookup( (c"Array",2_u64), mk-vector(type((Type,Type))) ) {
149149
let lt = row.first;
150150
let rt = row.second;
151151
if can-unify(lt, original-base) then (
@@ -159,7 +159,7 @@ let weaken-quick-prop(original-base: Type, base: Type, pre: Type): Type = (
159159
let ti = 1_sz;
160160
while ti < tag-parts.length {
161161
let tag-part = tag-parts[ti];
162-
for list row in weaken-quick-prop-index.lookup( (tag-base, parameters.length as U64), ([] : List<(Type,Type)>) ) {
162+
for vector row in weaken-quick-prop-index.lookup( (tag-base, parameters.length as U64), mk-vector(type((Type,Type))) ) {
163163
let lt = row.first;
164164
let rt = row.second;
165165
if can-unify(lt, original-base) then (
@@ -216,15 +216,15 @@ let unenrich-quick-prop(original-base: Type, base: Type, pre: Type): Type = (
216216
let early-base = base;
217217
match pre {
218218
TGround { tag=tag, parameters=parameters } => (
219-
for list row in quick-prop.lookup( pre.ground-tag-and-arity, ([] : List<(Type,Type)>) ) {
219+
for vector row in quick-prop.lookup( pre.ground-tag-and-arity, mk-vector(type((Type,Type))) ) {
220220
let lt = row.first;
221221
let rt = row.second;
222222
if can-unify(lt, original-base) then (
223223
base = remove-info(base, rt);
224224
);
225225
};
226226
if tag==c"Array" and parameters.length==2 {
227-
for list row in quick-prop.lookup( (c"Array",2_u64), ([] : List<(Type,Type)>) ) {
227+
for vector row in quick-prop.lookup( (c"Array",2_u64), mk-vector(type((Type,Type))) ) {
228228
let lt = row.first;
229229
let rt = row.second;
230230
if can-unify(lt, original-base) then (
@@ -238,7 +238,7 @@ let unenrich-quick-prop(original-base: Type, base: Type, pre: Type): Type = (
238238
let ti = 1_sz;
239239
while ti < tag-parts.length {
240240
let tag-part = tag-parts[ti];
241-
for list row in quick-prop.lookup( (tag-base, parameters.length as U64), ([] : List<(Type,Type)>) ) {
241+
for vector row in quick-prop.lookup( (tag-base, parameters.length as U64), mk-vector(type((Type,Type))) ) {
242242
let lt = row.first;
243243
let rt = row.second;
244244
if can-unify(lt, original-base) then (

SRC/prop-stack-to-specialize.lsts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11

22
type StackToSpecialize = { key:CString, ctx:Maybe<TypeContext>, result-type:Type, term: AST };
33

4-
let stack-to-specialize = [] : List<StackToSpecialize>;
4+
let stack-to-specialize = mk-vector(type(StackToSpecialize));

SRC/prop-tctx-apply-callable.lsts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ let .apply-callable(tctx: TypeContext?, fname: CString, arg-types: Type, blame:
3434
if f-row.get-or-panic.dt-or-zero.is-open {
3535
let special-type = apply-tctx.substitute(f-row.get-or-panic.nt-or-zero).without-phi-keep-state;
3636
if not(is-special(fname,special-type)) {
37-
stack-to-specialize = cons( StackToSpecialize(fname,apply-tctx,special-type,f-row.get-or-panic.blame-or-zero), stack-to-specialize );
37+
stack-to-specialize = stack-to-specialize.push( StackToSpecialize(fname,apply-tctx,special-type,f-row.get-or-panic.blame-or-zero) );
3838
}
3939
}
4040
};

SRC/prop-tctx-find-callable.lsts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ let .find-callable(tctx: TypeContext?, fname: CString, arg-types: Type, blame: A
2525
let match-set = mk-vector(type(TypeContextRow));
2626

2727
# Find all accepting function candidates
28-
for list tr in tctx.lookups(fname) {
28+
for vector tr in tctx.lookups(fname) {
2929
# can-receive is an additional refinement on top of argument satisfaction
3030
# it is necessary for nullary or partial constructors that need a full type
3131
# like, None : TypeContext?
@@ -61,7 +61,7 @@ let .find-callable(tctx: TypeContext?, fname: CString, arg-types: Type, blame: A
6161
# Fail if function call is ambiguous
6262
if failable and not(non-zero(result)) then {
6363
eprint("Unable to find appropriate callable: \{fname} \{arg-types} return hint: \{return-type-hint}\nAt: \{blame.location}\n");
64-
for list tr in tctx.lookups(fname) {
64+
for vector tr in tctx.lookups(fname) {
6565
eprint("Candidate: \{tr.dt-or-zero}\n");
6666
};
6767
exit(1);

SRC/tctx-bind.lsts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ let .bind(tctx: TypeContext?, k: CString, nt: Type, dt: Type, blame: AST): TypeC
1919
);
2020

2121
let .bind-global(tctx: TypeContext?, k: CString, kt: Type, blame: AST): TypeContext? = (
22-
let found = global-tctx.lookup(k, [] : List<TypeContextRow>);
23-
found = cons( TypeContextRow(k,kt,kt,blame), found );
22+
let found = global-tctx.lookup(k, mk-vector(type(TypeContextRow)) );
23+
found = found.push( TypeContextRow(k,kt,kt,blame) );
2424
global-tctx = global-tctx.bind(k, found);
2525
tctx
2626
);
2727
let .bind-global(tctx: TypeContext?, k: CString, nt: Type, dt: Type, blame: AST): TypeContext? = (
28-
let found = global-tctx.lookup(k, [] : List<TypeContextRow>);
29-
found = cons( TypeContextRow(k,nt,dt,blame), found );
28+
let found = global-tctx.lookup(k, mk-vector(type(TypeContextRow)) );
29+
found = found.push( TypeContextRow(k,nt,dt,blame) );
3030
global-tctx = global-tctx.bind(k, found);
3131
tctx
3232
);

SRC/tctx-definition.lsts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
let global-tctx = {} : Hashtable<CString,List<TypeContextRow>>;
2+
let global-tctx = {} : Hashtable<CString,Vector<TypeContextRow>>;
33
let tctx-currently-processing-globals = true;
44

55
type TypeContextRow zero NullTypeContextRow implies MustRetain, MustRelease = NullTypeContextRow | TypeContextRow { key: CString, nt: Type, dt: Type, blame: AST };

SRC/tctx-lookup.lsts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ let .lookup(trs: List<TypeContextRow>, key: CString): TypeContextRow = (
1010
}
1111
}};
1212
if not(non-zero(default)) {
13-
for list tr in global-tctx.lookup(key, [] : List<TypeContextRow>) {
13+
for vector tr in global-tctx.lookup(key, mk-vector(type(TypeContextRow)) ) {
1414
if tr.key-or-zero == key {
1515
if non-zero(default) {
1616
eprint("Duplicate Global Symbol \{key}\n");
@@ -25,20 +25,20 @@ let .lookup(trs: List<TypeContextRow>, key: CString): TypeContextRow = (
2525
default
2626
);
2727

28-
let .lookups(tctx: TypeContext?, key: CString): List<TypeContextRow> = tctx.get-or(mk-tctx()).tctx.lookups(key);
29-
let .lookups(trs: List<TypeContextRow>, key: CString): List<TypeContextRow> = (
30-
let default = [] : List<TypeContextRow>;
28+
let .lookups(tctx: TypeContext?, key: CString): Vector<TypeContextRow> = tctx.get-or(mk-tctx()).tctx.lookups(key);
29+
let .lookups(trs: List<TypeContextRow>, key: CString): Vector<TypeContextRow> = (
30+
let default = mk-vector(type(TypeContextRow));
3131
let continue = true;
3232
for list tr in trs { if continue {
3333
if tr.key-or-zero == key {
34-
default = cons(tr, default);
34+
default = default.push(tr);
3535
continue = false;
3636
}
3737
}};
3838
if continue {
39-
for list tr in global-tctx.lookup(key, [] : List<TypeContextRow>) {
39+
for vector tr in global-tctx.lookup(key, mk-vector(type(TypeContextRow)) ) {
4040
if tr.key-or-zero == key {
41-
default = cons(tr, default);
41+
default = default.push(tr);
4242
}
4343
};
4444
};

SRC/typecheck-infer-expr.lsts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ let std-infer-expr(tctx: Maybe<TypeContext>, term: AST, is-scoped: Bool, used: I
193193
}};
194194
);
195195
Glb{key1=key, val=val} => (
196+
let prev-count-history = safe-alloc-block-count-monotonic-history;
196197
let rough-tt = typeof-term(term);
197198
if rough-tt.is-arrow and not(rough-tt.is-open) and not(rough-tt.is-t(c"TypedMacro",0)) {
198199
let tctx-tctx = tctx.get-or(mk-tctx());

0 commit comments

Comments
 (0)