Skip to content

[vcg] add field-access support for record/union references#176

Open
hoe-jo wants to merge 2 commits into
mainfrom
joho_enable_foreach
Open

[vcg] add field-access support for record/union references#176
hoe-jo wants to merge 2 commits into
mainfrom
joho_enable_foreach

Conversation

@hoe-jo
Copy link
Copy Markdown
Contributor

@hoe-jo hoe-jo commented Apr 15, 2026

The VCG previously had no support for checks that dereference a record
or union reference (e.g. parent.priority > 0). This commit implements
the full pipeline:

ast.py:

  • Add Expression.uses_field_access() base method: determine Field_Access_Expression
    whose prefix is a Record_Type or Union_Type.
  • Add Check.uses_field_access as a @Property that lazily evaluates
    and caches the result from the expression tree.
  • Fix Field_Access_Expression.evaluate() to handle the case where a
    field value is any Expression, not just Implicit_Null.

vcg.py:

  • Split check processing into two phases. Phase A ("at declaration")
    covers checks with no record/union field dereference and runs first.
    Phase B ("after references") runs second, so it can exploit the
    fatal-check knowledge accumulated by Phase A.

@hoe-jo hoe-jo requested a review from a team as a code owner April 15, 2026 15:29
same assumption about `normal_error_1`, any checks under
`fatal_error_1` do *not* get the truth of `normal_error_1` asserted.

#### Two-phase check analysis
Copy link
Copy Markdown

@SurajBDeore SurajBDeore May 14, 2026

Choose a reason for hiding this comment

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

Check.uses_field_access is a @Property (no parentheses) but on Expression subclasses it is a regular method (with ()). Could we add a note about this or make them consistent? It is easy to miss when reading the code.

Comment thread documentation/architecture.md Outdated

This ordering cannot be observed at runtime (all checks are evaluated
in declaration order), but it is important for the VCG because the
uninterpreted-function model for referenced records requires that
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

"requires" feels too strong here the VCG is still sound without this ordering, it just produces more false positives. Suggest changing to "is more precise when" to avoid implying it would be broken without it.

}

checks Container {
(forall e in items => e.value < limit), fatal "all items must be below limit"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The quantifier example (forall e in items => e.value < limit) currently produces a VCG warning "functional evaluation of field access not yet supported" — so the VCG does not analyse it. The docs should mention this limitation, otherwise users will expect VCG coverage they are not getting.

@SurajBDeore
Copy link
Copy Markdown

SurajBDeore commented May 14, 2026

No test covers an unguarded optional ref in Phase B every Phase B optional test is either behind an implies guard or a Phase A fatal check. Please check a case like ref optional T; checks U { ref.x > 0, "potato" } where VCG should warn vcg-evaluation-of-null its needed or we can skip this

@SurajBDeore
Copy link
Copy Markdown

The Phase B fatal quantifier (forall e in arr => e.x < x) is followed by a div-by-zero check on [len(arr) - 5] which has nothing to do with the quantifier result. So this test does not show that Phase B fatal knowledge actually helps a later check. it is necessary to add a second check that would give a false positive if the quantifier knowledge is missing, but passes when it is there?

@SurajBDeore
Copy link
Copy Markdown

and please also add description

@hoe-jo hoe-jo changed the title enable vcg checks in tuple access [vcg] add field-access support for record/union references May 18, 2026
@hoe-jo hoe-jo force-pushed the joho_enable_foreach branch from 1c17f75 to 17d848e Compare May 18, 2026 07:55
@hoe-jo hoe-jo requested a review from SurajBDeore May 18, 2026 12:04
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.

2 participants