AlloyTools / org.alloytools.alloy

Alloy is a language for describing structures and a tool for exploring them. It has been used in a wide range of applications from finding holes in security mechanisms to designing telephone switching networks. This repository contains the code for the tool.
Other
695 stars 124 forks source link

Forbid prime in fields and pred/fun parameters/return type #179

Closed grayswandyr closed 1 year ago

grayswandyr commented 2 years ago

Primes in fields and pred/fun parameters (and return type) should in my view raise syntax errors:

sig S { var s: S' }
pred p[x: S'] {}
fun q[x: S'] : S' { S }
run {}
dkasak commented 1 year ago

What about expressions? Does an expression such as

some s: S' {
    not (s in S)
    S' = S + s
}

Have a well-defined meaning? From testing, it seems to behave strangely and not in the way I expected.

grayswandyr commented 1 year ago

Sure it does.

var sig S {}

run {some s: S' {
    not (s in S)
    S' = S + s
} }

yields, as expected, a trace where you have an element s in state 1, that is not in state 0, and that is the only difference (for S) wrt state 0.

dkasak commented 1 year ago

I've since started using some s: S' - S instead but I've also changed my spec in other ways. And now predictably when changing some s: S' - S back to some s: S' { not (s in S) }, it works equivalently. :( So I must've been doing something else it didn't like.

So disregard the above, I'll report back if I manage to reproduce the odd behaviour.

grayswandyr commented 1 year ago

BTW, I think it's risky to "create" values of a toplevel var sig with such quantifications because you cannot talk about the pool of values you're drawing from. In that case, it's safer to explicitly model it with an ad-hoc sig:

sig Pool {}
var sig S in Pool {}

run {some s: Pool {
    s in Pool - S
    S' = S + s
} }
dkasak commented 1 year ago

Risky in what way? If I want to enforce invariants on the entire pool I can use S, and when talking about the new elements specifically, I can use S' - S. I wonder if I'm missing something.

grayswandyr commented 1 year ago

I just meant it can be confusing to newcomers.

nmacedo commented 1 year ago

Forbidden for 6.2.