Skip to content

Conversation

@ssomayyajula
Copy link
Contributor

@ssomayyajula ssomayyajula commented Jun 1, 2025

What was changed?

  • Invariant is a MemberDecl that holds all of the invariant clauses of an enclosing class (could be any type, but the wellformedness checks currently only make sense for classes). There is not yet a corresponding MemberSelectExpr (in fact, it won't even parse).
  • Resolution of invariants is not surprising, except there is a visitor-based check at the end of pass 0 to exclude fields inherited from a trait from being mentioned in an invariant (see InvariantChecker)
  • BoogieGenerator modified to add well-formedness checks for classes, largely copied from function well-formedness checks. A collection of invariants for a class induces the usual expression well-formedness checks + a check that they only read this
  • Resolution and well-formedness checks only kick in when --check-invariants is enabled (used to be --verify-invariants).

I want explicit feedback on any comments marked TODO (usually text of error messages).

How has this been tested?

Tests under Source/IntegrationTests/TestFiles/LitTests/LitTest/invariants/.

By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.

@RustanLeino
Copy link
Collaborator

Resolution of invariants done piecemeal under PreType/. Nothing particularly surprising, except it currently excludes fields inherited from a trait

If the purpose of this is just to disallow certain fields from being mentioned, then I suggest doing this in a resolver pass after PreType/. The initial name resolution / type inference that done in PreType/ (also called "pass 0" somewhere in the resolver) is rather delicate, so the fewer things we need to do in that phase, the better.

@ssomayyajula
Copy link
Contributor Author

Oh I see, is it fragile because either the inherited fields of a class are not fully resolved or the field reference in question is not by the time the check is made inResolveNameSegment?

Copy link
Member

@robin-aws robin-aws left a comment

Choose a reason for hiding this comment

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

Exciting! Mostly reviewed at a high level, will look closer at implementation in the next round.

ssomayyajula and others added 7 commits June 6, 2025 10:16
…dingly

- Wellformedness checks simplified, since they do not have to be scoped to an enclosing declaration
- VerifyInvariants renamed to CheckInvariants and is automatically checked when a MemberDecl is coerced to an Invariant
- Refinement is now implemented, solving issue in InheritedMemberError.dfy
- Printing now implemented
…om invariants to be done as a visitor-based check
Copy link
Collaborator

@RustanLeino RustanLeino left a comment

Choose a reason for hiding this comment

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

Thanks for moving the resolution checks out of "pass 0". Thanks also for taking refinement modules into considerations (that's easy to forget).

@ssomayyajula
Copy link
Contributor Author

Closing in favor of #6313

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants