Skip to content

Commit 4c0ec9d

Browse files
ondrejmirtesclaude
andcommitted
Declare TrinaryLogic and the result classes by their generated signatures
TrinaryLogic, AcceptsResult and IsSuperTypeOfResult spelled their arginfo by hand: parameter types named the PHPStanTurbo\ prefixed classes, no method declared a return type, and the properties were an untyped `value` and `object`-typed `result` slots instead of the twins' typed ones. TrinaryLogic also lacked the private YES/MAYBE/NO constants, its private create() and the static flyweight properties. The methods now register by the generated sig:: declarations, the properties come from declareProperties() and TrinaryLogic declares its constants and create(). The singletons clear IS_PROP_UNINIT when they initialize the now typed `int $value`, like the engine's write does. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018Fdg8n3eEi4ZoXa4dA2k4A
1 parent 8b9ba1a commit 4c0ec9d

5 files changed

Lines changed: 91 additions & 70 deletions

File tree

‎turbo-ext/src/AcceptsResult.cpp‎

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
#include "support.h"
2121
#include "generated/AcceptsResult.h"
22+
23+
namespace sigs = ptdecl::AcceptsResult::sig;
2224
#include "zv.h"
2325
#include "TypeTraits.h"
2426

@@ -670,8 +672,6 @@ void pt_accepts_result_rshutdown()
670672

671673
#include "reg.h"
672674

673-
#define ACCEPTS_RESULT_CLASS "PHPStanTurbo\\AcceptsResult"
674-
#define TRINARY_CLASS "PHPStanTurbo\\TrinaryLogic"
675675

