Skip to content

Commit 1f4b925

Browse files
ondrejmirtesclaude
andcommitted
Declare ScopeContext and the expression holders by their generated signatures
ScopeContext, ExpressionTypeHolder and ConditionalExpressionHolder declared untyped null-default properties and spelled their arginfo by hand, with erased or PHPStanTurbo\ prefixed parameter types and no return types. They now register by the generated sig:: declarations and declare the twins' typed (and for ExpressionTypeHolder readonly) properties through declareProperties(); the slots keep their order, so the native readers are unchanged. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018Fdg8n3eEi4ZoXa4dA2k4A
1 parent 4c0ec9d commit 1f4b925

4 files changed

Lines changed: 30 additions & 41 deletions

File tree

‎turbo-ext/src/ConditionalExpressionHolder.cpp‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#include "support.h"
1010
#include "generated/ConditionalExpressionHolder.h"
11+
12+
namespace sigs = ptdecl::ConditionalExpressionHolder::sig;
1113
#include "zv.h"
1214

1315
namespace phpstanturbo {
@@ -70,17 +72,14 @@ using phpstanturbo::ConditionalExpressionHolder;
7072

7173
#include "reg.h"
7274

73-
#define ETH_CLASS "PHPStanTurbo\\ExpressionTypeHolder"
7475

7576
void pt_register_conditional_expression_holder()
7677
{
7778
reg::Class cls("PHPStan\\Analyser\\ConditionalExpressionHolder");
7879
ptdecl::ConditionalExpressionHolder::declareClass(cls);
79-
/* conditionExpressionTypeHolders/typeHolder must stay in this order */
80-
cls.privateNullProperty("conditionExpressionTypeHolders");
81-
cls.privateNullProperty("typeHolder");
80+
ptdecl::ConditionalExpressionHolder::declareProperties(cls);
8281

83-
cls.method("__construct", reg::Public, 2, { reg::arrayArg("conditionExpressionTypeHolders"), reg::obj("typeHolder", ETH_CLASS) }, [](INTERNAL_FUNCTION_PARAMETERS) {
82+
cls.method(sigs::__construct, [](INTERNAL_FUNCTION_PARAMETERS) {
8483
zval *holders;
8584
zval *typeHolder;
8685
ZEND_PARSE_PARAMETERS_START(2, 2)
@@ -90,17 +89,17 @@ void pt_register_conditional_expression_holder()
9089
if (UNEXPECTED(!ConditionalExpressionHolder(ZEND_THIS).construct(zv::ArrRef(holders), zv::Ref(typeHolder)))) RETURN_THROWS();
9190
});
9291

93-
cls.method("getConditionExpressionTypeHolders", reg::Public, 0, {}, [](INTERNAL_FUNCTION_PARAMETERS) {
92+
cls.method(sigs::getConditionExpressionTypeHolders, [](INTERNAL_FUNCTION_PARAMETERS) {
9493
ZEND_PARSE_PARAMETERS_NONE();
9594
ConditionalExpressionHolder(ZEND_THIS).getConditionExpressionTypeHolders().intoReturnValue(return_value);
9695
});
9796

98-
cls.method("getTypeHolder", reg::Public, 0, {}, [](INTERNAL_FUNCTION_PARAMETERS) {
97+
cls.method(sigs::getTypeHolder, [](INTERNAL_FUNCTION_PARAMETERS) {
9998
ZEND_PARSE_PARAMETERS_NONE();
10099
ConditionalExpressionHolder(ZEND_THIS).getTypeHolder().intoReturnValue(return_value);
101100
});
102101

103-
cls.method("getKey", reg::Public, 0, {}, [](INTERNAL_FUNCTION_PARAMETERS) {
102+
cls.method(sigs::getKey, [](INTERNAL_FUNCTION_PARAMETERS) {
104103
ZEND_PARSE_PARAMETERS_NONE();
105104
zv::Val key = ConditionalExpressionHolder(ZEND_THIS).getKey();
106105
if (UNEXPECTED(key.isUndef())) RETURN_THROWS();

‎turbo-ext/src/ExpressionTypeHolder.cpp‎

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
#include "support.h"
1616
#include "generated/ExpressionTypeHolder.h"
17+
18+
namespace sigs = ptdecl::ExpressionTypeHolder::sig;
1719
#include "zv.h"
1820

1921
namespace phpstanturbo {
@@ -77,19 +79,14 @@ using phpstanturbo::ExpressionTypeHolder;
7779

7880
#include "reg.h"
7981

80-
#define ETH_CLASS "PHPStanTurbo\\ExpressionTypeHolder"
81-
#define TRINARY_CLASS "PHPStanTurbo\\TrinaryLogic"
8282

8383
void pt_register_expression_type_holder()
8484
{
8585
reg::Class cls("PHPStan\\Analyser\\ExpressionTypeHolder");
8686
ptdecl::ExpressionTypeHolder::declareClass(cls);
87-
/* expr/type/certainty must stay in this order (OBJ_PROP_NUM slots) */
88-
cls.privateNullProperty("expr");
89-
cls.privateNullProperty("type");
90-
cls.privateNullProperty("certainty");
87+
ptdecl::ExpressionTypeHolder::declareProperties(cls);
9188

92-
cls.method("__construct", reg::Public, 3, { reg::any("expr"), reg::any("type"), reg::obj("certainty", TRINARY_CLASS) }, [](INTERNAL_FUNCTION_PARAMETERS) {
89+
cls.method(sigs::__construct, [](INTERNAL_FUNCTION_PARAMETERS) {
9390
zval *expr, *type, *certainty;
9491
ZEND_PARSE_PARAMETERS_START(3, 3)
9592
Z_PARAM_OBJECT(expr)
@@ -99,19 +96,19 @@ void pt_register_expression_type_holder()
9996
ExpressionTypeHolder(ZEND_THIS).construct(zv::Ref(expr), zv::Ref(type), zv::Ref(certainty));
10097
});
10198

102-
cls.method("createYes", reg::PublicStatic, 2, { reg::any("expr"), reg::any("type") }, [](INTERNAL_FUNCTION_PARAMETERS) {
99+
cls.method(sigs::createYes, [](INTERNAL_FUNCTION_PARAMETERS) {
103100
zval *expr, *type;
104101
if (!zp::parse<zp::Obj, zp::Obj>(execute_data, expr, type)) RETURN_THROWS();
105102
ExpressionTypeHolder::createYes(expr, type).intoReturnValue(return_value);
106103
});
107104

108-
cls.method("createMaybe", reg::PublicStatic, 2, { reg::any("expr"), reg::any("type") }, [](INTERNAL_FUNCTION_PARAMETERS) {
105+
cls.method(sigs::createMaybe, [](INTERNAL_FUNCTION_PARAMETERS) {
109106
zval *expr, *type;
110107
if (!zp::parse<zp::Obj, zp::Obj>(execute_data, expr, type)) RETURN_THROWS();
111108
ExpressionTypeHolder::createMaybe(expr, type).intoReturnValue(return_value);
112109
});
113110

114-
cls.method("equalTypes", reg::Public, 1, { reg::obj("other", ETH_CLASS) }, [](INTERNAL_FUNCTION_PARAMETERS) {
111+
cls.method(sigs::equalTypes, [](INTERNAL_FUNCTION_PARAMETERS) {
115112
zval *other;
116113
bool out;
117114
ZEND_PARSE_PARAMETERS_START(1, 1)
@@ -121,7 +118,7 @@ void pt_register_expression_type_holder()
121118
RETURN_BOOL(out);
122119
});
123120

124-
cls.method("equals", reg::Public, 1, { reg::obj("other", ETH_CLASS) }, [](INTERNAL_FUNCTION_PARAMETERS) {
121+
cls.method(sigs::equals, [](INTERNAL_FUNCTION_PARAMETERS) {
125122
zval *other;
126123
bool out;
127124
ZEND_PARSE_PARAMETERS_START(1, 1)
@@ -131,7 +128,7 @@ void pt_register_expression_type_holder()
131128
RETURN_BOOL(out);
132129
});
133130

134-
cls.method("and", reg::Public, 1, { reg::obj("other", ETH_CLASS) }, [](INTERNAL_FUNCTION_PARAMETERS) {
131+
cls.method(sigs::and_, [](INTERNAL_FUNCTION_PARAMETERS) {
135132
zval *other;
136133
ZEND_PARSE_PARAMETERS_START(1, 1)
137134
Z_PARAM_OBJECT_OF_CLASS(other, pt_ce_expr_type_holder)
@@ -141,17 +138,17 @@ void pt_register_expression_type_holder()
141138
result.intoReturnValue(return_value);
142139
});
143140

144-
cls.method("getExpr", reg::Public, 0, {}, [](INTERNAL_FUNCTION_PARAMETERS) {
141+
cls.method(sigs::getExpr, [](INTERNAL_FUNCTION_PARAMETERS) {
145142
ZEND_PARSE_PARAMETERS_NONE();
146143
ExpressionTypeHolder(ZEND_THIS).getExpr().intoReturnValue(return_value);
147144
});
148145

149-
cls.method("getType", reg::Public, 0, {}, [](INTERNAL_FUNCTION_PARAMETERS) {
146+
cls.method(sigs::getType, [](INTERNAL_FUNCTION_PARAMETERS) {
150147
ZEND_PARSE_PARAMETERS_NONE();
151148
ExpressionTypeHolder(ZEND_THIS).getType().intoReturnValue(return_value);
152149
});
153150

154-
cls.method("getCertainty", reg::Public, 0, {}, [](INTERNAL_FUNCTION_PARAMETERS) {
151+
cls.method(sigs::getCertainty, [](INTERNAL_FUNCTION_PARAMETERS) {
155152
ZEND_PARSE_PARAMETERS_NONE();
156153
ExpressionTypeHolder(ZEND_THIS).getCertainty().intoReturnValue(return_value);
157154
});

‎turbo-ext/src/ScopeContext.cpp‎

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "generated/ScopeContext.h"
1919

2020
namespace slots = ptdecl::ScopeContext::slot;
21+
namespace sigs = ptdecl::ScopeContext::sig;
2122
#include "zv.h"
2223
#include "TypeTraits.h"
2324

@@ -211,23 +212,18 @@ using phpstanturbo::ScopeContext;
211212

212213
#include "reg.h"
213214

214-
#define SCOPE_CONTEXT_CLASS "PHPStanTurbo\\ScopeContext"
215215

216216
void pt_register_scope_context();
217217

218218
void pt_register_scope_context()
219219
{
220220
reg::Class cls("PHPStan\\Analyser\\ScopeContext");
221221
ptdecl::ScopeContext::declareClass(cls);
222-
/* file/classReflection/traitReflection must stay in this order
223-
* (OBJ_PROP_NUM slots) */
224-
cls.privateNullProperty("file");
225-
cls.privateNullProperty("classReflection");
226-
cls.privateNullProperty("traitReflection");
222+
ptdecl::ScopeContext::declareProperties(cls);
227223

228224
/* private like the twin's: `new ScopeContext(...)` from userland fails
229225
* the same way; the native factories fill the slots without it */
230-
cls.method("__construct", reg::Private, 3, { reg::stringArg("file"), reg::objectArg("classReflection", true), reg::objectArg("traitReflection", true) }, [](INTERNAL_FUNCTION_PARAMETERS) {
226+
cls.method(sigs::__construct, [](INTERNAL_FUNCTION_PARAMETERS) {
231227
zend_string *file;
232228
zval *classReflection, *traitReflection;
233229
if (!zp::parse<zp::Str, zp::ObjOrNull, zp::ObjOrNull>(execute_data, file, classReflection, traitReflection)) RETURN_THROWS();
@@ -237,7 +233,7 @@ void pt_register_scope_context()
237233
ScopeContext(ZEND_THIS).construct(zv::Ref(&fileZv), zv::Ref(classReflection != NULL ? classReflection : &null), zv::Ref(traitReflection != NULL ? traitReflection : &null));
238234
});
239235

240-
cls.method("create", reg::PublicStatic, 1, { reg::stringArg("file") }, [](INTERNAL_FUNCTION_PARAMETERS) {
236+
cls.method(sigs::create, [](INTERNAL_FUNCTION_PARAMETERS) {
241237
zend_string *file;
242238
if (!zp::parse<zp::Str>(execute_data, file)) RETURN_THROWS();
243239
zval fileZv;
@@ -247,30 +243,30 @@ void pt_register_scope_context()
247243
result.intoReturnValue(return_value);
248244
});
249245

250-
cls.method("beginFile", reg::Public, 0, {}, [](INTERNAL_FUNCTION_PARAMETERS) {
246+
cls.method(sigs::beginFile, [](INTERNAL_FUNCTION_PARAMETERS) {
251247
ZEND_PARSE_PARAMETERS_NONE();
252248
zv::Val result = ScopeContext(ZEND_THIS).beginFile();
253249
if (UNEXPECTED(result.isUndef())) RETURN_THROWS();
254250
result.intoReturnValue(return_value);
255251
});
256252

257-
cls.method("enterClass", reg::Public, 1, { reg::objectArg("classReflection") }, [](INTERNAL_FUNCTION_PARAMETERS) {
253+
cls.method(sigs::enterClass, [](INTERNAL_FUNCTION_PARAMETERS) {
258254
zval *classReflection;
259255
if (!zp::parse<zp::Obj>(execute_data, classReflection)) RETURN_THROWS();
260256
zv::Val result = ScopeContext(ZEND_THIS).enterClass(zv::Ref(classReflection));
261257
if (UNEXPECTED(result.isUndef())) RETURN_THROWS();
262258
result.intoReturnValue(return_value);
263259
});
264260

265-
cls.method("enterTrait", reg::Public, 1, { reg::objectArg("traitReflection") }, [](INTERNAL_FUNCTION_PARAMETERS) {
261+
cls.method(sigs::enterTrait, [](INTERNAL_FUNCTION_PARAMETERS) {
266262
zval *traitReflection;
267263
if (!zp::parse<zp::Obj>(execute_data, traitReflection)) RETURN_THROWS();
268264
zv::Val result = ScopeContext(ZEND_THIS).enterTrait(zv::Ref(traitReflection));
269265
if (UNEXPECTED(result.isUndef())) RETURN_THROWS();
270266
result.intoReturnValue(return_value);
271267
});
272268

273-
cls.method("equals", reg::Public, 1, { reg::obj("otherContext", SCOPE_CONTEXT_CLASS) }, [](INTERNAL_FUNCTION_PARAMETERS) {
269+
cls.method(sigs::equals, [](INTERNAL_FUNCTION_PARAMETERS) {
274270
zval *otherContext;
275271
bool out;
276272
ZEND_PARSE_PARAMETERS_START(1, 1)
@@ -280,17 +276,17 @@ void pt_register_scope_context()
280276
RETURN_BOOL(out);
281277
});
282278

283-
cls.method("getFile", reg::Public, 0, {}, [](INTERNAL_FUNCTION_PARAMETERS) {
279+
cls.method(sigs::getFile, [](INTERNAL_FUNCTION_PARAMETERS) {
284280
ZEND_PARSE_PARAMETERS_NONE();
285281
ScopeContext(ZEND_THIS).getFile().intoReturnValue(return_value);
286282
});
287283

288-
cls.method("getClassReflection", reg::Public, 0, {}, [](INTERNAL_FUNCTION_PARAMETERS) {
284+
cls.method(sigs::getClassReflection, [](INTERNAL_FUNCTION_PARAMETERS) {
289285
ZEND_PARSE_PARAMETERS_NONE();
290286
ScopeContext(ZEND_THIS).getClassReflection().intoReturnValue(return_value);
291287
});
292288

293-
cls.method("getTraitReflection", reg::Public, 0, {}, [](INTERNAL_FUNCTION_PARAMETERS) {
289+
cls.method(sigs::getTraitReflection, [](INTERNAL_FUNCTION_PARAMETERS) {
294290
ZEND_PARSE_PARAMETERS_NONE();
295291
ScopeContext(ZEND_THIS).getTraitReflection().intoReturnValue(return_value);
296292
});

‎turbo-ext/tests/signature-parity.php‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,13 @@
3535
*/
3636
$knownDrift = [
3737
'PhpParser\\NodeTraverser' => 'pending',
38-
'PHPStan\\Analyser\\ConditionalExpressionHolder' => 'pending',
3938
'PHPStan\\Analyser\\ExpressionResult' => 'pending',
4039
'PHPStan\\Analyser\\ExpressionResultStorage' => 'pending',
41-
'PHPStan\\Analyser\\ExpressionTypeHolder' => 'pending',
4240
'PHPStan\\Analyser\\ExprHandler\\AssignHandler' => 'pending',
4341
'PHPStan\\Analyser\\ExprHandler\\Helper\\OutputBufferHelper' => 'pending',
4442
'PHPStan\\Analyser\\IssetabilityDescriptor' => 'pending',
4543
'PHPStan\\Analyser\\IssetabilityLinkInfo' => 'pending',
4644
'PHPStan\\Analyser\\MutatingScope' => 'pending',
47-
'PHPStan\\Analyser\\ScopeContext' => 'pending',
4845
'PHPStan\\Analyser\\ScopeOps' => 'pending',
4946
'PHPStan\\Analyser\\StmtHandler\\ForeachHandler' => 'pending',
5047
'PHPStan\\Analyser\\TypeSpecifier' => 'pending',

0 commit comments

Comments
 (0)