peachpiecompiler / peachpie

PeachPie - the PHP compiler and runtime for .NET and .NET Core
https://www.peachpie.io
Apache License 2.0
2.33k stars 202 forks source link

Compiler Crash: MoveToImmutable can only be performed when Count equals Capacity #1102

Closed smx-smx closed 5 months ago

smx-smx commented 1 year ago

It looks like using the spread operator to build another array (PHP 7.4 feature/replacement for array_merge) always induces a compiler error, as reproducible by the following example:

<?php

$arr1 = ['a'];
$arr2 = [...$arr1, '1']; //<--this line triggers the compiler error
var_dump($arr2);

Compiler log (version 1.1.5):

C:\Users\user\.nuget\packages\peachpie.net.sdk\1.1.5\build\Peachpie.NET.Core.Sdk.targets(245,5): error : MoveToImmutable can only be performed when Count equals Capacity. [D:\peachpie_bug\Website\Website.msbuildproj]
C:\Users\user\.nuget\packages\peachpie.net.sdk\1.1.5\build\Peachpie.NET.Core.Sdk.targets(245,5): error :    at System.Collections.Immutable.ImmutableArray`1.Builder.MoveToImmutable() [D:\peachpie_bug\Website\Website.msbuildproj]
C:\Users\user\.nuget\packages\peachpie.net.sdk\1.1.5\build\Peachpie.NET.Core.Sdk.targets(245,5): error :    at Pchp.CodeAnalysis.Semantics.SemanticsBinder.BindArrayItems(Item[] items) in D:\a\1\s\src\Peachpie.CodeAnalysis\Semantics\Semant
icsBinder.cs:line 1130 [D:\peachpie_bug\Website\Website.msbuildproj]
C:\Users\user\.nuget\packages\peachpie.net.sdk\1.1.5\build\Peachpie.NET.Core.Sdk.targets(245,5): error :    at Pchp.CodeAnalysis.Semantics.SemanticsBinder.BindArrayEx(ArrayEx x, BoundAccess access) in D:\a\1\s\src\Peachpie.CodeAnalysis\Se
mantics\SemanticsBinder.cs:line 1030 [D:\peachpie_bug\Website\Website.msbuildproj]
C:\Users\user\.nuget\packages\peachpie.net.sdk\1.1.5\build\Peachpie.NET.Core.Sdk.targets(245,5): error :    at Pchp.CodeAnalysis.Semantics.SemanticsBinder.BindExpressionCore(Expression expr, BoundAccess access) in D:\a\1\s\src\Peachpie.Co
deAnalysis\Semantics\SemanticsBinder.cs:line 527 [D:\peachpie_bug\Website\Website.msbuildproj]
C:\Users\user\.nuget\packages\peachpie.net.sdk\1.1.5\build\Peachpie.NET.Core.Sdk.targets(245,5): error :    at Pchp.CodeAnalysis.Semantics.SemanticsBinder.BindExpression(Expression expr, BoundAccess access) in D:\a\1\s\src\Peachpie.CodeAn
alysis\Semantics\SemanticsBinder.cs:line 509 [D:\peachpie_bug\Website\Website.msbuildproj]
C:\Users\user\.nuget\packages\peachpie.net.sdk\1.1.5\build\Peachpie.NET.Core.Sdk.targets(245,5): error :    at Pchp.CodeAnalysis.Semantics.SemanticsBinder.BindAssignEx(AssignEx expr, BoundAccess access) in D:\a\1\s\src\Peachpie.CodeAnalys
is\Semantics\SemanticsBinder.cs:line 1411 [D:\peachpie_bug\Website\Website.msbuildproj]
C:\Users\user\.nuget\packages\peachpie.net.sdk\1.1.5\build\Peachpie.NET.Core.Sdk.targets(245,5): error :    at Pchp.CodeAnalysis.Semantics.SemanticsBinder.BindExpressionCore(Expression expr, BoundAccess access) in D:\a\1\s\src\Peachpie.Co
deAnalysis\Semantics\SemanticsBinder.cs:line 532 [D:\peachpie_bug\Website\Website.msbuildproj]
C:\Users\user\.nuget\packages\peachpie.net.sdk\1.1.5\build\Peachpie.NET.Core.Sdk.targets(245,5): error :    at Pchp.CodeAnalysis.Semantics.SemanticsBinder.BindExpression(Expression expr, BoundAccess access) in D:\a\1\s\src\Peachpie.CodeAn
alysis\Semantics\SemanticsBinder.cs:line 509 [D:\peachpie_bug\Website\Website.msbuildproj]
C:\Users\user\.nuget\packages\peachpie.net.sdk\1.1.5\build\Peachpie.NET.Core.Sdk.targets(245,5): error :    at Pchp.CodeAnalysis.Semantics.SemanticsBinder.BindStatementCore(Statement stmt) in D:\a\1\s\src\Peachpie.CodeAnalysis\Semantics\S
emanticsBinder.cs:line 351 [D:\peachpie_bug\Website\Website.msbuildproj]
C:\Users\user\.nuget\packages\peachpie.net.sdk\1.1.5\build\Peachpie.NET.Core.Sdk.targets(245,5): error :    at Pchp.CodeAnalysis.Semantics.SemanticsBinder.BindStatement(Statement stmt) in D:\a\1\s\src\Peachpie.CodeAnalysis\Semantics\Seman
ticsBinder.cs:line 344 [D:\peachpie_bug\Website\Website.msbuildproj]
C:\Users\user\.nuget\packages\peachpie.net.sdk\1.1.5\build\Peachpie.NET.Core.Sdk.targets(245,5): error :    at Pchp.CodeAnalysis.Semantics.SemanticsBinder.BindWholeStatement(Statement stmt) in D:\a\1\s\src\Peachpie.CodeAnalysis\Semantics\
SemanticsBinder.cs:line 342 [D:\peachpie_bug\Website\Website.msbuildproj]
C:\Users\user\.nuget\packages\peachpie.net.sdk\1.1.5\build\Peachpie.NET.Core.Sdk.targets(245,5): error :    at Pchp.CodeAnalysis.Semantics.Graph.BuilderVisitor.Add(Statement stmt) in D:\a\1\s\src\Peachpie.CodeAnalysis\Semantics\Graph\Buil
derVisitor.cs:line 209 [D:\peachpie_bug\Website\Website.msbuildproj]
C:\Users\user\.nuget\packages\peachpie.net.sdk\1.1.5\build\Peachpie.NET.Core.Sdk.targets(245,5): error :    at Pchp.CodeAnalysis.Semantics.Graph.BuilderVisitor.VisitExpressionStmt(ExpressionStmt x) in D:\a\1\s\src\Peachpie.CodeAnalysis\Se
mantics\Graph\BuilderVisitor.cs:line 534 [D:\peachpie_bug\Website\Website.msbuildproj]
C:\Users\user\.nuget\packages\peachpie.net.sdk\1.1.5\build\Peachpie.NET.Core.Sdk.targets(245,5): error :    at Devsense.PHP.Syntax.Ast.ExpressionStmt.VisitMe(TreeVisitor visitor) [D:\peachpie_bug\Website\Website.msbuildproj]
C:\Users\user\.nuget\packages\peachpie.net.sdk\1.1.5\build\Peachpie.NET.Core.Sdk.targets(245,5): error :    at Devsense.PHP.Syntax.TreeVisitor.VisitElement(ILangElement element) [D:\peachpie_bug\Website\Website.msbuildproj]
C:\Users\user\.nuget\packages\peachpie.net.sdk\1.1.5\build\Peachpie.NET.Core.Sdk.targets(245,5): error :    at Pchp.CodeAnalysis.EnumeratorExtension.ForEach[T](IEnumerable`1 enumerable, Action`1 func) in D:\a\1\s\src\Peachpie.CodeAnalysis
\Utilities\EnumeratorExtension.cs:line 62 [D:\peachpie_bug\Website\Website.msbuildproj]
C:\Users\user\.nuget\packages\peachpie.net.sdk\1.1.5\build\Peachpie.NET.Core.Sdk.targets(245,5): error :    at Pchp.CodeAnalysis.Semantics.Graph.BuilderVisitor..ctor(IList`1 statements, SemanticsBinder binder) in D:\a\1\s\src\Peachpie.Cod
eAnalysis\Semantics\Graph\BuilderVisitor.cs:line 176 [D:\peachpie_bug\Website\Website.msbuildproj]
C:\Users\user\.nuget\packages\peachpie.net.sdk\1.1.5\build\Peachpie.NET.Core.Sdk.targets(245,5): error :    at Pchp.CodeAnalysis.Semantics.Graph.BuilderVisitor.Build(IList`1 statements, SemanticsBinder binder) in D:\a\1\s\src\Peachpie.Cod
eAnalysis\Semantics\Graph\BuilderVisitor.cs:line 192 [D:\peachpie_bug\Website\Website.msbuildproj]
C:\Users\user\.nuget\packages\peachpie.net.sdk\1.1.5\build\Peachpie.NET.Core.Sdk.targets(245,5): error :    at Pchp.CodeAnalysis.Semantics.Graph.ControlFlowGraph..ctor(IList`1 statements, SemanticsBinder binder) in D:\a\1\s\src\Peachpie.C
odeAnalysis\Semantics\Graph\ControlFlowGraph.cs:line 125 [D:\peachpie_bug\Website\Website.msbuildproj]
C:\Users\user\.nuget\packages\peachpie.net.sdk\1.1.5\build\Peachpie.NET.Core.Sdk.targets(245,5): error :    at Pchp.CodeAnalysis.Symbols.SourceRoutineSymbol.get_ControlFlowGraph() in D:\a\1\s\src\Peachpie.CodeAnalysis\Symbols\Source\Sourc
eRoutineSymbol.cs:line 52 [D:\peachpie_bug\Website\Website.msbuildproj]
C:\Users\user\.nuget\packages\peachpie.net.sdk\1.1.5\build\Peachpie.NET.Core.Sdk.targets(245,5): error :    at Pchp.CodeAnalysis.SourceCompiler.EnqueueRoutine(SourceRoutineSymbol routine) in D:\a\1\s\src\Peachpie.CodeAnalysis\Compilation\
SourceCompiler.cs:line 119 [D:\peachpie_bug\Website\Website.msbuildproj]
C:\Users\user\.nuget\packages\peachpie.net.sdk\1.1.5\build\Peachpie.NET.Core.Sdk.targets(245,5): error :    at System.Threading.Tasks.Parallel.<>c__DisplayClass44_0`2.<PartitionerForEachWorker>b__1(IEnumerator& partitionState, Int32 timeo
ut, Boolean& replicationDelegateYieldedBeforeCompletion) [D:\peachpie_bug\Website\Website.msbuildproj]
C:\Users\user\.nuget\packages\peachpie.net.sdk\1.1.5\build\Peachpie.NET.Core.Sdk.targets(245,5): error : --- End of stack trace from previous location --- [D:\peachpie_bug\Website\Website.msbuildproj]
C:\Users\user\.nuget\packages\peachpie.net.sdk\1.1.5\build\Peachpie.NET.Core.Sdk.targets(245,5): error :    at System.Threading.Tasks.Parallel.<>c__DisplayClass44_0`2.<PartitionerForEachWorker>b__1(IEnumerator& partitionState, Int32 timeo
ut, Boolean& replicationDelegateYieldedBeforeCompletion) [D:\peachpie_bug\Website\Website.msbuildproj]
C:\Users\user\.nuget\packages\peachpie.net.sdk\1.1.5\build\Peachpie.NET.Core.Sdk.targets(245,5): error :    at System.Threading.Tasks.TaskReplicator.Replica.Execute() [D:\peachpie_bug\Website\Website.msbuildproj]

The build failed. Fix the build errors and run again.
jakubmisek commented 1 year ago

thanks!

You're right, also this feature is not supported yet, and as a consequence it crashes the compiler