|
19 | 19 | #include "hphp/compiler/option.h" |
20 | 20 | #include "hphp/compiler/package.h" |
21 | 21 |
|
| 22 | +#include "hphp/hack/src/hackc/ffi_bridge/compiler_ffi.rs.h" |
| 23 | + |
22 | 24 | #include "hphp/hhbbc/hhbbc.h" |
23 | 25 | #include "hphp/hhbbc/misc.h" |
24 | 26 | #include "hphp/hhbbc/options.h" |
|
31 | 33 | #include "hphp/runtime/base/variable-serializer.h" |
32 | 34 | #include "hphp/runtime/version.h" |
33 | 35 |
|
| 36 | +#include "hphp/runtime/vm/builtin-symbol-map.h" |
34 | 37 | #include "hphp/runtime/vm/disas.h" |
35 | 38 | #include "hphp/runtime/vm/preclass-emitter.h" |
36 | 39 | #include "hphp/runtime/vm/repo-autoload-map-builder.h" |
@@ -816,6 +819,38 @@ void logPhaseStats(const std::string& phase, const Package& package, |
816 | 819 | sample.setStr(phase + "_fellback", client.fellback() ? "true" : "false"); |
817 | 820 | } |
818 | 821 |
|
| 822 | +namespace { |
| 823 | + // Upload all builtin decls, and pass their IndexMeta summary and |
| 824 | + // Ref<UnitDecls> to callback() to include in the overall UnitIndex. This |
| 825 | + // makes systemlib decls visible to files being compiled as part of the |
| 826 | + // full repo build, but does not make repo decls available to systemlib. |
| 827 | + coro::Task<bool> indexBuiltinSymbolDecls( |
| 828 | + const Package::IndexCallback& callback, |
| 829 | + coro::TicketExecutor& executor, |
| 830 | + extern_worker::Client& client |
| 831 | + ) { |
| 832 | + std::vector<coro::TaskWithExecutor<void>> tasks; |
| 833 | + auto const declCallback = [&](auto const* d) -> coro::Task<void> { |
| 834 | + auto const facts = hackc::decls_to_facts_cpp_ffi(*d, ""); |
| 835 | + auto summary = summary_of_facts(facts); |
| 836 | + callback( |
| 837 | + "", |
| 838 | + summary, |
| 839 | + HPHP_CORO_AWAIT(client.store(Package::UnitDecls{ |
| 840 | + summary, |
| 841 | + std::string{d->serialized.begin(), d->serialized.end()} |
| 842 | + })) |
| 843 | + ); |
| 844 | + HPHP_CORO_RETURN_VOID; |
| 845 | + }; |
| 846 | + for (auto const& d: Native::getAllBuiltinDecls()) { |
| 847 | + tasks.emplace_back(declCallback(d).scheduleOn(executor.sticky())); |
| 848 | + } |
| 849 | + HPHP_CORO_AWAIT(coro::collectRange(std::move(tasks))); |
| 850 | + HPHP_CORO_RETURN(true); |
| 851 | + } |
| 852 | +} |
| 853 | + |
819 | 854 | // Compute a UnitIndex by parsing decls for all autoload-eligible files. |
820 | 855 | // If no Autoload.Query is specified by RepoOptions, this just indexes |
821 | 856 | // the input files. |
@@ -862,8 +897,25 @@ std::unique_ptr<UnitIndex> computeIndex( |
862 | 897 | // index just the input files |
863 | 898 | addInputsToPackage(indexPackage, po); |
864 | 899 | } |
| 900 | + // Here, we are doing the following in parallel: |
| 901 | + // * Indexing the build package |
| 902 | + // * Indexing builtin decls to be used by decl driven bytecode compilation |
| 903 | + // If DDB is not enabled, we will return early from the second task. |
| 904 | + auto const [indexingRepoOK, indexingSystemlibDeclsOK] = coro::wait( |
| 905 | + coro::collect( |
| 906 | + indexPackage.index(indexUnit), |
| 907 | + coro::invoke([&]() -> coro::Task<bool> { |
| 908 | + if (RO::EvalEnableDecl) { |
| 909 | + HPHP_CORO_RETURN(HPHP_CORO_AWAIT( |
| 910 | + indexBuiltinSymbolDecls(indexUnit, executor, client) |
| 911 | + )); |
| 912 | + } |
| 913 | + HPHP_CORO_RETURN(true); |
| 914 | + }) |
| 915 | + ) |
| 916 | + ); |
865 | 917 |
|
866 | | - if (!coro::wait(indexPackage.index(indexUnit))) return nullptr; |
| 918 | + if (!indexingRepoOK || !indexingSystemlibDeclsOK) return nullptr; |
867 | 919 |
|
868 | 920 | logPhaseStats("index", indexPackage, client, sample, |
869 | 921 | indexTimer.getMicroSeconds()); |
|
0 commit comments