facebook/hhvm — pull request #2639 by Aatch (2014-05-08 23:54:44+00:00)
Title: Check to see if the RHS of a type alias exists before attempting to load it.

The specific case encountered was in BeatBox, where we rebuild the map on failure so any changes are picked up. The failure handler was being called for `hh\vector`, `hh\immvector` and other collections, but the kind was "type", not class, this caused us to rebuild the map multiple times per request, slowing it down a lot.

More generally, a failure handler might treat any missing symbol as an unrecoverable error and abort the request immediately, and while that's not completely prevented by this patch, sending speculative requests for symbols we *know* exist is Bad™.

This change makes `Unit::defTypeAlias` do the following sequence if the RHS is an object or type alias:

* Lookup class, if it exists, record it and exit.
* Lookup type alias, if it exists, record it and exit.
* Attempt to load class, if it succeeds, record it and exit.
* Attempt to load type alias, if it succeeds, record it and exit.

The only case now that can trigger the failure handler is when the RHS references a type alias that hasn't be seen yet (it will fail trying to load the class).

---

/cc @jdelong