Skip to content

Commit

Permalink
Partial support for hhas files in repo mode
Browse files Browse the repository at this point in the history
Summary:
Basic support for hhas files in repo mode.

This doesn't support using or defining traits in hhas files.

Reviewed By: paulbiss

Differential Revision: D3209389

fb-gh-sync-id: 719047f98d365632fa0a9bd84764e4793c2cf795
fbshipit-source-id: 719047f98d365632fa0a9bd84764e4793c2cf795
  • Loading branch information
Mark Williams authored and Hhvm Bot committed Apr 29, 2016
1 parent 48ea749 commit ae4e1b0
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 4 deletions.
9 changes: 9 additions & 0 deletions hphp/compiler/analysis/analysis_result.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#include "hphp/compiler/expression/simple_function_call.h"
#include "hphp/runtime/base/zend-printf.h"
#include "hphp/runtime/base/program-functions.h"
#include "hphp/runtime/vm/unit-emitter.h"
#include "hphp/util/logger.h"
#include "hphp/util/hash.h"
#include "hphp/util/job-queue.h"
Expand Down Expand Up @@ -125,6 +126,14 @@ void AnalysisResult::addFileScope(FileScopePtr fileScope) {
m_fileScopes.push_back(fileScope);
}

void AnalysisResult::addHhasFile(std::unique_ptr<UnitEmitter>&& ue) {
m_hhasFiles.emplace_back(std::move(ue));
}

std::vector<std::unique_ptr<UnitEmitter>> AnalysisResult::getHhasFiles() {
return std::move(m_hhasFiles);
}

bool AnalysisResult::inParseOnDemandDirs(const std::string &filename) const {
for (size_t i = 0; i < m_parseOnDemandDirs.size(); i++) {
if (filename.find(m_parseOnDemandDirs[i]) == 0) return true;
Expand Down
5 changes: 5 additions & 0 deletions hphp/compiler/analysis/analysis_result.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ DECLARE_BOOST_TYPES(FunctionScope);
DECLARE_BOOST_TYPES(AnalysisResult);
DECLARE_BOOST_TYPES(ScalarExpression);

struct UnitEmitter;

struct AnalysisResult : BlockScope, FunctionContainer {
/**
* There are multiple passes over our syntax trees. This lists all of them.
Expand Down Expand Up @@ -257,6 +259,8 @@ struct AnalysisResult : BlockScope, FunctionContainer {
StringToClassScopePtrVecMap getExtensionClasses();
void addInteger(int64_t n);

void addHhasFile(std::unique_ptr<UnitEmitter>&& ue);
std::vector<std::unique_ptr<UnitEmitter>> getHhasFiles();
private:
std::function<void(AnalysisResultPtr)> m_finish;
Package *m_package;
Expand All @@ -266,6 +270,7 @@ struct AnalysisResult : BlockScope, FunctionContainer {
Phase m_phase;
StringToFileScopePtrMap m_files;
std::vector<FileScopePtr> m_fileScopes;
std::vector<std::unique_ptr<UnitEmitter>> m_hhasFiles;

StringBag m_extraCodeFileNames;
std::map<std::string, std::string> m_extraCodes;
Expand Down
5 changes: 4 additions & 1 deletion hphp/compiler/analysis/emitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9913,7 +9913,10 @@ void emitAllHHBC(AnalysisResultPtr&& ar) {
dispatcher.start();
ar->visitFiles(addEmitterWorker, &dispatcher);

std::vector<std::unique_ptr<UnitEmitter>> ues;
auto ues = ar->getHhasFiles();
if (!Option::UseHHBBC && ues.size()) {
batchCommit(std::move(ues));
}

if (Option::GenerateBinaryHHBC) {
// kBatchSize needs to strike a balance between reducing transaction commit
Expand Down
25 changes: 25 additions & 0 deletions hphp/compiler/package.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
#include "hphp/runtime/base/file-util.h"
#include "hphp/runtime/base/execution-context.h"
#include "hphp/runtime/base/program-functions.h"
#include "hphp/runtime/vm/as.h"
#include "hphp/runtime/vm/unit-emitter.h"
#include "hphp/zend/zend-string.h"

using namespace HPHP;
using std::set;
Expand Down Expand Up @@ -243,6 +246,9 @@ bool Package::parse(bool check) {
return true;
}

LitstrTable::get().setWriting();
SCOPE_EXIT { LitstrTable::get().setReading(); };

unsigned int threadCount = Option::ParserThreadCount;
if (threadCount > m_filesToParse.size()) {
threadCount = m_filesToParse.size();
Expand Down Expand Up @@ -302,6 +308,25 @@ bool Package::parseImpl(const char *fileName) {
return false;
}

if (RuntimeOption::EvalAllowHhas) {
if (const char* dot = strrchr(fileName, '.')) {
if (!strcmp(dot + 1, "hhas")) {
std::ifstream s(fileName);
std::string content {
std::istreambuf_iterator<char>(s), std::istreambuf_iterator<char>()
};
MD5 md5{string_md5(content.data(), content.size()).c_str()};

std::unique_ptr<UnitEmitter> ue{
assemble_string(content.data(), content.size(), fileName, md5)
};
Lock lock(m_ar->getMutex());
m_ar->addHhasFile(std::move(ue));
return true;
}
}
}

int lines = 0;
try {
Logger::Verbose("parsing %s ...", fullPath.c_str());
Expand Down
2 changes: 1 addition & 1 deletion hphp/runtime/vm/as.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1878,7 +1878,7 @@ void parse_method(AsmState& as) {
as.fe = as.ue->newMethodEmitter(makeStaticString(name), as.pce);
as.pce->addMethod(as.fe);
as.fe->init(as.in.getLineNumber(), as.in.getLineNumber() + 1 /* XXX */,
as.ue->bcPos(), attrs, true, 0);
as.ue->bcPos(), attrs, false, 0);
std::tie(as.fe->retUserType, as.fe->retTypeConstraint) = typeInfo;
as.fe->userAttributes = userAttrs;

Expand Down
Empty file.
Empty file.
1 change: 1 addition & 0 deletions hphp/test/quick/hphp_config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ hhvm.force_hh = true
hhvm.enable_xhp = true
hhvm.jit_enable_rename_function = true
hhvm.hack.lang.autoprime_generators = true
hhvm.allow_hhas = true
3 changes: 1 addition & 2 deletions hphp/test/run
Original file line number Diff line number Diff line change
Expand Up @@ -1645,8 +1645,7 @@ function run_test($options, $test) {
}

if (isset($options['repo'])) {
if ($test_ext === 'hhas' ||
strpos($hhvm, '-m debug') !== false ||
if (strpos($hhvm, '-m debug') !== false ||
file_exists($test.'.norepo')) {
return 'skip-norepo';
}
Expand Down
1 change: 1 addition & 0 deletions hphp/test/slow/hphp_config.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
hhvm.enable_zend_compat = true
hhvm.hack.lang.ints_overflow_to_ints = true
hhvm.hack.lang.autoprime_generators = true
hhvm.allow_hhas = true

0 comments on commit ae4e1b0

Please sign in to comment.