Fix soundness bug with clone overrides of subtypes#1062
Open
oskgo wants to merge 1 commit into
Open
Conversation
…pe with compatible base type and predicate
There was a problem hiding this comment.
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 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 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.