runtimeverification / k

K Framework Tools 7.0
BSD 3-Clause "New" or "Revised" License
444 stars 145 forks source link

[K-Bug] checkSubstitutionCoverage error in Haskell backend #3413

Open jeanas opened 1 year ago

jeanas commented 1 year ago

What component is the issue in?

haskell-backend

Which command

What K Version?

v5.6.90 (Thu May 11 22:42:38 CEST 2023)

Operating System

Linux

K Definitions (If Possible)

This is minimized from a larger file that is supposed to reduce λ-terms (NB I am a beginner with K).

module LAMBDA-SYNTAX
  import DOMAINS

  syntax Lambda ::= Id
                    | Lambda Lambda
                        | "/\\\\" Id "." Lambda
                        | "(" Lambda ")" [bracket]
endmodule

module LAMBDA
  imports LAMBDA-SYNTAX

  syntax State ::= ListFreeVariables()
                   | RenameBoundVariables()
                       | Reduce()
                       | Replace()

  syntax KItem ::= AppLeftFreezer(Lambda)
                   | AppRightFreezer(Lambda)
                       | AbstracFreezer(Id)
                       | todo(KItem)
                       | done(KItem)

  configuration
    <state> ListFreeVariables() </state>
    <list-free-variables> todo($PGM) ~> .K </list-free-variables>
        <all-free-variables> .Set </all-free-variables>
        <bound-variables> .Set ~> .K </bound-variables>
        <rename-bound-variables> todo($PGM) ~> .K </rename-bound-variables>
        <bound-variable-renamings> .Map ~> .K </bound-variable-renamings>
        <bound-variable-renaming-sources> .Map </bound-variable-renaming-sources>
        <reduce> .K </reduce>
        <replace> .K </replace>
        <replace-var> .K </replace-var>
        <replace-term> .K </replace-term>

  rule <state> ListFreeVariables() </state>
       <list-free-variables>
         todo(X:Id) ~> Rest => done(X:Id) ~> Rest
       </list-free-variables>
       <bound-variables> _S SetItem(X) ~> _BoundRest </bound-variables>

  rule <state> ListFreeVariables() </state>
       <list-free-variables>
         todo(X:Id) ~> Rest => done(X:Id) ~> Rest
       </list-free-variables>
       <all-free-variables>
         S => S SetItem(X)
       </all-free-variables>
       <bound-variable-renaming-sources>
         M => (X |-> 0) M
       </bound-variable-renaming-sources>
     [owise]

  rule <state> ListFreeVariables() </state>
       <list-free-variables>
         todo(U V) ~> Rest => todo(U) ~> AppRightFreezer(V) ~> Rest
       </list-free-variables>

  rule <state> ListFreeVariables() </state>
       <list-free-variables>
         todo(/\\ X . U) ~> Rest => todo(U) ~> AbstracFreezer(X) ~> Rest
       </list-free-variables>
       <bound-variables>
         S ~> BoundRest => S SetItem(X) ~> S ~> BoundRest
       </bound-variables>

  rule [debugme]: <state> ListFreeVariables() </state>
       <list-free-variables>
         done(U) ~> AbstracFreezer(X) ~> Rest => done(/\\ X . U) ~> Rest
       </list-free-variables>
       <bound-variables>
         _S ~> BoundRest => BoundRest
       </bound-variables>

endmodule

Steps to Reproduce

Save the above as lambda.k. Save the following as simple.lambda:

(/\\ x . x) (/\\ y . (/\\ z . (y z)))

Then run:

kompile --backend haskell lambda.k
krun simple.lambda

This gives this huge error message:

