Skip to content

Commit 2039100

Browse files
authored
Merge pull request #2064 from andrew4328/lsts-parser-improvements-fdsklwel
Lsts parser improvements fdsklwel
2 parents f296e3c + b0f87a1 commit 2039100

10 files changed

Lines changed: 4416 additions & 4597 deletions

File tree

BOOTSTRAP/cli.c

Lines changed: 4260 additions & 4402 deletions
Large diffs are not rendered by default.

BOOTSTRAP/monolithic.lsts

Lines changed: 74 additions & 94 deletions
Large diffs are not rendered by default.

Makefile

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,35 @@ LSTSFLAGS = MALLOC_CHECK_=3
88
# recommendation: ulimit -s unlimited
99

1010
dev: install-production
11-
lm --v3 --print-ast tests/promises/lm-ast/constructor.lsts > out.txt
11+
lm --print-ast tests/promises/lm-ast/constructor.lsts > out.txt
1212
gcc tmp.c
1313
./a.out
1414

1515
build: compile-production
16-
time env $(LSTSFLAGS) ./production --v3 -o deploy1.c SRC/index.lsts
16+
time env $(LSTSFLAGS) ./production -o deploy1.c SRC/index.lsts
1717
$(CC) $(CFLAGS) deploy1.c -o deploy1
18-
time env $(LSTSFLAGS) ./deploy1 --v3 -o deploy2.c SRC/index.lsts
18+
time env $(LSTSFLAGS) ./deploy1 -o deploy2.c SRC/index.lsts
1919
diff deploy1.c deploy2.c
2020
mv deploy1.c BOOTSTRAP/cli.c
2121
rm -f deploy1 deploy1.c deploy2.c
2222
cargo test regression_tests
2323

2424
gperf: install-bootstrap
25-
LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libprofiler.so CPUPROFILE=out.prof lm --v3 SRC/index.lsts
25+
LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libprofiler.so CPUPROFILE=out.prof lm SRC/index.lsts
2626
google-pprof --text /home/andrew/.local/bin/lm out.prof > profile_results.txt
2727

2828
deploy: build smoke-test
2929
deploy-lite: build smoke-test-lite
3030

31-
gprofng: install-production
31+
gprofng: install-bootstrap
3232
gprofng collect app lm SRC/index.lsts
3333

3434
gprofng-view:
3535
gprofng display text -functions test.1.er > gprofng.view
3636
nano gprofng.view
3737

3838
valgrind: install-production
39-
valgrind --tool=callgrind lm --v3 SRC/index.lsts
39+
valgrind --tool=callgrind lm SRC/index.lsts
4040

4141
valgrind-view:
4242
callgrind_annotate callgrind.out.18778
@@ -52,7 +52,7 @@ gprof-view-call-graph:
5252
gprof -q bootstrap.exe gmon.out
5353

5454
profile: install-bootstrap
55-
perf record lm --v2 SRC/index.lsts
55+
perf record lm SRC/index.lsts
5656
./report.sh
5757

5858
compile-bootstrap:
@@ -62,7 +62,7 @@ compile-bootstrap:
6262

6363
compile-production: compile-bootstrap
6464
rm -f production
65-
$(LSTSFLAGS) time ./bootstrap.exe --v3 -o production.c SRC/index.lsts
65+
$(LSTSFLAGS) time ./bootstrap.exe -o production.c SRC/index.lsts
6666
$(CC) $(CFLAGS) -o production production.c
6767
rm -f production.c
6868

PLUGINS/FRONTEND/LSTS/lsts-parse.lsts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,6 @@ let lsts-parse-type-conjugate(tokens: List<Token>): Tuple<Type,List<Token>> = (
355355
lsts-parse-expect(c"[Type Tag]", tokens);
356356
};
357357
let base = lsts-substitute-type-aliases(lsts-parse-head(tokens)); tokens = tail(tokens);
358-
if not(config-v3) and not(config-v23) and base==c"Hashtable" then base = c"HashtableEq";
359358
while non-zero(tokens) and lsts-parse-head(tokens)==c":" and lsts-parse-head(tail(tokens))==c":" {
360359
lsts-parse-expect(c":", tokens); tokens = tail(tokens);
361360
lsts-parse-expect(c":", tokens); tokens = tail(tokens);
@@ -379,11 +378,7 @@ let lsts-parse-type-conjugate(tokens: List<Token>): Tuple<Type,List<Token>> = (
379378
};
380379
lsts-parse-expect(c">", tokens); tokens = tail(tokens);
381380
};
382-
if not(config-v3) and not(config-v23) and base==c"OwnedData" and args.length==1 {
383-
head(args);
384-
} else if base==c"CompatOwnedData" and args.length==1 {
385-
t1(c"OwnedData",head(args));
386-
} else ts( base, args );
381+
ts( base, args );
387382
};
388383
while lsts-parse-head(tokens) == c"[" or lsts-parse-head(tokens)==c"?" {
389384
if lsts-parse-head(tokens)==c"[" {
@@ -695,9 +690,7 @@ let lsts-parse-mul(tokens: List<Token>): Tuple<AST,List<Token>> = (
695690

696691
let lsts-parse-map(tokens: List<Token>): Tuple<AST,List<Token>> = (
697692
lsts-parse-expect(c"{", tokens); let loc = head(tokens).location; tokens = tail(tokens);
698-
let term = if config-v3 or config-v23
699-
then mk-app( Var( c"mk-hashtable", with-location(mk-token("mk-hashtable"),loc) ), mk-nil() )
700-
else Lit( c"HashtableEqEOF", with-location(mk-token("HashtableEqEOF"),loc) );
693+
let term = mk-app( Var( c"mk-hashtable", with-location(mk-token("mk-hashtable"),loc) ), mk-nil() );
701694
if lsts-parse-head(tokens)==c"for" {
702695
fail("TODO map comprehension at \{loc}\n")
703696
} else {
@@ -948,15 +941,11 @@ let lsts-parse-typedef(tokens: List<Token>): (AST, List<Token>) = (
948941
lsts-parse-expect(c"implies", tokens); tokens = tail(tokens);
949942
(let i, tokens) = lsts-parse-type(tokens);
950943
if i.is-t(c"CompatMustRelease",0) then infers = infers.push(t0(c"MustRelease"));
951-
else if config-v23 and i.is-t(c"MustRelease",0) then ()
952-
else if config-v23 and i.is-t(c"MustRetain",0) then ()
953944
else infers = infers.push(i);
954945
while lsts-parse-head(tokens)==c"," {
955946
lsts-parse-expect(c",", tokens); tokens = tail(tokens);
956947
(i, tokens) = lsts-parse-type(tokens);
957948
if i.is-t(c"CompatMustRelease",0) then infers = infers.push(t0(c"MustRelease"));
958-
else if config-v23 and i.is-t(c"MustRelease",0) then ()
959-
else if config-v23 and i.is-t(c"MustRetain",0) then ()
960949
else infers = infers.push(i);
961950
}
962951
};

SRC/ast-misc-globals.lsts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,3 @@ let ast-parsed-program = mk-eof();
2828

2929
let parse-suffixes = [] : List<(CString,Type)>;
3030
non-zero(parse-suffixes); # TODO remove
31-
32-
let config-v3 = true;
33-
let config-v1 = false;
34-
let config-v0 = false;

SRC/type-can-unify.lsts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,14 @@
22
let $"<:"(pt: Type, fpt: Type): Bool = can-unify(fpt,pt);
33

44
let can-unify(fpt: Vector<Type>, pt: Vector<Type>): Bool = (
5-
let fptv = fpt[:];
6-
let ptv = pt[:];
7-
if fptv.length == ptv.length {
8-
let ok = true;
9-
while ok and non-zero(fptv) {
10-
if not(can-unify(head(fptv), head(ptv))) then (ok = false);
11-
fptv = tail(fptv); ptv = tail(ptv);
12-
};
13-
ok
14-
} else false
15-
);
16-
17-
let can-unify(fpt: VectorView<Type>, pt: VectorView<Type>): Bool = (
5+
# It is important here to unify tail first
6+
# Cons<Cons<x,y>,z> should check depth first in order to check arity before anything else
187
if fpt.length == pt.length {
8+
let ci = fpt.length;
199
let ok = true;
20-
while ok and non-zero(fpt) {
21-
if not(can-unify(head(fpt), head(pt))) then (ok = false);
22-
fpt = tail(fpt); pt = tail(pt);
10+
while ok and ci > 0 {
11+
ci = ci - 1;
12+
if not can-unify(fpt[ci], pt[ci]) then ok = false;
2313
};
2414
ok
2515
} else false
@@ -97,12 +87,22 @@ let can-unify(fpt: Type, pt: Type): Bool = (
9787
);
9888
Tuple{ first:TAnd{ lconjugate=conjugate }, rt=second } => (
9989
let result = true;
100-
for c in lconjugate { result = result and can-unify(c,rt) };
90+
let ci1 = 0_sz;
91+
while ci1 < lconjugate.length {
92+
result = result and can-unify(lconjugate[ci1],rt);
93+
if not result then ci1 = lconjugate.length;
94+
else ci1 = ci1 + 1;
95+
};
10196
result
10297
);
10398
Tuple{ lt=first, second:TAnd{ rconjugate=conjugate } } => (
10499
let result = false;
105-
for c in rconjugate { result = result or can-unify(lt,c) };
100+
let ci2 = 0_sz;
101+
while ci2 < rconjugate.length {
102+
result = result or can-unify(lt,rconjugate[ci2]);
103+
if result then ci2 = rconjugate.length;
104+
else ci2 = ci2 + 1;
105+
};
106106
result
107107
);
108108

SRC/typecheck-infer-expr.lsts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -542,9 +542,7 @@ let std-infer-call-arg(tctx: TypeContext?, term: AST, function-name: CString, hi
542542
}} else if function-name==c"map::cons" { match term {
543543
App{k=left, m=right} => (
544544
(tctx, let new-k) = std-infer-expr(tctx, k, false, Call(function-name), ta);
545-
let direct-hint = if config-v3 or config-v23
546-
then t2(c"Hashtable",typeof-term(new-k).normalize.slot(c"Cons",2).l1,typeof-term(new-k).normalize.slot(c"Cons",2).l2) && t0(c"ReturnHint")
547-
else t2(c"HashtableEq",typeof-term(new-k).normalize.slot(c"Cons",2).l1,typeof-term(new-k).normalize.slot(c"Cons",2).l2);
545+
let direct-hint = t2(c"Hashtable",typeof-term(new-k).normalize.slot(c"Cons",2).l1,typeof-term(new-k).normalize.slot(c"Cons",2).l2) && t0(c"ReturnHint");
548546
(tctx, let new-m) = std-infer-expr(tctx, m, false, Used(), direct-hint);
549547
if not(is(k,new-k)) or not(is(m,new-m)) then { k = new-k; m = new-m; term = mk-cons(k, m); };
550548
tctx = tctx.ascript(term, t2(c"Cons",typeof-term(k),typeof-term(m)));

SRC/typecheck-phi-merge.lsts

Lines changed: 53 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,79 +2,84 @@
22
let worst-phi-length = 0_sz;
33

44
let phi-merge(tctx-globals: TypeContext?, tctx-primary: PBTree<U64,PhiContextRow>, tctx-secondary: PBTree<U64,PhiContextRow>, blame: AST): PBTree<U64,PhiContextRow> = (
5-
phi-merge-inner(tctx-globals, tctx-primary, tctx-secondary, blame, mk-vector(type(U64))).second.prune-moved
5+
phi-merge-inner(tctx-globals, tctx-primary, tctx-secondary, blame, mk-set(type(U64))).second
66
);
77

8-
9-
let phi-merge-inner(tctx-globals: TypeContext?, tctx-primary: PBTree<U64,PhiContextRow>, tctx-secondary: PBTree<U64,PhiContextRow>, blame: AST, seen: Vector<U64>): (Vector<U64>, PBTree<U64,PhiContextRow>) = (
8+
let phi-merge-inner(tctx-globals: TypeContext?, tctx-primary: PBTree<U64,PhiContextRow>, tctx-secondary: PBTree<U64,PhiContextRow>, blame: AST, seen: Set<U64>): (Set<U64>, PBTree<U64,PhiContextRow>) = (
109
match tctx-secondary {
1110
PBLeaf{} => (seen, tctx-primary);
1211
PBNode1{ k1=k1, tr=v1, left=left, right=right } => (
13-
(seen, tctx-primary) = phi-merge-inner(tctx-globals, tctx-primary, left, blame, seen);
14-
let sid = tr.phi-id-or-zero;
12+
let sid = k1;
1513
let st = tr.phi-tt-or-zero;
1614
let pblame = tr.blame-or-zero;
1715
let sdead-on-arrival = tr.dead-on-arrival-or-zero;
1816
let sis-global = tr.is-global-or-zero;
19-
if not(seen.contains(sid)) {
20-
let pt = tctx-primary.lookup(sid, NullPhiContextRow);
21-
if not(non-zero(pt)) then tctx-primary = tctx-primary.bind(sid, PhiContextRow(sid,st,pblame,sdead-on-arrival,sis-global));
22-
else if sdead-on-arrival or pt.dead-on-arrival-or-zero
23-
then {
24-
# This case happens if an ethereal variable gets copied and merged somehow, it doesn't really matter which one you pick but we prefer the moved one
25-
if not(pt.phi-tt-or-zero.is-linear-live) then ()
26-
else tctx-primary = tctx-primary.bind(sid, PhiContextRow(sid,st,blame,true,sis-global));
27-
} else (
28-
let rt = tctx-globals.phi-merge(pt.phi-tt-or-zero, st, blame);
29-
if not(is(pt.phi-tt-or-zero,rt)) then tctx-primary = tctx-primary.bind(sid, PhiContextRow(sid,rt,blame,false,sis-global));
30-
);
31-
seen = seen.push(sid);
17+
if not(seen.has(sid)) {
18+
if not st.is-linear-dead {
19+
let pt = tctx-primary.lookup(sid, NullPhiContextRow);
20+
if not(non-zero(pt)) then tctx-primary = tctx-primary.bind(sid, PhiContextRow(sid,st,pblame,sdead-on-arrival,sis-global));
21+
else if sdead-on-arrival or pt.dead-on-arrival-or-zero
22+
then {
23+
# This case happens if an ethereal variable gets copied and merged somehow, it doesn't really matter which one you pick but we prefer the moved one
24+
if not(pt.phi-tt-or-zero.is-linear-live) then ()
25+
else tctx-primary = tctx-primary.bind(sid, PhiContextRow(sid,st,blame,true,sis-global));
26+
} else (
27+
let rt = tctx-globals.phi-merge(pt.phi-tt-or-zero, st, blame);
28+
if not(is(pt.phi-tt-or-zero,rt)) then tctx-primary = tctx-primary.bind(sid, PhiContextRow(sid,rt,blame,false,sis-global));
29+
);
30+
};
31+
seen = seen.bind(sid);
3232
};
33+
(seen, tctx-primary) = phi-merge-inner(tctx-globals, tctx-primary, left, blame, seen);
3334
(seen, tctx-primary) = phi-merge-inner(tctx-globals, tctx-primary, right, blame, seen);
3435
(seen, tctx-primary)
3536
);
3637
PBNode2{ k12=k1, tr=v1, k22=k2, tr2=v2, left=left, mid=mid, right=right } => (
37-
(seen, tctx-primary) = phi-merge-inner(tctx-globals, tctx-primary, left, blame, seen);
38-
let sid = tr.phi-id-or-zero;
38+
let sid = k12;
3939
let st = tr.phi-tt-or-zero;
4040
let pblame = tr.blame-or-zero;
4141
let sdead-on-arrival = tr.dead-on-arrival-or-zero;
4242
let sis-global = tr.is-global-or-zero;
43-
if not(seen.contains(sid)) {
44-
let pt = tctx-primary.lookup(sid, NullPhiContextRow);
45-
if not(non-zero(pt)) then tctx-primary = tctx-primary.bind(sid, PhiContextRow(sid,st,pblame,sdead-on-arrival,sis-global));
46-
else if sdead-on-arrival or pt.dead-on-arrival-or-zero
47-
then {
48-
# This case happens if an ethereal variable gets copied and merged somehow, it doesn't really matter which one you pick but we prefer the moved one
49-
if not(pt.phi-tt-or-zero.is-linear-live) then ()
50-
else tctx-primary = tctx-primary.bind(sid, PhiContextRow(sid,st,blame,true,sis-global));
51-
} else (
52-
let rt = tctx-globals.phi-merge(pt.phi-tt-or-zero, st, blame);
53-
if not(is(pt.phi-tt-or-zero,rt)) then tctx-primary = tctx-primary.bind(sid, PhiContextRow(sid,rt,blame,false,sis-global));
54-
);
55-
seen = seen.push(sid);
43+
if not(seen.has(sid)) {
44+
if not st.is-linear-dead {
45+
let pt = tctx-primary.lookup(sid, NullPhiContextRow);
46+
if not(non-zero(pt)) then tctx-primary = tctx-primary.bind(sid, PhiContextRow(sid,st,pblame,sdead-on-arrival,sis-global));
47+
else if sdead-on-arrival or pt.dead-on-arrival-or-zero
48+
then {
49+
# This case happens if an ethereal variable gets copied and merged somehow, it doesn't really matter which one you pick but we prefer the moved one
50+
if not(pt.phi-tt-or-zero.is-linear-live) then ()
51+
else tctx-primary = tctx-primary.bind(sid, PhiContextRow(sid,st,blame,true,sis-global));
52+
} else (
53+
let rt = tctx-globals.phi-merge(pt.phi-tt-or-zero, st, blame);
54+
if not(is(pt.phi-tt-or-zero,rt)) then tctx-primary = tctx-primary.bind(sid, PhiContextRow(sid,rt,blame,false,sis-global));
55+
);
56+
};
57+
seen = seen.bind(sid);
5658
};
57-
(seen, tctx-primary) = phi-merge-inner(tctx-globals, tctx-primary, mid, blame, seen);
5859
tr = tr2;
59-
sid = tr.phi-id-or-zero;
60+
sid = k22;
6061
st = tr.phi-tt-or-zero;
6162
pblame = tr.blame-or-zero;
6263
sdead-on-arrival = tr.dead-on-arrival-or-zero;
6364
sis-global = tr.is-global-or-zero;
64-
if not(seen.contains(sid)) {
65-
let pt = tctx-primary.lookup(sid, NullPhiContextRow);
66-
if not(non-zero(pt)) then tctx-primary = tctx-primary.bind(sid, PhiContextRow(sid,st,pblame,sdead-on-arrival,sis-global));
67-
else if sdead-on-arrival or pt.dead-on-arrival-or-zero
68-
then {
69-
# This case happens if an ethereal variable gets copied and merged somehow, it doesn't really matter which one you pick but we prefer the moved one
70-
if not(pt.phi-tt-or-zero.is-linear-live) then ()
71-
else tctx-primary = tctx-primary.bind(sid, PhiContextRow(sid,st,blame,true,sis-global));
72-
} else (
73-
let rt = tctx-globals.phi-merge(pt.phi-tt-or-zero, st, blame);
74-
if not(is(pt.phi-tt-or-zero,rt)) then tctx-primary = tctx-primary.bind(sid, PhiContextRow(sid,rt,blame,false,sis-global));
75-
);
76-
seen = seen.push(sid);
65+
if not(seen.has(sid)) {
66+
if not st.is-linear-dead {
67+
let pt = tctx-primary.lookup(sid, NullPhiContextRow);
68+
if not(non-zero(pt)) then tctx-primary = tctx-primary.bind(sid, PhiContextRow(sid,st,pblame,sdead-on-arrival,sis-global));
69+
else if sdead-on-arrival or pt.dead-on-arrival-or-zero
70+
then {
71+
# This case happens if an ethereal variable gets copied and merged somehow, it doesn't really matter which one you pick but we prefer the moved one
72+
if not(pt.phi-tt-or-zero.is-linear-live) then ()
73+
else tctx-primary = tctx-primary.bind(sid, PhiContextRow(sid,st,blame,true,sis-global));
74+
} else (
75+
let rt = tctx-globals.phi-merge(pt.phi-tt-or-zero, st, blame);
76+
if not(is(pt.phi-tt-or-zero,rt)) then tctx-primary = tctx-primary.bind(sid, PhiContextRow(sid,rt,blame,false,sis-global));
77+
);
78+
};
79+
seen = seen.bind(sid);
7780
};
81+
(seen, tctx-primary) = phi-merge-inner(tctx-globals, tctx-primary, left, blame, seen);
82+
(seen, tctx-primary) = phi-merge-inner(tctx-globals, tctx-primary, mid, blame, seen);
7883
(seen, tctx-primary) = phi-merge-inner(tctx-globals, tctx-primary, right, blame, seen);
7984
(seen, tctx-primary)
8085
);

SRC/unit-main-core.lsts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ let ast-typed-count = 0_sz;
3737
let config-print-ast = false;
3838

3939
let main(argc: C_int, argv: CString[]): Nil = (
40-
config-v23 = false;
4140
let argi = 1_sz;
4241
let input = [] : List<CString>;
4342
let highlight = false;
@@ -50,11 +49,6 @@ let main(argc: C_int, argv: CString[]): Nil = (
5049
c"--parse" => config-mode = ModeParse();
5150
c"--preprocess" => config-mode = ModePreprocess();
5251
c"--compile" => config-mode = ModeCompile();
53-
c"--v0" => (config-v3 = false; config-v0 = true;);
54-
c"--v1" => (config-v3 = false; config-v1 = true;);
55-
c"--v2" => config-v3 = false;
56-
c"--v23" => (config-v3 = false; config-v23 = true;);
57-
c"--v3" => config-v3 = true;
5852
c"--highlight" => (
5953
config-mode = ModeTokenize();
6054
highlight = true;

tests/regress.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ fn run_bootstrap(target: &str, leave_tmp: bool, is_v3: bool) -> String {
3838
let exit = Command::new("./bootstrap.exe")
3939
.stdout(std::process::Stdio::piped())
4040
.stderr(std::process::Stdio::piped())
41-
.arg("--v3")
4241
.arg("-o")
4342
.arg("tmp.c")
4443
.arg(target)

0 commit comments

Comments
 (0)