Skip to content

Commit

Permalink
Tweak default implementation of array_cow_set to await discarded value
Browse files Browse the repository at this point in the history
Reviewed By: davidpichardie

Differential Revision: D52017880

fbshipit-source-id: ebd7d5d678619256cabf185fcd83dc9498638b43
  • Loading branch information
Nick Benton authored and facebook-github-bot committed Dec 11, 2023
1 parent 0bab3b8 commit cfedb47
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions infer/src/pulse/PulseModelsDSL.ml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ module Syntax = struct
Option.value_map o ~default:(ret ()) ~f


let ignore (m : 'a model_monad) : unit model_monad =
let* _ = m in
ret ()


let get_data : model_data model_monad = fun data astate -> ret data data astate

let ok x = Ok x
Expand Down
2 changes: 2 additions & 0 deletions infer/src/pulse/PulseModelsDSL.mli
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ module Syntax : sig

val option_iter : 'a option -> f:('a -> unit model_monad) -> unit model_monad

val ignore : 'a model_monad -> unit model_monad

val assign_ret : aval -> unit model_monad
(** assign the value to the return variable of the current function *)

Expand Down
3 changes: 3 additions & 0 deletions infer/src/pulse/PulseModelsHack.ml
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,9 @@ let hack_array_cow_set this args : model =
let this = payload_of_arg this in
let args = payloads_of_args args in
let default () =
let* () =
option_iter (List.last args) ~f:(fun value_written -> ignore (await_hack_value value_written))
in
let* fresh = mk_fresh ~model_desc:"hack_array_cow_set" () in
assign_ret fresh
in
Expand Down
5 changes: 5 additions & 0 deletions infer/tests/codetoanalyze/hack/pulse/asyncvec.hack
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,8 @@ async function vecupdateFN(): Awaitable<void> {
await $v[1];
await $v[0];
}

async function nodynamictypeOK(mixed $c): Awaitable<void> {
$c[0] = genInt3();
await ($c[0]);
}

0 comments on commit cfedb47

Please sign in to comment.