summaryrefslogtreecommitdiff
path: root/Zend/zend_compile.h
Commit message (Collapse)AuthorAgeFilesLines
* Allow observer handlers disabling optimization in RETURN opcode handler, ↵Dmitry Stogov2021-01-261-0/+3
| | | | that may cause loss value of returned local variable.
* Make constexpr compilation robust against multiple compilationNikita Popov2020-09-271-1/+1
| | | | | | | | | | | | | Instead of setting the old AST type to zero, replace the AST with the compiled constexpr AST zval. This requires passing in a zend_ast** instead of a zend_ast*. This allows compiling ASTs containing constexprs multiple times -- the second time, the existing compiled representation will be resused. This means we no longer need to copy the attributes AST for promoted properties.
* Renumber ZEND_ACC_... constantsDmitry Stogov2020-09-151-25/+25
|
* Accept zend_string instead of zval in zend_compile_stringNikita Popov2020-09-071-2/+2
|
* Improve type declarations for Zend APIsGeorge Peter Banyard2020-08-281-12/+12
| | | | | | | | | Voidification of Zend API which always succeeded Use bool argument types instead of int for boolean arguments Use bool return type for functions which return true/false (1/0) Use zend_result return type for functions which return SUCCESS/FAILURE as they don't follow normal boolean semantics Closes GH-6002
* Implement named parametersNikita Popov2020-07-311-0/+5
| | | | | | | | | | | | | | | | | | From an engine perspective, named parameters mainly add three concepts: * The SEND_* opcodes now accept a CONST op2, which is the argument name. For now, it is looked up by linear scan and runtime cached. * This may leave UNDEF arguments on the stack. To avoid having to deal with them in other places, a CHECK_UNDEF_ARGS opcode is used to either replace them with defaults, or error. * For variadic functions, EX(extra_named_params) are collected and need to be freed based on ZEND_CALL_HAS_EXTRA_NAMED_PARAMS. RFC: https://wiki.php.net/rfc/named_params Closes GH-5357.
* Implement nullsafe ?-> operatorIlija Tovilo2020-07-241-0/+4
| | | | | | | | RFC: https://wiki.php.net/rfc/nullsafe_operator Closes GH-5619. Co-authored-by: Nikita Popov <nikita.ppv@gmail.com>
* Add flag to forbid dynamic property creation on internal classesNikita Popov2020-06-241-1/+4
| | | | | | | | | | | | | | | | | | | While performing resource -> object migrations, we're adding defensive classes that are final, non-serializable and non-clonable (unless they are, of course). This path adds a ZEND_ACC_NO_DYNAMIC_PROPERTIES flag, that also forbids the creation of dynamic properties on these objects. This is a subset of #3931 and targeted at internal usage only (though may be extended to userland at some point in the future). It's already possible to achieve this (what the removed WeakRef/WeakMap code does), but there's some caveats: First, this simple approach is only possible if the class has no declared properties, otherwise it's necessary to special-case those properties. Second, it's easy to make it overly strict, e.g. by forbidding isset($obj->prop) as well. And finally, it requires a lot of boilerplate code for each class. Closes GH-5572.
* Fix bug #77966: Cannot alias a method named "namespace"Nikita Popov2020-06-081-0/+6
| | | | | | | | | | | | | | | | | | | | This is a bit tricky: In this cases we have "namespace as", which means that we will only recognize "namespace" as an identifier when the lookahead token is already at the "as". This means that zend_lex_tstring picks up the wrong identifier. We solve this by actually assigning the identifier as the semantic value on the parser stack -- as in almost all cases we will not actually need the identifier, this is just an (offset, size) reference, not a copy of the string. Additionally, we need to teach the lexer feedback mechanism used by tokenizer TOKEN_PARSE mode to apply feedback to something other than the very last token. To that purpose we pass through the token text and check the tokens in reverse order to find the right one. Closes GH-5668.
* Constify char * arguments of APIstwosee2020-06-081-1/+1
| | | | Closes GH-5676.
* Implement "Constructor Promotion" RFCNikita Popov2020-06-051-2/+9
| | | | | | RFC: https://wiki.php.net/rfc/constructor_promotion Closes GH-5291.
* Add AttributesBenjamin Eberlei2020-06-041-0/+5
| | | | Co-authored-by: Martin Schröder <m.schroeder2007@gmail.com>
* Avoid throw expression leaksNikita Popov2020-04-271-0/+2
| | | | | | | | | Mark "throw" used in expression context with a flag, and don't treat it as a BB terminator in that case. This prevents us from optimizing away the following opcodes as unreachable, which may result in live ranges being dropped incorrectly. Close GH-5450.
* Remove ZEND_ACC_DTOR flagNikita Popov2020-04-171-4/+1
| | | | | | | | | | This is only used in reflection, where doing a simple string check is acceptable. I'm also dropping the "dtor" printing in the reflection dump. Dtors are just one of many magic methods, I don't think there's a point in explicitly highlighting them, when the name is already unambiguous.
* Add zend_create_member_string() APINikita Popov2020-04-141-0/+1
| | | | This is a recurring pattern.
* Store default parameter values of internal functions in arg infoMáté Kocsis2020-04-081-0/+7
| | | | | | | Closes GH-5353. From now on, PHP will have reflection information about default values of parameters of internal functions. Co-authored-by: Nikita Popov <nikita.ppv@gmail.com>
* Unify checks for binary operator errors for ct evalNikita Popov2020-04-011-1/+1
| | | | | Move everything into one function and share it with opcache. This fixes some discrepancies.
* Avoid more null arithmeticNikita Popov2020-02-271-1/+1
|
* Remove more null arithmetic UBNikita Popov2020-02-271-0/+1
| | | | | Introduce an EX_NUM_TO_VAR macro to mirror EX_VAR_TO_NUM and replace usages of the ZEND_CALL_VAR_NUM(NULL) pattern.
* Avoid null arithmetic UB in EX_VAR_TO_NUMNikita Popov2020-02-271-1/+1
|
* Remove ZEND_ACC_IMPLEMENT_INTERFACES flagNikita Popov2020-02-061-4/+1
| | | | | | | This is equivalent to checking ce->num_interfaces. The only subtle moment is during inheritance, where num_interface may change when parent interfaces are inherited. The check in zend_do_link_class thus uses "interfaces", not "ce->num_interfaces".
* Remove ZEND_ACC_IMPLEMENTS_TRAITS flagNikita Popov2020-02-061-4/+1
| | | | This is equivalent to checking ce->num_traits.
* Remove ZEND_ACC_INHERITED flagNikita Popov2020-02-061-4/+1
| | | | | It is equivalent to checking ce->parent != NULL. Just adds more state that needs to be kept in sync.
* Export zend_type_to_string() with ZEND_APIDerick Rethans2020-02-031-1/+1
|
* Implement union typesNikita Popov2019-11-081-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | According to RFC: https://wiki.php.net/rfc/union_types_v2 The type representation now makes use of both the pointer payload and the type mask at the same time. Additionall, zend_type_list is introduced as a new kind of pointer payload, which is used to store multiple class types. Each of the class types is a tagged pointer, which may be either a class name or class entry. The latter is only used for typed properties, while arguments/returns will instead use cache slots. A type list can contain a mix of both names and CEs at the same time, as not all classes may be resolvable. One thing this is missing is support for union types in arginfo and stubs, which I want to handle separately. I've also dropped the special object code from the JIT implementation for now -- I plan to add this back in a different form at a later time. For now I did not want to include non-trivial JIT changes together with large functional changes. Another possible piece of follow-up work is to implement "iterable" as an internal alias for "array|Traversable". I believe this will eliminate quite a few special-cases that had to be implemented. Closes GH-4838.
* Make zend_type a 2-field structNikita Popov2019-11-081-7/+9
| | | | | | | | | | | | | We now store the pointer payload and the type mask separately. This is in preparation for union types, where we will be using both at the same time. To avoid increasing the size of arginfo structures, the pass_by_reference and is_variadic fields are now stored as part of the type_mask (8-bit are reserved for custom use). Different types of pointer payloads are distinguished based on bits in the type_mask.
* Fix miscellaneous typos in docs and error messagesTyson Andre2019-10-281-1/+1
| | | | Closes GH-4863.
* Merge branch 'PHP-7.4'Dmitry Stogov2019-10-221-0/+3
|\ | | | | | | | | * PHP-7.4: Allow loading FFI bindings through ffi.preload directive
| * Allow loading FFI bindings through ffi.preload directiveDmitry Stogov2019-10-221-0/+3
| |
* | SAMRT BRANCH improvement.Dmitry Stogov2019-10-091-0/+4
| | | | | | | | | | Avoid need of insertion NOP opcoes between unrelated SMART BRANCH instruction and following JMPZ/JMPNZ. Now instead of checking the opcode of following instruction, the same information is encoded into SMART BRANH result_type.
* | Added "const" qualifierDmitry Stogov2019-10-081-1/+1
| |
* | Throw Error when writing property of non-objectNikita Popov2019-09-271-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This removes object auto-vivification support. This also means that we can remove the corresponding special handling for typed properites: We no longer need to check that a property is convertible to stdClass if such a conversion might take place indirectly due to a nested property write. Additionally OBJ_W style operations now no longer modify the object operand, and as such we no longer need to treat op1 as a def in SSA form. The next step would be to actually compile the whole LHS of OBJ_W operations in R rather than W mode, but that causes issues with SimpleXML, whose object handlers depend on the current compilation structure. Part of https://wiki.php.net/rfc/engine_warnings.
* | Change representation of zend_type from type code to MAY_BE_* maskNikita Popov2019-09-231-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | This switches zend_type from storing a single IS_* type code to storing a MAY_BE_* type mask. Right now most code still assumes that there is only a single type in the mask (or two together with MAY_BE_NULL). But this will make it a lot simpler to introduce union types. An additional advantage (and why I'm doing this separately), is that a number of special cases no longer need to be handled separately: We can do a single mask & (1 << type) check to handle all simple types, booleans (true|false) and null.
* | Merge branch 'PHP-7.4'Nikita Popov2019-09-141-1/+1
|\ \ | |/
| * Define OBJ_PROP_TO_OFFSET() using XtOffsetOf()Nikita Popov2019-09-141-1/+1
| | | | | | | | This avoids null pointer arithmetic UB.
* | Merge branch 'PHP-7.4'Nikita Popov2019-09-121-1/+4
|\ \ | |/
| * Allow throwing exception while loading parent classNikita Popov2019-09-121-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a fix for symfony/symfony#32995. The behavior is: * Throwing exception when loading parent/interface is allowed (and we will also throw one if the class is simply not found). * If this happens, the bucket key for the class is reset, so it's possibly to try registering the same class again. * However, if the class has already been used due to a variance obligation, the exception is upgraded to a fatal error, as we cannot safely unregister the class stub anymore.
* | Merge branch 'PHP-7.4'Nikita Popov2019-09-111-1/+5
|\ \ | |/
| * Only allow "nearly linked" classes for parent/interfaceNikita Popov2019-09-111-1/+5
| | | | | | | | | | | | | | | | | | | | | | The requirements for parent/interface are difference than for the variance checks in type declarations. The latter can work on fully unlinked classes, but the former need inheritance to be essentially finished, only variance checks may still be outstanding. Adding a new flag for this because we have lots of space, but we could also represent these "inheritance states" more compactly in the future.
* | Mention that arg_info[-1] holds the return infoIvan Enderlin2019-09-091-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I lost some time trying to know how to find the returned type. It's not that obvious it is stored in the _argument_ information array. For the sake of Internet, here is the full code checking that a function _has_ a returned type: ```c zend_function *function = /* e.g. fci_cache->function_handler */; if (!(function->op_array.fn_flags & ZEND_ACC_HAS_RETURN_TYPE)) { php_printf("no return type\n"); } else { php_printf("has a return type\n"); php_printf("return type = %s\n", zend_get_type_by_const(ZEND_TYPE_CODE(function->common.arg_info[-1].type))); } ```
* | Merge branch 'PHP-7.4'Dmitry Stogov2019-09-021-4/+5
|\ \ | |/ | | | | | | * PHP-7.4: Free two bits in fn_flags by merging ZEND_ACC_HEAP_RT_CACHE/ZEND_ACC_USER_ARG_INFO and ZEND_ACC_DONE_PASS_TWO/ZEND_ACC_ARENA_ALLOCATED that may be used only for user/internal functions
| * Free two bits in fn_flags by merging ↵Dmitry Stogov2019-09-021-4/+5
| | | | | | | | ZEND_ACC_HEAP_RT_CACHE/ZEND_ACC_USER_ARG_INFO and ZEND_ACC_DONE_PASS_TWO/ZEND_ACC_ARENA_ALLOCATED that may be used only for user/internal functions
* | Merge branch 'PHP-7.4'Dmitry Stogov2019-09-021-2/+2
|\ \ | |/ | | | | | | * PHP-7.4: Fixed information about unused flags
| * Fixed information about unused flagsDmitry Stogov2019-09-021-2/+2
| |
* | Merge branch 'PHP-7.4'Nikita Popov2019-08-231-0/+3
|\ \ | |/
| * Relax closure $this unbinding deprecationNikita Popov2019-08-231-0/+3
| | | | | | | | | | | | | | | | | | | | Only deprecate unbinding of $this from a closure if $this is syntactically used within the closure. This is desired to support Laravel's macro system, see laravel/framework#29482. This should still allow us to implement the performance improvements we're interested in for PHP 8, without breaking existing use-cases.
* | Merge branch 'PHP-7.4'Dmitry Stogov2019-07-191-1/+1
|\ \ | |/ | | | | | | * PHP-7.4: Use run-time cache to avoid repeatable hash lookups in ZEND_DECLARE_CLASS_DELAYED
| * Use run-time cache to avoid repeatable hash lookups in ↵Dmitry Stogov2019-07-191-1/+1
| | | | | | | | ZEND_DECLARE_CLASS_DELAYED
* | Merge branch 'PHP-7.4'Nikita Popov2019-07-191-1/+2
|\ \ | |/
| * Deprecate alternative array access syntaxrjhdby2019-07-191-1/+2
| | | | | | | | RFC: https://wiki.php.net/rfc/deprecate_curly_braces_array_access