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 +----------------------------------------------------------------------+
19 #include "hphp/runtime/vm/class.h"
21 #include <folly/Optional.h>
24 ///////////////////////////////////////////////////////////////////////////////
31 ///////////////////////////////////////////////////////////////////////////////
32 struct RuntimeCoeffects
{
33 using storage_t
= uint16_t;
35 static RuntimeCoeffects
fromValue(uint16_t value
) {
36 return RuntimeCoeffects
{value
};
39 static RuntimeCoeffects
none() {
40 return RuntimeCoeffects::fromValue(0);
43 static RuntimeCoeffects
full() {
44 return RuntimeCoeffects::fromValue(std::numeric_limits
<storage_t
>::max());
47 uint16_t value() const { return m_data
; }
49 const std::string
toString() const;
51 // Checks whether provided coeffects in `this` can call
52 // required coeffects in `o`
53 bool canCall(const RuntimeCoeffects o
) const {
56 return (m_data
& (~o
.m_data
)) == 0;
59 bool canCallWithWarning(const RuntimeCoeffects
) const;
61 // This operator is equivalent to | of [coeffectA | coeffectB]
62 RuntimeCoeffects
& operator&=(const RuntimeCoeffects
);
65 explicit RuntimeCoeffects(uint16_t data
) : m_data(data
) {}
69 struct StaticCoeffects
{
70 using storage_t
= RuntimeCoeffects::storage_t
;
72 const folly::Optional
<std::string
> toString() const;
74 RuntimeCoeffects
toAmbient() const;
75 RuntimeCoeffects
toRequired() const;
77 // Returns the corresponding shallow bits for coeffects that are local
78 RuntimeCoeffects
toShallowWithLocals() const;
80 static StaticCoeffects
fromValue(uint16_t value
) {
81 return StaticCoeffects
{value
};
84 uint16_t value() const { return m_data
; }
86 static StaticCoeffects
none() {
87 return StaticCoeffects::fromValue(0);
90 // This operator is equivalent to & of [coeffectA & coeffectB]
91 StaticCoeffects
& operator|=(const StaticCoeffects
);
94 void serde(SerDe
& sd
) {
99 // Returns the local bits
100 storage_t
locals() const;
103 explicit StaticCoeffects(uint16_t data
) : m_data(data
) {}
107 static_assert(sizeof(StaticCoeffects
) == sizeof(uint16_t), "");
108 static_assert(sizeof(StaticCoeffects
) == sizeof(RuntimeCoeffects
), "");
110 ///////////////////////////////////////////////////////////////////////////////
112 struct CoeffectRule final
{
117 CoeffectRule() = default;
119 /////////////////////////////////////////////////////////////////////////////
120 // Native coeffect rules ////////////////////////////////////////////////////
122 CoeffectRule(FunParam
, uint32_t index
)
123 : m_type(Type::FunParam
)
127 CoeffectRule(CCParam
, uint32_t index
, const StringData
* ctx_name
)
128 : m_type(Type::CCParam
)
131 { assertx(ctx_name
); }
133 CoeffectRule(CCThis
, const StringData
* ctx_name
)
134 : m_type(Type::CCThis
)
136 { assertx(ctx_name
); }
138 RuntimeCoeffects
emit(const Func
*, uint32_t, void*) const;
139 jit::SSATmp
* emitJit(jit::irgen::IRGS
&, const Func
*,
140 uint32_t, jit::SSATmp
*) const;
142 folly::Optional
<std::string
> toString(const Func
*) const;
143 std::string
getDirectiveString() const;
145 template<class SerDe
>
157 Type m_type
{Type::Invalid
};
159 LowPtr
<const StringData
> m_name
{nullptr};
162 ///////////////////////////////////////////////////////////////////////////////