Skip to content

Commit

Permalink
Fixed singleton labeled tuple in function application
Browse files Browse the repository at this point in the history
  • Loading branch information
7h3kk1d committed Nov 4, 2024
1 parent 8d3d3e6 commit 12eef70
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 56 deletions.
61 changes: 10 additions & 51 deletions src/haz3lcore/dynamics/Elaborator.re
Original file line number Diff line number Diff line change
Expand Up @@ -18,59 +18,18 @@ module ElaborationResult = {
| DoesNotElaborate;
};

let rec fresh_cast = (d: DHExp.t, t1: Typ.t, t2: Typ.t): DHExp.t => {
switch (t1.term) {
| Label(_) =>
// TODO Remove duplication in cases
Typ.eq(t1, t2)
? d
: {
let d' =
DHExp.Cast(d, t1, Typ.temp(Unknown(Internal)))
|> DHExp.fresh
|> Casts.transition_multiple;
DHExp.Cast(d', Typ.temp(Unknown(Internal)), t2)
let fresh_cast = (d: DHExp.t, t1: Typ.t, t2: Typ.t): DHExp.t => {
Typ.eq(t1, t2)
? d
: {
let d' =
DHExp.Cast(d, t1, Typ.temp(Unknown(Internal)))
|> DHExp.fresh
|> Casts.transition_multiple;
} // These should be a different sort. I don't think we should be casting them.
| _ =>
switch (t2.term) {
| Prod([{term: TupLabel({term: Label(l), _}, t), _}]) =>
switch (t1.term) {
| Prod([{term: TupLabel({term: Label(l'), _}, _), _}]) when l == l' =>
Typ.eq(t1, t2)
? d
: {
let d' =
DHExp.Cast(d, t1, Typ.temp(Unknown(Internal)))
|> DHExp.fresh
|> Casts.transition_multiple;
DHExp.Cast(d', Typ.temp(Unknown(Internal)), t2)
|> DHExp.fresh
|> Casts.transition_multiple;
}
| _ =>
Tuple([
TupLabel(Label(l) |> DHExp.fresh, fresh_cast(d, t1, t))
|> DHExp.fresh,
])
|> DHExp.fresh
}
| _ =>
// TODO Remove duplication in cases
Typ.eq(t1, t2)
? d
: {
let d' =
DHExp.Cast(d, t1, Typ.temp(Unknown(Internal)))
|> DHExp.fresh
|> Casts.transition_multiple;
DHExp.Cast(d', Typ.temp(Unknown(Internal)), t2)
|> DHExp.fresh
|> Casts.transition_multiple;
}
}
};
DHExp.Cast(d', Typ.temp(Unknown(Internal)), t2)
|> DHExp.fresh
|> Casts.transition_multiple;
};
};

let fresh_pat_cast = (p: DHPat.t, t1: Typ.t, t2: Typ.t): DHPat.t => {
Expand Down
12 changes: 7 additions & 5 deletions src/haz3lcore/statics/Statics.re
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ and uexp_to_info_map =
);
let go_pat = upat_to_info_map(~ctx, ~ancestors);
let elaborate_singleton_tuple = (uexp: Exp.t, inner_ty, l, m) => {
print_endline("Elaborating singleton tuple");
let (term, rewrap) = UExp.unwrap(uexp);
let original_expression = Exp.fresh(term);
let (original_info, m) =
Expand Down Expand Up @@ -484,11 +485,12 @@ and uexp_to_info_map =
copied: arg.copied,
};
arg;
| (TupLabel(_), Prod([{term: TupLabel(_), _}])) =>
Tuple([arg]) |> Exp.fresh
| (_, Prod([{term: TupLabel({term: Label(name), _}, _), _}])) =>
Tuple([TupLabel(Label(name) |> Exp.fresh, arg) |> Exp.fresh])
|> Exp.fresh
// Now doing the singleton label elaboration below. I'll discuss with Anthony before removing these
// | (TupLabel(_), Prod([{term: TupLabel(_), _}])) =>
// Tuple([arg]) |> Exp.fresh
// | (_, Prod([{term: TupLabel({term: Label(name), _}, _), _}])) =>
// Tuple([TupLabel(Label(name) |> Exp.fresh, arg) |> Exp.fresh])
// |> Exp.fresh
| (_, _) => arg
};
let (arg, m) = go(~mode=Ana(ty_in), arg, m);
Expand Down
50 changes: 50 additions & 0 deletions test/Test_Statics.re
Original file line number Diff line number Diff line change
Expand Up @@ -627,4 +627,54 @@ let tests =
),
parse_exp({|let x : (a=b=c=?) = b=? in x|}),
),
fully_consistent_typecheck(
"Singleton labeled argument function application with unknown type",
{|(fun a=x->x)(a=1)|},
Some(unknown(Internal)),
Ap(
Forward,
Fun(
Tuple([
TupLabel(Label("a") |> Pat.fresh, Var("x") |> Pat.fresh)
|> Pat.fresh,
])
|> Pat.fresh,
Var("x") |> Exp.fresh,
None,
None,
)
|> Exp.fresh,
Tuple([
TupLabel(Label("a") |> Exp.fresh, Int(1) |> Exp.fresh)
|> Exp.fresh,
])
|> Exp.fresh,
)
|> Exp.fresh,
),
fully_consistent_typecheck(
"Singleton labeled argument function application with no labeled param",
{|(fun a=x->x)(1)|},
Some(int),
Ap(
Forward,
Fun(
Tuple([
TupLabel(Label("a") |> Pat.fresh, Var("x") |> Pat.fresh)
|> Pat.fresh,
])
|> Pat.fresh,
Var("x") |> Exp.fresh,
None,
None,
)
|> Exp.fresh,
Tuple([
TupLabel(Label("a") |> Exp.fresh, Int(1) |> Exp.fresh)
|> Exp.fresh,
])
|> Exp.fresh,
)
|> Exp.fresh,
),
];

0 comments on commit 12eef70

Please sign in to comment.