Skip to content

Fix soundness bug with clone overrides of subtypes#1062

Open
oskgo wants to merge 1 commit into
mainfrom
fix-subtype
Open

Fix soundness bug with clone overrides of subtypes#1062
oskgo wants to merge 1 commit into
mainfrom
fix-subtype

Conversation

@oskgo

@oskgo oskgo commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Emit error when overriding a subtype with a type that is not a subtype with compatible base type and predicate. See the added test for why this is a problem. The gist is that you could obtain theories with two sets of lemmas that are incompatible with each other, leading to contradictions.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR strengthens theory cloning soundness by rejecting subtype overrides that would otherwise allow cloning theories into inconsistent environments (potentially enabling contradictions).

Changes:

  • Adds a regression test that demonstrates an invalid subtype override during clone.
  • Extends cloning incompatibility reporting with subtype-specific incompatibility reasons (carrier type / predicate).
  • Implements subtype-compatibility checks during theory replay when overriding subtype-declared types.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/subtype-override.ec New regression test ensuring invalid subtype overrides fail during cloning.
src/ecUserMessages.ml Adds user-facing error messages for subtype-specific incompatibilities.
src/ecTheoryReplay.ml Adds subtype compatibility checks and attempts to preserve subtype metadata across type overrides.
src/ecThCloning.mli Extends incompatible with subtype-specific variants.
src/ecThCloning.ml Mirrors the incompatible type extensions in the implementation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/ecTheoryReplay.ml
Comment on lines +194 to +203
| Abstract, _ -> begin
match tyd1.tyd_subtype, tyd2.tyd_subtype with
| Some (ty1, f1), Some (ty2, f2) ->
if not (EcReduction.EqTest.for_type (toenv hyps) ty1 ty2) then
raise (Incompatible (SubtypeType (ty1, Some ty2)));
if not (EcReduction.is_conv ~ri:ri_compatible hyps f1 f2) then
raise (Incompatible (SubtypePred (f1, f2)))
| Some (ty1, _), None -> raise (Incompatible (SubtypeType (ty1, None)))
| _, _ -> ()
end
Comment thread src/ecTheoryReplay.ml
Comment on lines +438 to +442
let subtype =
match unloc ntyd with
| PTnamed (s) -> begin
match EcEnv.Ty.lookup_opt s.pl_desc env with
| Some (_, { tyd_subtype = Some (ty, f) }) -> Some (ty, f)
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