``` kore-exec: [334353] Error (ErrorRewritesInstantiation): While rewriting the configuration: \and{SortGeneratedTopCell{}}( /* term: */ /* T Fn D Sfa Cl */ Lbl'-LT-'generatedTop'-GT-'{}( /* T Fn D Sfa Cl */ Lbl'-LT-'state'-GT-'{}( /* T Fn D Sfa Cl */ LblListFreeVariables'LParRParUnds'LAMBDA'Unds'State{}() ), /* T Fn D Sfa Cl */ Lbl'-LT-'list-free-variables'-GT-'{}( /* T Fn D Sfa Cl */ kseq{}( /* T Fn D Sfa Cl */ Lbldone'LParUndsRParUnds'LAMBDA'Unds'KItem'Unds'KItem{}( /* T Fn D Sfa Cli */ /* Inj: */ inj{SortId{}, SortKItem{}}( /* T Fn D Sfa Cl */ \dv{SortId{}}(/* T Fn D Sfa Cl */ "x") ) ), /* T Fn D Sfa Cl */ kseq{}( /* T Fn D Sfa Cl */ LblAbstracFreezer'LParUndsRParUnds'LAMBDA'Unds'KItem'Unds'Id{}( /* T Fn D Sfa Cl */ \dv{SortId{}}(/* T Fn D Sfa Cl */ "x") ), /* T Fn D Sfa Cl */ kseq{}( /* T Fn D Sfa Cl */ LblAppRightFreezer'LParUndsRParUnds'LAMBDA'Unds'KItem'Unds'Lambda{}( /* T Fn D Sfa Cl */ Lbl'SlshBashBashUndsStopUndsUnds'LAMBDA-SYNTAX'Unds'Lambda'Unds'Id'Unds'Lambda{}( /* T Fn D Sfa Cl */ \dv{SortId{}}(/* T Fn D Sfa Cl */ "y"), /* T Fn D Sfa Cl */ Lbl'SlshBashBashUndsStopUndsUnds'LAMBDA-SYNTAX'Unds'Lambda'Unds'Id'Unds'Lambda{}( /* T Fn D Sfa Cl */ \dv{SortId{}}(/* T Fn D Sfa Cl */ "z"), /* T Fn D Sfa Cl */ Lbl'UndsUndsUnds'LAMBDA-SYNTAX'Unds'Lambda'Unds'Lambda'Unds'Lambda{}( /* T Fn D Sfa Cli */ /* Inj: */ inj{SortId{}, SortLambda{}}( /* T Fn D Sfa Cl */ \dv{SortId{}}(/* T Fn D Sfa Cl */ "y") ), /* T Fn D Sfa Cli */ /* Inj: */ inj{SortId{}, SortLambda{}}( /* T Fn D Sfa Cl */ \dv{SortId{}}(/* T Fn D Sfa Cl */ "z") ) ) ) ) ), /* T Fn D Sfa Cl */ dotk{}() ) ) ) ), /* T Fn D Sfa Cl */ Lbl'-LT-'all-free-variables'-GT-'{}( /* T Fn D Sfa Cl */ /* InternalSet: */ Lbl'Stop'Set{}() ), /* T Fn D Sfa Cl */ Lbl'-LT-'bound-variables'-GT-'{}( /* T Fn D Sfa Cl */ kseq{}( /* T Fn D Sfa Cli */ /* Inj: */ inj{SortSet{}, SortKItem{}}( /* T Fn D Sfa Cl */ /* InternalSet: */ /* concrete element: */ LblSetItem{}( /* Inj: */ inj{SortId{}, SortKItem{}}( \dv{SortId{}}("x") ) ) ), /* T Fn D Sfa Cl */ kseq{}( /* T Fn D Sfa Cli */ /* Inj: */ inj{SortSet{}, SortKItem{}}( /* T Fn D Sfa Cl */ /* InternalSet: */ Lbl'Stop'Set{}() ), /* T Fn D Sfa Cl */ dotk{}() ) ) ), /* T Fn D Sfa Cl */ Lbl'-LT-'rename-bound-variables'-GT-'{}( /* T Fn D Sfa Cl */ kseq{}( /* T Fn D Sfa Cl */ Lbltodo'LParUndsRParUnds'LAMBDA'Unds'KItem'Unds'KItem{}( /* T Fn D Sfa Cli */ /* Inj: */ inj{SortLambda{}, SortKItem{}}( /* T Fn D Sfa Cl */ Lbl'UndsUndsUnds'LAMBDA-SYNTAX'Unds'Lambda'Unds'Lambda'Unds'Lambda{}( /* T Fn D Sfa Cl */ Lbl'SlshBashBashUndsStopUndsUnds'LAMBDA-SYNTAX'Unds'Lambda'Unds'Id'Unds'Lambda{}( /* T Fn D Sfa Cl */ \dv{SortId{}}(/* T Fn D Sfa Cl */ "x"), /* T Fn D Sfa Cli */ /* Inj: */ inj{SortId{}, SortLambda{}}( /* T Fn D Sfa Cl */ \dv{SortId{}}(/* T Fn D Sfa Cl */ "x") ) ), /* T Fn D Sfa Cl */ Lbl'SlshBashBashUndsStopUndsUnds'LAMBDA-SYNTAX'Unds'Lambda'Unds'Id'Unds'Lambda{}( /* T Fn D Sfa Cl */ \dv{SortId{}}(/* T Fn D Sfa Cl */ "y"), /* T Fn D Sfa Cl */ Lbl'SlshBashBashUndsStopUndsUnds'LAMBDA-SYNTAX'Unds'Lambda'Unds'Id'Unds'Lambda{}( /* T Fn D Sfa Cl */ \dv{SortId{}}(/* T Fn D Sfa Cl */ "z"), /* T Fn D Sfa Cl */ Lbl'UndsUndsUnds'LAMBDA-SYNTAX'Unds'Lambda'Unds'Lambda'Unds'Lambda{}( /* T Fn D Sfa Cli */ /* Inj: */ inj{SortId{}, SortLambda{}}( /* T Fn D Sfa Cl */ \dv{SortId{}}(/* T Fn D Sfa Cl */ "y") ), /* T Fn D Sfa Cli */ /* Inj: */ inj{SortId{}, SortLambda{}}( /* T Fn D Sfa Cl */ \dv{SortId{}}(/* T Fn D Sfa Cl */ "z") ) ) ) ) ) ) ), /* T Fn D Sfa Cl */ dotk{}() ) ), /* T Fn D Sfa Cl */ Lbl'-LT-'bound-variable-renamings'-GT-'{}( /* T Fn D Sfa Cl */ kseq{}( /* T Fn D Sfa Cli */ /* Inj: */ inj{SortMap{}, SortKItem{}}( /* T Fn D Sfa Cl */ /* InternalMap: */ Lbl'Stop'Map{}() ), /* T Fn D Sfa Cl */ dotk{}() ) ), /* T Fn D Sfa Cl */ Lbl'-LT-'bound-variable-renaming-sources'-GT-'{}( /* T Fn D Sfa Cl */ /* InternalMap: */ Lbl'Stop'Map{}() ), /* T Fn D Sfa Cl */ Lbl'-LT-'reduce'-GT-'{}(/* T Fn D Sfa Cl */ dotk{}()), /* T Fn D Sfa Cl */ Lbl'-LT-'replace'-GT-'{}(/* T Fn D Sfa Cl */ dotk{}()), /* T Fn D Sfa Cl */ Lbl'-LT-'replace-var'-GT-'{}(/* T Fn D Sfa Cl */ dotk{}()), /* T Fn D Sfa Cl */ Lbl'-LT-'replace-term'-GT-'{}(/* T Fn D Sfa Cl */ dotk{}()), /* T Fn D Sfa Cl */ Lbl'-LT-'generatedCounter'-GT-'{}( /* T Fn D Sfa Cl */ \dv{SortInt{}}("0") ) ), \and{SortGeneratedTopCell{}}( /* predicate: */ /* D Sfa */ \top{SortGeneratedTopCell{}}(), /* substitution: */ \top{SortGeneratedTopCell{}}() )) Unable to instantiate semantic rule at /home/jean/Documents/bug-report/lambda.k:69:19-75:26 Unification did not find a solution for the variables: RuleVar'Unds'S RuleVarBoundRest The unification solution was: \and{SortGeneratedTopCell{}}( /* term: */ /* Spa */ \rewrites{SortGeneratedTopCell{}}( /* Spa */ \and{SortGeneratedTopCell{}}( /* D Sfa */ \top{SortGeneratedTopCell{}}(), /* T Fn D Sfa */ Lbl'-LT-'generatedTop'-GT-'{}( /* T Fn D Sfa Cl */ Lbl'-LT-'state'-GT-'{}( /* T Fn D Sfa Cl */ LblListFreeVariables'LParRParUnds'LAMBDA'Unds'State{}() ), /* T Fn D Sfa */ Lbl'-LT-'list-free-variables'-GT-'{}( /* T Fn D Sfa */ kseq{}( /* T Fn D Sfa */ Lbldone'LParUndsRParUnds'LAMBDA'Unds'KItem'Unds'KItem{}( /* T Fn D Sfa */ /* Inj: */ inj{SortLambda{}, SortKItem{}}( /* T Fn D Sfa */ RuleVarU:SortLambda{} ) ), /* T Fn D Sfa */ kseq{}( /* T Fn D Sfa */ LblAbstracFreezer'LParUndsRParUnds'LAMBDA'Unds'KItem'Unds'Id{}( /* T Fn D Sfa */ RuleVarX:SortId{} ), /* T Fn D Sfa */ RuleVarRest:SortK{} ) ) ), /* T Fn D Sfa */ RuleVar'Unds'Gen0:SortAllFreeVariablesCell{}, /* T Fn D Sfa */ Lbl'-LT-'bound-variables'-GT-'{}( /* T Fn D Sfa */ append{}( /* T Fn D Sfa */ RuleVar'Unds'S:SortK{}, /* T Fn D Sfa */ RuleVarBoundRest:SortK{} ) ), /* T Fn D Sfa */ RuleVar'Unds'Gen1:SortRenameBoundVariablesCell{}, /* T Fn D Sfa */ RuleVar'Unds'Gen2:SortBoundVariableRenamingsCell{}, /* T Fn D Sfa */ RuleVar'Unds'Gen3:SortBoundVariableRenamingSourcesCell{}, /* T Fn D Sfa */ RuleVar'Unds'Gen4:SortReduceCell{}, /* T Fn D Sfa */ RuleVar'Unds'Gen5:SortReplaceCell{}, /* T Fn D Sfa */ RuleVar'Unds'Gen6:SortReplaceVarCell{}, /* T Fn D Sfa */ RuleVar'Unds'Gen7:SortReplaceTermCell{}, /* T Fn D Sfa */ RuleVar'Unds'Gen8:SortGeneratedCounterCell{} ) ), /* T Fn D Spa */ Lbl'-LT-'generatedTop'-GT-'{}( /* T Fn D Sfa Cl */ Lbl'-LT-'state'-GT-'{}( /* T Fn D Sfa Cl */ LblListFreeVariables'LParRParUnds'LAMBDA'Unds'State{}() ), /* T Fn D Spa */ Lbl'-LT-'list-free-variables'-GT-'{}( /* T Fn D Spa */ kseq{}( /* T Fn D Spa */ Lbldone'LParUndsRParUnds'LAMBDA'Unds'KItem'Unds'KItem{}( /* T Fn D Spa */ /* Inj: */ inj{SortLambda{}, SortKItem{}}( /* T Fn D Spa */ Lbl'SlshBashBashUndsStopUndsUnds'LAMBDA-SYNTAX'Unds'Lambda'Unds'Id'Unds'Lambda{}( /* T Fn D Sfa */ RuleVarX:SortId{}, /* T Fn D Sfa */ RuleVarU:SortLambda{} ) ) ), /* T Fn D Sfa */ RuleVarRest:SortK{} ) ), /* T Fn D Sfa */ RuleVar'Unds'Gen0:SortAllFreeVariablesCell{}, /* T Fn D Spa */ Lbl'-LT-'bound-variables'-GT-'{}( /* T Fn D Sfa */ RuleVarBoundRest:SortK{} ), /* T Fn D Sfa */ RuleVar'Unds'Gen1:SortRenameBoundVariablesCell{}, /* T Fn D Sfa */ RuleVar'Unds'Gen2:SortBoundVariableRenamingsCell{}, /* T Fn D Sfa */ RuleVar'Unds'Gen3:SortBoundVariableRenamingSourcesCell{}, /* T Fn D Sfa */ RuleVar'Unds'Gen4:SortReduceCell{}, /* T Fn D Sfa */ RuleVar'Unds'Gen5:SortReplaceCell{}, /* T Fn D Sfa */ RuleVar'Unds'Gen6:SortReplaceVarCell{}, /* T Fn D Sfa */ RuleVar'Unds'Gen7:SortReplaceTermCell{}, /* T Fn D Sfa */ RuleVar'Unds'Gen8:SortGeneratedCounterCell{} ) ), \and{SortGeneratedTopCell{}}( /* predicate: */ /* Sfa */ \equals{SortK{}, SortGeneratedTopCell{}}( /* T Fn D Sfa Cl */ kseq{}( /* T Fn D Sfa Cli */ /* Inj: */ inj{SortSet{}, SortKItem{}}( /* T Fn D Sfa Cl */ /* InternalSet: */ /* concrete element: */ LblSetItem{}( /* Inj: */ inj{SortId{}, SortKItem{}}( \dv{SortId{}}("x") ) ) ), /* T Fn D Sfa Cl */ kseq{}( /* T Fn D Sfa Cli */ /* Inj: */ inj{SortSet{}, SortKItem{}}( /* T Fn D Sfa Cl */ /* InternalSet: */ Lbl'Stop'Set{}() ), /* T Fn D Sfa Cl */ dotk{}() ) ), /* T Fn D Sfa */ append{}( /* T Fn D Sfa */ RuleVar'Unds'S:SortK{}, /* T Fn D Sfa */ RuleVarBoundRest:SortK{} ) ), /* substitution: */ \and{SortGeneratedTopCell{}}( /* Spa */ \equals{SortAllFreeVariablesCell{}, SortGeneratedTopCell{}}( /* T Fn D Sfa */ RuleVar'Unds'Gen0:SortAllFreeVariablesCell{}, /* T Fn D Sfa Cl */ Lbl'-LT-'all-free-variables'-GT-'{}( /* T Fn D Sfa Cl */ /* InternalSet: */ Lbl'Stop'Set{}() ) ), \and{SortGeneratedTopCell{}}( /* Spa */ \equals{SortRenameBoundVariablesCell{}, SortGeneratedTopCell{}}( /* T Fn D Sfa */ RuleVar'Unds'Gen1:SortRenameBoundVariablesCell{}, /* T Fn D Sfa Cl */ Lbl'-LT-'rename-bound-variables'-GT-'{}( /* T Fn D Sfa Cl */ kseq{}( /* T Fn D Sfa Cl */ Lbltodo'LParUndsRParUnds'LAMBDA'Unds'KItem'Unds'KItem{}( /* T Fn D Sfa Cli */ /* Inj: */ inj{SortLambda{}, SortKItem{}}( /* T Fn D Sfa Cl */ Lbl'UndsUndsUnds'LAMBDA-SYNTAX'Unds'Lambda'Unds'Lambda'Unds'Lambda{}( /* T Fn D Sfa Cl */ Lbl'SlshBashBashUndsStopUndsUnds'LAMBDA-SYNTAX'Unds'Lambda'Unds'Id'Unds'Lambda{}( /* T Fn D Sfa Cl */ \dv{SortId{}}(/* T Fn D Sfa Cl */ "x"), /* T Fn D Sfa Cli */ /* Inj: */ inj{SortId{}, SortLambda{}}( /* T Fn D Sfa Cl */ \dv{SortId{}}(/* T Fn D Sfa Cl */ "x") ) ), /* T Fn D Sfa Cl */ Lbl'SlshBashBashUndsStopUndsUnds'LAMBDA-SYNTAX'Unds'Lambda'Unds'Id'Unds'Lambda{}( /* T Fn D Sfa Cl */ \dv{SortId{}}(/* T Fn D Sfa Cl */ "y"), /* T Fn D Sfa Cl */ Lbl'SlshBashBashUndsStopUndsUnds'LAMBDA-SYNTAX'Unds'Lambda'Unds'Id'Unds'Lambda{}( /* T Fn D Sfa Cl */ \dv{SortId{}}(/* T Fn D Sfa Cl */ "z"), /* T Fn D Sfa Cl */ Lbl'UndsUndsUnds'LAMBDA-SYNTAX'Unds'Lambda'Unds'Lambda'Unds'Lambda{}( /* T Fn D Sfa Cli */ /* Inj: */ inj{SortId{}, SortLambda{}}( /* T Fn D Sfa Cl */ \dv{SortId{}}(/* T Fn D Sfa Cl */ "y") ), /* T Fn D Sfa Cli */ /* Inj: */ inj{SortId{}, SortLambda{}}( /* T Fn D Sfa Cl */ \dv{SortId{}}(/* T Fn D Sfa Cl */ "z") ) ) ) ) ) ) ), /* T Fn D Sfa Cl */ dotk{}() ) ) ), \and{SortGeneratedTopCell{}}( /* Spa */ \equals{SortBoundVariableRenamingsCell{}, SortGeneratedTopCell{}}( /* T Fn D Sfa */ RuleVar'Unds'Gen2:SortBoundVariableRenamingsCell{}, /* T Fn D Sfa Cl */ Lbl'-LT-'bound-variable-renamings'-GT-'{}( /* T Fn D Sfa Cl */ kseq{}( /* T Fn D Sfa Cli */ /* Inj: */ inj{SortMap{}, SortKItem{}}( /* T Fn D Sfa Cl */ /* InternalMap: */ Lbl'Stop'Map{}() ), /* T Fn D Sfa Cl */ dotk{}() ) ) ), \and{SortGeneratedTopCell{}}( /* Spa */ \equals{SortBoundVariableRenamingSourcesCell{}, SortGeneratedTopCell{}}( /* T Fn D Sfa */ RuleVar'Unds'Gen3:SortBoundVariableRenamingSourcesCell{}, /* T Fn D Sfa Cl */ Lbl'-LT-'bound-variable-renaming-sources'-GT-'{}( /* T Fn D Sfa Cl */ /* InternalMap: */ Lbl'Stop'Map{}() ) ), \and{SortGeneratedTopCell{}}( /* Spa */ \equals{SortReduceCell{}, SortGeneratedTopCell{}}( /* T Fn D Sfa */ RuleVar'Unds'Gen4:SortReduceCell{}, /* T Fn D Sfa Cl */ Lbl'-LT-'reduce'-GT-'{}(/* T Fn D Sfa Cl */ dotk{}()) ), \and{SortGeneratedTopCell{}}( /* Spa */ \equals{SortReplaceCell{}, SortGeneratedTopCell{}}( /* T Fn D Sfa */ RuleVar'Unds'Gen5:SortReplaceCell{}, /* T Fn D Sfa Cl */ Lbl'-LT-'replace'-GT-'{}(/* T Fn D Sfa Cl */ dotk{}()) ), \and{SortGeneratedTopCell{}}( /* Spa */ \equals{SortReplaceVarCell{}, SortGeneratedTopCell{}}( /* T Fn D Sfa */ RuleVar'Unds'Gen6:SortReplaceVarCell{}, /* T Fn D Sfa Cl */ Lbl'-LT-'replace-var'-GT-'{}(/* T Fn D Sfa Cl */ dotk{}()) ), \and{SortGeneratedTopCell{}}( /* Spa */ \equals{SortReplaceTermCell{}, SortGeneratedTopCell{}}( /* T Fn D Sfa */ RuleVar'Unds'Gen7:SortReplaceTermCell{}, /* T Fn D Sfa Cl */ Lbl'-LT-'replace-term'-GT-'{}(/* T Fn D Sfa Cl */ dotk{}()) ), \and{SortGeneratedTopCell{}}( /* Spa */ \equals{SortGeneratedCounterCell{}, SortGeneratedTopCell{}}( /* T Fn D Sfa */ RuleVar'Unds'Gen8:SortGeneratedCounterCell{}, /* T Fn D Sfa Cl */ Lbl'-LT-'generatedCounter'-GT-'{}( /* T Fn D Sfa Cl */ \dv{SortInt{}}("0") ) ), \and{SortGeneratedTopCell{}}( /* Spa */ \equals{SortK{}, SortGeneratedTopCell{}}( /* T Fn D Sfa */ RuleVarRest:SortK{}, /* T Fn D Sfa Cl */ kseq{}( /* T Fn D Sfa Cl */ LblAppRightFreezer'LParUndsRParUnds'LAMBDA'Unds'KItem'Unds'Lambda{}( /* T Fn D Sfa Cl */ Lbl'SlshBashBashUndsStopUndsUnds'LAMBDA-SYNTAX'Unds'Lambda'Unds'Id'Unds'Lambda{}( /* T Fn D Sfa Cl */ \dv{SortId{}}(/* T Fn D Sfa Cl */ "y"), /* T Fn D Sfa Cl */ Lbl'SlshBashBashUndsStopUndsUnds'LAMBDA-SYNTAX'Unds'Lambda'Unds'Id'Unds'Lambda{}( /* T Fn D Sfa Cl */ \dv{SortId{}}(/* T Fn D Sfa Cl */ "z"), /* T Fn D Sfa Cl */ Lbl'UndsUndsUnds'LAMBDA-SYNTAX'Unds'Lambda'Unds'Lambda'Unds'Lambda{}( /* T Fn D Sfa Cli */ /* Inj: */ inj{SortId{}, SortLambda{}}( /* T Fn D Sfa Cl */ \dv{SortId{}}(/* T Fn D Sfa Cl */ "y") ), /* T Fn D Sfa Cli */ /* Inj: */ inj{SortId{}, SortLambda{}}( /* T Fn D Sfa Cl */ \dv{SortId{}}(/* T Fn D Sfa Cl */ "z") ) ) ) ) ), /* T Fn D Sfa Cl */ dotk{}() ) ), \and{SortGeneratedTopCell{}}( /* Spa */ \equals{SortLambda{}, SortGeneratedTopCell{}}( /* T Fn D Sfa */ RuleVarU:SortLambda{}, /* T Fn D Sfa Cli */ /* Inj: */ inj{SortId{}, SortLambda{}}( /* T Fn D Sfa Cl */ \dv{SortId{}}(/* T Fn D Sfa Cl */ "x") ) ), /* Spa */ \equals{SortId{}, SortGeneratedTopCell{}}( /* T Fn D Sfa */ RuleVarX:SortId{}, /* T Fn D Sfa Cl */ \dv{SortId{}}(/* T Fn D Sfa Cl */ "x") ) ))))))))))) )) Error! Please report this. CallStack (from HasCallStack): checkSubstitutionCoverage, called at src/Kore/Rewrite/RewriteStep.hs:253:13 in kore-0.60.0.0-4eN71WxNolKFApfOeZr3qd:Kore.Rewrite.RewriteStep Created bug report: kore-exec.tar.gz [Error] krun: kore-exec ./lambda-kompiled/haskellDefinition.bin --module LAMBDA --pattern .krun-2023-05-14-21-00-28-tTPvT1C4Fx/tmp.in.OJdxlSuE2I --output .krun-2023-05-14-21-00-28-tTPvT1C4Fx/result.kore [Error] krun: Backend crashed during rewriting with exit code 1 ```

