Skip to content

Commit

Permalink
Merge pull request #877 from hacspec/fix-exponential-visiting-in-spec…
Browse files Browse the repository at this point in the history
…ialize

Avoid recursing twice on the arguments.
  • Loading branch information
franziskuskiefer authored Sep 4, 2024
2 parents c707da1 + 6ed4f9e commit 46ea40a
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions engine/lib/phases/phase_specialize.ml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,14 @@ module Make (F : Features.T) =

method! visit_expr () e =
match e.e with
| App { f = { e = GlobalVar f; _ } as f'; args = l; _ } -> (
| App
{
f = { e = GlobalVar f; _ } as f';
args = l;
trait;
generic_args;
bounds_impls;
} -> (
let l = List.map ~f:(self#visit_expr ()) l in
let matching =
List.filter patterns ~f:(fun { fn; args; _ } ->
Expand All @@ -139,7 +146,32 @@ module Make (F : Features.T) =
bounds_impls = [];
};
}
| [] -> super#visit_expr () e
| [] -> (
(* In this case we need to avoid recursing again through the arguments *)
let visited =
super#visit_expr ()
{
e with
e =
App
{
f = f';
args = [];
trait;
generic_args;
bounds_impls;
};
}
in
match visited.e with
| App { f; trait; generic_args; bounds_impls; _ } ->
{
visited with
e =
App
{ f; args = l; trait; generic_args; bounds_impls };
}
| _ -> super#visit_expr () e)
| _ ->
Error.assertion_failure e.span
"Found multiple matching patterns")
Expand Down

0 comments on commit 46ea40a

Please sign in to comment.