From 2440ee69aeac5d7adeaf79b77dd2ae72dc38e4da Mon Sep 17 00:00:00 2001 From: Josh Berdine Date: Mon, 10 Jun 2019 07:18:22 -0700 Subject: [PATCH] [sledge] Preserve sharing of Func.parent Summary: Previously the locals of a function were computed after backpatching the blocks in its cfg. This resulted in loss of sharing, and incorrect locals if queried through the parent of a block. Reviewed By: kren1 Differential Revision: D15738027 fbshipit-source-id: d7e70530a --- sledge/src/llair/llair.ml | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/sledge/src/llair/llair.ml b/sledge/src/llair/llair.ml index 29122d23d..00edb1d44 100644 --- a/sledge/src/llair/llair.ml +++ b/sledge/src/llair/llair.ml @@ -397,6 +397,7 @@ module Func = struct let invariant func = Invariant.invariant [%here] func [%sexp_of: t] @@ fun () -> + assert (func == func.entry.parent) ; let {name= {typ}; cfg} = func in match typ with | Pointer _ -> @@ -416,6 +417,11 @@ module Func = struct let find functions name = Map.find functions name let mk ~name ~entry ~cfg = + let locals = + Vector.fold ~init:entry.locals cfg ~f:(fun locals block -> + Set.union locals block.locals ) + in + let entry = {entry with locals} in let func = {name; entry; cfg} in let resolve_parent_and_jumps block = block.parent <- func ; @@ -434,12 +440,8 @@ module Func = struct | Return _ | Throw _ | Unreachable -> () in resolve_parent_and_jumps entry ; - let locals = - Vector.fold ~init:entry.locals cfg ~f:(fun locals block -> - resolve_parent_and_jumps block ; - Set.union locals block.locals ) - in - {func with entry= {entry with locals}} |> check invariant + Vector.iter cfg ~f:resolve_parent_and_jumps ; + func |> check invariant let mk_undefined ~name ~params = let entry =