-
Notifications
You must be signed in to change notification settings - Fork 45
Fix SMT encoding for polymorphic Sequence preconditions (#1201) #1205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main2
Are you sure you want to change the base?
Changes from all commits
0fcdc25
99b84e5
8acaa4b
a5d36ed
50b0e12
1d47569
75e806e
192b780
6835d65
f6d195a
7c3a3f0
42fc6e9
18878bd
53a3df5
04d5215
0851e73
1af9382
4c66905
b61880f
cd1cac7
7b72423
4693781
792abcc
a845a65
dee8093
9606877
94a008e
f631f32
7346fe8
44d88da
f94fafa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -105,4 +105,43 @@ info: [WFObligation(safeDiv, (∀ (bvar:int) ((~Bool.Implies : (arrow bool (arro | |
| #eval collectWFObligations testFactory | ||
| esM[((λ (int): %0) ((~safeDiv a) b))] | ||
|
|
||
| /-! ### Polymorphic preconditions: type substitution at call site | ||
|
|
||
| A polymorphic function whose precondition mentions the type variable `%a` | ||
| must have that variable substituted with the call site's instantiated type. | ||
| Without this, downstream SMT encoding fails on unresolved type vars (issue #1201). | ||
| -/ | ||
|
|
||
| -- A polymorphic function `polySel<a>(s : Sequence a) : a` whose precondition | ||
| -- contains an operator annotated with the type variable `%a`. This mirrors | ||
| -- `Sequence.select`'s `0 <= i && i < Sequence.length(s : Sequence %a)` | ||
| -- bound check, which uses an annotated `Sequence.length` op. | ||
| private def polySelFunc : LFunc TestParams := | ||
| { name := "polySel" | ||
| typeArgs := ["a"] | ||
| inputs := [("s", mty[Sequence %a])] | ||
| output := mty[%a] | ||
| -- precondition: ((~lenOf : (Sequence %a) → int) s) | ||
| -- The op carries a `%a` annotation that must be substituted at the call site. | ||
| preconditions := [⟨esM[((~lenOf : (Sequence %a) → int) s)], ()⟩] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This precondition doesn't seem to have type
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it is testing specifically on type substitution under polymorphism, trying to show that the |
||
| } | ||
|
|
||
| private def polyFactory : Factory TestParams := .ofArray #[polySelFunc] | ||
|
|
||
| -- Call site annotates the operator with the instantiated arrow type | ||
| -- `Sequence int → int`. After value substitution alone, the op annotation | ||
| -- `(~lenOf : (Sequence %a) → int)` would still carry `%a`; the fix must also | ||
| -- apply the call-site type substitution `[%a → int]`. | ||
| /-- info: [WFObligation(polySel, ((~lenOf : (arrow (Sequence int) int)) myseq), ())] -/ | ||
| #guard_msgs in | ||
| #eval collectWFObligations polyFactory | ||
| esM[((~polySel : (Sequence int) → int) myseq)] | ||
|
|
||
| -- Same expectation when the operator is unannotated: the argument-types | ||
| -- fallback unifies `Sequence int` against `Sequence %a` to derive `[%a → int]`. | ||
| /-- info: [WFObligation(polySel, ((~lenOf : (arrow (Sequence int) int)) (myseq : (Sequence int))), ())] -/ | ||
| #guard_msgs in | ||
| #eval collectWFObligations polyFactory | ||
| esM[(~polySel (myseq : (Sequence int)))] | ||
|
|
||
| end Lambda | ||
Uh oh!
There was an error while loading. Please reload this page.