-
Notifications
You must be signed in to change notification settings - Fork 153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ordering instance for Sentences #3590
Conversation
13f644a
to
3510547
Compare
@gtrepta This |
I'm not sure what the Compare you're referring to is. But Ordering.by allows you to define a sorting strategy for a (normally ADT) type ex. For the case class https://www.scala-lang.org/api/2.12.14/scala/math/Ordering.html |
Got it! But I'm not sure yet how we (or Scala implicitly) decide how to compare and sort the type K. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We really need to consider the Att on the objects to sort them. Even though it can be costly, it will be worse to sort them later regarding the Att.
By considering the Att, we can safely compare two objects for equality, and we can safely enable decoupling the Add Kore Attribute function on ModuleToKore.
Ordering for K is here: k/kore/src/main/scala/org/kframework/kore/interface.scala Lines 33 to 61 in ab225b2
I can create an ordering for attributes as well. But, are you thinking about the attributes being factored in when ordering sentences? |
To give you more context, we had to revert these 2 PRs(#3523, #3522) due to the slowdown in the |
Nevertheless, @gtrepta, I would like to have a third opinion on this, perhaps @dwightguth or @radumereuta can help us on this. |
implicit val ord = new Ordering[Sentence] { | ||
def compare(a: Sentence, b: Sentence): Int = { | ||
(a, b) match { | ||
case (_:SyntaxSort, _) => -1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't feel quite right. Shouldn't it have a case where both are the same and it compares their contents?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had them there but removing them didn't break the unit tests I wrote, so I figured when they're the same type then the ordering for that specific type is used instead of going up the type heirarchy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like we do need those extra cases. I pushed the fix.
Can you remind me why the ordering is needed? To make comparisons faster? |
@radumereuta The compile pipeline didn't run any slower on those semantics. |
Hey @gtrepta, this test is failing rn, any ideas on the reason?
|
It's most likely some nondeterminism from printing/converting sets, the expected output only recognizes one of multiple possible outcomes. I've seen plenty of tests break in this fashion, normally we just update the expected output in the PR that it's breaking in. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks for your contribution on this @gtrepta!
This reverts commit b54de26.
fixes: #3530