Skip to content

subtype: generalize over section-declared free types at section close#1002

Merged
fdupress merged 1 commit intomainfrom
fix-subtype-section-generalize
May 8, 2026
Merged

subtype: generalize over section-declared free types at section close#1002
fdupress merged 1 commit intomainfrom
fix-subtype-section-generalize

Conversation

@strub
Copy link
Copy Markdown
Member

@strub strub commented May 8, 2026

[subtype X = { x : T | P x }] declared inside [section. declare type
c. ...] previously stayed monomorphic at section close. The cloned
auto-axioms ([insubN], [insubT], [valP], [valK]) and the [val] / [insub]
operators correctly gained a [c] tparam, but [X] itself didn't — the
result was an inconsistent state where the operations were polymorphic
over [c] but returned a single shared [X] type for every instantiation,
a soundness gap flagged by [FIXME:SUBTYPE] at [add_subtype].

This patch threads the carrier and predicate through the subtype's
[tydecl] so [tydecl_fv] picks up their dependency on section-declared
free types and the existing [generalize_tydecl] machinery adds the
right tparams at close.

Tests in [tests/subtype-section-generalize.ec] cover three cases:

  1. carrier mentions a section-declared free type — subtype is unary.
  2. predicate mentions a section-declared free type (carrier doesn't) —
    same outcome via fv collected from the predicate.
  3. nested sections, subtype declared in the inner one, depending on
    free types from both levels — subtype is binary after both closes.
    Each test instantiates [val] and [valP] at two distinct carriers in a
    single lemma; would fail to type-check if the cloned type or axiom
    had stayed monomorphic.

Closes #1001

@strub strub self-assigned this May 8, 2026
@strub strub requested a review from oskgo May 8, 2026 06:54
Copy link
Copy Markdown
Contributor

@oskgo oskgo left a comment

Choose a reason for hiding this comment

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

Looks like this handles all the edge cases I had found. Awesome!

I think there were some theories where I was using an inlined Subtype or Quotient construction because of this. I need to get around to migrating those now.

@fdupress
Copy link
Copy Markdown
Member

fdupress commented May 8, 2026

Be careful that the "update" button creates a merge commit by default. You need to open the drop-down and select "Update by rebase"

@strub
Copy link
Copy Markdown
Member Author

strub commented May 8, 2026

Yes. I only have my phone. So not hesitate to revert the merge and rebase. (The CI will forbid merging it anyway)

[subtype X = { x : T | P x }] declared inside [section. declare type
c. ...] previously stayed monomorphic at section close. The cloned
auto-axioms ([insubN], [insubT], [valP], [valK]) and the [val] / [insub]
operators correctly gained a [c] tparam, but [X] itself didn't — the
result was an inconsistent state where the operations were polymorphic
over [c] but returned a single shared [X] type for every instantiation,
a soundness gap flagged by [FIXME:SUBTYPE] at [add_subtype].

This patch threads the carrier and predicate through the subtype's
[tydecl] so [tydecl_fv] picks up their dependency on section-declared
free types and the existing [generalize_tydecl] machinery adds the
right tparams at close.

Tests in [tests/subtype-section-generalize.ec] cover three cases:
1. carrier mentions a section-declared free type — subtype is unary.
2. predicate mentions a section-declared free type (carrier doesn't) —
   same outcome via fv collected from the predicate.
3. nested sections, subtype declared in the inner one, depending on
   free types from both levels — subtype is binary after both closes.
Each test instantiates [val] and [valP] at two distinct carriers in a
single lemma; would fail to type-check if the cloned type or axiom
had stayed monomorphic.
@fdupress fdupress force-pushed the fix-subtype-section-generalize branch from a5296d9 to 4bb149e Compare May 8, 2026 14:40
@fdupress fdupress enabled auto-merge May 8, 2026 14:40
@fdupress fdupress added this pull request to the merge queue May 8, 2026
Merged via the queue into main with commit ac42e2a May 8, 2026
17 checks passed
@fdupress fdupress deleted the fix-subtype-section-generalize branch May 8, 2026 15:13
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.

Subtype inside a section is not generalized over section-declared free types at section close (soundness gap)

3 participants