runtimeverification / k

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

[K-Bug] Internal error for nested private imports #3097

Open virgil-serbanuta opened 1 year ago

virgil-serbanuta commented 1 year ago

What component is the issue in?

Front-End

Which command

What K Version?

v5.5.40-0-g98574f12a2-dirty

Operating System

Linux

K Definitions (If Possible)

c.k:

module A
  syntax A ::= "a"
endmodule

module B
  imports private A

  syntax C ::= B
             | A
  syntax B ::= "b"

  syntax B ::= f(C)  [function, total]

endmodule

module C
  imports private B

  rule f(V:B) => V
  rule f(_) => "a" [owise]
endmodule

Steps to Reproduce

kompile c.k --backend haskell

Will display:

[Error] Internal: Unexpected result from z3: (error "line 44 column 13: unknown
constant SortA")
        Source(/.../c.k)
        Location(19,8,19,19)
        19 |      rule f(V:B) => V
           .           ^~~~~~~~~~~

Expected Results

Kompile be able to compile that file. Or, in the worst case, it should provide a decent error message.

radumereuta commented 1 year ago

I did a timeboxed investigation and there seems to be a problem in the way we calculate the sentences in a module. Should probably be something like this:

  private lazy val importedSentences = fullImports flatMap {_.publicSentences}

  lazy val publicSentences: Set[Sentence] = publicLocalSentences | imports.filter(_.isPublic).flatMap(_.module.publicSentences)
  lazy val sentences: Set[Sentence] = localSentences | importedSentences

But then there is also another issue in RuleGrammarGenerator since by the time we get to the end of the generator we have way too many sentences.

ehildenb commented 1 year ago

A couple weird things:

virgil-serbanuta commented 1 year ago

Yes, "a" was a mistake. You get the same error if you remove the last rule or if you change it to

  rule f(_) => b [owise]
ehildenb commented 1 year ago

@virgil-serbanuta is this blocking?

virgil-serbanuta commented 1 year ago

No.