Skip to content

make the "inner cast" be a synonym for a strict cast#2352

Merged
dwightguth merged 2 commits intomasterfrom
close-type-loophole
Dec 6, 2021
Merged

make the "inner cast" be a synonym for a strict cast#2352
dwightguth merged 2 commits intomasterfrom
close-type-loophole

Conversation

@dwightguth
Copy link
Copy Markdown
Contributor

This would close the "type loophole" that lets you put a term of any sort anywhere. Since when you did this, a bunch of stuff broke, we don't really have more than the single instance in any of our semantics of this actually being used. Hence the reason this PR is so small.

The singular usage is on line 1649 of domains.k.

@dwightguth dwightguth marked this pull request as ready for review December 1, 2021 16:10
@radumereuta
Copy link
Copy Markdown
Contributor

Why not remove it completely?
If it's because we use it, can we give a warning for a transition period, and then remove it?

@dwightguth
Copy link
Copy Markdown
Contributor Author

As I have said elsewhere, it is not currently possible to strict-cast a term whose last production item is a non terminal. This feature is needed in order to disambiguate the particular rule that currently is using an inner cast as a workaround. Simply removing it entirely does not work because then that rule parses incorrectly.

@radumereuta
Copy link
Copy Markdown
Contributor

You mean this rule {SB:String +String S:String}<:StringBuffer => (SB +String S)::String
So strict cast doesn't go through parentheses? Is the RHS being checked?
Maybe we should change that too then.
Something feels weird here.

@dwightguth
Copy link
Copy Markdown
Contributor Author

Logically, a strict cast doesn't pass through a bracket because strict casts only affect the term they are applied to, which in this case would be a bracket. The inside of the bracket would still be non strict, and thus the bracket essentially negates the strictness of the cast. I guess maybe you could make an argument that since this makes strict casting a bracket completely useless, that we should instead change the behavior of the type inferencer so that a term inside a bracket inside a strict cast is also strict. That requires a much more involved change to the type inferencer, but it's doable and then you would be able to write the rule in question using a strict cast.

Is that what you would prefer to see instead? If we did that, we ought to be able to entirely delete the inner cast syntax. It might break some existing definitions in theory, because of the modified behavior of strict casts, though. This change is much more backwards compatible.

I'm willing to be flexible. Make your arguments for or against each idea.

@dwightguth
Copy link
Copy Markdown
Contributor Author

dwightguth commented Dec 1, 2021

By the way, one argument against making strictness pass through casts is that someone could theoretically write a grammar where the bracket itself needed to be strict casted in order to disambiguate it, which would no longer be possible without unintended side effects if we made such a change to the inferencer. Now such a grammar is highly unlikely in practice, but it is a limitation on the expressivity of k in terms of the set of grammars it is able to faithfully represent, so if you're concerned about theoretical completeness in the design of the parser, it's probably worth keeping the inferencer code the way it is in this PR instead.

Copy link
Copy Markdown
Contributor

@radumereuta radumereuta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that you mention it, I don't have a better suggestion.
Let's keep it this way. If we run into issues, we can address them then.
Feel free to add automerge if you don't want to wait for Everett.

@dwightguth dwightguth enabled auto-merge (squash) December 6, 2021 17:44
@dwightguth dwightguth merged commit 44ebd70 into master Dec 6, 2021
@dwightguth dwightguth deleted the close-type-loophole branch December 6, 2021 18:39
rv-jenkins added a commit that referenced this pull request Dec 8, 2023
This PR cleans up a few issues related to the `{...}<:S` syntax for
strict casts. Specifically,

- Add a section to Lesson 1.11 explaining the need for the braced strict
cast syntax
- Change the klabel from `#InnerCast` to `#SyntacticCastBraced`
   - `#InnerCast` was a holdover from prior to #2352 
- Opinionatedly, change the syntax from `{...}<:S` to `{...}::S`
- Makes it more obvious this is just an alternative syntax for strict
casts `::S`
- To me, the syntax `<:S` is misleading in that it reads as "subsort of
`S`", but the actual meaning is "exactly the sort `S` and not a proper
subsort".
- Minimal fallout - there is only one rule in `rv-match` and two tests
in `pyk` where this needs to be changed
(https://github.com/search?q=org%3Aruntimeverification+%7D%3C%3A&type=code)

The commit history is clean and I can just drop the last commit if we
don't want to change the syntax.

---------

Co-authored-by: rv-jenkins <admin@runtimeverification.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants