tlaplus: Inconsistency in placement of comments as returned by OpDefOrDeclNode.getComment

We are now using OpDefOrDeclNode.getComment to parse annotations in TLA+ declarations, see this PR. While it works well, we have noticed a few inconsistencies in the placement of comments. For instance, in the recursive definitions, a comment has to be placed between RECURSIVE ... and the definition, whereas in the local definitions, a comment has to be placed in front of LOCAL.

Below you can find an example of how annotations should be placed in front of declarations. It would be great, if SANY was using a more consistent scheme for getComment.

-------- MODULE Annotations ----------
EXTENDS Integers

CONSTANT
  \* @type: Int;
  N

VARIABLE
  \* @type: Set(Int);
  set

\* @pure
\* @type: Int => Int;
Inc(n) == n + 1

\* @type: Int => Int;
LOCAL LocalInc(x) == x + 1

A(n) ==
  LET \* @pure
      \* @type: Int => Int;
      Dec(x) == x + 1
  IN
  Dec(n)

RECURSIVE Fact(_)
\* @tailrec
\* @type: Int => Int;
Fact(n) ==
  IF n <= 1 THEN 1 ELSE n * Fact(n - 1)

\* @tailrec
\* @type: Int -> Int;
FactFun[n \in Int] ==
  IF n <= 1 THEN 1 ELSE n * FactFun[n - 1]

======================================

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Comments: 17 (10 by maintainers)

Most upvoted comments

FWIW: Annotations appear to be an interesting alternative to the config file. Especially, when combined with multi-module .tla files:

spec.tla

---- MODULE spec ----
\* @Const(42)
CONSTANT N

VARIABLE v

Init == v = N

Next == v = v'

\* @BehaviorSpec
Spec == Init /\ [][Next]_v

\* @Invariant
Inv == v = 42

====

model.tla

---- MODULE model ----
VARIABLE v

INSTANCE spec WITH N <- 42

\* @StateContraint
StateConstraint == v = 42
====

Why do we have to care about the JLS? Anyway, make it “@apalache_type”.

I would love to, but I think we first need a consensus on what style is seen consistent. Probably the easiest thing to do would be to place annotations after LOCAL.