Skip to content

Allow to check TVar invariants #1649

@amesgen

Description

@amesgen

The goal of this issue is to easily enable custom invariant checking for StrictTVars etc. that are always tested on CI (and not just nightly CI).

Status quo

We use the strict-checked-vars library to get variants of StrictTVars/StrictMVars which allow one to check invariants every time their value is updated. This library provides two flags, checktvarinvariants and checkmvarinvariants (disabled by default), which one needs to enable to actually get invariant-checking behavior.

By default, the invariant we check is the nothunks property; also see the description of this module. Sometimes, we additionally have domain-specific invariants using newTVarWithInvariant/newMVarWithInvariant.

Notably, in regular CI, we don't actually enable these invariants at all, because the nothunks checks are way too expensive for the regular CI. However, the domain-specific invariants would be nice to check even in regular CI (especially as we are neglecting our nightly CI...)

Desired change

It is suboptimal that we can't have invariants for eg TVars which are checked in regular CI, as well as when running tests locally. Therefore, the goal is to gate the nothunks checks behind an additional flag (say expensive-invariants), which is only enabled on nightly CI, and to then enable checktvarinvariants and checkmvarinvariants even on regular CI.

There are also one more place where we call checkInvariant with nothunks checks apart from the TVars/MVars; this should also be gated behind the new expensive-invariants flag:

continueWithState !s (Stateful f) =
checkInvariant (show <$> unsafeNoThunks s) $ f s

(#1615 will add something similar)

This will result in the following setup:

  • In production: No invariant checking at all
  • In regular CI: Cheap invariant checking (domain-specific invariants)
  • In nightly CI: Cheap and expensive invariant checking

Motivated by #1615 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions