Use worklist inside analyze_class
commitc274e08ee1eb6a9b3ab765b216a5c629a09fdee3
authorRick Lavoie <rlavoie@fb.com>
Thu, 29 Apr 2021 04:57:39 +0000 (28 21:57 -0700)
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
Thu, 29 Apr 2021 05:00:47 +0000 (28 22:00 -0700)
treea983241313c252e654fe287c7ac403788fdc7780
parentf85534345c11032e40d4c6a4f7405737f55f6caf
Use worklist inside analyze_class

Summary:
Inside analyze_class(), we loop until all private properties have
reached a fixed point. However we don't use a worklist, we re-analyze
every method over and over. This is inefficient, since most methods
will not be accessing that property. Reduce the number of re-analyzes
by using an explicit worklist. If we access a private property during
analyze, we record a dependency on that property by that
function. Whenever the property's type changes, we re-schedule any
function with a dependency on it. We keep analyzing until the worklist
is empty.

Note: these dependencies are different than the one in the Index. This
dependencies only related methods on the particular class being
analyzed, to private properties on the same class. Once
analyze_class() is over, these dependencies are thrown away.

As another optimization, do a pass over all properties before
analysis. Compute whether their initial values can violate their
type-hint initially. This is superior to defaulting to "true" and
letting normal analysis update it. The vast majority of properties
will have a "false" value initially, so it just causes another round
of analysis. This is similar to how we pre-compute return types (for
the same reason).

Differential Revision: D28024817

fbshipit-source-id: bf071fcc4d8f271c74cc66629b36a3a7bbc1036f
hphp/hhbbc/analyze.cpp
hphp/hhbbc/analyze.h
hphp/hhbbc/class-util.cpp
hphp/hhbbc/class-util.h
hphp/hhbbc/index.cpp
hphp/hhbbc/index.h
hphp/hhbbc/interp-internal.h
hphp/hhbbc/interp-minstr.cpp
hphp/hhbbc/interp-state.cpp
hphp/hhbbc/interp-state.h
hphp/hhbbc/whole-program.cpp