Skip to content
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

Disallow sorts with case-insensitive equal names #4508

Open
Baltoli opened this issue Jul 9, 2024 · 4 comments
Open

Disallow sorts with case-insensitive equal names #4508

Baltoli opened this issue Jul 9, 2024 · 4 comments

Comments

@Baltoli
Copy link
Contributor

Baltoli commented Jul 9, 2024

Consider the following definition:

module TEST
  imports BOOL

  syntax Foo ::= "Foo"
  syntax FOO ::= "FOO"

  syntax KItem ::= result(KItem, Bool, Bool)
  rule F:Foo => result(F, isFoo(F), isFOO(F))
  rule F:FOO => result(F, isFoo(F), isFOO(F))
endmodule

We can see by inspection that there is no term X for which isFoo(X) and isFOO(X) are both true. However, on macOS, we can observe the following executions:

$ kompile test.k
$ krun -cPGM='Foo'
<k>
  result ( Foo , false , false ) ~> .K
</k>
$ krun -cPGM='FOO'
<k>
  result ( FOO , true , true ) ~> .K
</k>

That is, isFoo(Foo) => false, and isFOO(Foo) => true! Both of these rewrites are incorrect.

Some digging reveals that the reason for this is the case-insensitive filesystem on macOS; when decision trees are compiled, files LblisFoo.yaml and LblisFOO.yaml are both generated. However, one of them overwrites the other because of case-insensitivity. This means that the logic for all case-insensitive-equal sorts gets collapsed into one.

The solution (I think) is to disallow sorts that are equal up to casing.

@dwightguth
Copy link
Collaborator

I'm not sure this is the solution I would recommend. The problem is that even if you restrict sort names, you are still stuck with collisions in the casing of other symbols, and that's a potentially very restrictive thing to disallow completely. It's probably better to find a way to pick the filenames such that they are unique modulo case insensitivity.

@dwightguth
Copy link
Collaborator

One thing to note is that the llvm backend emits a table mapping symbol names to filenames, because we already have had problems in the past with filenames longer than the max filename length on Linux. So you probably just need to detect in the Scala code when files might collide and give them new names

@ehildenb
Copy link
Member

Could we suffix each file with a hash of the original (case sensitive) sort name? Just the first 6 characters of the hash should be enough I guess.

@Baltoli
Copy link
Contributor Author

Baltoli commented Jul 15, 2024

Could we suffix each file with a hash of the original (case sensitive) sort name? Just the first 6 characters of the hash should be enough I guess.

Yeah I didn't think this through in sufficient detail last week when recording the issue - I think something like this is the right solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants