From 999e32b65a8a4bb59e27e538fa68ffae4b99d863 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Wed, 25 Sep 2019 13:21:13 +0200 Subject: Implement union types 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. --- Zend/zend_API.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'Zend/zend_API.c') diff --git a/Zend/zend_API.c b/Zend/zend_API.c index 3c1ca4c718..87cfd5f139 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -2054,7 +2054,7 @@ ZEND_API int zend_register_functions(zend_class_entry *scope, const zend_functio internal_function->num_args--; } if (ZEND_TYPE_IS_SET(info->type)) { - if (ZEND_TYPE_IS_CLASS(info->type)) { + if (ZEND_TYPE_HAS_NAME(info->type)) { const char *type_name = ZEND_TYPE_LITERAL_NAME(info->type); if (!scope && (!strcasecmp(type_name, "self") || !strcasecmp(type_name, "parent"))) { zend_error_noreturn(E_CORE_ERROR, "Cannot declare a return type of %s outside of a class scope", type_name); @@ -2135,7 +2135,9 @@ ZEND_API int zend_register_functions(zend_class_entry *scope, const zend_functio memcpy(new_arg_info, arg_info, sizeof(zend_arg_info) * num_args); reg_function->common.arg_info = new_arg_info + 1; for (i = 0; i < num_args; i++) { - if (ZEND_TYPE_IS_CLASS(new_arg_info[i].type)) { + if (ZEND_TYPE_HAS_CLASS(new_arg_info[i].type)) { + ZEND_ASSERT(ZEND_TYPE_HAS_NAME(new_arg_info[i].type) + && "Only simple classes are currently supported"); const char *class_name = ZEND_TYPE_LITERAL_NAME(new_arg_info[i].type); ZEND_TYPE_SET_PTR(new_arg_info[i].type, zend_string_init_interned(class_name, strlen(class_name), 1)); -- cgit v1.2.1