isFunctionType
in PlutusIR.Transform.ThunkRecursions
misses a case for polymorphic functions
#4782
Labels
Costing
Anything relating to costs, fees, gas, etc.
Low priority
Doesn't require immediate attention
Performance
status: triaged
Summary
isFunctionType
inPlutusIR.Transform.ThunkRecursions
misses a case for polymorphic functions. This means that thethunkRecursions
pass will create a non-strict let-binding for such functions, which in the subsequentcompileNonStrictBindings True
will then give an unnecessary (Scott-encoded) unit argument. This matters, because this unit argument then makes it all the way through to the untyped Plutus core, resulting in larger than necessary core (indeed, Section 7 of "Formal Specification of the Plutus Core Language" explicitly states that the reason force/delay were introduced in the first place is the size of these unit arguments).Steps to reproduce the behavior
Consider
(the
newtype
is merely there to giveCompiledCode
a monomorphic type). If we trace the compilation of the monomorphic reverse through the pipeline, just beforethunkRecursions
we have(this is using my custom pretty-printer, excuse the non-standard syntax); the subsequent
thunkRecursions
pass then does not affectreverseMono
binding at all, and consequentlycompileNonStrictBindings True
doesn't do anything either. In the polymorphic case we see insteadwhich then by
thunkRecursions
is turned intoand then by
compileNonStrictBindings True
intowhere we see that Scott-encoded unit argument being introduced. This then makes it all the way to the core.
Actual Result
The untyped Plutus core for
reversePoly
isExpected Result
The untyped Plutus core for
reverseMono
iswhich is significantly smaller. Some size difference is perhaps expected (polymorphism leading to force/delay constructors elsewhere), but that is orthogonal to this ticket. The extra
(\ ~ x_2 -> x_2)
argument in the polymorphic version should not be needed.Describe the approach you would take to fix this
No response
System info
The above is tested with 4127e9c , though I see that
isFunctionType
has not changed in latestmaster
.The text was updated successfully, but these errors were encountered: