Skip to content

Commit 9c99b4c

Browse files
authored
Merge pull request #2380 from zephir-lang/development
0.16.1
2 parents 4fac47b + a153e83 commit 9c99b4c

36 files changed

+608
-535
lines changed

Diff for: CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ and this project adheres to [Semantic Versioning](https://semver.org).
66

77
## [Unreleased]
88

9+
## [0.16.1] - 2022-08-21
10+
### Changed
11+
- Changed usage of `utf8_decode()` function in favour of `mb_convert_encoding()` [#2376](https://github.com/zephir-lang/zephir/issues/2376)
12+
13+
### Fixed
14+
- Fixed generation of `ARG_INFO` for nullable object (`?object`) [#2374](https://github.com/zephir-lang/zephir/issues/2374)
15+
916
## [0.16.0] - 2022-03-20
1017
### Added
1118
- Added custom list of arg info definition (Phalcon only) [#2341](https://github.com/zephir-lang/zephir/issues/2341)
@@ -573,6 +580,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
573580

574581

575582
[Unreleased]: https://github.com/zephir-lang/zephir/compare/0.16.0...HEAD
583+
[0.16.1]: https://github.com/zephir-lang/zephir/compare/0.16.0...0.16.1
576584
[0.16.0]: https://github.com/zephir-lang/zephir/compare/0.15.2...0.16.0
577585
[0.15.2]: https://github.com/zephir-lang/zephir/compare/0.15.1...0.15.2
578586
[0.15.1]: https://github.com/zephir-lang/zephir/compare/0.15.0...0.15.1

Diff for: Library/ArgInfoDefinition.php

+43-24
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,9 @@ public function render(): void
167167

168168
private function richRenderStart(): void
169169
{
170-
if (array_key_exists('object', $this->functionLike->getReturnTypes())) {
171-
$class = 'NULL';
172-
173-
if (1 === count($this->functionLike->getReturnClassTypes())) {
174-
$class = key($this->functionLike->getReturnClassTypes());
175-
$class = escape_class($this->compilationContext->getFullName($class));
176-
}
170+
if (array_key_exists('object', $this->functionLike->getReturnTypes()) && 1 === count($this->functionLike->getReturnClassTypes())) {
171+
$class = key($this->functionLike->getReturnClassTypes());
172+
$class = escape_class($this->compilationContext->getFullName($class));
177173

178174
$this->codePrinter->output(
179175
sprintf(
@@ -237,6 +233,33 @@ private function richRenderStart(): void
237233
return;
238234
}
239235

236+
if ($this->functionLike->isReturnTypeNullableObject()) {
237+
$this->codePrinter->output('#if PHP_VERSION_ID >= 80000');
238+
$this->codePrinter->output(
239+
sprintf(
240+
'ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(%s, %d, %d, %s)',
241+
$this->name,
242+
(int) $this->returnByRef,
243+
$this->functionLike->getNumberOfRequiredParameters(),
244+
'MAY_BE_NULL|MAY_BE_OBJECT',
245+
)
246+
);
247+
$this->codePrinter->output('#else');
248+
$this->codePrinter->output(
249+
sprintf(
250+
'ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(%s, %d, %d, %s, %d)',
251+
$this->name,
252+
(int) $this->returnByRef,
253+
$this->functionLike->getNumberOfRequiredParameters(),
254+
'IS_OBJECT',
255+
1,
256+
)
257+
);
258+
$this->codePrinter->output('#endif');
259+
260+
return;
261+
}
262+
240263
if (count($this->functionLike->getReturnTypes()) > 1) {
241264
$types = [];
242265
$mayBeTypes = $this->functionLike->getMayBeArgTypes();
@@ -332,23 +355,19 @@ private function renderEnd(): void
332355
case '0:variable':
333356
case '1:variable':
334357
if (isset($parameter['cast'])) {
335-
switch ($parameter['cast']['type']) {
336-
case 'variable':
337-
$value = $parameter['cast']['value'];
338-
$this->codePrinter->output(
339-
sprintf(
340-
"\tZEND_ARG_OBJ_INFO(%d, %s, %s, %d)",
341-
$this->passByReference($parameter),
342-
$parameter['name'],
343-
escape_class($this->compilationContext->getFullName($value)),
344-
(int) $this->allowNull($parameter)
345-
)
346-
);
347-
break;
348-
349-
default:
350-
throw new Exception('Unexpected exception');
358+
if ($parameter['cast']['type'] !== 'variable') {
359+
throw new Exception('Unexpected exception');
351360
}
361+
362+
$this->codePrinter->output(
363+
sprintf(
364+
"\tZEND_ARG_OBJ_INFO(%d, %s, %s, %d)",
365+
$this->passByReference($parameter),
366+
$parameter['name'],
367+
escape_class($this->compilationContext->getFullName($parameter['cast']['value'])),
368+
(int) $this->allowNull($parameter)
369+
)
370+
);
352371
} else {
353372
$this->codePrinter->output(
354373
sprintf(
@@ -450,7 +469,7 @@ private function allowNull(array $parameter): bool
450469
return false;
451470
}
452471

453-
if ('null' == $parameter['default']['type']) {
472+
if ('null' === $parameter['default']['type']) {
454473
return true;
455474
}
456475

Diff for: Library/Backends/ZendEngine3/Backend.php

+1-9
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@
2727

2828
use function Zephir\add_slashes;
2929

30-
/**
31-
* Zephir\Backends\ZendEngine3\Backend.
32-
*/
3330
class Backend extends BackendZendEngine2
3431
{
3532
protected $name = 'ZendEngine3';
@@ -1001,12 +998,7 @@ public function copyOnWrite(Variable $target, $var, CompilationContext $context)
1001998

1002999
public function forStatement(Variable $exprVariable, $keyVariable, $variable, $duplicateKey, $duplicateHash, $statement, $statementBlock, CompilationContext $compilationContext)
10031000
{
1004-
/*
1005-
* Create a hash table and hash pointer temporary variables.
1006-
*/
1007-
//$arrayPointer = $compilationContext->symbolTable->addTemp('HashPosition', $compilationContext);
1008-
//$arrayHash = $compilationContext->symbolTable->addTemp('HashTable', $compilationContext);
1009-
/*
1001+
/**
10101002
* Create a temporary zval to fetch the items from the hash.
10111003
*/
10121004
$compilationContext->headersManager->add('kernel/fcall');

Diff for: Library/Backends/ZendEngine3/FcallManager.php

+2-5
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,11 @@
1515
use Zephir\Fcall\FcallManagerInterface;
1616
use function Zephir\file_put_contents_ex;
1717

18-
/**
19-
* Zephir\Backends\ZendEngine3\FcallManager.
20-
*/
2118
class FcallManager implements FcallManagerInterface
2219
{
23-
protected $requiredMacros = [];
20+
protected array $requiredMacros = [];
2421

25-
public function macroIsRequired($macro)
22+
public function macroIsRequired($macro): bool
2623
{
2724
return isset($this->requiredMacros[$macro]);
2825
}

Diff for: Library/Builder/Statements/LetStatementBuilder.php

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
* the LICENSE file that was distributed with this source code.
1010
*/
1111

12+
declare(strict_types=1);
13+
1214
namespace Zephir\Builder\Statements;
1315

1416
/**

Diff for: Library/Cache/ClassEntryCache.php

+7-6
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,19 @@
99
* the LICENSE file that was distributed with this source code.
1010
*/
1111

12+
declare(strict_types=1);
13+
1214
namespace Zephir\Cache;
1315

1416
use Zephir\CompilationContext;
17+
use Zephir\Variable;
1518

1619
/**
17-
* ClassEntryCache.
18-
*
1920
* Classes located in the PHP userland are cached to avoid further relocates
2021
*/
2122
class ClassEntryCache
2223
{
23-
protected $cache = [];
24+
protected array $cache = [];
2425

2526
/**
2627
* Retrieves/Creates a class entry cache.
@@ -29,11 +30,11 @@ class ClassEntryCache
2930
* @param bool $dynamic
3031
* @param CompilationContext $compilationContext
3132
*
32-
* @return \Zephir\Variable
33+
* @return Variable
3334
*/
34-
public function get($className, $dynamic, CompilationContext $compilationContext)
35+
public function get(string $className, bool $dynamic, CompilationContext $compilationContext): Variable
3536
{
36-
/*
37+
/**
3738
* Creates a guard variable if the class name is not dynamic
3839
*/
3940
if (!$dynamic) {

Diff for: Library/Cache/FunctionCache.php

+10-15
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@
99
* the LICENSE file that was distributed with this source code.
1010
*/
1111

12+
declare(strict_types=1);
13+
1214
namespace Zephir\Cache;
1315

14-
use Zephir\Call;
1516
use Zephir\CompilationContext;
1617
use Zephir\Passes\CallGathererPass;
1718

1819
/**
19-
* FunctionCache.
20-
*
2120
* Calls in Zephir implement monomorphic and polymorphic caches to
2221
* improve performance. Method/Functions lookups are cached in a standard
2322
* first-level method lookup cache.
@@ -36,14 +35,14 @@
3635
*/
3736
class FunctionCache
3837
{
39-
protected $cache = [];
38+
protected array $cache = [];
4039

41-
protected $gatherer;
40+
protected ?CallGathererPass $gatherer = null;
4241

4342
/**
4443
* FunctionCache constructor.
4544
*
46-
* @param CallGathererPass $gatherer
45+
* @param CallGathererPass|null $gatherer
4746
*/
4847
public function __construct(CallGathererPass $gatherer = null)
4948
{
@@ -54,13 +53,12 @@ public function __construct(CallGathererPass $gatherer = null)
5453
* Retrieves/Creates a function cache for a function call.
5554
*
5655
* @param string $functionName
57-
* @param Call $call
5856
* @param CompilationContext $compilationContext
5957
* @param bool $exists
6058
*
6159
* @return string
6260
*/
63-
public function get($functionName, CompilationContext $compilationContext, Call $call, $exists)
61+
public function get(string $functionName, CompilationContext $compilationContext, bool $exists): string
6462
{
6563
if (isset($this->cache[$functionName])) {
6664
return $this->cache[$functionName].', '.SlotsCache::getExistingFunctionSlot($functionName);
@@ -73,13 +71,10 @@ public function get($functionName, CompilationContext $compilationContext, Call
7371
$cacheSlot = SlotsCache::getFunctionSlot($functionName);
7472

7573
$number = 0;
76-
if (!$compilationContext->insideCycle) {
77-
$gatherer = $this->gatherer;
78-
if ($gatherer) {
79-
$number = $gatherer->getNumberOfFunctionCalls($functionName);
80-
if ($number <= 1) {
81-
return 'NULL, '.$cacheSlot;
82-
}
74+
if (!$compilationContext->insideCycle && $this->gatherer !== null) {
75+
$number = $this->gatherer->getNumberOfFunctionCalls($functionName);
76+
if ($number <= 1) {
77+
return 'NULL, '.$cacheSlot;
8378
}
8479
}
8580

Diff for: Library/Cache/MethodCache.php

+18-21
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,19 @@
99
* the LICENSE file that was distributed with this source code.
1010
*/
1111

12+
declare(strict_types=1);
13+
1214
namespace Zephir\Cache;
1315

16+
use ReflectionClass;
17+
use ReflectionException;
1418
use Zephir\ClassDefinition;
1519
use Zephir\CompilationContext;
1620
use Zephir\MethodCallWarmUp;
1721
use Zephir\Passes\CallGathererPass;
1822
use Zephir\Variable;
1923

2024
/**
21-
* MethodCache.
22-
*
2325
* Calls in Zephir implement monomorphic and polymorphic caches to
2426
* improve performance. Method/Functions lookups are cached in a standard
2527
* first-level method lookup cache.
@@ -38,14 +40,12 @@
3840
*/
3941
class MethodCache
4042
{
41-
protected $cache = [];
43+
protected array $cache = [];
4244

43-
protected $gatherer;
45+
protected ?CallGathererPass $gatherer = null;
4446

4547
/**
46-
* MethodCache.
47-
*
48-
* @param CallGathererPass $gatherer
48+
* @param CallGathererPass|null $gatherer
4949
*/
5050
public function __construct(CallGathererPass $gatherer = null)
5151
{
@@ -60,8 +60,10 @@ public function __construct(CallGathererPass $gatherer = null)
6060
* @param Variable $caller
6161
*
6262
* @return string
63+
*
64+
* @throws ReflectionException
6365
*/
64-
public function get(CompilationContext $compilationContext, $methodName, Variable $caller)
66+
public function get(CompilationContext $compilationContext, string $methodName, Variable $caller): string
6567
{
6668
$compiler = $compilationContext->compiler;
6769

@@ -185,27 +187,22 @@ public function get(CompilationContext $compilationContext, $methodName, Variabl
185187
/**
186188
* Checks if the class is suitable for caching.
187189
*
188-
* @param ClassDefinition $classDefinition
190+
* @param ClassDefinition|ReflectionClass|null $classDefinition
189191
*
190192
* @return bool
191193
*/
192-
private function isClassCacheable($classDefinition)
194+
private function isClassCacheable($classDefinition = null): bool
193195
{
194196
if ($classDefinition instanceof ClassDefinition) {
195197
return true;
196198
}
197-
if ($classDefinition instanceof \ReflectionClass) {
198-
if ($classDefinition->isInternal() && $classDefinition->isInstantiable()) {
199-
$extension = $classDefinition->getExtension();
200-
switch ($extension->getName()) {
201-
case 'Reflection':
202-
case 'Core':
203-
case 'SPL':
204-
return true;
205-
}
206-
}
199+
200+
if (!($classDefinition instanceof ReflectionClass)) {
201+
return false;
207202
}
208203

209-
return false;
204+
return $classDefinition->isInternal() &&
205+
$classDefinition->isInstantiable() &&
206+
in_array($classDefinition->getExtension()->getName(), ['Reflection', 'Core', 'SPL']);
210207
}
211208
}

0 commit comments

Comments
 (0)