2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present 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"
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"
29 #include "hphp/util/rds-local.h"
33 static std::atomic
<bool> s_foundHHConfig(false);
34 void checkHHConfig(const Unit
* unit
) {
36 if (RuntimeOption::RepoAuthoritative
||
37 !RuntimeOption::LookForTypechecker
||
39 isDebuggerAttached()) {
43 const std::string
&s
= unit
->filepath()->toCppString();
44 boost::filesystem::path
p(s
);
46 while (p
!= "/" && p
!= "") {
50 if (boost::filesystem::exists(p
)) {
57 if (p
== "/" || p
== "") {
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 "
62 "`-d hhvm.hack.lang.look_for_typechecker=0` "
63 "to disable this check (not recommended).",
65 "http://docs.hhvm.com/hack/typechecker/setup"
68 s_foundHHConfig
= true;
73 * The default of "true" here is correct -- see autoTypecheckRequestInit().
75 static RDS_LOCAL_NO_CHECK(bool, tl_doneAutoTypecheck
)(true);
78 * autoTypecheckRequestInit() and autoTypecheckRequestExit() work together to
79 * ensure a couple of things.
81 * The most obvious is that we only run auto-typechecking once per request;
82 * we need to reset the thread-local flag on the next request.
84 * More subtle is that we need to block auto-typechecking until the VM is fully
85 * initalized, and systemlib is fully merged. In most cases, systemlib is
86 * persistent, and we could check SystemLib::s_inited. However, if
87 * JitEnableRenameFunction is enabled, then systemlib has to actually be merged
88 * every request -- and since much of systemlib is written in Hack, that would
89 * trigger auto-typecheck. So we overload the meaning of tl_doneAutoTypecheck to
90 * make sure that we don't enable auto-typechecking until systemlib is fully
93 void autoTypecheckRequestInit() {
94 *tl_doneAutoTypecheck
= false;
98 * See autoTypecheckRequestInit().
100 void autoTypecheckRequestExit() {
101 *tl_doneAutoTypecheck
= true;
104 void autoTypecheck(const Unit
* unit
) {
105 if (RuntimeOption::RepoAuthoritative
||
106 !RuntimeOption::AutoTypecheck
||
107 *tl_doneAutoTypecheck
||
108 isDebuggerAttached()) {
111 *tl_doneAutoTypecheck
= true;
113 vm_call_user_func("\\HH\\Client\\typecheck_and_error",
114 Variant
{ArrayData::Create()});