You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In C, enums are not closed - an enum is more or less just an alias for an integer type large enough to hold all enumerated values. However, in most cases I would guess we want to enforce closedness. It'd be nice for CN to either:
Implicitly enforce closedness, or
Add a predicate which enforces this property.
Current State
The function enum_test() is not statically safe in arbitrary calling contexts, and CN correctly complains if we try to verify it:
To solve this in CN as it is today, we need to write a predicate that enforces the enumeration is in bounds, and then thread this predicate wherever we need it in the program. This generates boilerplate and honestly is a bit confusing given this property seems 'obvious'. For example, here is one I wrote for the MKM code:
Since this predicate is totally schematic, it might be nice to just define it automatically. We could either make it available to the programmer, or enforce it implicitly (with an escape hatch for when we want to break the enum discipline).
In C,
enum
s are not closed - anenum
is more or less just an alias for an integer type large enough to hold all enumerated values. However, in most cases I would guess we want to enforce closedness. It'd be nice for CN to either:Current State
The function
enum_test()
is not statically safe in arbitrary calling contexts, and CN correctly complains if we try to verify it:To solve this in CN as it is today, we need to write a predicate that enforces the enumeration is in bounds, and then thread this predicate wherever we need it in the program. This generates boilerplate and honestly is a bit confusing given this property seems 'obvious'. For example, here is one I wrote for the MKM code:
Proposal
Since this predicate is totally schematic, it might be nice to just define it automatically. We could either make it available to the programmer, or enforce it implicitly (with an escape hatch for when we want to break the enum discipline).
The text was updated successfully, but these errors were encountered: