Skip to content

Commit 851f342

Browse files
authored
Merge branch 'dev' into fix-2099
2 parents abe9c7b + 062397c commit 851f342

File tree

2 files changed

+45
-30
lines changed

2 files changed

+45
-30
lines changed

src/language/dynamics/transition/Ascriptions.re

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,10 @@ let rec transition = (~recursive=false, d: DHExp.t): option(DHExp.t) => {
2727
switch (DHExp.term_of(d)) {
2828
| Asc(e, t) =>
2929
switch (DHExp.term_of(e), Typ.term_of(Typ.unroll(t))) {
30-
| (Asc(e, t'), t)
30+
| (Asc(e, t'), _)
3131
// This is only necessary because sometimes we add two ascriptions and aren't marking it as a non-value
32-
when
33-
Typ.is_consistent(
34-
Ctx.empty,
35-
Typ.unroll(t |> Typ.temp),
36-
Typ.unroll(t'),
37-
) =>
38-
switch (
39-
Typ.meet(Ctx.empty, Typ.unroll(t |> Typ.temp), Typ.unroll(t'))
40-
) {
32+
when Typ.is_consistent(Ctx.empty, Typ.unroll(t), Typ.unroll(t')) =>
33+
switch (Typ.meet(Ctx.empty, Typ.unroll(t), Typ.unroll(t'))) {
4134
| Some(t) => Some(recur(Asc(e, t) |> DHExp.fresh))
4235
| None => None //TODO This is an impossible case since we checked consistency
4336
}
@@ -133,26 +126,26 @@ let rec transition = (~recursive=false, d: DHExp.t): option(DHExp.t) => {
133126
|> DHExp.fresh,
134127
),
135128
);
136-
| (If(cond, e1, e2), t) =>
129+
| (If(cond, e1, e2), _) =>
137130
Some(
138131
IdTagged.fast_copy(
139132
DHExp.rep_id(e),
140133
If(
141134
recur(cond),
142-
recur(Asc(e1, t |> Typ.temp) |> DHExp.fresh),
143-
recur(Asc(e2, t |> Typ.temp) |> DHExp.fresh),
135+
recur(Asc(e1, t) |> DHExp.fresh),
136+
recur(Asc(e2, t) |> DHExp.fresh),
144137
)
145138
|> DHExp.fresh,
146139
),
147140
)
148-
| (Match(scrut, rules), t) =>
141+
| (Match(scrut, rules), _) =>
149142
Some(
150143
IdTagged.fast_copy(
151144
DHExp.rep_id(e),
152145
Match(
153146
scrut,
154147
List.map(
155-
((p, body)) => (p, Asc(body, t |> Typ.temp) |> DHExp.fresh),
148+
((p, body)) => (p, Asc(body, t) |> DHExp.fresh),
156149
rules,
157150
),
158151
)

test/evaluator/Test_Evaluator_Sum_Types.re

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,47 @@ let tests = (
2828
)
2929
}),
3030
test_case(
31-
"Constructors can pass through consistent ascriptions", `Quick, () => {
32-
evaluation_test(
33-
{|A : (+A +B) : (+A + ?)|},
34-
constructor(
35-
"A",
36-
Some(
31+
"Constructors can pass through consistent ascriptions",
32+
`Quick,
33+
() => {
34+
evaluation_test(
35+
{|A : (+A +B) : (+A + ?)|},
36+
constructor(
37+
"A",
3738
Some(
38-
Typ.(
39-
sum([
40-
Variant("A", ConstructorMap.empty_variant_ann, None),
41-
Variant("B", ConstructorMap.empty_variant_ann, None),
42-
])
39+
Some(
40+
Typ.(
41+
sum([
42+
Variant("A", ConstructorMap.empty_variant_ann, None),
43+
Variant("B", ConstructorMap.empty_variant_ann, None),
44+
])
45+
),
4346
),
4447
),
4548
),
46-
),
47-
elaborate(parse_exp({|A : (+A +B) : (+A + ?)|})),
48-
)
49-
}),
49+
elaborate(parse_exp({|A : (+A +B) : (+A + ?)|})),
50+
);
51+
evaluation_test(
52+
"Ascriptions don't do unnecessary unrolling",
53+
asc(
54+
empty_hole(),
55+
Typ.rec_(
56+
TPat.var("X"),
57+
Typ.sum([
58+
Variant(
59+
"A",
60+
ConstructorMap.empty_variant_ann,
61+
Some(Typ.var("X")),
62+
),
63+
]),
64+
),
65+
),
66+
elaborate(
67+
parse_exp("(if true then ? else ?) : (rec X -> + A(X))"),
68+
),
69+
);
70+
},
71+
),
5072
test_case(
5173
"Constructors don't pass through inconsistent ascriptions", `Quick, () => {
5274
evaluation_test(

0 commit comments

Comments
 (0)