Skip to content

Commit

Permalink
Merge pull request #2380 from zephir-lang/development
Browse files Browse the repository at this point in the history
0.16.1
  • Loading branch information
Jeckerson authored Aug 21, 2022
2 parents 4fac47b + a153e83 commit 9c99b4c
Show file tree
Hide file tree
Showing 36 changed files with 608 additions and 535 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ and this project adheres to [Semantic Versioning](https://semver.org).

## [Unreleased]

## [0.16.1] - 2022-08-21
### Changed
- Changed usage of `utf8_decode()` function in favour of `mb_convert_encoding()` [#2376](https://github.com/zephir-lang/zephir/issues/2376)

### Fixed
- Fixed generation of `ARG_INFO` for nullable object (`?object`) [#2374](https://github.com/zephir-lang/zephir/issues/2374)

## [0.16.0] - 2022-03-20
### Added
- Added custom list of arg info definition (Phalcon only) [#2341](https://github.com/zephir-lang/zephir/issues/2341)
Expand Down Expand Up @@ -573,6 +580,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).


[Unreleased]: https://github.com/zephir-lang/zephir/compare/0.16.0...HEAD
[0.16.1]: https://github.com/zephir-lang/zephir/compare/0.16.0...0.16.1
[0.16.0]: https://github.com/zephir-lang/zephir/compare/0.15.2...0.16.0
[0.15.2]: https://github.com/zephir-lang/zephir/compare/0.15.1...0.15.2
[0.15.1]: https://github.com/zephir-lang/zephir/compare/0.15.0...0.15.1
Expand Down
67 changes: 43 additions & 24 deletions Library/ArgInfoDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,9 @@ public function render(): void

private function richRenderStart(): void
{
if (array_key_exists('object', $this->functionLike->getReturnTypes())) {
$class = 'NULL';

if (1 === count($this->functionLike->getReturnClassTypes())) {
$class = key($this->functionLike->getReturnClassTypes());
$class = escape_class($this->compilationContext->getFullName($class));
}
if (array_key_exists('object', $this->functionLike->getReturnTypes()) && 1 === count($this->functionLike->getReturnClassTypes())) {
$class = key($this->functionLike->getReturnClassTypes());
$class = escape_class($this->compilationContext->getFullName($class));

$this->codePrinter->output(
sprintf(
Expand Down Expand Up @@ -237,6 +233,33 @@ private function richRenderStart(): void
return;
}

if ($this->functionLike->isReturnTypeNullableObject()) {
$this->codePrinter->output('#if PHP_VERSION_ID >= 80000');
$this->codePrinter->output(
sprintf(
'ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(%s, %d, %d, %s)',
$this->name,
(int) $this->returnByRef,
$this->functionLike->getNumberOfRequiredParameters(),
'MAY_BE_NULL|MAY_BE_OBJECT',
)
);
$this->codePrinter->output('#else');
$this->codePrinter->output(
sprintf(
'ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(%s, %d, %d, %s, %d)',
$this->name,
(int) $this->returnByRef,
$this->functionLike->getNumberOfRequiredParameters(),
'IS_OBJECT',
1,
)
);
$this->codePrinter->output('#endif');

return;
}

if (count($this->functionLike->getReturnTypes()) > 1) {
$types = [];
$mayBeTypes = $this->functionLike->getMayBeArgTypes();
Expand Down Expand Up @@ -332,23 +355,19 @@ private function renderEnd(): void
case '0:variable':
case '1:variable':
if (isset($parameter['cast'])) {
switch ($parameter['cast']['type']) {
case 'variable':
$value = $parameter['cast']['value'];
$this->codePrinter->output(
sprintf(
"\tZEND_ARG_OBJ_INFO(%d, %s, %s, %d)",
$this->passByReference($parameter),
$parameter['name'],
escape_class($this->compilationContext->getFullName($value)),
(int) $this->allowNull($parameter)
)
);
break;

default:
throw new Exception('Unexpected exception');
if ($parameter['cast']['type'] !== 'variable') {
throw new Exception('Unexpected exception');
}

$this->codePrinter->output(
sprintf(
"\tZEND_ARG_OBJ_INFO(%d, %s, %s, %d)",
$this->passByReference($parameter),
$parameter['name'],
escape_class($this->compilationContext->getFullName($parameter['cast']['value'])),
(int) $this->allowNull($parameter)
)
);
} else {
$this->codePrinter->output(
sprintf(
Expand Down Expand Up @@ -450,7 +469,7 @@ private function allowNull(array $parameter): bool
return false;
}

if ('null' == $parameter['default']['type']) {
if ('null' === $parameter['default']['type']) {
return true;
}

Expand Down
10 changes: 1 addition & 9 deletions Library/Backends/ZendEngine3/Backend.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@

use function Zephir\add_slashes;

/**
* Zephir\Backends\ZendEngine3\Backend.
*/
class Backend extends BackendZendEngine2
{
protected $name = 'ZendEngine3';
Expand Down Expand Up @@ -1001,12 +998,7 @@ public function copyOnWrite(Variable $target, $var, CompilationContext $context)

public function forStatement(Variable $exprVariable, $keyVariable, $variable, $duplicateKey, $duplicateHash, $statement, $statementBlock, CompilationContext $compilationContext)
{
/*
* Create a hash table and hash pointer temporary variables.
*/
//$arrayPointer = $compilationContext->symbolTable->addTemp('HashPosition', $compilationContext);
//$arrayHash = $compilationContext->symbolTable->addTemp('HashTable', $compilationContext);
/*
/**
* Create a temporary zval to fetch the items from the hash.
*/
$compilationContext->headersManager->add('kernel/fcall');
Expand Down
7 changes: 2 additions & 5 deletions Library/Backends/ZendEngine3/FcallManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,11 @@
use Zephir\Fcall\FcallManagerInterface;
use function Zephir\file_put_contents_ex;

/**
* Zephir\Backends\ZendEngine3\FcallManager.
*/
class FcallManager implements FcallManagerInterface
{
protected $requiredMacros = [];
protected array $requiredMacros = [];

public function macroIsRequired($macro)
public function macroIsRequired($macro): bool
{
return isset($this->requiredMacros[$macro]);
}
Expand Down
2 changes: 2 additions & 0 deletions Library/Builder/Statements/LetStatementBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
* the LICENSE file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Zephir\Builder\Statements;

/**
Expand Down
13 changes: 7 additions & 6 deletions Library/Cache/ClassEntryCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,19 @@
* the LICENSE file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Zephir\Cache;

use Zephir\CompilationContext;
use Zephir\Variable;

/**
* ClassEntryCache.
*
* Classes located in the PHP userland are cached to avoid further relocates
*/
class ClassEntryCache
{
protected $cache = [];
protected array $cache = [];

/**
* Retrieves/Creates a class entry cache.
Expand All @@ -29,11 +30,11 @@ class ClassEntryCache
* @param bool $dynamic
* @param CompilationContext $compilationContext
*
* @return \Zephir\Variable
* @return Variable
*/
public function get($className, $dynamic, CompilationContext $compilationContext)
public function get(string $className, bool $dynamic, CompilationContext $compilationContext): Variable
{
/*
/**
* Creates a guard variable if the class name is not dynamic
*/
if (!$dynamic) {
Expand Down
25 changes: 10 additions & 15 deletions Library/Cache/FunctionCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@
* the LICENSE file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Zephir\Cache;

use Zephir\Call;
use Zephir\CompilationContext;
use Zephir\Passes\CallGathererPass;

/**
* FunctionCache.
*
* Calls in Zephir implement monomorphic and polymorphic caches to
* improve performance. Method/Functions lookups are cached in a standard
* first-level method lookup cache.
Expand All @@ -36,14 +35,14 @@
*/
class FunctionCache
{
protected $cache = [];
protected array $cache = [];

protected $gatherer;
protected ?CallGathererPass $gatherer = null;

/**
* FunctionCache constructor.
*
* @param CallGathererPass $gatherer
* @param CallGathererPass|null $gatherer
*/
public function __construct(CallGathererPass $gatherer = null)
{
Expand All @@ -54,13 +53,12 @@ public function __construct(CallGathererPass $gatherer = null)
* Retrieves/Creates a function cache for a function call.
*
* @param string $functionName
* @param Call $call
* @param CompilationContext $compilationContext
* @param bool $exists
*
* @return string
*/
public function get($functionName, CompilationContext $compilationContext, Call $call, $exists)
public function get(string $functionName, CompilationContext $compilationContext, bool $exists): string
{
if (isset($this->cache[$functionName])) {
return $this->cache[$functionName].', '.SlotsCache::getExistingFunctionSlot($functionName);
Expand All @@ -73,13 +71,10 @@ public function get($functionName, CompilationContext $compilationContext, Call
$cacheSlot = SlotsCache::getFunctionSlot($functionName);

$number = 0;
if (!$compilationContext->insideCycle) {
$gatherer = $this->gatherer;
if ($gatherer) {
$number = $gatherer->getNumberOfFunctionCalls($functionName);
if ($number <= 1) {
return 'NULL, '.$cacheSlot;
}
if (!$compilationContext->insideCycle && $this->gatherer !== null) {
$number = $this->gatherer->getNumberOfFunctionCalls($functionName);
if ($number <= 1) {
return 'NULL, '.$cacheSlot;
}
}

Expand Down
39 changes: 18 additions & 21 deletions Library/Cache/MethodCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@
* the LICENSE file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Zephir\Cache;

use ReflectionClass;
use ReflectionException;
use Zephir\ClassDefinition;
use Zephir\CompilationContext;
use Zephir\MethodCallWarmUp;
use Zephir\Passes\CallGathererPass;
use Zephir\Variable;

/**
* MethodCache.
*
* Calls in Zephir implement monomorphic and polymorphic caches to
* improve performance. Method/Functions lookups are cached in a standard
* first-level method lookup cache.
Expand All @@ -38,14 +40,12 @@
*/
class MethodCache
{
protected $cache = [];
protected array $cache = [];

protected $gatherer;
protected ?CallGathererPass $gatherer = null;

/**
* MethodCache.
*
* @param CallGathererPass $gatherer
* @param CallGathererPass|null $gatherer
*/
public function __construct(CallGathererPass $gatherer = null)
{
Expand All @@ -60,8 +60,10 @@ public function __construct(CallGathererPass $gatherer = null)
* @param Variable $caller
*
* @return string
*
* @throws ReflectionException
*/
public function get(CompilationContext $compilationContext, $methodName, Variable $caller)
public function get(CompilationContext $compilationContext, string $methodName, Variable $caller): string
{
$compiler = $compilationContext->compiler;

Expand Down Expand Up @@ -185,27 +187,22 @@ public function get(CompilationContext $compilationContext, $methodName, Variabl
/**
* Checks if the class is suitable for caching.
*
* @param ClassDefinition $classDefinition
* @param ClassDefinition|ReflectionClass|null $classDefinition
*
* @return bool
*/
private function isClassCacheable($classDefinition)
private function isClassCacheable($classDefinition = null): bool
{
if ($classDefinition instanceof ClassDefinition) {
return true;
}
if ($classDefinition instanceof \ReflectionClass) {
if ($classDefinition->isInternal() && $classDefinition->isInstantiable()) {
$extension = $classDefinition->getExtension();
switch ($extension->getName()) {
case 'Reflection':
case 'Core':
case 'SPL':
return true;
}
}

if (!($classDefinition instanceof ReflectionClass)) {
return false;
}

return false;
return $classDefinition->isInternal() &&
$classDefinition->isInstantiable() &&
in_array($classDefinition->getExtension()->getName(), ['Reflection', 'Core', 'SPL']);
}
}
Loading

0 comments on commit 9c99b4c

Please sign in to comment.