Here is the file it created: kore-exec.tar.gz

If the LLVM backend is used, it doesn't crash, but it stops at a point where I would have thought that the rule marked debugme would apply. Not sure if I'm doing something silly.

I tried debugging with GDB but it gives errors as well. Not sure if this is related. Excerpt from GDB session:

``` jean@ubuntu22:~/Documents/bug-report$ kompile --enable-llvm-debug lambda.k jean@ubuntu22:~/Documents/bug-report$ krun --debugger simple.lambda GNU gdb (Ubuntu 12.1-0ubuntu1~22.04) 12.1 Copyright (C) 2022 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-linux-gnu". Type "show configuration" for configuration details. For bug reporting instructions, please see: . Find the GDB manual and other documentation resources online at: . For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from ./lambda-kompiled/interpreter... (gdb) k start Temporary breakpoint 1 at 0x73e50 Starting program: /home/jean/Documents/bug-report/lambda-kompiled/interpreter .krun-2023-05-14-21-03-48-uFQyu6QtbK/tmp.in.WhF8QtUabr -1 .krun-2023-05-14-21-03-48-uFQyu6QtbK/result.kore [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". Temporary breakpoint 1, 0x00005555555c7e50 in main () 0x00005555555a5f20 in k_step (subject= ListFreeVariables ( ) todo ( ( /\\ x . x ) /\\ y . /\\ z . ( y z ) ) ~> . .Set .Set ~> . todo ( ( /\\ x . x ) /\\ y . /\\ z . ( y z ) ) ~> . .Map ~> . .Map . . . . ) at /home/jean/Documents/bug-report/lambda.k:56 56 rule ListFreeVariables() (gdb) k step Continuing. Temporary breakpoint -9, 0x00005555555a5f20 in k_step (subject= ListFreeVariables ( ) todo ( /\\ x . x ) ~> AppRightFreezer ( /\\ y . /\\ z . ( y z ) ) ~> . .Set .Set ~> . todo ( ( /\\ x . x ) /\\ y . /\\ z . ( y z ) ) ~> . .Map ~> . .Map . . . . ) at /home/jean/Documents/bug-report/lambda.k:56 56 rule ListFreeVariables() (gdb) k step Continuing. Temporary breakpoint -10, 0x00005555555a5f20 in k_step (subject= ListFreeVariables ( ) todo ( x ) ~> AbstracFreezer ( x ) ~> AppRightFreezer ( /\\ y . /\\ z . ( y z ) ) ~> . .Set SetItem ( x ) ~> .Set ~> . todo ( ( /\\ x . x ) /\\ y . /\\ z . ( y z ) ) ~> . .Map ~> . .Map . . . . ) at /home/jean/Documents/bug-report/lambda.k:56 56 rule ListFreeVariables() (gdb) k step Continuing. Temporary breakpoint -11, 0x00005555555a5f20 in k_step (subject= ListFreeVariables ( ) done ( x ) ~> AbstracFreezer ( x ) ~> AppRightFreezer ( /\\ y . /\\ z . ( y z ) ) ~> . .Set SetItem ( x ) ~> .Set ~> . todo ( ( /\\ x . x ) /\\ y . /\\ z . ( y z ) ) ~> . .Map ~> . .Map . . . . ) at /home/jean/Documents/bug-report/lambda.k:56 56 rule ListFreeVariables() (gdb) k match LAMBDA.debugme subject Traceback (most recent call last): File "", line 793, in invoke gdb.error: No type named . Python Exception : No type named . Error occurred in Python: No type named . ```

