Liqwid-Labs/liqwid-plutarch-extra

PInner Monoid instance in Plutarch.Orphans causes (plutarch-compile-time) infinite loops where (PInner a ~ a)

Closed this issue · 1 comments

t1lde commented

See:

-- | @since 1.3.0
instance
{-# OVERLAPPABLE #-}
(Semigroup (Term s a), a ~ PInner b) =>
Semigroup (Term s b)
where
(<>) = punsafeDowncast .* ((<>) `on` punsafeCoerce)
-- | @since 1.3.0
instance
{-# OVERLAPPABLE #-}
(Monoid (Term s a), a ~ PInner b) =>
Monoid (Term s b)
where
mempty = punsafeDowncast mempty

This causes most types without Monoid/Semigroup instances to erroneously receive instances!

For example - the following cause an infinite loop at plutarch compile time:

printTerm (Config DoTracing) (d :: Term s PScriptContext)
printTerm (Config DoTracing) (d :: Term s PDatum)

This is due to most of the Builtin types having (PInner a ~ a), so effectively every type will cause such looping !

Fascinating. How did you track this down?