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

Implement Labeled Tuples #1235

Merged
merged 266 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
266 commits
Select commit Hold shift + click to select a range
cbe3125
merge complete
WondAli Jul 31, 2024
e0952df
renamed some variables to be more accurate
WondAli Aug 8, 2024
bf1137c
dot operator update
WondAli Aug 12, 2024
9ab0f49
dot operator static fixes
WondAli Aug 16, 2024
db194f8
Creation of Label term, bug fixes, documentation updates
WondAli Aug 23, 2024
c20706a
fixes to labeled expressions as singleton tuples
WondAli Aug 24, 2024
fe24986
minor test_elaboration update
WondAli Aug 24, 2024
773fa9b
singleton tuple fixes
WondAli Aug 27, 2024
e76f5e2
fix statics to check for mismatched labels
WondAli Aug 27, 2024
a802eb7
fix to let elaboration so that dot operators operate on annotated typ…
WondAli Aug 28, 2024
65eec8e
merge (not working)
WondAli Sep 12, 2024
4753f3f
fix to precedence and cast ground_caes_of
WondAli Sep 13, 2024
cae4bb5
elaborator fixes
WondAli Sep 13, 2024
bc22754
updated parser for dot operator
WondAli Sep 13, 2024
e810400
debug
7h3kk1d Sep 20, 2024
840f06f
Temp commit
7h3kk1d Sep 21, 2024
58fc12c
Add rearrange2
7h3kk1d Sep 21, 2024
2b1eda8
I got some version of elaboration working
7h3kk1d Sep 21, 2024
2be5a46
Fix formatting
7h3kk1d Sep 21, 2024
f7a2666
Cleanup
7h3kk1d Sep 23, 2024
a2c34df
Revert makefile changes
7h3kk1d Sep 23, 2024
50536fe
Cleanup debugging code
7h3kk1d Sep 23, 2024
4226bb4
More cleanup
7h3kk1d Sep 23, 2024
8eef13c
Got a version of evaluation to work
7h3kk1d Sep 23, 2024
998caeb
Stop elaborating labels in Dot
7h3kk1d Sep 27, 2024
000b853
updates to elaboration, label extraction, ap in progress
WondAli Sep 27, 2024
76247f0
merged with labeled-tuple-rewrite
WondAli Sep 27, 2024
8379dec
Missing labeled tuple labels elboration (#1399)
WondAli Sep 27, 2024
d5dfa8f
cleaned LabeledTuple util file
WondAli Sep 27, 2024
7d707c9
Rearranging does not occur past elaboration. Functions reworked to al…
WondAli Sep 29, 2024
20c51f9
Add support for fast_equal on TupLabel expressions
7h3kk1d Oct 2, 2024
49c11d9
Add test for elaboration adding labels to labeled tuples
7h3kk1d Oct 2, 2024
38b10c1
Inline expectation
7h3kk1d Oct 2, 2024
c315caa
Fix typos
7h3kk1d Oct 2, 2024
5707718
Add test for rearranging labels during elaboration
7h3kk1d Oct 2, 2024
e4fb061
Merge remote-tracking branch 'origin/dev' into labeled-tuple-rewrite
7h3kk1d Oct 2, 2024
8d6528e
Add test for labeled tuple projection evaluation
7h3kk1d Oct 2, 2024
a5c83bc
Add statics test for labeled parameter in function
7h3kk1d Oct 2, 2024
f4d778e
Added tests to assure that types are inconsistent when unlabeled vari…
7h3kk1d Oct 4, 2024
32173ea
removed function implicit labelling and rearranging in type consisten…
WondAli Oct 4, 2024
318cfb3
Add basic elaboration tests for singleton tuples
7h3kk1d Oct 11, 2024
c8ef191
Modify singleton labeled tuple elaboration
7h3kk1d Oct 11, 2024
22cd8d6
Add parser tests for singleton tuples
7h3kk1d Oct 11, 2024
f04c976
Wrap all tuplabels in tuples in parser
7h3kk1d Oct 11, 2024
78e817c
Remove is_contained logic
7h3kk1d Oct 11, 2024
7008809
More tests
7h3kk1d Oct 13, 2024
59ff548
Add assertions that there's no static errors in static tests
7h3kk1d Oct 13, 2024
158a62d
Merge branch 'dev' into labeled-tuple-rewrite
7h3kk1d Oct 13, 2024
0669d9c
Ensure more tests are fully consistent
7h3kk1d Oct 13, 2024
c27642b
Stop recalculating statics in tests
7h3kk1d Oct 13, 2024
bcd9fe2
Add support for displaying TupLabel with label and type in view_ty fu…
7h3kk1d Oct 13, 2024
926c5c7
Add labeled tuples doc page
7h3kk1d Oct 14, 2024
5f790cb
revert scratch file
7h3kk1d Oct 14, 2024
39cbba1
Revert init.ml
7h3kk1d Oct 14, 2024
b242321
Add sdocumentation page for labeled tuples
7h3kk1d Oct 14, 2024
de85c69
Tests for multiple labels
7h3kk1d Oct 14, 2024
3c36566
Update Makefile to include dev profile in watch-test
7h3kk1d Oct 14, 2024
72b4cac
Add test case for singleton labeled tuple adding label
7h3kk1d Oct 14, 2024
828da51
Make labeled tuple not need parens in display
7h3kk1d Oct 14, 2024
7688a2b
Add test case for let statement that adds labels during elaboration
7h3kk1d Oct 14, 2024
c86e5f0
Add support for lifting single values into a singleton labeled tuple …
7h3kk1d Oct 14, 2024
dac5119
Refmt
7h3kk1d Oct 14, 2024
3420d2c
Additional test for singleton labels
7h3kk1d Oct 14, 2024
1fa320c
SIngleton labels kind of work
7h3kk1d Oct 14, 2024
c87048d
Remove singleton product from type view
7h3kk1d Oct 14, 2024
01f84c5
Fix the duplicate singleton label statics
7h3kk1d Oct 15, 2024
e018126
Fix stack overflow
7h3kk1d Oct 15, 2024
11804a2
Fix warning in test statics
7h3kk1d Oct 15, 2024
523177e
First attempt singleton labeled tuple elaboration
7h3kk1d Oct 15, 2024
c4db0d0
Remove debug comment
7h3kk1d Oct 16, 2024
03208ff
Fix test
7h3kk1d Oct 16, 2024
0f8521a
More singleton label elaborator fixes
7h3kk1d Oct 16, 2024
1bee9bb
Update init
7h3kk1d Oct 18, 2024
e66dd80
Add tests for singleton labeled argument function application
7h3kk1d Oct 18, 2024
b42c613
Progress on elaborating singleton tuples with mismatched labels
7h3kk1d Oct 21, 2024
9a918ef
Fix warnings
7h3kk1d Oct 21, 2024
a603ae7
Merge remote-tracking branch 'origin/dev' into labeled-tuple-rewrite
7h3kk1d Oct 30, 2024
61937e7
Merge remote-tracking branch 'origin/dev' into labeled-tuple-rewrite
7h3kk1d Oct 31, 2024
d88395e
Closer to getting singleton labeled tuples to work
7h3kk1d Oct 31, 2024
7c5abb5
Fix unused warnings
7h3kk1d Nov 1, 2024
d163367
Errored statuses showed up right
7h3kk1d Nov 1, 2024
0343f51
Extract functions to be slightly more legible
7h3kk1d Nov 1, 2024
8d3d3e6
Merge branch 'dev' into labeled-tuple-rewrite
7h3kk1d Nov 1, 2024
12eef70
Fixed singleton labeled tuple in function application
7h3kk1d Nov 4, 2024
868ed9b
Fix statics test
7h3kk1d Nov 4, 2024
effab75
Merge remote-tracking branch 'origin/dev' into labeled-tuple-rewrite
7h3kk1d Nov 7, 2024
d1cd408
Add some information on the lifted type to the cursor inspector
7h3kk1d Nov 8, 2024
ece70b4
label uniqueness checking
WondAli Nov 10, 2024
3624020
Start elaborating singleton labeled tuple patterns
7h3kk1d Nov 8, 2024
ecbd7ce
Singleton labeled tuple pattern elaboration disabled under ascription
7h3kk1d Nov 15, 2024
24de2fa
Fix assertions
7h3kk1d Nov 15, 2024
58029ad
Stop debugging
7h3kk1d Nov 15, 2024
69fb726
Remove unnecessary module name
7h3kk1d Nov 15, 2024
4a78f89
Fix tests and strip casts out of some of the tests
7h3kk1d Nov 15, 2024
30e3b9c
Bugfix: statics now check that the first argument in a TupLabel is a …
WondAli Nov 18, 2024
5529383
Progress on improving cursor inspector for automatic labelling
7h3kk1d Nov 18, 2024
4a8776c
Fix unused module open
7h3kk1d Nov 18, 2024
7166f28
Add sugar to info
7h3kk1d Nov 18, 2024
6e71d52
Add more labeling information to cursor inspector
7h3kk1d Nov 21, 2024
ddaaaa9
Add pattern labels to cursor inspector
7h3kk1d Nov 26, 2024
88931f4
Remove lifted_ty from Info types
7h3kk1d Nov 26, 2024
3a96a5a
Cursor inspector changes
7h3kk1d Dec 5, 2024
68f85ab
updated dot operator to use labels
WondAli Dec 6, 2024
bd36673
Fix cursor inspector message
7h3kk1d Dec 10, 2024
7158c4a
Use unelaborated syntax for ExplainThis
7h3kk1d Dec 27, 2024
fdb8a5e
Progress on cursor inspector for pattern singleton elaboration
7h3kk1d Dec 27, 2024
9b437b4
Update Label view to include label name in type representation
7h3kk1d Dec 30, 2024
694d904
updated cursor view
WondAli Jan 3, 2025
8774ec0
Merge remote-tracking branch 'origin/dev' into labeled-tuple-rewrite
7h3kk1d Jan 6, 2025
0491273
Start Test_ExpToSegment
7h3kk1d Jan 6, 2025
8cf761f
Some ExpToSegment issues
7h3kk1d Jan 6, 2025
3407529
Add parse_and_evaluate function and update tests for multiple labels …
7h3kk1d Jan 7, 2025
b1ad1b2
Add equality check for Dot labels in fast_equal function
7h3kk1d Jan 7, 2025
75139c8
Add test case for labeled tuple field access in evaluation
7h3kk1d Jan 7, 2025
c9fd566
TEMP COMMIT precedence fixes
7h3kk1d Jan 7, 2025
37e593b
Change test to be consistent with ExpToSegment
7h3kk1d Jan 7, 2025
5d81de3
Fix synswitch for pattern elaboration with singleton labeled tuples
7h3kk1d Jan 8, 2025
e98c220
Fix statics for labeled tuple with extra label
7h3kk1d Jan 10, 2025
e3771cf
Additional information on statics errors
7h3kk1d Jan 15, 2025
582054b
Remove extra duplicate label error
7h3kk1d Jan 21, 2025
99c046b
Rename Duplicate_Labels to DuplicateLabels
7h3kk1d Jan 21, 2025
e7e9071
Rename BadLabelContained to BadLabelsContained
7h3kk1d Jan 21, 2025
c21e630
Add docstring
7h3kk1d Jan 21, 2025
ad3390e
Deduplicate tuplabel statics
7h3kk1d Jan 21, 2025
5fda224
Add view_any function and refactor common_err_view to utilize it
7h3kk1d Jan 21, 2025
1f00032
Refactor Mode.of_label
7h3kk1d Jan 21, 2025
dfd8867
Dead code elimination
7h3kk1d Jan 21, 2025
066e548
Refactor maketerm handling in MakeTerm.re to preserve tuplabel ids
7h3kk1d Jan 21, 2025
1fd55eb
Fix statics test relying on id equality
7h3kk1d Jan 21, 2025
b6af70b
Improve error message for duplicated labels
7h3kk1d Jan 21, 2025
b59e718
Improve type status
7h3kk1d Jan 21, 2025
70e8939
Comment out unused code
7h3kk1d Jan 21, 2025
5780e6d
Merge remote-tracking branch 'origin/dev' into labeled-tuple-rewrite
7h3kk1d Jan 21, 2025
50f1f8d
Fix some parsing issues from menhir merge
7h3kk1d Jan 22, 2025
f53f6fc
Stop rearranging in Typ.match_synswitch
7h3kk1d Jan 22, 2025
57bd91f
Parenthesize all tuples in ExpToSegment
7h3kk1d Jan 22, 2025
7a644a8
Adjust label precedence
7h3kk1d Jan 22, 2025
7f73f78
Start working on menhir support for labeled tuples
7h3kk1d Jan 22, 2025
02fb8a6
Always parenthesize tuples in ExpToSegment
7h3kk1d Jan 22, 2025
c08189f
negative sizes in ast gen
7h3kk1d Jan 22, 2025
629d17a
Stop parenthesizing tuplabels in pats
7h3kk1d Jan 22, 2025
3c4f331
Fix tests
7h3kk1d Jan 22, 2025
435aadc
Update labeled tuples doc buffer
7h3kk1d Jan 23, 2025
d83cf63
Remove restrictions on singleton tuples in ExpToSegment
7h3kk1d Jan 23, 2025
9a841e2
Incorrect dot field access should be indet
7h3kk1d Jan 23, 2025
945dc49
Cleanup
7h3kk1d Jan 23, 2025
1e3c11b
Address todos
7h3kk1d Jan 23, 2025
4c3885f
PR Cleanup
7h3kk1d Jan 23, 2025
4f20caa
Change Info Duplicate to DuplicateLabel
7h3kk1d Jan 23, 2025
51f11e6
Switch string for LabeledTuple.label
7h3kk1d Jan 23, 2025
c94dbd3
Clean up singleton labels info
7h3kk1d Jan 23, 2025
2ec4498
Remove unused sugar type
7h3kk1d Jan 23, 2025
2e24d88
Address todos
7h3kk1d Jan 23, 2025
89261e8
Move parse_exp to MakeTerm and strip_casts to DHExp
7h3kk1d Jan 23, 2025
5d6a595
Cleanup Test_Elaboration
7h3kk1d Jan 23, 2025
2815b5b
Fix typo
7h3kk1d Jan 23, 2025
447e5b5
Refactor evaluator tests to use parse_and_evaluate_test
7h3kk1d Jan 23, 2025
24873e2
Clean up ExpToSegment tests
7h3kk1d Jan 23, 2025
29419f7
cleanup
WondAli Jan 24, 2025
48c0b88
Remove comment
7h3kk1d Jan 23, 2025
bb5cbe3
Remove debug print statement
7h3kk1d Jan 23, 2025
8463e71
Cleanup Test_Statics
7h3kk1d Jan 23, 2025
39cdc87
Move labeled tuple test name inside module
7h3kk1d Jan 23, 2025
be71664
Rename LabeledTuple.equals to be more clear
7h3kk1d Jan 24, 2025
1c6819e
Add test case for destructuring labeled tuple
7h3kk1d Jan 24, 2025
a9a0ceb
Remove comment
7h3kk1d Jan 24, 2025
aebab41
revert pattern match change
7h3kk1d Jan 24, 2025
42b1893
Remove debug statement
7h3kk1d Jan 24, 2025
26af04c
Remove commented out code
7h3kk1d Jan 24, 2025
891c726
Statics cleanup
7h3kk1d Jan 24, 2025
bcb6c00
Revert float formatting change
7h3kk1d Jan 24, 2025
9691826
Cleanup Test_Statics
7h3kk1d Jan 24, 2025
f94ce87
LabeledTuple comments cleanup
7h3kk1d Jan 24, 2025
02f9076
Simplify duplicate_labels
7h3kk1d Jan 24, 2025
c92c081
Rename uniques
7h3kk1d Jan 27, 2025
f0bbfba
Refactor get_duplicate_labels_base
7h3kk1d Jan 27, 2025
f4289eb
Remove comments
7h3kk1d Jan 27, 2025
96a8016
Remove commented-out code
7h3kk1d Jan 28, 2025
28118d9
Merge remote-tracking branch 'origin/dev' into labeled-tuple-rewrite
7h3kk1d Jan 28, 2025
eeb15d1
Improve DotExp ExplainThis
7h3kk1d Jan 28, 2025
d0db048
Fix dotexp explain this
7h3kk1d Jan 28, 2025
4508c68
There's no typelevel projection
7h3kk1d Jan 28, 2025
2061d7a
Fix singleton labeled argument explainthis
7h3kk1d Jan 28, 2025
ab332a3
Remove impossible cases from explain this
7h3kk1d Jan 28, 2025
cdf4329
Improve label explain this message
7h3kk1d Jan 28, 2025
4ba16ca
Improve tuplabele expression explain this
7h3kk1d Jan 28, 2025
df9a25f
TupLabel pattern explain this
7h3kk1d Jan 28, 2025
a163ec6
TupLabel type explain this
7h3kk1d Jan 28, 2025
c0d9738
Remove unused code
7h3kk1d Jan 28, 2025
4d23cbb
Remove unused examples
7h3kk1d Jan 28, 2025
1cb94a2
Add comment
7h3kk1d Jan 28, 2025
2a12e1c
Remove unused code
7h3kk1d Jan 28, 2025
13f8a26
Improve tuple explain this with label examples
7h3kk1d Jan 29, 2025
bd6d36f
Stop adding space after label in labeled tuples ExpToSegment
7h3kk1d Jan 29, 2025
c7095fb
Stop suggestions for labels
7h3kk1d Jan 29, 2025
dde8d77
Stop suggesting == in labeled tuple
7h3kk1d Jan 29, 2025
44b4474
Revert accidental commit
7h3kk1d Jan 29, 2025
1a0a666
Update doc buffers
7h3kk1d Jan 29, 2025
8633ae3
LabelNotFound type include s label name and list of labels for better…
7h3kk1d Jan 29, 2025
a6f9935
For singleton tuples the tile id is the id of the tuple not the tuplabel
7h3kk1d Jan 30, 2025
57d34d7
Merge remote-tracking branch 'origin/dev' into labeled-tuple-rewrite
7h3kk1d Jan 30, 2025
3213b3d
More suggestion fixes
7h3kk1d Jan 30, 2025
267d58b
Improve label cursor inspector messages
7h3kk1d Jan 30, 2025
f416cd9
EmptyHole label projection gives unknown type
7h3kk1d Jan 30, 2025
6b2f170
Empty labels not marked as bad label
7h3kk1d Jan 30, 2025
58cb29b
Merge remote-tracking branch 'origin/dev' into labeled-tuple-rewrite
7h3kk1d Jan 30, 2025
f646f5d
Add unexpected labels as an error on the label
7h3kk1d Jan 30, 2025
a3102c2
Refactor TupleLabelError to use a record type
7h3kk1d Jan 30, 2025
74adf02
Make patterns work the same as expressions
7h3kk1d Jan 30, 2025
2ac62ce
Add reordering and inferred labels to cursor inspector
7h3kk1d Jan 31, 2025
589dc1a
Combine singleton and multi tuple label inference
7h3kk1d Jan 31, 2025
c53144e
Remove accidental commited file
7h3kk1d Jan 31, 2025
fe8d6a6
Fix reordering check logic
7h3kk1d Jan 31, 2025
5653c29
Add the inferred label to expressions cursor inspector for tuple infe…
7h3kk1d Jan 31, 2025
ca56d9f
Pats statics for label explanation
7h3kk1d Jan 31, 2025
e739f52
Improve doc buffer and cursor inspector fixes
7h3kk1d Feb 3, 2025
925f75e
Remove suggest on tuplabels
7h3kk1d Feb 3, 2025
2e82f0a
Nonprod type expectation shouldn't trigger unexpected labels
7h3kk1d Feb 3, 2025
ec7d211
Stop adding spaces after label equals in ExpToSegment
7h3kk1d Feb 4, 2025
11f1058
Move reordering message to the end of the cursor inspector
7h3kk1d Feb 4, 2025
57fe6c4
Remove colon from label cursor inspector
7h3kk1d Feb 5, 2025
b1d94af
Add label sort to cursor inspector/info
7h3kk1d Feb 5, 2025
0224a5c
Stop casting labels
7h3kk1d Feb 5, 2025
8a7d5dd
Remove debug print statement
7h3kk1d Feb 5, 2025
f46a77d
Stop adding labels in elaboration for different cardinalities
7h3kk1d Feb 6, 2025
c995a1d
Add label sort colors
7h3kk1d Feb 6, 2025
5abde19
Update terminology from "Product type" to "Tuple type" in explanations
7h3kk1d Feb 7, 2025
6afab2b
Stop adding colon to labels in synthesis position
7h3kk1d Feb 7, 2025
9d54d9f
Update label type to label
7h3kk1d Feb 7, 2025
c691d45
Invalid label to malformed
7h3kk1d Feb 7, 2025
655eb49
refmt
7h3kk1d Feb 7, 2025
7b5b473
Rename UnexpectedLabel to InvalidLabel
7h3kk1d Feb 7, 2025
ec6ad7e
Labeled tuple element to labeled tuple item
7h3kk1d Feb 7, 2025
e1fad3f
Update explain this description for tup labels
7h3kk1d Feb 7, 2025
5e2075b
Update explanation for label
7h3kk1d Feb 7, 2025
9c0bc7d
Reformat
7h3kk1d Feb 7, 2025
2929297
Add new line and labeled function arg example to basic reference
7h3kk1d Feb 7, 2025
3fb8500
PR cleanup
7h3kk1d Feb 8, 2025
905fd01
Formatting
7h3kk1d Feb 10, 2025
22d4bde
Merge remote-tracking branch 'origin/dev' into labeled-tuple-rewrite
7h3kk1d Feb 10, 2025
28596bb
Revert accidental commit
7h3kk1d Feb 10, 2025
9a55f9b
PR Cleanup
7h3kk1d Feb 10, 2025
389faa7
Use locally abstract type
7h3kk1d Feb 10, 2025
4a4f980
Remove stale comments
7h3kk1d Feb 10, 2025
327279a
PR Cleanup
7h3kk1d Feb 10, 2025
5b8635b
Wrap malformed labels in MultiHoles to stop evaluation
7h3kk1d Feb 10, 2025
87401fa
Fix exponential notation for floating point
7h3kk1d Feb 11, 2025
7084291
Reparse all doc buffers
7h3kk1d Feb 11, 2025
2cb6d4a
Refmt
7h3kk1d Feb 11, 2025
f9a8381
Remove rearrange2
7h3kk1d Feb 11, 2025
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
295 changes: 295 additions & 0 deletions src/haz3lcore/LabeledTuple.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,295 @@
open Util;

exception Exception;

[@deriving (show({with_path: false}), sexp, yojson)]
type t = string;
7h3kk1d marked this conversation as resolved.
Show resolved Hide resolved

let equal: (option((t, 'a)), option((t, 'b))) => bool =
(left, right) => {
switch (left, right) {
| (Some((s1, _)), Some((s2, _))) => String.equal(s1, s2)
7h3kk1d marked this conversation as resolved.
Show resolved Hide resolved
| (_, _) => false
};
};

let length = String.length;

let compare = String.compare;

let find_opt: ('a => bool, list('a)) => option('a) = List.find_opt;

// returns a pair containing a list of option(t) and a list of 'a
let seperate_labels:
('a => option((t, 'a)), list('a)) => (list(option(t)), list('a)) =
(get_label, es) => {
let results =
List.fold_left(
((ls, ns), e) =>
switch (get_label(e)) {
| Some((s1, e)) => (ls @ [Some(s1)], ns @ [e])
| None => (ls @ [None], ns @ [e])
},
([], []),
es,
);
results;
};