Expected Results

No crash.

goodlyrottenapple commented 1 year ago

@jeanas The issue you are experiencing comes from the overloading of the ~> symbol when compiling your definition from the highl-level K language to the kore format used by the haskell/llvm execution engines. If you inspect the definition.kore file inside the lambda-kompiled/ folder, you will find that the

<bound-variables>
  _S ~> BoundRest => BoundRest
</bound-variables>

portion of the problematic rule has been translated into the kore language as:

Lbl'-LT-'bound-variables'-GT-'{}(
  append{}(
    Var'Unds'S:SortK{},
    VarBoundRest:SortK{}
  )
)

In the above pattern, both variables have been given the most generic sort possible, namely K. However, as per the error message, your <bound-variables> cell just before the failure looks like this:

Lbl'-LT-'bound-variables'-GT-'{}(
  kseq{}(
    inj{SortSet{}, SortKItem{}}(
      LblSetItem{}(
        inj{SortId{}, SortKItem{}}(
          \dv{SortId{}}("x")
        )
      )
    ),
    kseq{}(
      inj{SortSet{}, SortKItem{}}(
        Lbl'Stop'Set{}()
      ),
      dotk{}()
    )
  )
)

In the high-level K syntax, this corresponds to

<bound-variables>
  SetItem ( x ) ~> .Set ~> .
