Analyze closure bodies in the class context they actually run in
commitec3f2035a12889637303a7b9f8d347f4a7b55421
authorJordan DeLong <jdelong@fb.com>
Fri, 24 Jan 2014 02:23:03 +0000 (23 18:23 -0800)
committerSara Golemon <sgolemon@fb.com>
Tue, 4 Feb 2014 17:22:49 +0000 (4 09:22 -0800)
tree7f19b70fcd09d19aeca1ed7d326d16171e8d55ae
parentb6105cb17295ed55bf5400f5b10c6059e24d0583
Analyze closure bodies in the class context they actually run in

Closure bodies run in the context of the class that allocated
them.  Previously, we were giving up on private and static property
inference in any class that allocated closures because we couldn't see
the closure bodies as part of class-at-a-time analysis (and couldn't
take their effects into account).  This diff hooks that up, and also
adds links between inner and outer generators (which should probably
be helpful for other things later).

After this diff, we still give up on classes containing closures that
contain yield.  Classes with async function closures are working in a
slightly strange way: we essentially only analyze the "eager" version
for its effects on $this and self.  I think this is fine for now, but
it's relying on a bunch of undocumented invariants (essentially it's
relying on the fact that the two function bodies "do the same thing"):
@jano is planning to combine the bytecode bodies for async functions so
we probably don't need to worry too about documenting all that in the
spec until the implementation stabilizes more.

Reviewed By: @bertmaher

Differential Revision: D1143994
30 files changed:
hphp/hhbbc/abstract-interp.cpp
hphp/hhbbc/abstract-interp.h
hphp/hhbbc/check.cpp
hphp/hhbbc/debug.h
hphp/hhbbc/emit.cpp
hphp/hhbbc/index.cpp
hphp/hhbbc/index.h
hphp/hhbbc/parse.cpp
hphp/hhbbc/representation.h
hphp/hhbbc/show.cpp
hphp/hhbbc/whole-program.cpp
hphp/runtime/vm/class.h
hphp/test/slow/hhbbc/closure_context_001.php [new file with mode: 0644]
hphp/test/slow/hhbbc/closure_context_001.php.expect [new file with mode: 0644]
hphp/test/slow/hhbbc/closure_context_002.php [new file with mode: 0644]
hphp/test/slow/hhbbc/closure_context_002.php.expect [new file with mode: 0644]
hphp/test/slow/hhbbc/closure_context_003.php [new file with mode: 0644]
hphp/test/slow/hhbbc/closure_context_003.php.expect [new file with mode: 0644]
hphp/test/slow/hhbbc/closure_context_004.php [new file with mode: 0644]
hphp/test/slow/hhbbc/closure_context_004.php.expect [new file with mode: 0644]
hphp/test/slow/hhbbc/closure_context_005.php [new file with mode: 0644]
hphp/test/slow/hhbbc/closure_context_005.php.expect [new file with mode: 0644]
hphp/test/slow/hhbbc/closure_context_006.php [new file with mode: 0644]
hphp/test/slow/hhbbc/closure_context_006.php.expect [new file with mode: 0644]
hphp/test/slow/hhbbc/closure_context_007.php [new file with mode: 0644]
hphp/test/slow/hhbbc/closure_context_007.php.expect [new file with mode: 0644]
hphp/test/slow/hhbbc/trait_generator_closure_001.php [new file with mode: 0644]
hphp/test/slow/hhbbc/trait_generator_closure_001.php.expect [new file with mode: 0644]
hphp/test/slow/hhbbc/trait_generator_closure_002.php [new file with mode: 0644]
hphp/test/slow/hhbbc/trait_generator_closure_002.php.expect [new file with mode: 0644]