Precise type checking for records #789
Replies: 8 comments 19 replies
-
@konnov I know the point of this is make type inference of records more precise (I think this is a noble goal and I support your efforts here), but personally, I don't find it to be such a big deal to write type annotations for each operator in my specs. That being said, if it was still required to write annotations for the patterns that are not closed under negation and no longer required for the ones that are closed under negation, that would already be a nice improvement! |
Beta Was this translation helpful? Give feedback.
-
I can see, how we could update the type checker to deal with the patterns A, C, and F. They would not require any complex control-flow tracking. The patterns B, D, and E would require control-sensitive type checking. |
Beta Was this translation helpful? Give feedback.
-
@konnov Could you explain a bit why |
Beta Was this translation helpful? Give feedback.
-
I'm not sure how useful my view will be, but I'm sharing in case the different After looking over these examples (here and in It looks like this "type field" convention with records is an idiom for encoding iiuc, a perfectly adequate alternative representation of the messages in the Phase1b(acc) ==
\E m \in msgs :
/\ m.type = "phase1a"
/\ aState[m.ins][acc].mbal < m.bal
/\ ... would become Phase1b(acc) ==
\E m \in phase1a_msgs :
/\ aState[m.ins][acc].mbal < m.bal
/\ ... This would be cumbersome to write and read in practice (mostly due to the need There is a separate question of how we might refine the type checking of records With this narrow focus, I wonder if we might not justify imposing some more With this constraint, something like Phase1b(acc) ==
\E m \in msgs :
/\ m.type = "phase1a"
/\ ... would need to be rewritten as Phase1b(acc) ==
\E m \in msgs :
CASE m.type == "phase1a" ->
/\ <the rest of body of the operator>
[] OTHER -> FALSE I'm presupposing here that limiting the ways of typing and eliminating these Of course, as an alternative, we could explore going the other direction: As someone who has not written much TLA+, either of these two options are more |
Beta Was this translation helpful? Give feedback.
-
The farsite spec might be another source for common patterns related to records. |
Beta Was this translation helpful? Give feedback.
-
I think that actually pattern |
Beta Was this translation helpful? Give feedback.
-
An alternative proposed by @shonfeder and written by @Kukovec: https://apalache.informal.systems/docs/idiomatic/003record-sets.html |
Beta Was this translation helpful? Give feedback.
-
For the note, this idea is fully implemented now, see: https://apalache.informal.systems/docs/HOWTOs/howto-write-type-annotations.html |
Beta Was this translation helpful? Give feedback.
-
What is discussed below is implemented in Type System 1.2, see the Transition to Type System 1.2.
As discussed in ADR002, the type checker is not checking the record types precisely. Consider the following operator:
The type checker assigns the type
Set([type: Str, a: Int, b: Int])
toS
. As a result, one can write the expressionm.a > m.b
, which does not make a lot of sense. This may lead to unexpected results in a large specification. In the above example, the model checker would just produce some values form.a
orm.b
, which will probably result in a strange counterexample.In issue #401, we have started the discussion on improving the type checker (and the model checker as well). We have to identify code patterns that admit precise type checking for records. The following example demonstrates available patterns and potential solutions. Some of them (A, C, F) are more stable than the other (B, D, E).
Please let us know what you think!
Beta Was this translation helpful? Give feedback.
All reactions