Fix multifile ordering dependent decl behavior
commitc81554ec82f04c431e8e4a160497ce7ec0a227db
authorThomas Jiang <thomasjiang@fb.com>
Wed, 21 Sep 2022 17:07:19 +0000 (21 10:07 -0700)
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
Wed, 21 Sep 2022 17:07:19 +0000 (21 10:07 -0700)
treeba28e12c538ab7dd1cd25638a4a609ef80004deb
parent5e0b72357b85cbfb7921948acc3509d24677fbf4
Fix multifile ordering dependent decl behavior

Summary:
In the diff below this, I demonstrate the issue - "multifile single file" tests are subject to ordering differences in OCaml in our "rupro vs ocaml decl comparison" binary.

This diff corrects this behavior in our binary.

The ordering dependent behavior occurs here:

```
      (* Compute OCaml folded decls *)
      List.iter files ~f:(fun filename ->
          Errors.run_in_context filename Errors.Decl (fun () ->
              Decl.make_env ~sh:SharedMem.Uses ctx filename));
```

`Decl.make_env` is stateful, as it does a parse and decl and fold of the file and then updates the global state with the decls. This global state is then used in the next `Decl.make_env` call. This means that the files passed in first to `Decl.make_env` provide the decls for the later files passed in.

This is opposed to the Rust behavior:

https://www.internalfb.com/code/fbsource/[dcfed651fdd7]/fbcode/hphp/hack/src/hackrs/decl_folded_class_ffi.rs?lines=88-106

Where we parse all of the files for decls and then update the shallow decl store. Then we fold all of the decls once the shallow decl store has all of the decls.

The OCaml behavior should match the rust behavior, which this diff addresses. We will first parse and decl all of the files - and then, once we have done this to all of the files, we will attempt to fold them.

Reviewed By: panopticoncentral

Differential Revision: D39672218

fbshipit-source-id: 16b16434036378e13ce6c9e3c0d58067576b4e3d
hphp/hack/src/compare_folded_decls_file.ml
hphp/hack/test/typecheck/inheritance/multifile_decl_ordering.php.rupro_folded_decl.exp [deleted file]