</bound-variables>

as you can see, in this instance the compiler has transformed ~> into a kseq{}. This is because it inferred the types of the arguments to be of a more specific sort than K, namely that of Set injected into the sort KItem. Because of this more specific type,we have a kseq instead of append. Thus, a fix for your rule would be to add a more specific type to _S, as you know it must be a Set:

rule [debugme]: <state> ListFreeVariables() </state>
       <list-free-variables>
         done(U) ~> AbstracFreezer(X) ~> Rest => done(/\\ X . U) ~> Rest
       </list-free-variables>
       <bound-variables>
         _S:Set ~> BoundRest => BoundRest
       </bound-variables>
Baltoli commented 1 year ago

Restriction - is anything in a K sequence other than the last element in the sequence of sort K? For example, here, we'd emit an error that _S is inferred as sort K (but it's OK for the continuation BoundRest to be).

@radumereuta suggests rewriting the ~> production to be KItem ~> K rather than K ~> K or have two overloaded productions with the KItem one preferred. Investigate whether this breaks things.

@dwightguth please take a look at this issue and comment on any potential issues you see, particularly with respect to the Maude backend.

radumereuta commented 1 year ago

Renaming the first argument into KItem might not work because of stuff like this:

//You can write a single character to a file using `#putc`. You can also write 
//a string to a file using `#write`. The returned value on success is `.K`.

  syntax K ::= "#putc" "(" fd: Int "," value: Int ")"      [function, hook(IO.putc), impure]
             | "#write" "(" fd: Int "," value: String ")" [function, hook(IO.write), impure]

  rule ListItem(#ostream(N:Int => {#write(N, S) ~> N:Int}:>Int)) // this fails to parse now

We will have to do a lot of fiddling with productions in order to change it. Probably easier to have a special case in the type inferencer.

Baltoli commented 1 year ago

Wasn't the consensus that we wanted to avoid modifying the type inferencer @radumereuta? We throw an error if any element of a kseq is inferred as K other than the continuation, but allow users to explicitly sort elements as K if they so choose.

Good catch on the .K productions - the kast.md change probably doesn't make sense as a result of that.

radumereuta commented 1 year ago

We should try to infer the correct sort first. If that's too hard, then we can throw an error. We could special case it to consider the LHS of a ~> as having sort KItem when inferring sorts for variables.

radumereuta commented 1 year ago

For this example, which is common, we need to infer: (L:KItem => R:K) ~> K:K All but the last element on the LHS is sort KItem All the element on the RHS and the last on the LHS is sort K.

radumereuta commented 1 year ago

When this is fixed, we should also close https://github.com/runtimeverification/k/issues/3478 as it is related. @dwightguth you said you have one more issue that might be related, please add it here.