676676
static zend_result pt_verify_accepts_result_variadic(zval *args, uint32_t count, uint32_t offset)
677677
{
@@ -757,8 +757,11 @@ void pt_register_accepts_result()
757757
{
758758
reg::Class cls("PHPStan\\Type\\AcceptsResult");
759759
ptdecl::AcceptsResult::declareClass(cls);
760+
/* the static flyweight properties stay unused: the natives keep the
761+
* singletons in the request globals */
762+
ptdecl::AcceptsResult::declareProperties(cls);
760763

761-
cls.method("__construct", reg::Public, 2, { reg::obj("result", TRINARY_CLASS), reg::arrayArg("reasons") }, [](INTERNAL_FUNCTION_PARAMETERS) {
764+
cls.method(sigs::__construct, [](INTERNAL_FUNCTION_PARAMETERS) {
762765
zval *result, *reasons;
763766
ZEND_PARSE_PARAMETERS_START(2, 2)
764767
Z_PARAM_OBJECT_OF_CLASS(result, pt_ce_trinary)
@@ -767,61 +770,61 @@ void pt_register_accepts_result()
767770
if (UNEXPECTED(!AcceptsResult(Z_OBJ_P(ZEND_THIS)).construct(result, reasons))) RETURN_THROWS();
768771
});
769772

770-
cls.method("yes", reg::Public, 0, {}, [](INTERNAL_FUNCTION_PARAMETERS) {
773+
cls.method(sigs::yes, [](INTERNAL_FUNCTION_PARAMETERS) {
771774
pt_accepts_result_bool(INTERNAL_FUNCTION_PARAM_PASSTHRU, PT_TRI_YES);
772775
});
773776

774-
cls.method("maybe", reg::Public, 0, {}, [](INTERNAL_FUNCTION_PARAMETERS) {
777+
cls.method(sigs::maybe, [](INTERNAL_FUNCTION_PARAMETERS) {
775778
pt_accepts_result_bool(INTERNAL_FUNCTION_PARAM_PASSTHRU, PT_TRI_MAYBE);
776779
});
777780

778-
cls.method("no", reg::Public, 0, {}, [](INTERNAL_FUNCTION_PARAMETERS) {
781+
cls.method(sigs::no, [](INTERNAL_FUNCTION_PARAMETERS) {
779782
pt_accepts_result_bool(INTERNAL_FUNCTION_PARAM_PASSTHRU, PT_TRI_NO);
780783
});
781784

782-
cls.method("createYes", reg::PublicStatic, 0, {}, [](INTERNAL_FUNCTION_PARAMETERS) {
785+
cls.method(sigs::createYes, [](INTERNAL_FUNCTION_PARAMETERS) {
783786
ZEND_PARSE_PARAMETERS_NONE();
784787
zv::Val result = AcceptsResult::createYes();
785788
if (UNEXPECTED(result.isUndef())) RETURN_THROWS();
786789
result.intoReturnValue(return_value);
787790
});
788791

789-
cls.method("createNo", reg::PublicStatic, 0, { reg::withDefault(reg::arrayArg("reasons"), "[]") }, [](INTERNAL_FUNCTION_PARAMETERS) {
792+
cls.method(sigs::createNo, [](INTERNAL_FUNCTION_PARAMETERS) {
790793
zval *reasons = NULL;
791794
if (!zp::parse<zp::Opt<zp::Arr>>(execute_data, reasons)) RETURN_THROWS();
792795
zv::Val result = AcceptsResult::createNo(reasons);
793796
if (UNEXPECTED(result.isUndef())) RETURN_THROWS();
794797
result.intoReturnValue(return_value);
795798
});
796799

797-
cls.method("createMaybe", reg::PublicStatic, 0, {}, [](INTERNAL_FUNCTION_PARAMETERS) {
800+
cls.method(sigs::createMaybe, [](INTERNAL_FUNCTION_PARAMETERS) {
798801
ZEND_PARSE_PARAMETERS_NONE();
799802
zv::Val result = AcceptsResult::createMaybe();
800803
if (UNEXPECTED(result.isUndef())) RETURN_THROWS();
801804
result.intoReturnValue(return_value);
802805
});
803806

804-
cls.method("createFromBoolean", reg::PublicStatic, 1, { reg::boolArg("value") }, [](INTERNAL_FUNCTION_PARAMETERS) {
807+
cls.method(sigs::createFromBoolean, [](INTERNAL_FUNCTION_PARAMETERS) {
805808
bool value;
806809
if (!zp::parse<zp::Bool>(execute_data, value)) RETURN_THROWS();
807810
zv::Val result = AcceptsResult::createFromBoolean(value);
808811
if (UNEXPECTED(result.isUndef())) RETURN_THROWS();
809812
result.intoReturnValue(return_value);
810813
});
811814

812-
cls.method("and", reg::Public, 1, { reg::obj("other", ACCEPTS_RESULT_CLASS) }, [](INTERNAL_FUNCTION_PARAMETERS) {
815+
cls.method(sigs::and_, [](INTERNAL_FUNCTION_PARAMETERS) {
813816
pt_accepts_result_and_or(INTERNAL_FUNCTION_PARAM_PASSTHRU, true);
814817
});
815818
/* the operand's class checked as Z_PARAM_OBJECT_OF_CLASS does; any other
816819
* object takes the engine path, which raises the TypeError */
817820
cls.op(PT_OP_AND, PT_OP_LAMBDA { if (UNEXPECTED(!instanceof_function(Z_OBJCE_P(argv), pt_ce_accepts_result))) { return pt_type_call_engine(self, "and", sizeof("and") - 1, 1, argv); } return AcceptsResult(self).and_(argv); });
818821

819-
cls.method("or", reg::Public, 1, { reg::obj("other", ACCEPTS_RESULT_CLASS) }, [](INTERNAL_FUNCTION_PARAMETERS) {
822+
cls.method(sigs::or_, [](INTERNAL_FUNCTION_PARAMETERS) {
820823
pt_accepts_result_and_or(INTERNAL_FUNCTION_PARAM_PASSTHRU, false);
821824
});
822825
cls.op(PT_OP_OR, PT_OP_LAMBDA { if (UNEXPECTED(!instanceof_function(Z_OBJCE_P(argv), pt_ce_accepts_result))) { return pt_type_call_engine(self, "or", sizeof("or") - 1, 1, argv); } return AcceptsResult(self).or_(argv); });
823826

824-
cls.method("decorateReasons", reg::Public, 1, { reg::callableArg("cb") }, [](INTERNAL_FUNCTION_PARAMETERS) {
827+
cls.method(sigs::decorateReasons, [](INTERNAL_FUNCTION_PARAMETERS) {
825828
zend_fcall_info fci;
826829
zend_fcall_info_cache fcc;
827830
ZEND_PARSE_PARAMETERS_START(1, 1)
@@ -832,15 +835,15 @@ void pt_register_accepts_result()
832835
result.intoReturnValue(return_value);
833836
});
834837

835-
cls.method("extremeIdentity", reg::PublicStatic, 0, { reg::variadicObj("operands", ACCEPTS_RESULT_CLASS) }, [](INTERNAL_FUNCTION_PARAMETERS) {
838+
cls.method(sigs::extremeIdentity, [](INTERNAL_FUNCTION_PARAMETERS) {
836839
pt_accepts_result_variadic_op(INTERNAL_FUNCTION_PARAM_PASSTHRU, true);
837840
});
838841

839-
cls.method("maxMin", reg::PublicStatic, 0, { reg::variadicObj("operands", ACCEPTS_RESULT_CLASS) }, [](INTERNAL_FUNCTION_PARAMETERS) {
842+
cls.method(sigs::maxMin, [](INTERNAL_FUNCTION_PARAMETERS) {
840843
pt_accepts_result_variadic_op(INTERNAL_FUNCTION_PARAM_PASSTHRU, false);
841844
});
842845

843-
cls.method("lazyMaxMin", reg::PublicStatic, 2, { reg::arrayArg("objects"), reg::callableArg("callback") }, [](INTERNAL_FUNCTION_PARAMETERS) {
846+
cls.method(sigs::lazyMaxMin, [](INTERNAL_FUNCTION_PARAMETERS) {
844847
zval *objects;
845848
zend_fcall_info fci;
846849
zend_fcall_info_cache fcc;
@@ -853,8 +856,6 @@ void pt_register_accepts_result()
853856
result.intoReturnValue(return_value);
854857
});
855858

856-
cls.publicReadonlyProperty("result", MAY_BE_OBJECT);
857-
cls.publicReadonlyProperty("reasons", MAY_BE_ARRAY);
858859
cls.shadow(&pt_ce_accepts_result);
859860
}
860861

‎turbo-ext/src/IsSuperTypeOfResult.cpp‎

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#include "support.h"
2323
#include "generated/IsSuperTypeOfResult.h"
2424

25+
namespace sigs = ptdecl::IsSuperTypeOfResult::sig;
26+
2527
namespace slots = ptdecl::IsSuperTypeOfResult::slot;
2628
#include "zv.h"
2729

@@ -478,8 +480,6 @@ void pt_is_super_type_of_result_rshutdown()
478480
#include "reg.h"
479481
#include "TypeTraits.h"
480482

481-
#define IS_SUPER_TYPE_OF_RESULT_CLASS "PHPStanTurbo\\IsSuperTypeOfResult"
482-
#define TRINARY_CLASS "PHPStanTurbo\\TrinaryLogic"
483483

484484
static zend_result pt_verify_is_super_type_of_result_variadic(zval *args, uint32_t count, uint32_t offset)
485485
{
@@ -579,8 +579,11 @@ void pt_register_is_super_type_of_result()
579579
{
580580
reg::Class cls("PHPStan\\Type\\IsSuperTypeOfResult");
581581
ptdecl::IsSuperTypeOfResult::declareClass(cls);
582+
/* the static flyweight properties stay unused: the natives keep the
583+
* singletons in the request globals */
584+
ptdecl::IsSuperTypeOfResult::declareProperties(cls);
582585

583-
cls.method("__construct", reg::Public, 2, { reg::obj("result", TRINARY_CLASS), reg::arrayArg("reasons"), reg::withDefault(reg::arrayArg("lazyReasons"), "[]") }, [](INTERNAL_FUNCTION_PARAMETERS) {
586+
cls.method(sigs::__construct, [](INTERNAL_FUNCTION_PARAMETERS) {
584587
zval *result, *reasons;
585588
zval *lazyReasons = NULL;
586589
ZEND_PARSE_PARAMETERS_START(2, 3)
@@ -592,75 +595,75 @@ void pt_register_is_super_type_of_result()
592595
if (UNEXPECTED(!IsSuperTypeOfResult(Z_OBJ_P(ZEND_THIS)).construct(result, reasons, lazyReasons))) RETURN_THROWS();
593596
});
594597

595-
cls.method("yes", reg::Public, 0, {}, [](INTERNAL_FUNCTION_PARAMETERS) {
598+
cls.method(sigs::yes, [](INTERNAL_FUNCTION_PARAMETERS) {
596599
pt_is_super_type_of_result_bool(INTERNAL_FUNCTION_PARAM_PASSTHRU, PT_TRI_YES);
597600
});
598601

599-
cls.method("maybe", reg::Public, 0, {}, [](INTERNAL_FUNCTION_PARAMETERS) {
602+
cls.method(sigs::maybe, [](INTERNAL_FUNCTION_PARAMETERS) {
600603
pt_is_super_type_of_result_bool(INTERNAL_FUNCTION_PARAM_PASSTHRU, PT_TRI_MAYBE);
601604
});
602605

603-
cls.method("no", reg::Public, 0, {}, [](INTERNAL_FUNCTION_PARAMETERS) {
606+
cls.method(sigs::no, [](INTERNAL_FUNCTION_PARAMETERS) {
604607
pt_is_super_type_of_result_bool(INTERNAL_FUNCTION_PARAM_PASSTHRU, PT_TRI_NO);
605608
});
606609

607-
cls.method("getReasons", reg::Public, 0, {}, [](INTERNAL_FUNCTION_PARAMETERS) {
610+
cls.method(sigs::getReasons, [](INTERNAL_FUNCTION_PARAMETERS) {
608611
ZEND_PARSE_PARAMETERS_NONE();
609612
zv::Val result = IsSuperTypeOfResult(Z_OBJ_P(ZEND_THIS)).getReasons();
610613
if (UNEXPECTED(result.isUndef())) RETURN_THROWS();
611614
result.intoReturnValue(return_value);
612615
});
613616

614-
cls.method("createYes", reg::PublicStatic, 0, {}, [](INTERNAL_FUNCTION_PARAMETERS) {
617+
cls.method(sigs::createYes, [](INTERNAL_FUNCTION_PARAMETERS) {
615618
ZEND_PARSE_PARAMETERS_NONE();
616619
zv::Val result = IsSuperTypeOfResult::createYes();
617620
if (UNEXPECTED(result.isUndef())) RETURN_THROWS();
618621
result.intoReturnValue(return_value);
619622
});
620623

621-
cls.method("createNo", reg::PublicStatic, 0, { reg::withDefault(reg::arrayArg("reasons"), "[]"), reg::withDefault(reg::arrayArg("lazyReasons"), "[]") }, [](INTERNAL_FUNCTION_PARAMETERS) {
624+
cls.method(sigs::createNo, [](INTERNAL_FUNCTION_PARAMETERS) {
622625
zval *reasons = NULL, *lazyReasons = NULL;
623626
if (!zp::parse<zp::Opt<zp::Arr>, zp::Opt<zp::Arr>>(execute_data, reasons, lazyReasons)) RETURN_THROWS();
624627
zv::Val result = IsSuperTypeOfResult::createNo(reasons, lazyReasons);
625628
if (UNEXPECTED(result.isUndef())) RETURN_THROWS();
626629
result.intoReturnValue(return_value);
627630
});
628631

629-
cls.method("createMaybe", reg::PublicStatic, 0, {}, [](INTERNAL_FUNCTION_PARAMETERS) {
632+
cls.method(sigs::createMaybe, [](INTERNAL_FUNCTION_PARAMETERS) {
630633
ZEND_PARSE_PARAMETERS_NONE();
631634
zv::Val result = IsSuperTypeOfResult::createMaybe();
632635
if (UNEXPECTED(result.isUndef())) RETURN_THROWS();
633636
result.intoReturnValue(return_value);
634637
});
635638

636-
cls.method("createFromBoolean", reg::PublicStatic, 1, { reg::boolArg("value") }, [](INTERNAL_FUNCTION_PARAMETERS) {
639+
cls.method(sigs::createFromBoolean, [](INTERNAL_FUNCTION_PARAMETERS) {
637640
bool value;
638641
if (!zp::parse<zp::Bool>(execute_data, value)) RETURN_THROWS();
639642
zv::Val result = IsSuperTypeOfResult::createFromBoolean(value);
640643
if (UNEXPECTED(result.isUndef())) RETURN_THROWS();
641644
result.intoReturnValue(return_value);
642645
});
643646

644-
cls.method("toAcceptsResult", reg::Public, 0, {}, [](INTERNAL_FUNCTION_PARAMETERS) {
647+
cls.method(sigs::toAcceptsResult, [](INTERNAL_FUNCTION_PARAMETERS) {
645648
ZEND_PARSE_PARAMETERS_NONE();
646649
zv::Val result = IsSuperTypeOfResult(Z_OBJ_P(ZEND_THIS)).toAcceptsResult();
647650
if (UNEXPECTED(result.isUndef())) RETURN_THROWS();
648651
result.intoReturnValue(return_value);
649652
});
650653

651-
cls.method("and", reg::Public, 0, { reg::variadicObj("others", IS_SUPER_TYPE_OF_RESULT_CLASS) }, [](INTERNAL_FUNCTION_PARAMETERS) {
654+
cls.method(sigs::and_, [](INTERNAL_FUNCTION_PARAMETERS) {
652655
pt_is_super_type_of_result_and_or(INTERNAL_FUNCTION_PARAM_PASSTHRU, true);
653656
});
654657
/* the one-operand call native code makes; the operand checked as the
655658
* variadic `self` parameter is */
656659
cls.op(PT_OP_AND, PT_OP_LAMBDA { if (UNEXPECTED(pt_verify_is_super_type_of_result_variadic(argv, 1, 1) != SUCCESS)) { return zv::Val(); } return IsSuperTypeOfResult(self).and_(argv, 1); });
657660

658-
cls.method("or", reg::Public, 0, { reg::variadicObj("others", IS_SUPER_TYPE_OF_RESULT_CLASS) }, [](INTERNAL_FUNCTION_PARAMETERS) {
661+
cls.method(sigs::or_, [](INTERNAL_FUNCTION_PARAMETERS) {
659662
pt_is_super_type_of_result_and_or(INTERNAL_FUNCTION_PARAM_PASSTHRU, false);
660663
});
661664
cls.op(PT_OP_OR, PT_OP_LAMBDA { if (UNEXPECTED(pt_verify_is_super_type_of_result_variadic(argv, 1, 1) != SUCCESS)) { return zv::Val(); } return IsSuperTypeOfResult(self).or_(argv, 1); });
662665

663-
cls.method("decorateReasons", reg::Public, 1, { reg::callableArg("cb") }, [](INTERNAL_FUNCTION_PARAMETERS) {
666+
cls.method(sigs::decorateReasons, [](INTERNAL_FUNCTION_PARAMETERS) {
664667
zend_fcall_info fci;
665668
zend_fcall_info_cache fcc;
666669
ZEND_PARSE_PARAMETERS_START(1, 1)
@@ -671,15 +674,15 @@ void pt_register_is_super_type_of_result()
671674
result.intoReturnValue(return_value);
672675
});
673676

674-
cls.method("extremeIdentity", reg::PublicStatic, 0, { reg::variadicObj("operands", IS_SUPER_TYPE_OF_RESULT_CLASS) }, [](INTERNAL_FUNCTION_PARAMETERS) {
677+
cls.method(sigs::extremeIdentity, [](INTERNAL_FUNCTION_PARAMETERS) {
675678
pt_is_super_type_of_result_variadic_op(INTERNAL_FUNCTION_PARAM_PASSTHRU, true);
676679
});
677680

678-
cls.method("maxMin", reg::PublicStatic, 0, { reg::variadicObj("operands", IS_SUPER_TYPE_OF_RESULT_CLASS) }, [](INTERNAL_FUNCTION_PARAMETERS) {
681+
cls.method(sigs::maxMin, [](INTERNAL_FUNCTION_PARAMETERS) {
679682
pt_is_super_type_of_result_variadic_op(INTERNAL_FUNCTION_PARAM_PASSTHRU, false);
680683
});
681684

682-
cls.method("lazyMaxMin", reg::PublicStatic, 2, { reg::arrayArg("objects"), reg::callableArg("callback") }, [](INTERNAL_FUNCTION_PARAMETERS) {
685+
cls.method(sigs::lazyMaxMin, [](INTERNAL_FUNCTION_PARAMETERS) {
683686
zval *objects;
684687
zend_fcall_info fci;
685688
zend_fcall_info_cache fcc;
@@ -692,23 +695,20 @@ void pt_register_is_super_type_of_result()
692695
result.intoReturnValue(return_value);
693696
});
694697

695-
cls.method("negate", reg::Public, 0, {}, [](INTERNAL_FUNCTION_PARAMETERS) {
698+
cls.method(sigs::negate, [](INTERNAL_FUNCTION_PARAMETERS) {
696699
ZEND_PARSE_PARAMETERS_NONE();
697700
zv::Val result = IsSuperTypeOfResult(Z_OBJ_P(ZEND_THIS)).negate();
698701
if (UNEXPECTED(result.isUndef())) RETURN_THROWS();
699702
result.intoReturnValue(return_value);
700703
});
701704

702-
cls.method("describe", reg::Public, 0, {}, [](INTERNAL_FUNCTION_PARAMETERS) {
705+
cls.method(sigs::describe, [](INTERNAL_FUNCTION_PARAMETERS) {
703706
ZEND_PARSE_PARAMETERS_NONE();
704707
const char *described = IsSuperTypeOfResult(Z_OBJ_P(ZEND_THIS)).describe();
705708
if (UNEXPECTED(described == NULL)) RETURN_THROWS();
706709
RETURN_STRING(described);
707710
});
708711

709-
cls.publicReadonlyProperty("result", MAY_BE_OBJECT);
710-
cls.publicReadonlyProperty("reasons", MAY_BE_ARRAY);
711-
cls.publicReadonlyProperty("lazyReasons", MAY_BE_ARRAY);
712712
cls.shadow(&pt_ce_is_super_type_of_result);
713713

714714
/* the decorateReasons() lazy-reason holder: an internal detail with no PHP

0 commit comments

Comments
 (0)