Skip to content

Commit

Permalink
Avoid recursing twice on the arguments.
Browse files Browse the repository at this point in the history
  • Loading branch information
maximebuyse committed Sep 4, 2024
1 parent c707da1 commit 6ed4f9e
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 6ed4f9e

Please sign in to comment.