dotnet-websharper / core

WebSharper - Full-stack, functional, reactive web apps and microservices in F# and C#
https://websharper.com
Apache License 2.0
593 stars 52 forks source link

Failing to optimize #1328

Closed granicz closed 1 year ago

granicz commented 1 year ago

From @cata, originally filed as a comment on dotnet-websharper/ui#267:

"Compilation fails for one of our library projects, with:"

WEBSHARPERTASK : error WS9001: Unexpected error during JavaScript compilation: Trying to optimize currification of a non-function type: ConcreteType  { Generics =     [FSharpFuncTyp
e        (ConcreteType           { Generics = []             Entity = { Assembly = "netstandard"  FullName = "System.String" } },         ConcreteType           { Generics = []
             Entity = { Assembly = "netstandard"  FullName = "System.String" } });      VoidType;      ConcreteType        { Generics = []          Entity = { Assembly = "netstan
dard"  FullName = "System.String" } };      ConcreteType        { Generics = []          Entity = { Assembly = "netstandard"  FullName = "System.String" } };      ConcreteType
       { Generics = []          Entity = { Assembly = "netstandard"  FullName = "System.String" } }]    Entity =     { Assembly = "FSharp.Core"  FullName = "Microsoft.FSharp.Core
.PrintfFormat`5" } } for var a at    at Microsoft.FSharp.Core.PrintfModule.PrintFormatToStringThenFail@1448.Invoke(String message)   at WebSharper.Compiler.CompilationHelpers.Optimiz
eLocalCurriedFunc..ctor(Id var, Int32 currying)   at WebSharper.Compiler.Breaker.removeLets(Expression expr)   at WebSharper.Compiler.Translator.RemoveLets.TransformExpression(Expre
ssion a)   at WebSharper.Core.AST.Transformer.TransformExprSourcePos(SourcePos a, Expression b)   at WebSharper.Core.AST.Transformer.TransformLet(Id a, Expression b, Expression c)
  at WebSharper.Core.AST.Transformer.TransformExprSourcePos(SourcePos a, Expression b)   at WebSharper.Core.AST.Transformer.TransformConditional(Expression a, Expression b, Expressio
n c)   at WebSharper.Core.AST.Transformer.TransformExprSourcePos(SourcePos a, Expression b)   at WebSharper.Core.AST.Transformer.TransformLet(Id a, Expression b, Expression c)   at
 WebSharper.Core.AST.Transformer.TransformExprSourcePos(SourcePos a, Expression b)   at WebSharper.Core.AST.Transformer.TransformConditional(Expression a, Expression b, Expression c)
   at WebSharper.Core.AST.Transformer.TransformExprSourcePos(SourcePos a, Expression b)   at WebSharper.Core.AST.Transformer.TransformExprSourcePos(SourcePos a, Expression b)   at
WebSharper.Core.AST.Transformer.TransformLet(Id a, Expression b, Expression c)   at WebSharper.Core.AST.Transformer.TransformExprSourcePos(SourcePos a, Expression b)   at WebSharper
.Core.AST.Transformer.TransformReturn(Expression a)   at WebSharper.Core.AST.Transformer.TransformFunction(FSharpList`1 a, FSharpOption`1 b, FSharpOption`1 c, Statement d)   at WebS
harper.Core.AST.Transformer.TransformExpression(Expression x)   at WebSharper.Core.AST.Transformer.TransformLet(Id a, Expression b, Expression c)   at WebSharper.Core.AST.Transforme
r.TransformExprSourcePos(SourcePos a, Expression b)   at WebSharper.Core.AST.Transformer.TransformReturn(Expression a)   at WebSharper.Core.AST.Transformer.TransformFunction(FSharpL
ist`1 a, FSharpOption`1 b, FSharpOption`1 c, Statement d)   at WebSharper.Core.AST.Transformer.TransformExpression(Expression x)   at WebSharper.Core.AST.Transformer.TransformExprSo
urcePos(SourcePos a, Expression b)   at WebSharper.Core.AST.Transformer.TransformApplication(Expression a, FSharpList`1 b, ApplicationInfo c)   at WebSharper.Core.AST.Transformer.Tr
ansformExprSourcePos(SourcePos a, Expression b)   at WebSharper.Core.AST.Transformer.TransformApplication(Expression a, FSharpList`1 b, ApplicationInfo c)   at WebSharper.Core.AST.T
ransformer.TransformExprSourcePos(SourcePos a, Expression b)   at WebSharper.Core.AST.Transformer.TransformApplication(Expression a, FSharpList`1 b, ApplicationInfo c)   at WebSharp
er.Core.AST.Transformer.TransformExprSourcePos(SourcePos a, Expression b)   at WebSharper.Core.AST.Transformer.TransformApplication(Expression a, FSharpList`1 b, ApplicationInfo c)
  at WebSharper.Core.AST.Transformer.TransformExprSourcePos(SourcePos a, Expression b)   at WebSharper.Core.AST.Transformer.TransformLet(Id a, Expression b, Expression c)   at WebSh
arper.Core.AST.Transformer.TransformExprSourcePos(SourcePos a, Expression b)   at WebSharper.Core.AST.Transformer.TransformLet(Id a, Expression b, Expression c)   at WebSharper.Core
.AST.Transformer.TransformExprSourcePos(SourcePos a, Expression b)   at WebSharper.Core.AST.Transformer.TransformExprSourcePos(SourcePos a, Expression b)   at WebSharper.Core.AST.Tr
ansformer.TransformLet(Id a, Expression b, Expression c)   at WebSharper.Core.AST.Transformer.TransformExprSourcePos(SourcePos a, Expression b)   at WebSharper.Core.AST.Transformer.
TransformLet(Id a, Expression b, Expression c)   at WebSharper.Core.AST.Transformer.TransformExprSourcePos(SourcePos a, Expression b)   at WebSharper.Core.AST.Transformer.TransformL
et(Id a, Expression b, Expression c)   at WebSharper.Core.AST.Transformer.TransformExprSourcePos(SourcePos a, Expression b)   at WebSharper.Core.AST.Transformer.TransformLet(Id a, E
xpression b, Expression c)   at WebSharper.Core.AST.Transformer.TransformExprSourcePos(SourcePos a, Expression b)   at WebSharper.Core.AST.Transformer.TransformLet(Id a, Expression
b, Expression c)   at WebSharper.Core.AST.Transformer.TransformExprSourcePos(SourcePos a, Expression b)   at WebSharper.Core.AST.Transformer.TransformItemSet(Expression a, Expressio
n b, Expression c)   at WebSharper.Core.AST.Transformer.TransformExprStatement(Expression a)   at WebSharper.Core.AST.Transformer.TransformBlock(FSharpList`1 a)   at WebSharper.Com
piler.Translator.DotNetToJavaScript.breakStatement(Statement e)   at WebSharper.Compiler.Translator.DotNetToJavaScript.CompileStaticConstructor(Statement expr, Hashed`1 typ) [C:\code
\motivity\src\Motivity.Configuration\Motivity.Configuration.fsproj]

@Jand42 you might want to reword "currification" - you probably meant "currying."

Jand42 commented 1 year ago

Indeed, this needs rewording and figuring out why it fails. https://github.com/dotnet-websharper/core/blob/ffe4a606b1916d8df3ad38e6facedf8e369d8ea4/src/compiler/WebSharper.Compiler/CompilationHelpers.fs#L1625

This failure is related to tracking types in expressions for .ts output - can be loosened for when we focus on .js + .d.ts working fully first.

granicz commented 1 year ago

I'd prefer to resolve the issue and not disable it. What's the offending t in type notation? I can't decypher it from the error.

Jand42 commented 1 year ago

It's "Microsoft.FSharp.Core.PrintfFormat`5" which is what F# translates printf family format strings. WS translates it to function, so it should be recognized as such for typing