Permalink
Browse files

Various fixes for hackc repo mode

Summary:
- use the correct path for the file to parse
 - don't hold a lock while parsing
 - give the ParseOnDemandCallbacks a const pointer to the AnalysisResult to make it harder to do non thread-safe things.
 - set the worker count from ParserThreadCount
 - don't read the source file, compute an md5 sum, and then throw it all away when hackc isn't enabled.

Reviewed By: aaronkroth

Differential Revision: D6775338

fbshipit-source-id: c297f91063aa88d15d6a42020134cc2dda3fd4ed
  • Loading branch information...
markw65 authored and hhvm-bot committed Jan 23, 2018
1 parent ff23826 commit 5e719a2a31305804998b6593b50bc6974617a972
@@ -68,7 +68,7 @@ using namespace HPHP;
AnalysisResult::AnalysisResult()
: BlockScope("Root", "", StatementPtr(), BlockScope::ProgramScope),
m_package(nullptr), m_parseOnDemand(false), m_phase(ParseAllFiles),
m_asmCallbacks(this) {
m_asmCallbacks(AnalysisResultConstRawPtr{this}) {
}
AnalysisResult::~AnalysisResult() {
@@ -114,7 +114,7 @@ struct AnalysisResult : BlockScope, FunctionContainer {
};
struct ParseOnDemandCalbacks : AsmCallbacks {
explicit ParseOnDemandCalbacks(AnalysisResult* ar) : m_ar(ar) {}
explicit ParseOnDemandCalbacks(AnalysisResultConstRawPtr ar) : m_ar(ar) {}
virtual void onInclude(const std::string& include) override {
m_ar->parseOnDemand(include);
@@ -130,7 +130,7 @@ struct AnalysisResult : BlockScope, FunctionContainer {
}
private:
AnalysisResult* m_ar;
AnalysisResultConstRawPtr m_ar;
};
public:
@@ -281,6 +281,8 @@ bool Package::parse(bool check) {
auto const threadCount = Option::ParserThreadCount <= 0 ?
1 : Option::ParserThreadCount;
// If we're using the hack compiler, make sure it agrees on the thread count.
RuntimeOption::EvalHackCompilerWorkers = threadCount;
ParserDispatcher dispatcher { threadCount, 0, false, this };
m_dispatcher = &dispatcher;
@@ -353,8 +355,10 @@ bool Package::parseImpl(const std::string* fileName) {
}
}
{
std::ifstream s(*fileName);
if ((RuntimeOption::EvalHackCompilerDefault &&
!RuntimeOption::EvalHackCompilerCommand.empty()) ||
RuntimeOption::EvalPHP7CompilerEnabled) {
std::ifstream s(fullPath);
std::string content {
std::istreambuf_iterator<char>(s), std::istreambuf_iterator<char>() };
MD5 md5{string_md5(content)};
@@ -366,8 +370,8 @@ bool Package::parseImpl(const std::string* fileName) {
if (auto uc = UnitCompiler::create(
content.data(), content.size(), fileName->c_str(), md5)) {
try {
Lock lock(m_ar->getMutex());
if (auto ue = uc->compile(m_ar->getParseOnDemandCallBacks())) {
Lock lock(m_ar->getMutex());
m_ar->addHhasFile(std::move(ue));
return true;
} else {

0 comments on commit 5e719a2

Please sign in to comment.