// returns ordered list of (Some(string), TupLabel)
// and another of (None, not-TupLabel)
// TODO: Need to check uniqueness earlier
// TODO: Make more efficient
let validate_uniqueness:
('a => option((t, 'a)), list('a)) =>
(bool, list((option(t), 'a)), list('a)) =
(get_label, es) => {
let results =
List.fold_left(
((b, ls, ns), e) =>
switch (get_label(e)) {
| Some((s1, _))
when
b
&& List.fold_left(
(v, l) =>
switch (l) {
| (Some(s2), _) when v => compare(s1, s2) != 0
7h3kk1d marked this conversation as resolved.
Show resolved Hide resolved
| _ => false
},
true,
ls,
) => (
b,
ls @ [(Some(s1), e)],
ns,
)
| None => (b, ls, ns @ [e])
| _ => (false, ls, ns)
},
(true, [], []),
es,
);
results;
};

// Assumes all labels are unique
// filt returns Some(string) if TupLabel or None if not a TupLabel
// returns a permutation of l2 that matches labels in l1
// other labels are in order, even if not matching.
let rearrange:
(
'a => option((t, 'a)),
'b => option((t, 'b)),
list('a),
list('b),
(t, 'b) => 'b
) =>
list('b) =
(get_label1, get_label2, l1, l2, constructor) => {
// TODO: Error handling in case of bad arguments
let (_, l1_lab, _) = validate_uniqueness(get_label1, l1);
let (_, l2_lab, _) = validate_uniqueness(get_label2, l2);
// Second item in the pair is the full tuplabel
let l2_matched =
List.fold_left(
(l2_matched, l1_item) => {
let l2_item =
find_opt(
l2_item => {
switch (l1_item, l2_item) {
| ((Some(s1), _), (Some(s2), _)) => compare(s1, s2) == 0
7h3kk1d marked this conversation as resolved.
Show resolved Hide resolved
| (_, _) => false
}
},
l2_lab,
);
switch (l2_item) {
| Some(l2_item) => l2_matched @ [l2_item]
| None => l2_matched
};
},
[],
l1_lab,
);
// Second item in the pair is just the element half of the tuplabel
let l2_rem =
List.fold_left(
(l2_rem, item) => {
switch (get_label2(item)) {
| Some((s1, _))
when
List.exists(
l => {
switch (l) {
| (Some(s2), _) => compare(s1, s2) == 0
| _ => false
}
},
l2_matched,
) => l2_rem
| Some((s1, it)) => l2_rem @ [(Some(s1), it)]
| _ => l2_rem @ [(None, item)]
}
},
[],
l2,
);
let rec rearrange_helper =
(
l1: list('x),
l2_matched: list((option(t), 'y)),
l2_rem: list((option(t), 'y)),
)
: list('y) =>
switch (l1) {
| [hd, ...tl] =>
switch (get_label1(hd)) {
| Some((s1, _)) =>
switch (l2_matched) {
| [] =>
switch (l2_rem) {
| [hd2, ...tl2] =>
switch (hd2) {
| (Some(s2), rem_val) =>
[constructor(s2, rem_val)]
@ rearrange_helper(tl, l2_matched, tl2)
| (None, rem_val) =>
[constructor(s1, rem_val)]
@ rearrange_helper(tl, l2_matched, tl2)
}
| [] => raise(Exception)
}
| [hd2, ...tl2] =>
switch (hd2) {
| (Some(s2), l2_val) when compare(s1, s2) == 0 =>
[l2_val] @ rearrange_helper(tl, tl2, l2_rem)
| _ =>
switch (l2_rem) {
| [hd2, ...tl2] =>
switch (hd2) {
| (Some(s2), rem_val) =>
[constructor(s2, rem_val)]
@ rearrange_helper(tl, l2_matched, tl2)
| (None, rem_val) =>
[constructor(s1, rem_val)]
@ rearrange_helper(tl, l2_matched, tl2)
}
| [] => raise(Exception)
}
}
}
| None =>
switch (l2_rem) {
| [(_, hd2), ...tl2] =>
[hd2] @ rearrange_helper(tl, l2_matched, tl2)
| [] => raise(Exception)
}
}
| [] => []
};
rearrange_helper(l1, l2_matched, l2_rem);
};

// Rename and clean this
// Assumes all labels are unique
// filt returns Some(string) if TupLabel or None if not a TupLabel
// In order of operations:
// Checks all labeled pairs in l2 are in l1 and performs f on each pair
// Checks all labeled pairs in l1 are in l2 and performs f on each pair
// Checks remaining None pairs in order and performs f on each pair
let ana_tuple:
(
'b => option((t, 'b)),
'c => option((t, 'c)),
('a, 'b, 'c) => 'a,
'a,
'a,
list('b),
list('c)
) =>
'a =
(get_label1, get_label2, f, accu, accu_fail, l1, l2) => {
7h3kk1d marked this conversation as resolved.
Show resolved Hide resolved
let (l1_valid, l1_lab, l1_none) = validate_uniqueness(get_label1, l1);
let (l2_valid, l2_lab, _) = validate_uniqueness(get_label2, l2);
// temporary solution if mess up earlier in tuple, such as make_term
if (!l1_valid || !l2_valid) {
accu_fail;
} else {
// this result represents to accu, and the matched l2 labels
let (accu, l2_labels_matched) =
List.fold_left(
((accu, l2_matched), l1_item) => {
let l2_item =
find_opt(
l2_item => {
switch (l1_item, l2_item) {
| ((Some(s1), _), (Some(s2), _)) => compare(s1, s2) == 0
| (_, _) => false
}
},
l2_lab,
);
switch (l1_item, l2_item) {
| ((_, l1_val), Some((l2_lab, l2_val))) => (
f(accu, l1_val, l2_val),
l2_matched @ [l2_lab],
)
| (_, None) => (accu_fail, l2_matched)
};
},
(accu, []),
l1_lab,
);
// short circuit on failure
if (accu == accu_fail) {
accu_fail;
} else {
// filter l2 to remove matched labels and remove labels
// TODO: Can be optimized
let l2_rem =
List.fold_left(
(l2_rem, item) => {
switch (get_label2(item)) {
| Some((s1, _))
when
List.exists(
l => {
switch (l) {
| Some(s2) => compare(s1, s2) == 0
| _ => false
}
},
l2_labels_matched,
) => l2_rem
| _ => l2_rem @ [item]
}
},
[],
l2,
);
// remaining checks are in order
let accu =
List.fold_left2(
(accu, l1_val, l2_val) => f(accu, l1_val, l2_val),
accu,
l1_none,
l2_rem,
);
accu;
};
};
};

let find_label: ('a => option((t, 'a)), list('a), t) => option('a) =
(filt, es, label) => {
find_opt(
e => {
switch (filt(e)) {
| Some((s, _)) => compare(s, label) == 0
| None => false
}
},
es,
);
};
3 changes: 3 additions & 0 deletions src/haz3lcore/dynamics/Casts.re
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ let rec ground_cases_of = (ty: Typ.t): ground_cases => {
| Int
| Float
| String
| Label(_)
| Var(_)
| Rec(_)
| TupLabel(_, {term: Unknown(_), _})
| Forall(_, {term: Unknown(_), _})
| Arrow({term: Unknown(_), _}, {term: Unknown(_), _})
| List({term: Unknown(_), _}) => Ground
Expand All @@ -81,6 +83,7 @@ let rec ground_cases_of = (ty: Typ.t): ground_cases => {
| Arrow(_, _) => grounded_Arrow
| Forall(_) => grounded_Forall
| List(_) => grounded_List
| TupLabel(_, _) => NotGroundOrHole(Unknown(Internal) |> Typ.temp)
| Ap(_) => failwith("type application in dynamics")
};
};
Expand Down
4 changes: 4 additions & 0 deletions src/haz3lcore/dynamics/Constraint.re
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type t =
| Or(t, t)
| InjL(t)
| InjR(t)
| TupLabel(t, t)
| Pair(t, t);

let rec dual = (c: t): t =>
Expand All @@ -32,6 +33,7 @@ let rec dual = (c: t): t =>
| Or(c1, c2) => And(dual(c1), dual(c2))
| InjL(c1) => Or(InjL(dual(c1)), InjR(Truth))
| InjR(c2) => Or(InjR(dual(c2)), InjL(Truth))
| TupLabel(c1, c2) => TupLabel(dual(c1), dual(c2))
| Pair(c1, c2) =>
Or(
Pair(c1, dual(c2)),
Expand All @@ -55,6 +57,7 @@ let rec truify = (c: t): t =>
| Or(c1, c2) => Or(truify(c1), truify(c2))
| InjL(c) => InjL(truify(c))
| InjR(c) => InjR(truify(c))
| TupLabel(c1, c2) => TupLabel(truify(c1), truify(c2))
| Pair(c1, c2) => Pair(truify(c1), truify(c2))
};

Expand All @@ -74,6 +77,7 @@ let rec falsify = (c: t): t =>
| Or(c1, c2) => Or(falsify(c1), falsify(c2))
| InjL(c) => InjL(falsify(c))
| InjR(c) => InjR(falsify(c))
| TupLabel(c1, c2) => TupLabel(falsify(c1), falsify(c2))
| Pair(c1, c2) => Pair(falsify(c1), falsify(c2))
};

Expand Down
6 changes: 6 additions & 0 deletions src/haz3lcore/dynamics/DHExp.re
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ let rec strip_casts =
switch (term_of(exp)) {
/* Leave non-casts unchanged */
| Tuple(_)
| TupLabel(_)
| Dot(_)
| Cons(_)
| ListConcat(_)
| ListLit(_)
Expand All @@ -71,6 +73,7 @@ let rec strip_casts =
| Int(_)
| Float(_)
| String(_)
| Label(_)
| Constructor(_)
| DynamicErrorHole(_)
| Closure(_)
Expand Down Expand Up @@ -126,6 +129,8 @@ let ty_subst = (s: Typ.t, tpat: TPat.t, exp: t): t => {
| Cons(_)
| ListConcat(_)
| Tuple(_)
| TupLabel(_)
| Dot(_)
| Match(_)
| DynamicErrorHole(_)
| Filter(_)
Expand All @@ -139,6 +144,7 @@ let ty_subst = (s: Typ.t, tpat: TPat.t, exp: t): t => {
| Int(_)
| Float(_)
| String(_)
| Label(_)
| FailedCast(_, _, _)
| MultiHole(_)
| Deferral(_)
Expand Down
Loading
Loading