Skip to content

Missed use of solved dictionaries leads to context stack overflow

Hello! I don't have a minimal example, but I've got a very clear strange bahavior:

We've got a function:

nstar3 :: ( ExprCons t layers m, Bindable t m, Self.MonadSelfBuilder (Binding (Expr2 t layers AnyLayout)) m
          , ExprInferable t layers m)
       => m (Binding (PrimExpr2' t layers Star))
nstar3 = Self.put . anyLayout2 =<<& (nstar2 >>= mkBinding)

If I use it in a different function and use following explicit type, I get the error:

test_gr3 :: ( ExprCons t layers m, Bindable t m, ExprInferable t layers m
            , MonadIO m, Show bind, Show (PrimExpr2' t layers Star), layers~'[Data, Type]
            , Self.MonadSelfBuilder (Binding (Expr2 t layers AnyLayout)) m
            , bind ~ Binding (PrimExpr2' t layers Star)
        ) => m bind
test_gr3 = nstar3

error (while using the function and evaluating monads):

    • Reduction stack overflow; size = 201
      When simplifying the following type:
        MonadFix
          (Self.SelfBuilderT (Binding (Expr2 t0 '[Data, Type] AnyLayout)) m)
      Use -freduction-depth=0 to disable this check
      (any upper bound you could choose might fail unpredictably with
       minor updates to GHC, so disabling the check is recommended if
       you're sure that type checking should terminate)
    • In the second argument of ‘($)’, namely ‘(test_gr3)’
      In the second argument of ‘($)’, namely
        ‘runInferenceT2 @TermType @Net $ (test_gr3)’
      In the second argument of ‘($)’, namely
        ‘runInferenceT2 @InfLayers @'[Data, Type]
         $ runInferenceT2 @TermType @Net $ (test_gr3)’

What is "funny" is that if I change the type of test_gr3 to a very similar one, I just replace the part => m bind with manually expanded one m (Binding (PrimExpr2' t layers Star)) everything compiles fine.

It would be really hard to get minimal example out of it – it uses nested mfixes and will take much time to cut it down. The question is – can we locate the error based on the description?

Edited by Simon Peyton Jones
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information