peachpiecompiler / peachpie

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

Translate(ErrorType App.Shell.AppShell) #1043

Open menturion opened 2 years ago

menturion commented 2 years ago

The following error is thrown (w/o a reference to the app's source code):

PeachPie PHP Compiler version 1.0.0-appv4840+631baa3c525c6dd80e02a2c56b9c3e945ea211d9
\.nuget\packages\peachpie.net.sdk\1.0.0-appv4840\build\Peachpie.NET.Core.Sdk.targets(245,5): error : Translate(ErrorType App.Shell.AppShell) 
\.nuget\packages\peachpie.net.sdk\1.0.0-appv4840\build\Peachpie.NET.Core.Sdk.targets(245,5): error :    at Pchp.CodeAnalysis.Emit.PEModuleBuilder.Translate(NamedTypeSymbol namedTypeSymbol, SyntaxNode syntaxOpt, DiagnosticBag diagnostics, Boolean fromImplements, Boolean needDeclaration) 
\.nuget\packages\peachpie.net.sdk\1.0.0-appv4840\build\Peachpie.NET.Core.Sdk.targets(245,5): error :    at Pchp.CodeAnalysis.Symbols.NamedTypeSymbol.Microsoft.Cci.ITypeDefinition.GetBaseClass(EmitContext context) 
\.nuget\packages\peachpie.net.sdk\1.0.0-appv4840\build\Peachpie.NET.Core.Sdk.targets(245,5): error :    at Microsoft.Cci.ReferenceIndexerBase.VisitTypeDefinitionNoMembers(ITypeDefinition typeDefinition) in C:\Users\jmise\Projects\Peachpie.Microsoft.CodeAnalysis\src\Compilers\Core\Portable\PEWriter\ReferenceIndexerBase.cs:line 274 
\.nuget\packages\peachpie.net.sdk\1.0.0-appv4840\build\Peachpie.NET.Core.Sdk.targets(245,5): error :    at Microsoft.Cci.ReferenceIndexerBase.Visit(ITypeDefinition typeDefinition) in C:\Users\jmise\Projects\Peachpie.Microsoft.CodeAnalysis\src\Compilers\Core\Portable\PEWriter\ReferenceIndexerBase.cs:line 285 
\.nuget\packages\peachpie.net.sdk\1.0.0-appv4840\build\Peachpie.NET.Core.Sdk.targets(245,5): error :    at Microsoft.Cci.MetadataVisitor.Visit(IEnumerable`1 types) in C:\Users\jmise\Projects\Peachpie.Microsoft.CodeAnalysis\src\Compilers\Core\Portable\PEWriter\MetadataVisitor.cs:line 365 
\.nuget\packages\peachpie.net.sdk\1.0.0-appv4840\build\Peachpie.NET.Core.Sdk.targets(245,5): error :    at Microsoft.Cci.ReferenceIndexer.Visit(CommonPEModuleBuilder module) in C:\Users\jmise\Projects\Peachpie.Microsoft.CodeAnalysis\src\Compilers\Core\Portable\PEWriter\ReferenceIndexer.cs:line 33 
\.nuget\packages\peachpie.net.sdk\1.0.0-appv4840\build\Peachpie.NET.Core.Sdk.targets(245,5): error :    at Microsoft.Cci.MetadataWriter.CreateIndices() in C:\Users\jmise\Projects\Peachpie.Microsoft.CodeAnalysis\src\Compilers\Core\Portable\PEWriter\MetadataWriter.cs:line 492 
\.nuget\packages\peachpie.net.sdk\1.0.0-appv4840\build\Peachpie.NET.Core.Sdk.targets(245,5): error :    at Microsoft.Cci.MetadataWriter.BuildMetadataAndIL(PdbWriter nativePdbWriterOpt, BlobBuilder ilBuilder, BlobBuilder mappedFieldDataBuilder, BlobBuilder managedResourceDataBuilder, Blob& mvidFixup, Blob& mvidStringFixup) in C:\Users\jmise\Projects\Peachpie.Microsoft.CodeAnalysis\src\Compilers\Core\Portable\PEWriter\MetadataWriter.cs:line 1781 
\.nuget\packages\peachpie.net.sdk\1.0.0-appv4840\build\Peachpie.NET.Core.Sdk.targets(245,5): error :    at Microsoft.Cci.PeWriter.WritePeToStream(EmitContext context, CommonMessageProvider messageProvider, Func`1 getPeStream, Func`1 getPortablePdbStreamOpt, PdbWriter nativePdbWriterOpt, String pdbPathOpt, Boolean metadataOnly, Boolean isDeterministic, Boolean emitTestCoverageData, Nullable`1 privateKeyOpt, CancellationToken cancellationToken) in C:\Users\jmise\Projects\Peachpie.Microsoft.CodeAnalysis\src\Compilers\Core\Portable\PEWriter\PeWriter.cs:line 69 
\.nuget\packages\peachpie.net.sdk\1.0.0-appv4840\build\Peachpie.NET.Core.Sdk.targets(245,5): error :    at Microsoft.CodeAnalysis.Compilation.SerializePeToStream(CommonPEModuleBuilder moduleBeingBuilt, DiagnosticBag metadataDiagnostics, CommonMessageProvider messageProvider, Func`1 getPeStream, Func`1 getMetadataPeStreamOpt, Func`1 getPortablePdbStreamOpt, PdbWriter nativePdbWriterOpt, String pdbPathOpt, Boolean metadataOnly, Boolean includePrivateMembers, Boolean isDeterministic, Boolean emitTestCoverageData, Nullable`1 privateKeyOpt, CancellationToken cancellationToken) in C:\Users\jmise\Projects\Peachpie.Microsoft.CodeAnalysis\src\Compilers\Core\Portable\Compilation\Compilation.cs:line 2927 
\.nuget\packages\peachpie.net.sdk\1.0.0-appv4840\build\Peachpie.NET.Core.Sdk.targets(245,5): error :    at Microsoft.CodeAnalysis.Compilation.SerializeToPeStream(CommonPEModuleBuilder moduleBeingBuilt, EmitStreamProvider peStreamProvider, EmitStreamProvider metadataPEStreamProvider, EmitStreamProvider pdbStreamProvider, Func`2 testSymWriterFactory, DiagnosticBag diagnostics, EmitOptions emitOptions, Nullable`1 privateKeyOpt, CancellationToken cancellationToken) in C:\Users\jmise\Projects\Peachpie.Microsoft.CodeAnalysis\src\Compilers\Core\Portable\Compilation\Compilation.cs:line 2826 
\.nuget\packages\peachpie.net.sdk\1.0.0-appv4840\build\Peachpie.NET.Core.Sdk.targets(245,5): error :    at Microsoft.CodeAnalysis.CommonCompiler.CompileAndEmit(TouchedFileLogger touchedFilesLogger, Compilation& compilation, ImmutableArray`1 analyzers, ImmutableArray`1 generators, ImmutableArray`1 additionalTextFiles, AnalyzerConfigSet analyzerConfigSet, ImmutableArray`1 sourceFileAnalyzerConfigOptions, ImmutableArray`1 embeddedTexts, DiagnosticBag diagnostics, CancellationToken cancellationToken, CancellationTokenSource& analyzerCts, Boolean& reportAnalyzer, AnalyzerDriver& analyzerDriver) in C:\Users\jmise\Projects\Peachpie.Microsoft.CodeAnalysis\src\Compilers\Core\Portable\CommandLine\CommonCompiler.cs:line 1205 
\.nuget\packages\peachpie.net.sdk\1.0.0-appv4840\build\Peachpie.NET.Core.Sdk.targets(245,5): error :    at Microsoft.CodeAnalysis.CommonCompiler.RunCore(TextWriter consoleOutput, ErrorLogger errorLogger, CancellationToken cancellationToken) in C:\Users\jmise\Projects\Peachpie.Microsoft.CodeAnalysis\src\Compilers\Core\Portable\CommandLine\CommonCompiler.cs:line 811 
\.nuget\packages\peachpie.net.sdk\1.0.0-appv4840\build\Peachpie.NET.Core.Sdk.targets(245,5): error :    at Microsoft.CodeAnalysis.CommonCompiler.Run(TextWriter consoleOutput, CancellationToken cancellationToken) in C:\Users\jmise\Projects\Peachpie.Microsoft.CodeAnalysis\src\Compilers\Core\Portable\CommandLine\CommonCompiler.cs:line 699 
\.nuget\packages\peachpie.net.sdk\1.0.0-appv4840\build\Peachpie.NET.Core.Sdk.targets(245,5): error :    at Peachpie.NET.Sdk.Tools.BuildTask.Execute() 
jakubmisek commented 2 years ago

thank you; it's a NotImplementedException which should be properly handled with a proper error message.

The root cause is that the class "App.Shell.AppShell" can't be probably resolved.

menturion commented 2 years ago

It would be helpful if the location where the class is referenced was specified in the error message.

menturion commented 2 years ago

This kind of error (i.e. classes that cannot be resolved) solely/often occurs in vendor libs that are referencing/extending optional ("require-dev") dependencies. Fixing these issues for vendor libs by excluding parts of affected libs is hard if not impossible w/o editing the affected code itself. However, editing vendor libs is a never ending task.

Would it be a feasible way to overcome the absence of a class definition if PeachPie would create an empty dummy class in case it detects the absence of this class (of an optional dependency)? This feature could be enabled for vendor libs by introducing a new compile option.

jakubmisek commented 2 years ago

That's correct, it may create a dummy class that throws in runtime. Or it can postpone the super-class declaration into the runtime.

Also, some composer packages get replaced by other packages in runtime using composer autoload, so ... compiler cannot know and the whole program should be rather jitted. Basically, we expected the use case where the developer prepares the PHP project in a similar way as other compiled languages (like C#) are.

menturion commented 2 years ago

Basically, we expected the use case where the developer prepares the PHP project in a similar way as other compiled languages (like C#) are.

... with the difference that the C# developer was aware of the fact at the time he started the project that he has to provide all the code :)

Could PeachPie easily dummy'fy (i.e. exclude) the classes and their non-existing methods if the developer would be able to tell PeachPie the (non-existing) classes that need to be excluded (e.g. like <Compile ExcludeClass="..." />)?