cedar-policy-symcc 0.7.0

Symbolic Cedar Compiler (SymCC): translates queries about Cedar policies to SMT
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
/*
 * Copyright Cedar Contributors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#![warn(missing_docs)]
#![doc = include_str!("../README.md")]

pub mod err;
mod symcc;
mod symccopt;

use cedar_policy::{Effect, Policy, PolicySet, RequestEnv, Schema};
use nonempty::{nonempty, NonEmpty};
use std::fmt;

use err::{Error, Result};
use solver::Solver;
use symcc::{well_typed_policies, well_typed_policy, Environment, SymCompiler};
use symccopt::{
    verify_always_allows_opt, verify_always_denies_opt, verify_always_matches_opt,
    verify_disjoint_opt, verify_equivalent_opt, verify_implies_opt, verify_matches_disjoint_opt,
    verify_matches_equivalent_opt, verify_matches_implies_opt, verify_never_errors_opt,
    verify_never_matches_opt, CompiledPolicies,
};

pub use symcc::bitvec;
pub use symcc::ext;
pub use symcc::extension_types;
pub use symcc::factory as term_factory;
pub use symcc::op;
pub use symcc::solver;
pub use symcc::solver_pool;
pub use symcc::term;
pub use symcc::term_type;
pub use symcc::type_abbrevs;
pub use symcc::verifier::Asserts;
pub use symcc::Interpretation;
pub use symcc::{CompiledSchema, Env, ResetMode, SmtLibScript, SymEnv};

impl SymEnv {
    /// Constructs a new [`SymEnv`] from the given [`Schema`] and [`RequestEnv`].
    pub fn new(schema: &Schema, req_env: &RequestEnv) -> Result<Self> {
        let env = Environment::from_request_env(req_env, schema.as_ref())
            .ok_or_else(|| Error::ActionNotInSchema(req_env.action().to_string()))?;
        Ok(Self::of_env(&env)?)
    }
}

/// Validated and well-typed policy.
#[derive(Clone, Debug)]
#[deprecated(since = "0.3.0", note = "use `CompiledPolicy` instead")]
pub struct WellTypedPolicy {
    policy: cedar_policy_core::ast::Policy,
}

#[expect(deprecated, reason = "impl on a deprecated struct")]
impl WellTypedPolicy {
    /// Returns a reference to the underlying policy.
    pub fn policy(&self) -> &cedar_policy_core::ast::Policy {
        &self.policy
    }

    /// Creates a well-typed policy with respect to the given request environment and schema.
    /// This ensures that the policy satisfies the well-typedness constraints required by the
    /// symbolic compiler, by applying Cedar's typechecker transformations.
    pub fn from_policy(
        policy: &Policy,
        env: &RequestEnv,
        schema: &Schema,
    ) -> Result<WellTypedPolicy> {
        well_typed_policy(policy.as_ref(), env, schema).map(|p| WellTypedPolicy { policy: p })
    }

    /// Converts a [`Policy`] to a [`WellTypedPolicy`] without type checking.
    /// Note that SymCC may fail on the policy produced by this function.
    pub fn from_policy_unchecked(policy: &Policy) -> Self {
        WellTypedPolicy {
            policy: policy.as_ref().clone(),
        }
    }
}

#[expect(deprecated, reason = "impl for a deprecated struct")]
impl fmt::Display for WellTypedPolicy {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{}", self.policy)
    }
}

/// Validated and well-typed policy set.
/// Similar to [`WellTypedPolicy`] but for policy sets.
#[derive(Clone, Debug)]
#[deprecated(since = "0.3.0", note = "use `CompiledPolicySet` instead")]
pub struct WellTypedPolicies {
    policies: cedar_policy_core::ast::PolicySet,
}

#[expect(deprecated, reason = "impl on a deprecated struct")]
impl WellTypedPolicies {
    /// Returns a reference to the underlying policy set
    pub fn policy_set(&self) -> &cedar_policy_core::ast::PolicySet {
        &self.policies
    }

    /// Creates a well-typed policy set with respect to the given request environment and schema.
    /// This ensures that the policies satisfy the well-typedness constraints required by the
    /// symbolic compiler, by applying Cedar's typechecker transformations.
    pub fn from_policies(
        ps: &PolicySet,
        env: &RequestEnv,
        schema: &Schema,
    ) -> Result<WellTypedPolicies> {
        well_typed_policies(ps.as_ref(), env, schema).map(|ps| WellTypedPolicies { policies: ps })
    }

    /// Converts a [`PolicySet`] to a [`WellTypedPolicies`] without type checking.
    /// Note that SymCC may fail on the policy set produced by this function.
    pub fn from_policies_unchecked(ps: &PolicySet) -> Self {
        WellTypedPolicies {
            policies: ps.as_ref().clone(),
        }
    }
}

#[expect(deprecated, reason = "impl for a deprecated struct")]
impl fmt::Display for WellTypedPolicies {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{}", self.policies)
    }
}

/// Represents a symbolically compiled policy. This can be fed into various
/// functions on [`CedarSymCompiler`] for efficient solver queries (that don't
/// have to repeat symbolic compilation).
#[derive(Debug, Clone)]
pub struct CompiledPolicy {
    policy: symccopt::CompiledPolicy,
}

impl CompiledPolicy {
    /// Compile a policy for the given `RequestEnv`.
    ///
    /// This does all the validating and well-typing that you need; you need not
    /// (and should not) call `WellTypedPolicy::from_policy()` prior to calling
    /// this.
    pub fn compile(policy: &Policy, env: &RequestEnv, schema: &Schema) -> Result<Self> {
        Ok(Self {
            policy: symccopt::CompiledPolicy::compile(policy.as_ref(), env, schema)?,
        })
    }

    /// Compile a policy for the given `RequestEnv`, using a custom `SymEnv`
    /// rather than the one that would naturally be derived from this
    /// `RequestEnv`.
    ///
    /// Most often, you want `compile()` instead.
    /// `compile_with_custom_symenv()` is generally used to compile with
    /// `SymEnv`s that are more concrete than the default `SymEnv`s, with
    /// constraints/concretizations of the entity hierarchy or request
    /// variables.
    ///
    /// Caller is responsible for some currently-undocumented invariants about
    /// the relationship between the `RequestEnv` and the `SymEnv`.
    /// This function has no analogue in the Lean (as of this writing).
    /// Use at your own risk.
    pub fn compile_with_custom_symenv(
        policy: &Policy,
        env: &RequestEnv,
        schema: &Schema,
        symenv: SymEnv,
    ) -> Result<Self> {
        Ok(Self {
            policy: symccopt::CompiledPolicy::compile_with_custom_symenv(
                policy.as_ref(),
                env,
                schema,
                symenv,
            )?,
        })
    }

    /// Get the `Effect` of this `CompiledPolicy`
    pub fn effect(&self) -> Effect {
        self.policy.effect()
    }

    /// Convert a `CompiledPolicy` to a `CompiledPolicySet` representing a
    /// singleton policyset with just that policy.
    ///
    /// This function is intended to be much more efficient than re-compiling
    /// with `CompiledPolicySet::compile()`.
    pub fn into_compiled_policyset(self) -> CompiledPolicySet {
        CompiledPolicySet {
            policies: self.policy.into_compiled_policyset(),
        }
    }
}

/// Represents a symbolically compiled policyset. This can be fed into various
/// functions on [`CedarSymCompiler`] for efficient solver queries (that don't
/// have to repeat symbolic compilation).
#[derive(Debug, Clone)]
pub struct CompiledPolicySet {
    policies: symccopt::CompiledPolicySet,
}

impl CompiledPolicySet {
    /// Compile a policyset for the given `RequestEnv`.
    ///
    /// This does all the validating and well-typing that you need; you need not
    /// (and should not) call `WellTypedPolicies::from_policies()` prior to
    /// calling this.
    pub fn compile(pset: &PolicySet, env: &RequestEnv, schema: &Schema) -> Result<Self> {
        Ok(Self {
            policies: symccopt::CompiledPolicySet::compile(pset.as_ref(), env, schema)?,
        })
    }

    /// Compile a set of policies for the given `RequestEnv`, using a custom
    /// `SymEnv` rather than the one that would naturally be derived from this
    /// `RequestEnv`.
    ///
    /// Most often, you want `compile()` instead.
    /// `compile_with_custom_symenv()` is generally used to compile with
    /// `SymEnv`s that are more concrete than the default `SymEnv`s, with
    /// constraints/concretizations of the entity hierarchy or request
    /// variables.
    ///
    /// Caller is responsible for some currently-undocumented invariants about
    /// the relationship between the `RequestEnv` and the `SymEnv`.
    /// This function has no analogue in the Lean (as of this writing).
    /// Use at your own risk.
    pub fn compile_with_custom_symenv(
        pset: &PolicySet,
        env: &RequestEnv,
        schema: &Schema,
        symenv: SymEnv,
    ) -> Result<Self> {
        Ok(Self {
            policies: symccopt::CompiledPolicySet::compile_with_custom_symenv(
                pset.as_ref(),
                env,
                schema,
                symenv,
            )?,
        })
    }
}

/// Cedar symbolic compiler, which takes your policies and schemas
/// and converts them to SMT queries to perform various verification
/// tasks such as checking if a policy set always allows/denies,
/// if two policy sets are equivalent, etc.
#[derive(Clone, Debug)]
pub struct CedarSymCompiler<S: Solver> {
    /// SymCompiler
    symcc: SymCompiler<S>,
}

impl<S: Solver> CedarSymCompiler<S> {
    /// Constructs a new [`CedarSymCompiler`] with the given [`Solver`] instance.
    ///
    /// Uses the default [`ResetMode`]; see [`Self::with_reset_mode()`].
    pub fn new(solver: S) -> Result<Self> {
        Ok(Self {
            symcc: SymCompiler::new(solver),
        })
    }

    /// Returns this [`CedarSymCompiler`] with the given [`ResetMode`], e.g.
    /// `CedarSymCompiler::new(solver)?.with_reset_mode(ResetMode::Comment)`.
    pub fn with_reset_mode(mut self, reset_mode: ResetMode) -> Self {
        self.symcc.set_reset_mode(reset_mode);
        self
    }

    /// Returns the [`ResetMode`] used for queries issued by this [`CedarSymCompiler`]
    pub fn reset_mode(&self) -> ResetMode {
        self.symcc.reset_mode()
    }

    /// Returns a reference to the [`Solver`] instance used to construct this [`CedarSymCompiler`]
    pub fn solver(&self) -> &S {
        self.symcc.solver()
    }

    /// Returns a mutable reference to the [`Solver`] instance used to construct this [`CedarSymCompiler`]
    pub fn solver_mut(&mut self) -> &mut S {
        self.symcc.solver_mut()
    }

    /// Calls the underlying solver to check if the given `asserts` are unsatisfiable.
    /// Returns `true` iff the asserts are unsatisfiable.
    ///
    /// NOTE: This API is an experimental feature that may break or change in the future.
    pub async fn check_unsat(&mut self, asserts: &WellFormedAsserts<'_>) -> Result<bool> {
        self.symcc
            .check_unsat(|_| Ok(asserts.asserts().clone()), asserts.symenv())
            .await
    }

    /// Calls the underlying solver with given raw `Asserts` and corresponding `SymEnv`,
    /// returning `true` iff the asserts are unsatisfiable.
    ///
    /// Caller is responsible for ensuring that the `Asserts` and `SymEnv` are
    /// well-formed and valid with respect to each other.
    ///
    /// NOTE: This API is an experimental feature that may break or change in the future.
    pub async fn check_unsat_raw(&mut self, asserts: Asserts, symenv: &SymEnv) -> Result<bool> {
        self.symcc.check_unsat(|_| Ok(asserts), symenv).await
    }

    /// Calls the underlying solver to check if the given `asserts` are unsatisfiable.
    /// Returns some counterexample to the given symbolic assertions iff they are satisfiable.
    ///
    /// NOTE: This API is an experimental feature that may break or change in the future.
    pub async fn check_sat(&mut self, asserts: &WellFormedAsserts<'_>) -> Result<Option<Env>> {
        // since `asserts.policies()` doesn't itself produce a clone-able
        // iterator, we create this iterator which is indeed (cheaply)
        // clone-able
        let policies: Vec<&CompiledPolicies<'_>> = asserts.policies().collect();
        let policies_iter = policies.iter().copied();

        self.symcc
            .sat_asserts_opt(asserts.asserts(), policies_iter)
            .await
    }

    /// Returns true iff the [`WellTypedPolicy`] does not error on any well-formed
    /// input in the given symbolic environment.
    ///
    /// Consider using the optimized version `check_never_errors_opt()` instead,
    /// which will allow you to reuse a `CompiledPolicy` across many queries.
    #[deprecated(since = "0.3.0", note = "use `check_never_errors_opt()` instead")]
    #[expect(deprecated, reason = "deprecated function uses deprecated types")]
    pub async fn check_never_errors(
        &mut self,
        policy: &WellTypedPolicy,
        symenv: &SymEnv,
    ) -> Result<bool> {
        self.symcc.check_never_errors(&policy.policy, symenv).await
    }

    /// Returns true iff the [`CompiledPolicy`] does not error on any
    /// well-formed input in the `RequestEnv` it was compiled for.
    pub async fn check_never_errors_opt(&mut self, policy: &CompiledPolicy) -> Result<bool> {
        self.symcc.check_never_errors_opt(&policy.policy).await
    }

    /// Similar to [`Self::check_never_errors`], but returns a counterexample
    /// if the policy could error on well-formed input.
    ///
    /// Consider using the optimized version `check_never_errors_with_counterexample_opt()`
    /// instead, which will allow you to reuse a `CompiledPolicy` across many
    /// queries.
    #[deprecated(
        since = "0.3.0",
        note = "use `check_never_errors_with_counterexample_opt()` instead"
    )]
    #[expect(deprecated, reason = "deprecated function uses deprecated types")]
    pub async fn check_never_errors_with_counterexample(
        &mut self,
        policy: &WellTypedPolicy,
        symenv: &SymEnv,
    ) -> Result<Option<Env>> {
        self.symcc
            .check_never_errors_with_counterexample(&policy.policy, symenv)
            .await
    }

    /// Similar to [`Self::check_never_errors_opt`], but returns a counterexample
    /// if the policy could error on well-formed input.
    pub async fn check_never_errors_with_counterexample_opt(
        &mut self,
        policy: &CompiledPolicy,
    ) -> Result<Option<Env>> {
        self.symcc
            .check_never_errors_with_counterexample_opt(&policy.policy)
            .await
    }

    /// Returns true iff the [`WellTypedPolicy`] matches all well-formed inputs in
    /// the given symbolic environment. That is, if `policy` is a `permit`
    /// policy, it allows all inputs in the `symenv`, or if `policy` is a
    /// `forbid` policy, it denies all inputs in the `symenv`.
    ///
    /// Consider using the optimized version `check_always_matches_opt()` instead,
    /// which will allow you to reuse a `CompiledPolicy` across many queries.
    #[deprecated(since = "0.3.0", note = "use `check_always_matches_opt()` instead")]
    #[expect(deprecated, reason = "deprecated function uses deprecated types")]
    pub async fn check_always_matches(
        &mut self,
        policy: &WellTypedPolicy,
        symenv: &SymEnv,
    ) -> Result<bool> {
        self.symcc
            .check_always_matches(&policy.policy, symenv)
            .await
    }

    /// Returns true iff the [`CompiledPolicy`] matches all well-formed inputs
    /// in the `RequestEnv` it was compiled for.
    pub async fn check_always_matches_opt(&mut self, policy: &CompiledPolicy) -> Result<bool> {
        self.symcc.check_always_matches_opt(&policy.policy).await
    }

    /// Similar to [`Self::check_always_matches`], but returns a counterexample
    /// if the policy does not match some well-formed input.
    ///
    /// Consider using the optimized version `check_always_matches_with_counterexample_opt()`
    /// instead, which will allow you to reuse a `CompiledPolicy` across many
    /// queries.
    #[deprecated(
        since = "0.3.0",
        note = "use `check_always_matches_with_counterexample_opt()` instead"
    )]
    #[expect(deprecated, reason = "deprecated function uses deprecated types")]
    pub async fn check_always_matches_with_counterexample(
        &mut self,
        policy: &WellTypedPolicy,
        symenv: &SymEnv,
    ) -> Result<Option<Env>> {
        self.symcc
            .check_always_matches_with_counterexample(&policy.policy, symenv)
            .await
    }

    /// Similar to [`Self::check_always_matches_opt`], but returns a counterexample
    /// if the policy does not match some well-formed input.
    pub async fn check_always_matches_with_counterexample_opt(
        &mut self,
        policy: &CompiledPolicy,
    ) -> Result<Option<Env>> {
        self.symcc
            .check_always_matches_with_counterexample_opt(&policy.policy)
            .await
    }

    /// Returns true iff the [`WellTypedPolicy`] matches no well-formed inputs in
    /// the given symbolic environment.
    ///
    /// Consider using the optimized version `check_never_matches_opt()` instead,
    /// which will allow you to reuse a `CompiledPolicy` across many queries.
    #[deprecated(since = "0.3.0", note = "use `check_never_matches_opt()` instead")]
    #[expect(deprecated, reason = "deprecated function uses deprecated types")]
    pub async fn check_never_matches(
        &mut self,
        policy: &WellTypedPolicy,
        symenv: &SymEnv,
    ) -> Result<bool> {
        self.symcc.check_never_matches(&policy.policy, symenv).await
    }

    /// Returns true iff the [`CompiledPolicy`] matches no well-formed inputs
    /// in the `RequestEnv` it was compiled for.
    pub async fn check_never_matches_opt(&mut self, policy: &CompiledPolicy) -> Result<bool> {
        self.symcc.check_never_matches_opt(&policy.policy).await
    }

    /// Similar to [`Self::check_never_matches`], but returns a counterexample
    /// if the policy matches some well-formed input.
    ///
    /// Consider using the optimized version `check_never_matches_with_counterexample_opt()`
    /// instead, which will allow you to reuse a `CompiledPolicy` across many
    /// queries.
    #[deprecated(
        since = "0.3.0",
        note = "use `check_never_matches_with_counterexample_opt()` instead"
    )]
    #[expect(deprecated, reason = "deprecated function uses deprecated types")]
    pub async fn check_never_matches_with_counterexample(
        &mut self,
        policy: &WellTypedPolicy,
        symenv: &SymEnv,
    ) -> Result<Option<Env>> {
        self.symcc
            .check_never_matches_with_counterexample(&policy.policy, symenv)
            .await
    }

    /// Similar to [`Self::check_never_matches_opt`], but returns a counterexample
    /// if the policy matches some well-formed input.
    pub async fn check_never_matches_with_counterexample_opt(
        &mut self,
        policy: &CompiledPolicy,
    ) -> Result<Option<Env>> {
        self.symcc
            .check_never_matches_with_counterexample_opt(&policy.policy)
            .await
    }

    /// Returns true iff `policy1` and `policy2` match exactly the same set of
    /// well-formed inputs in the given symbolic environment.
    ///
    /// Compare with `check_equivalent`, which takes two policysets (which could consist
    /// of a single policy, or more) and determines whether the _authorization behavior_
    /// of those policysets is equivalent for well-formed inputs in the `symenv`. This
    /// function differs from `check_equivalent` on singleton policysets in how it treats
    /// `forbid` policies -- while `check_equivalent` trivially holds for any pair of
    /// `forbid` policies (as they both always-deny), `check_matches_equivalent` only
    /// holds if the two policies match exactly the same set of inputs. Also, a nonempty
    /// `permit` and nonempty `forbid` policy can be `check_matches_equivalent`, but can
    /// never be `check_equivalent`. (By "nonempty" we mean, matches at least one request
    /// in the given symbolic environment.)
    ///
    /// Consider using the optimized version `check_matches_equivalent_opt()` instead,
    /// which will allow you to reuse a `CompiledPolicy` across many queries.
    #[deprecated(since = "0.3.0", note = "use `check_matches_equivalent_opt()` instead")]
    #[expect(deprecated, reason = "deprecated function uses deprecated types")]
    pub async fn check_matches_equivalent(
        &mut self,
        policy1: &WellTypedPolicy,
        policy2: &WellTypedPolicy,
        symenv: &SymEnv,
    ) -> Result<bool> {
        self.symcc
            .check_matches_equivalent(&policy1.policy, &policy2.policy, symenv)
            .await
    }

    /// Returns true iff the [`CompiledPolicy`] `policy1` and `policy2` match exactly
    /// the same set of well-formed inputs in the `RequestEnv` they were compiled for.
    /// (Caller guarantees that both policies were compiled for the same `RequestEnv`.)
    ///
    /// Compare with `check_equivalent_opt`, which takes two compiled policysets and
    /// determines whether the _authorization behavior_ of those policysets is equivalent
    /// for well-formed inputs in the `RequestEnv`. This function differs from
    /// `check_equivalent_opt` on singleton policysets in how it treats `forbid` policies --
    /// while `check_equivalent_opt` trivially holds for any pair of `forbid` policies
    /// (as they both always-deny), `check_matches_equivalent_opt` only holds if the two
    /// policies match exactly the same set of inputs. Also, a nonempty `permit` and
    /// nonempty `forbid` policy can be `check_matches_equivalent_opt`, but can never
    /// be `check_equivalent_opt`. (By "nonempty" we mean, matches at least one request
    /// in the `RequestEnv` they were compiled for.)
    ///
    /// Corresponds to `checkMatchesEquivalentOpt` in the Lean.
    pub async fn check_matches_equivalent_opt(
        &mut self,
        policy1: &CompiledPolicy,
        policy2: &CompiledPolicy,
    ) -> Result<bool> {
        self.symcc
            .check_matches_equivalent_opt(&policy1.policy, &policy2.policy)
            .await
    }

    /// Similar to [`Self::check_matches_equivalent`], but returns a counterexample
    /// on which the matching behavior of `policy1` and `policy2` differ.
    ///
    /// Corresponds to `matchesEquivalent?` in the Lean.
    ///
    /// Consider using the optimized version `check_matches_equivalent_with_counterexample_opt()`
    /// instead, which will allow you to reuse a `CompiledPolicy` across many queries.
    #[deprecated(
        since = "0.3.0",
        note = "use `check_matches_equivalent_with_counterexample_opt()` instead"
    )]
    #[expect(deprecated, reason = "deprecated function uses deprecated types")]
    pub async fn check_matches_equivalent_with_counterexample(
        &mut self,
        policy1: &WellTypedPolicy,
        policy2: &WellTypedPolicy,
        symenv: &SymEnv,
    ) -> Result<Option<Env>> {
        self.symcc
            .check_matches_equivalent_with_counterexample(&policy1.policy, &policy2.policy, symenv)
            .await
    }

    /// Similar to [`Self::check_matches_equivalent_opt`], but returns a counterexample
    /// on which the matching behavior of `policy1` and `policy2` differ.
    ///
    /// Corresponds to `matchesEquivalentOpt?` in the Lean.
    pub async fn check_matches_equivalent_with_counterexample_opt(
        &mut self,
        policy1: &CompiledPolicy,
        policy2: &CompiledPolicy,
    ) -> Result<Option<Env>> {
        self.symcc
            .check_matches_equivalent_with_counterexample_opt(&policy1.policy, &policy2.policy)
            .await
    }

    /// Returns true iff `policy1` matching implies that `policy2` matches, for every
    /// well-formed input in the `symenv`. That is, for every request where `policy1`
    /// matches, `policy2` also matches.
    ///
    /// Compare with `check_implies`, which takes two policysets (which could consist of
    /// a single policy, or more) and determines whether the _authorization decision_ of
    /// the first implies that of the second. This function differs from `check_implies`
    /// on singleton policysets in how it treats `forbid` policies -- while for
    /// `check_implies`, any `forbid` policy trivially implies any `permit` policy (as
    /// always-deny always implies any policy), for `check_matches_implies`, a `forbid`
    /// policy may or may not imply a `permit` policy, and a `permit` policy may or may
    /// not imply a `forbid` policy.
    ///
    /// Consider using the optimized version `check_matches_implies_opt()` instead,
    /// which will allow you to reuse a `CompiledPolicy` across many queries.
    #[deprecated(since = "0.3.0", note = "use `check_matches_implies_opt()` instead")]
    #[expect(deprecated, reason = "deprecated function uses deprecated types")]
    pub async fn check_matches_implies(
        &mut self,
        policy1: &WellTypedPolicy,
        policy2: &WellTypedPolicy,
        symenv: &SymEnv,
    ) -> Result<bool> {
        self.symcc
            .check_matches_implies(&policy1.policy, &policy2.policy, symenv)
            .await
    }

    /// Returns true iff the [`CompiledPolicy`] `policy1` matching implies that `policy2`
    /// matches, for every well-formed input in the `RequestEnv` they were compiled for.
    /// (Caller guarantees that both policies were compiled for the same `RequestEnv`.)
    ///
    /// Compare with `check_implies_opt`, which takes two compiled policysets and
    /// determines whether the _authorization decision_ of the first implies that of the
    /// second. This function differs from `check_implies_opt` on singleton policysets
    /// in how it treats `forbid` policies -- while for `check_implies_opt`, any `forbid`
    /// policy trivially implies any `permit` policy (as always-deny always implies any
    /// policy), for `check_matches_implies_opt`, a `forbid` policy may or may not imply
    /// a `permit` policy, and a `permit` policy may or may not imply a `forbid` policy.
    ///
    /// Corresponds to `checkMatchesImpliesOpt` in the Lean.
    pub async fn check_matches_implies_opt(
        &mut self,
        policy1: &CompiledPolicy,
        policy2: &CompiledPolicy,
    ) -> Result<bool> {
        self.symcc
            .check_matches_implies_opt(&policy1.policy, &policy2.policy)
            .await
    }

    /// Similar to [`Self::check_matches_implies`], but returns a counterexample
    /// that is matched by `policy1` but not by `policy2` if it exists.
    ///
    /// Corresponds to `matchesImplies?` in the Lean.
    ///
    /// Consider using the optimized version `check_matches_implies_with_counterexample_opt()`
    /// instead, which will allow you to reuse a `CompiledPolicy` across many queries.
    #[deprecated(
        since = "0.3.0",
        note = "use `check_matches_implies_with_counterexample_opt()` instead"
    )]
    #[expect(deprecated, reason = "deprecated function uses deprecated types")]
    pub async fn check_matches_implies_with_counterexample(
        &mut self,
        policy1: &WellTypedPolicy,
        policy2: &WellTypedPolicy,
        symenv: &SymEnv,
    ) -> Result<Option<Env>> {
        self.symcc
            .check_matches_implies_with_counterexample(&policy1.policy, &policy2.policy, symenv)
            .await
    }

    /// Similar to [`Self::check_matches_implies_opt`], but returns a counterexample
    /// that is matched by `policy1` but not by `policy2` if it exists.
    ///
    /// Corresponds to `matchesImpliesOpt?` in the Lean.
    pub async fn check_matches_implies_with_counterexample_opt(
        &mut self,
        policy1: &CompiledPolicy,
        policy2: &CompiledPolicy,
    ) -> Result<Option<Env>> {
        self.symcc
            .check_matches_implies_with_counterexample_opt(&policy1.policy, &policy2.policy)
            .await
    }

    /// Returns true iff there is no well-formed input in the `symenv` that is matched
    /// by both `policy1` and `policy2`. This checks that the sets of inputs matched by
    /// `policy1` and `policy2` are disjoint.
    ///
    /// Compare with `check_disjoint`, which takes two policysets (which could consist
    /// of a single policy, or more) and determines whether the _authorization behavior_
    /// of those policysets are disjoint. This function differs from `check_disjoint` on
    /// singleton policysets in how it treats `forbid` policies -- while for
    /// `check_disjoint`, any `forbid` policy is trivially disjoint from any other policy
    /// (as it allows nothing), `check_matches_disjoint` considers whether the `forbid`
    /// policy may _match_ (rather than _allow_) any input that is matched by the other
    /// policy.
    ///
    /// Consider using the optimized version `check_matches_disjoint_opt()` instead,
    /// which will allow you to reuse a `CompiledPolicy` across many queries.
    #[deprecated(since = "0.3.0", note = "use `check_matches_disjoint_opt()` instead")]
    #[expect(deprecated, reason = "deprecated function uses deprecated types")]
    pub async fn check_matches_disjoint(
        &mut self,
        policy1: &WellTypedPolicy,
        policy2: &WellTypedPolicy,
        symenv: &SymEnv,
    ) -> Result<bool> {
        self.symcc
            .check_matches_disjoint(&policy1.policy, &policy2.policy, symenv)
            .await
    }

    /// Returns true iff there is no well-formed input in the `RequestEnv` that is
    /// matched by both [`CompiledPolicy`] `policy1` and `policy2`.
    /// (Caller guarantees that both policies were compiled for the same `RequestEnv`.)
    ///
    /// Compare with `check_disjoint_opt`, which takes two compiled policysets and
    /// determines whether the _authorization behavior_ of those policysets are disjoint.
    /// This function differs from `check_disjoint_opt` on singleton policysets in how it
    /// treats `forbid` policies -- while for `check_disjoint_opt`, any `forbid` policy
    /// is trivially disjoint from any other policy (as it allows nothing),
    /// `check_matches_disjoint_opt` considers whether the `forbid` policy may _match_
    /// (rather than _allow_) any input that is matched by the other policy.
    ///
    /// Corresponds to `checkMatchesDisjointOpt` in the Lean.
    pub async fn check_matches_disjoint_opt(
        &mut self,
        policy1: &CompiledPolicy,
        policy2: &CompiledPolicy,
    ) -> Result<bool> {
        self.symcc
            .check_matches_disjoint_opt(&policy1.policy, &policy2.policy)
            .await
    }

    /// Similar to [`Self::check_matches_disjoint`], but returns a counterexample
    /// that is matched by both `policy1` and `policy2` if it exists.
    ///
    /// Corresponds to `matchesDisjoint?` in the Lean.
    ///
    /// Consider using the optimized version `check_matches_disjoint_with_counterexample_opt()`
    /// instead, which will allow you to reuse a `CompiledPolicy` across many queries.
    #[deprecated(
        since = "0.3.0",
        note = "use `check_matches_disjoint_with_counterexample_opt()` instead"
    )]
    #[expect(deprecated, reason = "deprecated function uses deprecated types")]
    pub async fn check_matches_disjoint_with_counterexample(
        &mut self,
        policy1: &WellTypedPolicy,
        policy2: &WellTypedPolicy,
        symenv: &SymEnv,
    ) -> Result<Option<Env>> {
        self.symcc
            .check_matches_disjoint_with_counterexample(&policy1.policy, &policy2.policy, symenv)
            .await
    }

    /// Similar to [`Self::check_matches_disjoint_opt`], but returns a counterexample
    /// that is matched by both `policy1` and `policy2` if it exists.
    ///
    /// Corresponds to `matchesDisjointOpt?` in the Lean.
    pub async fn check_matches_disjoint_with_counterexample_opt(
        &mut self,
        policy1: &CompiledPolicy,
        policy2: &CompiledPolicy,
    ) -> Result<Option<Env>> {
        self.symcc
            .check_matches_disjoint_with_counterexample_opt(&policy1.policy, &policy2.policy)
            .await
    }

    /// Returns true iff the authorization decision of `pset1` implies that of
    /// `pset2` for every well-formed input in the `symenv`. That is, every
    /// input allowed by `pset1` is allowed by `pset2`; `pset2` is either more
    /// permissive than, or equivalent to, `pset1`.
    ///
    /// Consider using the optimized version `check_implies_opt()` instead,
    /// which will allow you to reuse a `CompiledPolicySet` across many queries.
    #[deprecated(since = "0.3.0", note = "use `check_implies_opt()` instead")]
    #[expect(deprecated, reason = "deprecated function uses deprecated types")]
    pub async fn check_implies(
        &mut self,
        pset1: &WellTypedPolicies,
        pset2: &WellTypedPolicies,
        symenv: &SymEnv,
    ) -> Result<bool> {
        self.symcc
            .check_implies(&pset1.policies, &pset2.policies, symenv)
            .await
    }

    /// Returns true iff the authorization decision of `pset1` implies that of
    /// `pset2` for every well-formed input in the `RequestEnv` which both
    /// policysets were compiled for. (Caller guarantees that both policysets
    /// were compiled for the same `RequestEnv`.) That is, every input allowed
    /// by `pset1` is allowed by `pset2`; `pset2` is either more permissive
    /// than, or equivalent to, `pset1`.
    pub async fn check_implies_opt(
        &mut self,
        pset1: &CompiledPolicySet,
        pset2: &CompiledPolicySet,
    ) -> Result<bool> {
        self.symcc
            .check_implies_opt(&pset1.policies, &pset2.policies)
            .await
    }

    /// Similar to [`Self::check_implies`], but returns a counterexample
    /// that is allowed by `pset1` but not by `pset2` if it exists.
    ///
    /// Consider using the optimized version `check_implies_with_counterexample_opt()`
    /// instead, which will allow you to reuse a `CompiledPolicySet` across many
    /// queries.
    #[deprecated(
        since = "0.3.0",
        note = "use `check_implies_with_counterexample_opt()` instead"
    )]
    #[expect(deprecated, reason = "deprecated function uses deprecated types")]
    pub async fn check_implies_with_counterexample(
        &mut self,
        pset1: &WellTypedPolicies,
        pset2: &WellTypedPolicies,
        symenv: &SymEnv,
    ) -> Result<Option<Env>> {
        self.symcc
            .check_implies_with_counterexample(&pset1.policies, &pset2.policies, symenv)
            .await
    }

    /// Similar to [`Self::check_implies_opt`], but returns a counterexample
    /// that is allowed by `pset1` but not by `pset2` if it exists.
    pub async fn check_implies_with_counterexample_opt(
        &mut self,
        pset1: &CompiledPolicySet,
        pset2: &CompiledPolicySet,
    ) -> Result<Option<Env>> {
        self.symcc
            .check_implies_with_counterexample_opt(&pset1.policies, &pset2.policies)
            .await
    }

    /// Returns true iff `pset` allows all well-formed inputs in the `symenv`.
    ///
    /// Consider using the optimized version `check_always_allows_opt()` instead,
    /// which will allow you to reuse a `CompiledPolicySet` across many queries.
    #[deprecated(since = "0.3.0", note = "use `check_always_allows_opt()` instead")]
    #[expect(deprecated, reason = "deprecated function uses deprecated types")]
    pub async fn check_always_allows(
        &mut self,
        pset: &WellTypedPolicies,
        symenv: &SymEnv,
    ) -> Result<bool> {
        self.symcc.check_always_allows(&pset.policies, symenv).await
    }

    /// Returns true iff `pset` allows all well-formed inputs in the
    /// `RequestEnv` which it was compiled for.
    pub async fn check_always_allows_opt(&mut self, pset: &CompiledPolicySet) -> Result<bool> {
        self.symcc.check_always_allows_opt(&pset.policies).await
    }

    /// Similar to [`Self::check_always_allows`], but returns a counterexample
    /// that is denied by `pset` if it exists.
    ///
    /// Consider using the optimized version `check_always_allows_with_counterexample_opt()`
    /// instead, which will allow you to reuse a `CompiledPolicySet` across many
    /// queries.
    #[deprecated(
        since = "0.3.0",
        note = "use `check_always_allows_with_counterexample_opt()` instead"
    )]
    #[expect(deprecated, reason = "deprecated function uses deprecated types")]
    pub async fn check_always_allows_with_counterexample(
        &mut self,
        pset: &WellTypedPolicies,
        symenv: &SymEnv,
    ) -> Result<Option<Env>> {
        self.symcc
            .check_always_allows_with_counterexample(&pset.policies, symenv)
            .await
    }

    /// Similar to [`Self::check_always_allows_opt`], but returns a counterexample
    /// that is denied by `pset` if it exists.
    pub async fn check_always_allows_with_counterexample_opt(
        &mut self,
        pset: &CompiledPolicySet,
    ) -> Result<Option<Env>> {
        self.symcc
            .check_always_allows_with_counterexample_opt(&pset.policies)
            .await
    }

    /// Returns true iff `pset` denies all well-formed inputs in the `symenv`.
    ///
    /// Consider using the optimized version `check_always_denies_opt()` instead,
    /// which will allow you to reuse a `CompiledPolicySet` across many queries.
    #[deprecated(since = "0.3.0", note = "use `check_always_denies_opt()` instead")]
    #[expect(deprecated, reason = "deprecated function uses deprecated types")]
    pub async fn check_always_denies(
        &mut self,
        pset: &WellTypedPolicies,
        symenv: &SymEnv,
    ) -> Result<bool> {
        self.symcc.check_always_denies(&pset.policies, symenv).await
    }

    /// Returns true iff `pset` denies all well-formed inputs in the
    /// `RequestEnv` which it was compiled for.
    pub async fn check_always_denies_opt(&mut self, pset: &CompiledPolicySet) -> Result<bool> {
        self.symcc.check_always_denies_opt(&pset.policies).await
    }

    /// Similar to [`Self::check_always_denies`], but returns a counterexample
    /// that is allowed by `pset` if it exists.
    ///
    /// Consider using the optimized version `check_always_denies_with_counterexample_opt()`
    /// instead, which will allow you to reuse a `CompiledPolicySet` across many
    /// queries.
    #[deprecated(
        since = "0.3.0",
        note = "use `check_always_denies_with_counterexample_opt()` instead"
    )]
    #[expect(deprecated, reason = "deprecated function uses deprecated types")]
    pub async fn check_always_denies_with_counterexample(
        &mut self,
        pset: &WellTypedPolicies,
        symenv: &SymEnv,
    ) -> Result<Option<Env>> {
        self.symcc
            .check_always_denies_with_counterexample(&pset.policies, symenv)
            .await
    }

    /// Similar to [`Self::check_always_denies_opt`], but returns a counterexample
    /// that is allowed by `pset` if it exists.
    pub async fn check_always_denies_with_counterexample_opt(
        &mut self,
        pset: &CompiledPolicySet,
    ) -> Result<Option<Env>> {
        self.symcc
            .check_always_denies_with_counterexample_opt(&pset.policies)
            .await
    }

    /// Returns true iff `pset1` and `pset2` produce the same authorization
    /// decision on all well-formed inputs in the `symenv`.
    ///
    /// Consider using the optimized version `check_equivalent_opt()` instead,
    /// which will allow you to reuse a `CompiledPolicySet` across many queries.
    #[deprecated(since = "0.3.0", note = "use `check_equivalent_opt()` instead")]
    #[expect(deprecated, reason = "deprecated function uses deprecated types")]
    pub async fn check_equivalent(
        &mut self,
        pset1: &WellTypedPolicies,
        pset2: &WellTypedPolicies,
        symenv: &SymEnv,
    ) -> Result<bool> {
        self.symcc
            .check_equivalent(&pset1.policies, &pset2.policies, symenv)
            .await
    }

    /// Returns true iff `pset1` and `pset2` produce the same authorization
    /// decision on all well-formed inputs in the `RequestEnv` which both
    /// policysets were compiled for. (Caller guarantees that both policysets
    /// were compiled for the same `RequestEnv`.)
    pub async fn check_equivalent_opt(
        &mut self,
        pset1: &CompiledPolicySet,
        pset2: &CompiledPolicySet,
    ) -> Result<bool> {
        self.symcc
            .check_equivalent_opt(&pset1.policies, &pset2.policies)
            .await
    }

    /// Similar to [`Self::check_equivalent`], but returns a counterexample
    /// on which the authorization decisions of `pset1` and `pset2` differ.
    ///
    /// Consider using the optimized version `check_equivalent_with_counterexample_opt()`
    /// instead, which will allow you to reuse a `CompiledPolicySet` across many
    /// queries.
    #[deprecated(
        since = "0.3.0",
        note = "use `check_equivalent_with_counterexample_opt()` instead"
    )]
    #[expect(deprecated, reason = "deprecated function uses deprecated types")]
    pub async fn check_equivalent_with_counterexample(
        &mut self,
        pset1: &WellTypedPolicies,
        pset2: &WellTypedPolicies,
        symenv: &SymEnv,
    ) -> Result<Option<Env>> {
        self.symcc
            .check_equivalent_with_counterexample(&pset1.policies, &pset2.policies, symenv)
            .await
    }

    /// Similar to [`Self::check_equivalent_opt`], but returns a counterexample
    /// on which the authorization decisions of `pset1` and `pset2` differ.
    pub async fn check_equivalent_with_counterexample_opt(
        &mut self,
        pset1: &CompiledPolicySet,
        pset2: &CompiledPolicySet,
    ) -> Result<Option<Env>> {
        self.symcc
            .check_equivalent_with_counterexample_opt(&pset1.policies, &pset2.policies)
            .await
    }

    /// Returns true iff there is no well-formed input in the `symenv` that is
    /// allowed by both `pset1` and `pset2`. If this returns `false`, then there
    /// is at least one well-formed input that is allowed by both `pset1` and
    /// `pset2`.
    ///
    /// Consider using the optimized version `check_disjoint_opt()` instead,
    /// which will allow you to reuse a `CompiledPolicySet` across many queries.
    #[deprecated(since = "0.3.0", note = "use `check_disjoint_opt()` instead")]
    #[expect(deprecated, reason = "deprecated function uses deprecated types")]
    pub async fn check_disjoint(
        &mut self,
        pset1: &WellTypedPolicies,
        pset2: &WellTypedPolicies,
        symenv: &SymEnv,
    ) -> Result<bool> {
        self.symcc
            .check_disjoint(&pset1.policies, &pset2.policies, symenv)
            .await
    }

    /// Returns true iff there is no well-formed input in the `RequestEnv` that
    /// is allowed by both `pset1` and `pset2`.
    /// (Caller guarantees that `pset1` and `pset2` were compiled for
    /// the same `RequestEnv`.)
    pub async fn check_disjoint_opt(
        &mut self,
        pset1: &CompiledPolicySet,
        pset2: &CompiledPolicySet,
    ) -> Result<bool> {
        self.symcc
            .check_disjoint_opt(&pset1.policies, &pset2.policies)
            .await
    }

    /// Similar to [`Self::check_disjoint`], but returns a counterexample
    /// that is allowed by both `pset1` and `pset2`.
    ///
    /// Consider using the optimized version `check_disjoint_with_counterexample_opt()`
    /// instead, which will allow you to reuse a `CompiledPolicySet` across many
    /// queries.
    #[deprecated(
        since = "0.3.0",
        note = "use `check_disjoint_with_counterexample_opt()` instead"
    )]
    #[expect(deprecated, reason = "deprecated function uses deprecated types")]
    pub async fn check_disjoint_with_counterexample(
        &mut self,
        pset1: &WellTypedPolicies,
        pset2: &WellTypedPolicies,
        symenv: &SymEnv,
    ) -> Result<Option<Env>> {
        self.symcc
            .check_disjoint_with_counterexample(&pset1.policies, &pset2.policies, symenv)
            .await
    }

    /// Similar to [`Self::check_disjoint_opt`], but returns a counterexample
    /// that is allowed by both `pset1` and `pset2`.
    pub async fn check_disjoint_with_counterexample_opt(
        &mut self,
        pset1: &CompiledPolicySet,
        pset2: &CompiledPolicySet,
    ) -> Result<Option<Env>> {
        self.symcc
            .check_disjoint_with_counterexample_opt(&pset1.policies, &pset2.policies)
            .await
    }
}

/// Well-formed assertions generated by the symbolic compiler.
#[derive(Clone, Debug)]
pub struct WellFormedAsserts<'a> {
    asserts: Asserts,
    /// All `CompiledPolicy`s or `CompiledPolicySet`s that were used to generate the asserts.
    ///
    /// INVARIANT: All of these are for the same `symenv`.
    policies: NonEmpty<CompiledPolicies<'a>>,
}

impl<'a> WellFormedAsserts<'a> {
    /// Returns the symbolic environment these asserts were generated in.
    pub fn symenv(&self) -> &SymEnv {
        // Relying on the INVARIANT that all the items in `self.policies` have
        // the same `symenv`
        self.policies.first().symenv()
    }

    /// Returns the underlying raw [`Asserts`].
    pub fn asserts(&self) -> &Asserts {
        &self.asserts
    }

    /// Returns the `CompiledPolicies` that were used to generate the asserts
    //
    // This is not a public function because the `CompiledPolicies` type is not public
    fn policies<'s>(&'s self) -> impl Iterator<Item = &'s CompiledPolicies<'a>> + 's {
        self.policies.iter()
    }
}

/// Generate the [`WellFormedAsserts`] for the `check_never_errors()`
/// operation, without actually calling a solver.
///
/// That is, the result of
/// ```no_compile
/// compiler.check_unsat(never_errors_asserts(policy))
/// ```
/// should be the same as `compiler.check_never_errors_opt(policy)`.
///
/// Likewise, the result of
/// ```no_compile
/// compiler.check_sat(never_errors_asserts(policy))
/// ```
/// should be the same as `compiler.check_never_errors_with_counterexample_opt(policy)`.
///
/// NOTE: This API is an experimental feature, and the API may change
/// or break in the future.
pub fn never_errors_asserts<'a>(policy: &'a CompiledPolicy) -> WellFormedAsserts<'a> {
    WellFormedAsserts {
        asserts: verify_never_errors_opt(&policy.policy),
        policies: nonempty![CompiledPolicies::Policy(&policy.policy)],
    }
}

/// Generate the [`WellFormedAsserts`] for the `check_always_matches()`
/// operation, without actually calling a solver.
///
/// That is, the result of
/// ```no_compile
/// compiler.check_unsat(always_matches_asserts(policy))
/// ```
/// should be the same as `compiler.check_always_matches_opt(policy)`.
///
/// Likewise, the result of
/// ```no_compile
/// compiler.check_sat(always_matches_asserts(policy))
/// ```
/// should be the same as `compiler.check_always_matches_opt(policy)`.
///
/// NOTE: This API is an experimental feature, and the API may change
/// or break in the future.
pub fn always_matches_asserts<'a>(policy: &'a CompiledPolicy) -> WellFormedAsserts<'a> {
    WellFormedAsserts {
        asserts: verify_always_matches_opt(&policy.policy),
        policies: nonempty![CompiledPolicies::Policy(&policy.policy)],
    }
}

/// Generate the [`WellFormedAsserts`] for the `check_never_matches()`
/// operation, without actually calling a solver.
///
/// That is, the result of
/// ```no_compile
/// compiler.check_unsat(never_matches_asserts(policy))
/// ```
/// should be the same as `compiler.check_never_matches_opt(policy)`.
///
/// Likewise, the result of
/// ```no_compile
/// compiler.check_sat(never_matches_asserts(policy))
/// ```
/// should be the same as `compiler.check_never_matches_opt(policy)`.
///
/// NOTE: This API is an experimental feature, and the API may change
/// or break in the future.
pub fn never_matches_asserts<'a>(policy: &'a CompiledPolicy) -> WellFormedAsserts<'a> {
    WellFormedAsserts {
        asserts: verify_never_matches_opt(&policy.policy),
        policies: nonempty![CompiledPolicies::Policy(&policy.policy)],
    }
}

/// Generate the [`WellFormedAsserts`] for the `check_matches_equivalent()`
/// operation, without actually calling a solver.
///
/// That is, the result of
/// ```no_compile
/// compiler.check_unsat(matches_equivalent_asserts(policy1, policy2))
/// ```
/// should be the same as `compiler.check_matches_equivalent(policy1, policy2)`.
///
/// Likewise, the result of
/// ```no_compile
/// compiler.check_sat(matches_equivalent_asserts(policy1, policy2))
/// ```
/// should be the same as `compiler.check_matches_equivalent_opt(policy1, policy2)`.
///
/// NOTE: This API is an experimental feature, and the API may change
/// or break in the future.
pub fn matches_equivalent_asserts<'a>(
    policy1: &'a CompiledPolicy,
    policy2: &'a CompiledPolicy,
) -> WellFormedAsserts<'a> {
    WellFormedAsserts {
        asserts: verify_matches_equivalent_opt(&policy1.policy, &policy2.policy),
        policies: nonempty![
            CompiledPolicies::Policy(&policy1.policy),
            CompiledPolicies::Policy(&policy2.policy)
        ],
    }
}

/// Generate the [`WellFormedAsserts`] for the `check_matches_implies()`
/// operation, without actually calling a solver.
///
/// That is, the result of
/// ```no_compile
/// compiler.check_unsat(matches_implies_asserts(policy1, policy2))
/// ```
/// should be the same as `compiler.check_matches_implies(policy1, policy2)`.
///
/// Likewise, the result of
/// ```no_compile
/// compiler.check_sat(matches_implies_asserts(policy1, policy2))
/// ```
/// should be the same as `compiler.check_matches_implies_opt(policy1, policy2)`.
///
/// NOTE: This API is an experimental feature, and the API may change
/// or break in the future.
pub fn matches_implies_asserts<'a>(
    policy1: &'a CompiledPolicy,
    policy2: &'a CompiledPolicy,
) -> WellFormedAsserts<'a> {
    WellFormedAsserts {
        asserts: verify_matches_implies_opt(&policy1.policy, &policy2.policy),
        policies: nonempty![
            CompiledPolicies::Policy(&policy1.policy),
            CompiledPolicies::Policy(&policy2.policy)
        ],
    }
}

/// Generate the [`WellFormedAsserts`] for the `check_matches_disjoint()`
/// operation, without actually calling a solver.
///
/// That is, the result of
/// ```no_compile
/// compiler.check_unsat(matches_disjoint_asserts(policy1, policy2))
/// ```
/// should be the same as `compiler.check_matches_disjoint(policy1, policy2)`.
///
/// Likewise, the result of
/// ```no_compile
/// compiler.check_sat(matches_disjoint_asserts(policy1, policy2))
/// ```
/// should be the same as `compiler.check_matches_disjoint_opt(policy1, policy2)`.
///
/// NOTE: This API is an experimental feature, and the API may change
/// or break in the future.
pub fn matches_disjoint_asserts<'a>(
    policy1: &'a CompiledPolicy,
    policy2: &'a CompiledPolicy,
) -> WellFormedAsserts<'a> {
    WellFormedAsserts {
        asserts: verify_matches_disjoint_opt(&policy1.policy, &policy2.policy),
        policies: nonempty![
            CompiledPolicies::Policy(&policy1.policy),
            CompiledPolicies::Policy(&policy2.policy)
        ],
    }
}

/// Generate the [`WellFormedAsserts`] for the `check_always_allows()`
/// operation, without actually calling a solver.
///
/// That is, the result of
/// ```no_compile
/// compiler.check_unsat(always_allows_asserts(policies))
/// ```
/// should be the same as `compiler.check_always_allows(policies)`.
///
/// Likewise, the result of
/// ```no_compile
/// compiler.check_sat(always_allows_asserts(policies))
/// ```
/// should be the same as `compiler.check_always_allows_opt(policies)`.
///
/// NOTE: This API is an experimental feature, and the API may change
/// or break in the future.
pub fn always_allows_asserts<'a>(policies: &'a CompiledPolicySet) -> WellFormedAsserts<'a> {
    WellFormedAsserts {
        asserts: verify_always_allows_opt(&policies.policies),
        policies: nonempty![CompiledPolicies::PolicySet(&policies.policies)],
    }
}

/// Generate the [`WellFormedAsserts`] for the `check_always_denies()`
/// operation, without actually calling a solver.
///
/// That is, the result of
/// ```no_compile
/// compiler.check_unsat(always_denies_asserts(policies))
/// ```
/// should be the same as `compiler.check_always_denies(policies)`.
///
/// Likewise, the result of
/// ```no_compile
/// compiler.check_sat(always_denies_asserts(policies))
/// ```
/// should be the same as `compiler.check_always_denies_opt(policies)`.
///
/// NOTE: This API is an experimental feature, and the API may change
/// or break in the future.
pub fn always_denies_asserts<'a>(policies: &'a CompiledPolicySet) -> WellFormedAsserts<'a> {
    WellFormedAsserts {
        asserts: verify_always_denies_opt(&policies.policies),
        policies: nonempty![CompiledPolicies::PolicySet(&policies.policies)],
    }
}

/// Generate the [`WellFormedAsserts`] for the `check_implies()`
/// operation, without actually calling a solver.
///
/// That is, the result of
/// ```no_compile
/// compiler.check_unsat(implies_asserts(policies1, policies2))
/// ```
/// should be the same as `compiler.check_implies(policies1, policies2)`.
///
/// Likewise, the result of
/// ```no_compile
/// compiler.check_sat(implies_asserts(policies1, policies2))
/// ```
/// should be the same as `compiler.check_implies_opt(policies1, policies2)`.
///
/// NOTE: This API is an experimental feature, and the API may change
/// or break in the future.
pub fn implies_asserts<'a>(
    policies1: &'a CompiledPolicySet,
    policies2: &'a CompiledPolicySet,
) -> WellFormedAsserts<'a> {
    WellFormedAsserts {
        asserts: verify_implies_opt(&policies1.policies, &policies2.policies),
        policies: nonempty![
            CompiledPolicies::PolicySet(&policies1.policies),
            CompiledPolicies::PolicySet(&policies2.policies)
        ],
    }
}

/// Generate the [`WellFormedAsserts`] for the `check_equivalent()`
/// operation, without actually calling a solver.
///
/// That is, the result of
/// ```no_compile
/// compiler.check_unsat(equivalent_asserts(policies1, policies2))
/// ```
/// should be the same as `compiler.check_equivalent(policies1, policies2)`.
///
/// Likewise, the result of
/// ```no_compile
/// compiler.check_sat(equivalent_asserts(policies1, policies2))
/// ```
/// should be the same as `compiler.check_equivalent_opt(policies1, policies2)`.
///
/// NOTE: This API is an experimental feature, and the API may change
/// or break in the future.
pub fn equivalent_asserts<'a>(
    policies1: &'a CompiledPolicySet,
    policies2: &'a CompiledPolicySet,
) -> WellFormedAsserts<'a> {
    WellFormedAsserts {
        asserts: verify_equivalent_opt(&policies1.policies, &policies2.policies),
        policies: nonempty![
            CompiledPolicies::PolicySet(&policies1.policies),
            CompiledPolicies::PolicySet(&policies2.policies)
        ],
    }
}

/// Generate the [`WellFormedAsserts`] for the `check_disjoint()`
/// operation, without actually calling a solver.
///
/// That is, the result of
/// ```no_compile
/// compiler.check_unsat(disjoint_asserts(policies1, policies2))
/// ```
/// should be the same as `compiler.check_disjoint(policies1, policies2)`.
///
/// Likewise, the result of
/// ```no_compile
/// compiler.check_sat(disjoint_asserts(policies1, policies2))
/// ```
/// should be the same as `compiler.check_disjoint_opt(policies1, policies2)`.
///
/// NOTE: This API is an experimental feature, and the API may change
/// or break in the future.
pub fn disjoint_asserts<'a>(
    policies1: &'a CompiledPolicySet,
    policies2: &'a CompiledPolicySet,
) -> WellFormedAsserts<'a> {
    WellFormedAsserts {
        asserts: verify_disjoint_opt(&policies1.policies, &policies2.policies),
        policies: nonempty![
            CompiledPolicies::PolicySet(&policies1.policies),
            CompiledPolicies::PolicySet(&policies2.policies)
        ],
    }
}