Use RATs from HHBBC in init_use_vars
[hiphop-php.git] / hphp / runtime / vm / hh-utils.cpp
blobcb87d656fe1d437c25e4e6a45f2d289139c0f319
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-2015 Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
16 #include "hphp/runtime/vm/hh-utils.h"
18 #include <atomic>
20 #include <boost/filesystem.hpp>
22 #include "hphp/runtime/base/array-data.h"
23 #include "hphp/runtime/base/builtin-functions.h"
24 #include "hphp/runtime/base/runtime-error.h"
25 #include "hphp/runtime/base/runtime-option.h"
26 #include "hphp/runtime/vm/debugger-hook.h"
27 #include "hphp/runtime/vm/unit.h"
28 #include "hphp/system/systemlib.h"
30 namespace HPHP {
32 static std::atomic<bool> s_foundHHConfig(false);
33 void checkHHConfig(const Unit* unit) {
35 if (RuntimeOption::RepoAuthoritative ||
36 !RuntimeOption::LookForTypechecker ||
37 s_foundHHConfig ||
38 !unit->isHHFile() ||
39 isDebuggerAttached()) {
40 return;
43 const std::string &s = unit->filepath()->toCppString();
44 boost::filesystem::path p(s);
46 while (p != "/" && p != "") {
47 p.remove_filename();
48 p /= ".hhconfig";
50 if (boost::filesystem::exists(p)) {
51 break;
54 p.remove_filename();
57 if (p == "/" || p == "") {
58 raise_error(
59 "%s appears to be a Hack file, but you do not appear to be running "
60 "the Hack typechecker. See the documentation at %s for information on "
61 "getting it running. You can also set Hack.Lang.LookForTypechecker=0 "
62 "to disable this check (not recommended).",
63 s.c_str(),
64 "http://docs.hhvm.com/manual/en/install.hack.bootstrapping.php"
66 } else {
67 s_foundHHConfig = true;
71 /**
72 * The default of "true" here is correct -- see autoTypecheckRequestInit().
74 static __thread bool tl_doneAutoTypecheck = true;
76 /**
77 * autoTypecheckRequestInit() and autoTypecheckRequestExit() work together to
78 * ensure a couple of things.
80 * The most obvious is that we only run auto-typechecking once per request;
81 * we need to reset the thread-local flag on the next request.
83 * More subtle is that we need to block auto-typechecking until the VM is fully
84 * initalized, and systemlib is fully merged. In most cases, systemlib is
85 * persistent, and we could check SystemLib::s_inited. However, if
86 * JitEnableRenameFunction is enabled, then systemlib has to actually be merged
87 * every request -- and since much of systemlib is written in Hack, that would
88 * trigger auto-typecheck. So we overload the meaning of tl_doneAutoTypecheck to
89 * make sure that we don't enable auto-typechecking until systemlib is fully
90 * merged.
92 void autoTypecheckRequestInit() {
93 tl_doneAutoTypecheck = false;
96 /**
97 * See autoTypecheckRequestInit().
99 void autoTypecheckRequestExit() {
100 tl_doneAutoTypecheck = true;
103 void autoTypecheck(const Unit* unit) {
104 if (RuntimeOption::RepoAuthoritative ||
105 !RuntimeOption::AutoTypecheck ||
106 tl_doneAutoTypecheck ||
107 !unit->isHHFile() ||
108 isDebuggerAttached()) {
109 return;
111 tl_doneAutoTypecheck = true;
113 vm_call_user_func("\\HH\\Client\\typecheck_and_error",
114 Variant{staticEmptyArray()});