Decrease size of Expr and Ty and derive Copy
commita20f5a88962e89d399a4cf894752761cc0440bc3
authorJake Bailey (Hacklang) <jakebailey@fb.com>
Wed, 29 Apr 2020 22:48:52 +0000 (29 15:48 -0700)
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
Thu, 30 Apr 2020 21:24:12 +0000 (30 14:24 -0700)
treec9b21419bf10341456704717163c6916e4c73679
parent9d9d1419925b9994eeb9052a2859aba95df9ad78
Decrease size of Expr and Ty and derive Copy

Summary:
As discussed on {D21048807}, while the [general guidance for when to implement Copy](https://doc.rust-lang.org/std/marker/trait.Copy.html#when-should-my-type-be-copy) suggests that any type that *can* be Copy *should* be, not implementing Copy on large structs can be a helpful bumper reducing the incidence of accidental perf regressions (even if it doesn't *prevent* copying the large struct, since the compiler may still emit memcpys to implement moves). As a result, in this diff, we implement Copy only for a few small (i.e., with a size of three words or less) types for which a Copy implementation is convenient in the direct-decl-parser.

To reduce the size of Ty_ to three words, I boxed each variant's fields (as we do with aast::Expr_, aast::Stmt_, etc). To reduce the size of Ty to two words, I put the typing reason behind a reference. To reduce the size of Expr (as well as many other types), I removed the implementation of Copy from Pos, and always put it behind a reference (although it is only three words, positions are often copied into several places. Also, without the reference, larger structs can end up inlining several positions, paying that two-word overhead many times over).

Differential Revision: D21144457

fbshipit-source-id: f34b03b0ebf2d3a3fe572e71d6395517145d9a9b
15 files changed:
hphp/hack/src/hh_oxidize/convert_type.ml
hphp/hack/src/hh_oxidize/convert_type_decl.ml
hphp/hack/src/oxidized_by_ref/gen/aast.rs
hphp/hack/src/oxidized_by_ref/gen/aast_defs.rs
hphp/hack/src/oxidized_by_ref/gen/ast_defs.rs
hphp/hack/src/oxidized_by_ref/gen/decl_defs.rs
hphp/hack/src/oxidized_by_ref/gen/errors.rs
hphp/hack/src/oxidized_by_ref/gen/file_info.rs
hphp/hack/src/oxidized_by_ref/gen/nast.rs
hphp/hack/src/oxidized_by_ref/gen/scoured_comments.rs
hphp/hack/src/oxidized_by_ref/gen/shallow_decl_defs.rs
hphp/hack/src/oxidized_by_ref/gen/typing_defs.rs
hphp/hack/src/oxidized_by_ref/gen/typing_defs_core.rs
hphp/hack/src/oxidized_by_ref/gen/typing_reason.rs
hphp/hack/src/oxidized_by_ref/manual/pos.rs