Skip to content
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

Case expression exhaustiveness & redundancy checking #1114

Merged
merged 170 commits into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
170 commits
Select commit Hold shift + click to select a range
04cc5d5
Add some function from injection paper.
DavidFangWJ Jul 9, 2023
1d1b27a
Finished implementing algorithms from P8.
DavidFangWJ Jul 16, 2023
092775a
Translating part of old Constraint.re into this version.
DavidFangWJ Jul 21, 2023
d714115
Rebase the project on `adt_defs_after` instead of `dev`.
DavidFangWJ Aug 1, 2023
6cb7ca9
Finished porting `Constraint.re`.
DavidFangWJ Aug 7, 2023
47c1905
Ported `Incon.re` and `Sets.re`.
DavidFangWJ Aug 16, 2023
80e15bc
Fixed dependency problem.
DavidFangWJ Aug 23, 2023
45751ee
Add some function from injection paper.
DavidFangWJ Jul 9, 2023
0b768ec
Finished implementing algorithms from P8.
DavidFangWJ Jul 16, 2023
7d9b905
Translating part of old Constraint.re into this version.
DavidFangWJ Jul 21, 2023
90d8e98
Rebase, Part 1.
DavidFangWJ Aug 1, 2023
8c5a214
Rebase, Part 2.
DavidFangWJ Aug 7, 2023
b0b6ce6
Ported `Incon.re` and `Sets.re`.
DavidFangWJ Aug 16, 2023
d9ff681
Fixed dependency problem.
DavidFangWJ Aug 23, 2023
ea22b5d
Merge remote-tracking branch 'origin/haz3l-incon' into haz3l-incon
DavidFangWJ Aug 27, 2023
bfc1fae
Fixed a bug related to incomplete rebasing.
DavidFangWJ Aug 27, 2023
0beba60
Add some function from injection paper.
DavidFangWJ Jul 9, 2023
414ddff
Finished implementing algorithms from P8.
DavidFangWJ Jul 16, 2023
5b3df76
Translating part of old Constraint.re into this version.
DavidFangWJ Jul 21, 2023
16e1ba4
Rebase, Part 1.
DavidFangWJ Aug 1, 2023
aba862e
Rebase, Part 2.
DavidFangWJ Aug 7, 2023
2e526d4
Ported `Incon.re` and `Sets.re`.
DavidFangWJ Aug 16, 2023
841224f
Rebasing trial 2 step 1.
DavidFangWJ Sep 10, 2023
1635b42
Rebase the project on `adt_defs_after` instead of `dev`.
DavidFangWJ Aug 1, 2023
4da6ccb
Fixed a bug related to incomplete rebasing.
DavidFangWJ Aug 27, 2023
7ba2672
Rebasing trial 2 step 2.
DavidFangWJ Sep 13, 2023
f4c6ab9
I am not sure what is going on.
DavidFangWJ Sep 13, 2023
0e7bbd1
Fixed (?) dependencies and reformat in compilation.
DavidFangWJ Sep 14, 2023
da33210
Revised the description of inconsistency checking for list to Nil/Con…
DavidFangWJ Sep 15, 2023
a19bc2f
Init
pigumar1 Sep 20, 2023
e0fbe8d
Return `Constraint.re` and `Incon.re` to their old version.
DavidFangWJ Sep 24, 2023
7fcf183
Merge branch 'haz3l-incon' into haz3l-case-exhaustiveness
pigumar1 Sep 24, 2023
661f3a1
Merge branch 'dev' into haz3l-case-exhaustiveness
pigumar1 Sep 25, 2023
1022c55
Initialized error_exp.InexhaustiveMatch
pigumar1 Sep 27, 2023
70996ad
Add a new reason to have DHExp.InconsistentBranches in elaborator
pigumar1 Sep 27, 2023
e179d76
Initialized Self.exp.InexhaustiveMatch
pigumar1 Sep 27, 2023
f0b9fef
Added more guards & updated Info.status_exp
pigumar1 Sep 27, 2023
b66c0cc
Complete new self
pigumar1 Sep 27, 2023
f8ff3c4
Fixed the bug about type inconsistency
pigumar1 Sep 27, 2023
bf4c052
Formatted
pigumar1 Sep 27, 2023
213ad96
Made InexhaustiveMatch more general
pigumar1 Sep 29, 2023
c226608
Making InexhaustiveMatch even more general!
pigumar1 Sep 29, 2023
74b947a
Test
pigumar1 Sep 29, 2023
bbc8406
Make it less akaward
pigumar1 Sep 29, 2023
56d33fd
Revert Id.re
pigumar1 Sep 29, 2023
bae6457
Revert DHDoc_Exp.re
pigumar1 Sep 29, 2023
19589e1
Add constraint_ to Info.pat
pigumar1 Sep 29, 2023
6f89c09
Added ruls_to_info to statics.re
Oct 1, 2023
ed3759f
Added Constraint.Bool/NotBool
pigumar1 Oct 8, 2023
45c9e47
Add fixed_constraint_pat
pigumar1 Oct 8, 2023
0f63119
Implemented constraint emission for simple cases
pigumar1 Oct 8, 2023
d73d4ac
Wrote pattern to constraint for unit, tuple and list.
DavidFangWJ Oct 9, 2023
46b6d86
Generating Self.exp from constraints
Oct 14, 2023
932eff3
Folded result of is_exhaustive to generate Self.exp
Oct 14, 2023
4149adc
Indicated that InexhaustiveMatch is from Self.re
Oct 14, 2023
188d222
Error fixes
Oct 14, 2023
fc6f0ce
used Info.exp_ty over ruls_to_info_map
Oct 14, 2023
38d1232
Combined constraints with or_constraints()
Oct 16, 2023
6ff3c31
Extended ConstructorEntry, Part I
pigumar1 Oct 20, 2023
d719567
Extended ConstructorEntry, Part II
pigumar1 Oct 20, 2023
f132e82
Extended ConstructorEntry, Part III
pigumar1 Oct 20, 2023
1e543d5
Fixed the Pair bug in Constraint.constrains
pigumar1 Oct 20, 2023
cb1963d
Added Constraint.of_nth_variant
pigumar1 Oct 20, 2023
ffd0839
Extended ConstructorEntry, Part IV
pigumar1 Oct 20, 2023
5445ddf
Added Constraint.of_ap and Constraint.of_ctr
pigumar1 Oct 20, 2023
1500efe
Constraint emission for Constructor and Ap
pigumar1 Oct 20, 2023
aa7906e
Match Self generation code simplification
pigumar1 Oct 20, 2023
7a83890
Code simplification part II
pigumar1 Oct 20, 2023
8ab8464
rules_to_info_map
pigumar1 Oct 20, 2023
f61ab29
Fixed 0 rules bug
pigumar1 Oct 20, 2023
186cb1e
Init
pigumar1 Oct 20, 2023
33c484e
Added error_pat.Redundant
pigumar1 Oct 21, 2023
7276a41
Added Self.pat
pigumar1 Oct 21, 2023
5019383
Fixed Bool bug
pigumar1 Oct 21, 2023
c1bc425
Reviewed Constraint.dual
pigumar1 Oct 21, 2023
fcd0182
Merge branch 'haz3l-case-exhaustiveness' into haz3l-case-redundancy
pigumar1 Oct 21, 2023
643e123
Fixed String bug
pigumar1 Oct 21, 2023
bb0f356
Merge branch 'haz3l-case-exhaustiveness' into haz3l-case-redundancy
pigumar1 Oct 21, 2023
b3d8cce
Generating pattern constraints sequentially
Oct 21, 2023
5b311bc
Incon code simplification I
pigumar1 Oct 22, 2023
9ec5fe0
Applied Constraint.is_inl and Constraint.is_inr
pigumar1 Oct 22, 2023
7561afd
Incon code simplification II
pigumar1 Oct 22, 2023
65c8b14
Deleted the argument ~may in Incon.re
pigumar1 Oct 22, 2023
3c8e0f6
Incon code simplification III
pigumar1 Oct 22, 2023
f31485b
Deleted Constraint.Bool/NotBool
pigumar1 Oct 22, 2023
0d5f5b5
Inlined map_m_constraint
pigumar1 Oct 22, 2023
5361ce6
Adjusted info for redundant patterns
pigumar1 Oct 22, 2023
e9a8896
Revert InvalidOperationError.re
pigumar1 Oct 22, 2023
ad523c6
Merge branch 'haz3l-case-exhaustiveness' into haz3l-case-redundancy
pigumar1 Oct 22, 2023
3c4e58d
Made redundancy not a runtime error
pigumar1 Oct 23, 2023
cd03276
Allowed redundant patterns to have types in Self.typ_of_pat
pigumar1 Oct 23, 2023
dd9aed5
Having applications of non-ctrs and unbounded ctrs emit Falsity
pigumar1 Oct 23, 2023
324399a
Merge branch 'haz3l-case-exhaustiveness' of https://github.com/hazelg…
pigumar1 Oct 23, 2023
b1eaeb7
Merge branch 'haz3l-case-exhaustiveness' into haz3l-case-redundancy
pigumar1 Oct 23, 2023
8403af3
Fixed multiple-error-holes bug
pigumar1 Oct 26, 2023
d5d3fb9
Merge branch 'haz3l-case-exhaustiveness' into haz3l-case-redundancy
pigumar1 Oct 26, 2023
5d8a674
Removed “necessarily” in the user-facing message
pigumar1 Oct 26, 2023
dc87b52
Merge branch 'haz3l-case-exhaustiveness' into haz3l-case-redundancy
pigumar1 Oct 26, 2023
df04be9
Removed “necessarily” in the user-facing message
pigumar1 Oct 26, 2023
ed3138e
Reformatted
pigumar1 Oct 26, 2023
3223047
fix dhexp error hole formatting
disconcision Oct 26, 2023
83101d1
Merge branch 'haz3l-case-exhaustiveness' into haz3l-case-redundancy
pigumar1 Oct 26, 2023
fc39789
Merge branch 'dev' into haz3l-case-exhaustiveness
cyrus- Nov 10, 2023
e37a33d
Merge branch 'haz3l-case-exhaustiveness' into haz3l-case-redundancy
cyrus- Nov 10, 2023
717fe51
Small adjustments
pigumar1 Nov 18, 2023
9a8a8ec
Removed Constraint.constrains
pigumar1 Nov 18, 2023
079bef9
Compile
pigumar1 Nov 18, 2023
24a2c2e
Replaced is_inl/r with is_injL/R
pigumar1 Nov 18, 2023
2bd3eaa
Merge branch 'dev' into haz3l-case-exhaustiveness
pigumar1 Nov 18, 2023
71a5689
Merge branch 'haz3l-case-exhaustiveness' into haz3l-case-redundancy
pigumar1 Nov 18, 2023
e1bbb70
New structure for non-exhaustive case matches
DavidFangWJ Nov 19, 2023
5b72b62
Fix bug from last commit.
DavidFangWJ Nov 19, 2023
2ebb54a
init
pigumar1 Nov 22, 2023
3e9e158
Changed argument from ctx to mode in of_ap and of_ctr
pigumar1 Dec 17, 2023
4241f40
weak_head_normalized
pigumar1 Dec 17, 2023
63f3f39
Bug fix
pigumar1 Dec 17, 2023
a6b03f6
Clean
pigumar1 Dec 17, 2023
8c308ad
Added CtorMap.nth
pigumar1 Dec 17, 2023
a69e23a
Clean
pigumar1 Dec 17, 2023
4f510c1
Update ConstructorMap.re
pigumar1 Dec 18, 2023
606abc4
InexhaustiveMatch(option(error_exp)) => (option(error_common))
pigumar1 Dec 24, 2023
4cdad27
Merge branch 'dev' into haz3l-case-exhaustiveness
pigumar1 Dec 24, 2023
60d4aa0
reformatted
pigumar1 Dec 24, 2023
9df27d3
Merge branch 'haz3l-case-exhaustiveness' into haz3l-case-redundancy
pigumar1 Dec 25, 2023
c81ee31
Update Statics.re
pigumar1 Dec 25, 2023
20df586
Merge branch 'haz3l-case-exhaustiveness' into pattern-matching-base-a…
pigumar1 Jan 6, 2024
bd3a386
Switch nth's argument position
pigumar1 Jan 6, 2024
dca454f
Constraint emission for synthesized Ap pattern
pigumar1 Jan 6, 2024
3ea1874
Merge branch 'dev' into haz3l-case-exhaustiveness
pigumar1 Jan 12, 2024
d65eff9
Merge branch 'haz3l-case-exhaustiveness' into haz3l-case-redundancy
pigumar1 Jan 12, 2024
4c51b67
Merge branch 'haz3l-case-exhaustiveness' into pattern-matching-base-a…
pigumar1 Jan 12, 2024
c8c00e6
Fixed inf recursion bug
pigumar1 Jan 16, 2024
0025fe3
Merge branch 'haz3l-case-exhaustiveness' into haz3l-case-redundancy
pigumar1 Jan 16, 2024
42266ce
Fixed overwritten-map bug
pigumar1 Jan 18, 2024
cc45671
Letting constraint emission for ADTs based on scrutinee type (#1144)
cyrus- Feb 10, 2024
af6dabd
Merge branch 'dev' into haz3l-case-exhaustiveness
pigumar1 Feb 13, 2024
493cdc7
Resolve merge conflicts
pigumar1 Feb 13, 2024
129fcf2
Generalize frontend, part I
pigumar1 Feb 13, 2024
571d767
Case expression redundancy checking (#1124)
cyrus- Feb 13, 2024
51dec03
Inexhaustive self for functions
pigumar1 Feb 13, 2024
c47bc66
Inexhaustive self for let expressions
pigumar1 Feb 13, 2024
d35b283
Fixed TypeAnn escape checking bug
pigumar1 Feb 13, 2024
a53f02d
Update CursorInspector.re
pigumar1 Feb 13, 2024
076d78c
Merge branch 'dev' into haz3l-case-exhaustiveness
pigumar1 Apr 14, 2024
e37b742
Resolve merge issue
pigumar1 Apr 14, 2024
a511ce9
add constraint_ty
pigumar1 Apr 14, 2024
405bfcc
implement constraint_ty
pigumar1 Apr 14, 2024
b3510ee
add Mode.of_constraint
pigumar1 Apr 14, 2024
6365947
upstream constraint_ty in Statics.re
pigumar1 Apr 14, 2024
f1ce59d
Revert "upstream constraint_ty in Statics.re"
pigumar1 May 4, 2024
1ba9e2e
Revert "add Mode.of_constraint"
pigumar1 May 4, 2024
fd86321
Revert "implement constraint_ty"
pigumar1 May 4, 2024
17f55a4
Revert "add constraint_ty"
pigumar1 May 4, 2024
b17a165
scrut.ty => scrut_ty
pigumar1 May 4, 2024
368785c
changed rules_to_info_map signature
pigumar1 May 4, 2024
14af479
moved join check draft outside
pigumar1 May 4, 2024
cfad199
created branch for join check
pigumar1 May 4, 2024
a389e83
none branch for join check
pigumar1 May 4, 2024
64075db
factor out code
pigumar1 May 4, 2024
d736500
code simplification
pigumar1 May 5, 2024
804f5e2
rules_to_info_map => pats_to_info_map
pigumar1 May 5, 2024
81fa286
some branch for join check
pigumar1 May 5, 2024
3efe061
unknown scrutinee type handling mostly done
pigumar1 May 5, 2024
9f7087b
unknown scrutinee type handling done
pigumar1 May 5, 2024
9a021ce
scrut_ty => constraint_ty
pigumar1 May 5, 2024
f780316
code simplification
pigumar1 May 5, 2024
58f568b
code simplification
pigumar1 May 5, 2024
6ef95ca
Merge branch 'dev' into haz3l-case-exhaustiveness
pigumar1 May 5, 2024
4f2e960
Merge branch 'dev' into haz3l-case-exhaustiveness
pigumar1 May 14, 2024
d6d61c8
code clean
pigumar1 May 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
153 changes: 153 additions & 0 deletions src/haz3lcore/dynamics/Constraint.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
open Sexplib.Std;

[@deriving (show({with_path: false}), sexp, yojson)]
type t =
| Truth
| Falsity
| Hole
| Int(int)
| NotInt(int)
| Float(float)
| NotFloat(float)
| String(string)
| NotString(string)
| And(t, t)
| Or(t, t)
| InjL(t)
| InjR(t)
| Pair(t, t);

let rec dual = (c: t): t =>
switch (c) {
| Truth => Falsity
| Falsity => Truth
| Hole => Hole
| Int(n) => NotInt(n)
| NotInt(n) => Int(n)
| Float(n) => NotFloat(n)
| NotFloat(n) => Float(n)
| String(s) => NotString(s)
| NotString(s) => String(s)
| And(c1, c2) => Or(dual(c1), dual(c2))
| Or(c1, c2) => And(dual(c1), dual(c2))
| InjL(c1) => Or(InjL(dual(c1)), InjR(Truth))
| InjR(c2) => Or(InjR(dual(c2)), InjL(Truth))
| Pair(c1, c2) =>
Or(
Pair(c1, dual(c2)),
Or(Pair(dual(c1), c2), Pair(dual(c1), dual(c2))),
)
};

/** substitute Truth for Hole */
let rec truify = (c: t): t =>
switch (c) {
| Hole => Truth
| Truth
| Falsity
| Int(_)
| NotInt(_)
| Float(_)
| NotFloat(_)
| String(_)
| NotString(_) => c
| And(c1, c2) => And(truify(c1), truify(c2))
| Or(c1, c2) => Or(truify(c1), truify(c2))
| InjL(c) => InjL(truify(c))
| InjR(c) => InjR(truify(c))
| Pair(c1, c2) => Pair(truify(c1), truify(c2))
};

/** substitute Falsity for Hole */
let rec falsify = (c: t): t =>
switch (c) {
| Hole => Falsity
| Truth
| Falsity
| Int(_)
| NotInt(_)
| Float(_)
| NotFloat(_)
| String(_)
| NotString(_) => c
| And(c1, c2) => And(falsify(c1), falsify(c2))
| Or(c1, c2) => Or(falsify(c1), falsify(c2))
| InjL(c) => InjL(falsify(c))
| InjR(c) => InjR(falsify(c))
| Pair(c1, c2) => Pair(falsify(c1), falsify(c2))
};

let is_injL =
fun
| InjL(_) => true
| _ => false;

let is_injR =
fun
| InjR(_) => true
| _ => false;

let unwrapL =
fun
| InjL(c) => c
| _ => failwith("input can only be InjL(_)");

let unwrapR =
fun
| InjR(c) => c
| _ => failwith("input can only be InjR(_)");

let unwrap_pair =
fun
| Pair(c1, c2) => (c1, c2)
| _ => failwith("input can only be pair(_, _)");

let rec or_constraints = (lst: list(t)): t =>
switch (lst) {
| [] => Falsity
| [xi] => xi
| [xi, ...xis] => Or(xi, or_constraints(xis))
};

let rec ctr_of_nth_variant = (num_variants, nth): (t => t) =>
if (num_variants == 1) {
Fun.id;
cyrus- marked this conversation as resolved.
Show resolved Hide resolved
} else if (nth == 0) {
xi => InjL(xi);
} else {
xi => InjR(xi |> ctr_of_nth_variant(num_variants - 1, nth - 1));
};

let of_ap = (ctx, mode, ctr: option(Constructor.t), arg: t, syn_ty): t =>
switch (ctr) {
| Some(name) =>
let ty =
switch (mode) {
| Mode.Ana(ty) => Some(ty)
| Syn => syn_ty
| _ => None
};
switch (ty) {
| Some(ty) =>
switch (Typ.weak_head_normalize(ctx, ty)) {
| Sum(map) =>
let num_variants = ConstructorMap.cardinal(map);
switch (ConstructorMap.nth(map, name)) {
| Some(nth) => arg |> ctr_of_nth_variant(num_variants, nth)
| None => Falsity
};
| _ => Falsity
}
| None => Falsity
};
| None => Falsity
};

let of_ctr = (ctx, mode, name, self) => {
let syn_ty =
switch (self) {
| Self.IsConstructor({syn_ty, _}) => syn_ty
| _ => assert(false) // impossible
};
of_ap(ctx, mode, Some(name), Truth, syn_ty);
};
10 changes: 9 additions & 1 deletion src/haz3lcore/dynamics/Elaborator.re
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,8 @@ let rec dhexp_of_uexp =
|> OptUtil.sequence;
let d = DHExp.Case(d_scrut, d_rules, 0);
switch (err_status) {
| InHole(Common(Inconsistent(Internal(_)))) =>
| InHole(Common(Inconsistent(Internal(_))))
| InHole(InexhaustiveMatch(Some(Inconsistent(Internal(_))))) =>
DHExp.InconsistentBranches(id, 0, d)
| _ => ConsistentCase(d)
};
Expand All @@ -393,6 +394,13 @@ let rec dhexp_of_uexp =
and dhpat_of_upat = (m: Statics.Map.t, upat: Term.UPat.t): option(DHPat.t) => {
switch (Id.Map.find_opt(Term.UPat.rep_id(upat), m)) {
| Some(InfoPat({mode, self, ctx, _})) =>
// NOTE: for the current implementation, redundancy is considered a static error
// but not a runtime error.
let self =
switch (self) {
| Redundant(self) => self
| _ => self
};
let err_status = Info.status_pat(ctx, mode, self);
let maybe_reason: option(ErrStatus.HoleReason.t) =
switch (err_status) {
Expand Down
145 changes: 145 additions & 0 deletions src/haz3lcore/dynamics/Incon.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
open Sets;

let is_inconsistent_int = (xis: list(Constraint.t)): bool => {
let (int_set, not_int_list) =
List.fold_left(
((int_set, not_int_list), xi: Constraint.t) =>
switch (xi) {
| Int(n) => (IntSet.add(n, int_set), not_int_list)
| NotInt(n) => (int_set, [n, ...not_int_list])
| _ => failwith("input can only be Int | NotInt")
},
(IntSet.empty, []),
xis,
);
IntSet.cardinal(int_set) > 1
|| List.exists(IntSet.mem(_, int_set), not_int_list);
};

let is_inconsistent_float = (xis: list(Constraint.t)): bool => {
let (float_set, not_float_list) =
List.fold_left(
((float_set, not_float_list), xi: Constraint.t) =>
switch (xi) {
| Float(n) => (FloatSet.add(n, float_set), not_float_list)
| NotFloat(n) => (float_set, [n, ...not_float_list])
| _ => failwith("input can only be Float | NotFloat")
},
(FloatSet.empty, []),
xis,
);
FloatSet.cardinal(float_set) > 1
|| List.exists(FloatSet.mem(_, float_set), not_float_list);
};

let is_inconsistent_string = (xis: list(Constraint.t)): bool => {
let (string_set, not_string_list) =
List.fold_left(
((string_set, not_string_list), xi: Constraint.t) =>
switch (xi) {
| String(s) => (StringSet.add(s, string_set), not_string_list)
| NotString(s) => (string_set, [s, ...not_string_list])
| _ => failwith("input can only be String | NotString")
},
(StringSet.empty, []),
xis,
);
StringSet.cardinal(string_set) > 1
|| List.exists(StringSet.mem(_, string_set), not_string_list);
};

let rec is_inconsistent = (xis: list(Constraint.t)): bool =>
switch (xis) {
| [] => false
| _
when
List.exists(Constraint.is_injL, xis)
&& List.exists(Constraint.is_injR, xis) =>
true
| [xi, ...xis'] =>
switch (xi) {
| Truth => is_inconsistent(xis')
| Falsity => true
| Hole => assert(false) // Impossible
| And(xi1, xi2) => is_inconsistent([xi1, xi2, ...xis'])
| Or(xi1, xi2) =>
is_inconsistent([xi1, ...xis']) && is_inconsistent([xi2, ...xis'])
| InjL(_) =>
switch (List.partition(Constraint.is_injL, xis)) {
| (injLs, []) =>
injLs |> List.map(Constraint.unwrapL) |> is_inconsistent
| (injLs, others) => is_inconsistent(others @ injLs)
}
| InjR(_) =>
switch (List.partition(Constraint.is_injR, xis)) {
| (injRs, []) =>
injRs |> List.map(Constraint.unwrapR) |> is_inconsistent
| (injRs, others) => is_inconsistent(others @ injRs)
}
| Int(_)
| NotInt(_) =>
switch (
List.partition(
fun
| Constraint.Int(_)
| NotInt(_) => true
| _ => false,
xis,
)
) {
| (ns, []) => is_inconsistent_int(ns)
| (ns, others) => is_inconsistent(others @ ns)
}
| Float(_)
| NotFloat(_) =>
switch (
List.partition(
fun
| Constraint.Float(_)
| NotFloat(_) => true
| _ => false,
xis,
)
) {
| (fs, []) => is_inconsistent_float(fs)
| (fs, others) => is_inconsistent(others @ fs)
}
| String(_)
| NotString(_) =>
switch (
List.partition(
fun
| Constraint.String(_)
| NotString(_) => true
| _ => false,
xis,
)
) {
| (ss, []) => is_inconsistent_string(ss)
| (ss, others) => is_inconsistent(others @ ss)
}
| Pair(_, _) =>
switch (
List.partition(
fun
| Constraint.Pair(_) => true
| _ => false,
xis,
)
) {
| (pairs, []) =>
let (xisL, xisR) =
pairs |> List.map(Constraint.unwrap_pair) |> List.split;
is_inconsistent(xisL) || is_inconsistent(xisR);
| (pairs, others) => is_inconsistent(others @ pairs)
}
}
};

let is_redundant = (xi_cur: Constraint.t, xi_pre: Constraint.t): bool =>
is_inconsistent(
Constraint.[And(truify(xi_cur), dual(falsify(xi_pre)))],
);

let is_exhaustive = (xi: Constraint.t): bool =>
is_inconsistent(Constraint.[dual(truify(xi))]);
23 changes: 23 additions & 0 deletions src/haz3lcore/dynamics/Sets.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module IntSet =
Set.Make({
type t = int;
let compare = compare;
});

module BoolSet =
Set.Make({
type t = bool;
let compare = compare;
});

module FloatSet =
Set.Make({
type t = float;
let compare = compare;
});

module StringSet =
Set.Make({
type t = string;
let compare = compare;
});
9 changes: 9 additions & 0 deletions src/haz3lcore/statics/ConstructorMap.re
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,12 @@ let rec is_ground = (is_ground_value: 'a => bool, map: t('a)): bool =>
| [(_, head), ...tail] =>
is_ground_value(head) && tail |> is_ground(is_ground_value)
};

let nth = (map: t('a), ctr: Constructor.t): option(int) => {
// TODO: use List.find_index instead, which is available for OCaml 5.1
let ctrs_sorted = map |> sort |> ctrs_of;
List.find_opt(
nth => List.nth(ctrs_sorted, nth) == ctr,
List.init(List.length(ctrs_sorted), Fun.id),
);
};
Loading
Loading