Skip to content

Commit

Permalink
Fix convergence condition for loops
Browse files Browse the repository at this point in the history
Summary:
We were only looking for stability of the Next continuation to establish that the typing environment reached a fixpoint. This is unsound.

This diff fixes it by looking for stability of all continuations.

Reviewed By: andrewjkennedy

Differential Revision: D36345984

fbshipit-source-id: ade3cdca30f0e28393d6b1e93c5b3a43e701aad9
  • Loading branch information
madgen authored and facebook-github-bot committed May 13, 2022
1 parent 7becd74 commit c9f8eeb
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 8 deletions.
18 changes: 11 additions & 7 deletions hphp/hack/src/typing/typing.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2289,17 +2289,21 @@ and stmt_ env pos st =
let env = { env with in_loop = true } in
let rec loop env n =
(* Remember the old environment *)
let old_next_entry = Env.next_cont_opt env in
let old_conts = env.lenv.per_cont_env in
let (env, result) = f env in
let new_next_entry = Env.next_cont_opt env in
let new_conts = env.lenv.per_cont_env in
(* Finish if we reach the bound, or if the environments match *)
if
Int.equal n alias_depth
|| Typing_per_cont_ops.is_sub_opt_entry
Typing_subtype.is_sub_type
env
new_next_entry
old_next_entry
|| CMap.for_all2
~f:(fun _ old_cont_entry new_cont_entry ->
Typing_per_cont_ops.is_sub_opt_entry
Typing_subtype.is_sub_type
env
new_cont_entry
old_cont_entry)
old_conts
new_conts
then
let env = { env with in_loop = in_loop_outer } in
(env, result)
Expand Down
File renamed without changes.
4 changes: 4 additions & 0 deletions hphp/hack/test/typecheck/T120247995.php.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
File "T120247995.php", line 10, characters 13-16:
You are trying to access the method `ohno` but this is an int (Typing[4062])
File "interfaces.hhi", line 92, characters 46-47:
Definition is here
8 changes: 8 additions & 0 deletions hphp/hack/test/typecheck/control_flow/lambda.php.exp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ File "lambda.php", line 51, characters 11-21:[2]
[unresolved]
File "lambda.php", line 71, characters 9-19:[2]
([unresolved] | exact D | exact G | exact J)
File "lambda.php", line 23, characters 5-15:[3]
(exact A | exact B | exact C)
File "lambda.php", line 24, characters 5-15:[3]
(exact A | exact B | exact C)
File "lambda.php", line 51, characters 11-21:[3]
[unresolved]
File "lambda.php", line 71, characters 9-19:[3]
([unresolved] | exact D | exact G | exact J)
File "lambda.php", line 86, characters 3-13:
(exact A | exact B | exact C | exact E)
File "lambda.php", line 87, characters 3-13:
Expand Down
1 change: 0 additions & 1 deletion hphp/hack/test/typecheck/typehole/T120247995.php.exp

This file was deleted.

0 comments on commit c9f8eeb

Please sign in to comment.