Use req::Optional when we need exact scanning.
Summary:
The internal layout of folly::Optional<T> doesn't declare
an instance of T; it uses aliged_storage or something similar,
so we must conservative-scan it. Convert the uses that require
exact scanning to req::Optional<T>, which is a trivial subclass
that adds a custom scanner. (if hasValue() then scan T).
This conversion exposed a bug where during processing ini
options, a few RequestLocal<T> instances were initialized,
but not correctly shut down when we reset ExecutionContext.
(fixed by calling context->onRequestShutdown()).
While debugging that problem, I noticed the ThreadLocal<T> instances
for MemoryManager and LocalSettings were being initialized before
type_scan, causing their memoized tyindex to be incorrect. Fixed
that by explicitly restoring their tyindex after type_scan init.
Reviewed By: ricklavoie
Differential Revision:
D5630672
fbshipit-source-id:
9a3c93942efff88283d9ecee5db3676cc0e6fd41