Use closure names, not ids for CreateCl
commitbbd98fa80b68063127d0eed396a2e4a7632aaa49
authorRick Lavoie <rlavoie@fb.com>
Sun, 21 Aug 2022 22:58:56 +0000 (21 15:58 -0700)
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
Sun, 21 Aug 2022 22:58:56 +0000 (21 15:58 -0700)
treecc5e37bf87712b20cc75f47c920e37f5961ff080
parent47c4f4605fd67b79c4b5e42367f2f1348812e1e1
Use closure names, not ids for CreateCl

Summary:
All classes have an id, which is their index into their unit's
pre-class table. The only real use of this id is to represent a
closure in the CreateCl bytecode. This works because closures are always
stored in the same unit from which they're used.

However, the id is problematic because it's global to the unit, so
anything which wants to process things on a class level (like
distributed trait flattening) need to coordinate somehow.

Instead, change CreateCl to store the closure's name instead. Unlike
the id, the name is globally unique, so does not require
coordination. With this, we no longer need to store the id in the
pre-class anymore (which saves some space), and also simplifies some
logic during trait flattening and bytecode emission.

Note: this changes the logic for renaming closures a bit. We don't
bother with the hash of the unit name anymore, as simply appending the
destination class is enough to guarantee uniqueness.

Add some sanity check around the CreateCl bytecode to avoid invalid
things, like referring to non-closures, or closures outside of the
unit. This includes improved verifier logic.

I had to modify the Rust code to have it emit the name instead of the
id, but this lead to a rabbit-hole of "unused parameter" and like
errors, which required me to change way more than I really wanted.

Reviewed By: jano, edwinsmith

Differential Revision: D38890884

fbshipit-source-id: 03b86032b161abf866f801e3976f04168842a4e1
54 files changed:
hphp/compiler/compiler.cpp
hphp/compiler/package.cpp
hphp/hack/src/hackc/bytecode_printer/print_opcode.rs
hphp/hack/src/hackc/compile/closure_convert.rs
hphp/hack/src/hackc/emitter/emit_expression.rs
hphp/hack/src/hackc/emitter/instruction_sequence.rs
hphp/hack/src/hackc/hackc/assemble.rs
hphp/hack/src/hackc/hhbc/opcodes.rs
hphp/hack/src/hackc/ir/conversions/bc_to_ir/instrs.rs
hphp/hack/src/hackc/ir/conversions/ir_to_bc/class.rs
hphp/hack/src/hackc/ir/conversions/ir_to_bc/convert.rs
hphp/hack/src/hackc/ir/conversions/ir_to_bc/emitter.rs
hphp/hack/src/hackc/ir/conversions/ir_to_bc/func.rs
hphp/hack/src/hackc/sem_diff/body.rs
hphp/hack/src/hackc/sem_diff/sem_diff.rs
hphp/hack/src/hackc/sem_diff/state.rs
hphp/hack/src/hackc/sem_diff/work_queue.rs
hphp/hhbbc/emit.cpp
hphp/hhbbc/func-util.cpp
hphp/hhbbc/func-util.h
hphp/hhbbc/index.cpp
hphp/hhbbc/index.h
hphp/hhbbc/interp.cpp
hphp/hhbbc/parse.cpp
hphp/hhbbc/representation.cpp
hphp/hhbbc/representation.h
hphp/runtime/vm/as.cpp
hphp/runtime/vm/bytecode.cpp
hphp/runtime/vm/hackc-translator.cpp
hphp/runtime/vm/jit/irgen-create.cpp
hphp/runtime/vm/jit/prof-data-serialize.cpp
hphp/runtime/vm/opcodes.h
hphp/runtime/vm/preclass-emitter.cpp
hphp/runtime/vm/preclass-emitter.h
hphp/runtime/vm/preclass.cpp
hphp/runtime/vm/preclass.h
hphp/runtime/vm/repo-autoload-map-builder.cpp
hphp/runtime/vm/unit-emitter-inl.h
hphp/runtime/vm/unit-emitter.cpp
hphp/runtime/vm/unit-emitter.h
hphp/runtime/vm/unit-inl.h
hphp/runtime/vm/unit.h
hphp/runtime/vm/verifier/check-func.cpp
hphp/runtime/vm/verifier/check-unit.cpp
hphp/runtime/vm/verifier/check.h
hphp/runtime/vm/verifier/util.h
hphp/test/quick/asm_closure.hhas
hphp/test/quick/createcl.hhas
hphp/test/quick/createcl.hhas.expectf
hphp/test/quick/def_oob.hhas
hphp/test/quick/def_oob.hhas.expectf
hphp/test/slow/traits/flatten-stress.php [new file with mode: 0644]
hphp/test/slow/traits/flatten-stress.php.expect [new file with mode: 0644]
hphp/tools/hhbc-gen/hhbc.rs