schemurai 3.0.2 → 3.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +22 -3
- data/ext/schemurai_native/Cargo.lock +14 -3
- data/ext/schemurai_native/Cargo.toml +4 -3
- data/ext/schemurai_native/build.rs +7 -6
- data/ext/schemurai_native/extconf.rb +4 -0
- data/ext/schemurai_native/glue.c +33 -10
- data/ext/schemurai_native/protocol.def +52 -0
- data/ext/schemurai_native/protocol.h +2 -0
- data/ext/schemurai_native/src/container.rs +6 -6
- data/ext/schemurai_native/src/content.rs +63 -31
- data/ext/schemurai_native/src/diagnostics.rs +75 -116
- data/ext/schemurai_native/src/lib.rs +56 -54
- data/ext/schemurai_native/src/memo.rs +68 -28
- data/ext/schemurai_native/src/memo_scope.rs +30 -0
- data/ext/schemurai_native/src/number/arbitrary.rs +57 -1
- data/ext/schemurai_native/src/number.rs +10 -10
- data/ext/schemurai_native/src/pointer.rs +19 -6
- data/ext/schemurai_native/src/runtime.rs +27 -0
- data/ext/schemurai_native/src/scope.rs +52 -5
- data/lib/schemurai/evaluation_limits.rb +65 -0
- data/lib/schemurai/limited_evaluator.rb +2 -59
- data/lib/schemurai/version.rb +1 -1
- data/lib/schemurai/vm/limited_evaluator.rb +2 -57
- metadata +3 -2
|
@@ -713,6 +713,75 @@ impl Execution<'_> {
|
|
|
713
713
|
if !self.budget.checkpoint() {
|
|
714
714
|
return Err(Unsupported);
|
|
715
715
|
}
|
|
716
|
+
// Container entry policy is shared; child traversal stays specific
|
|
717
|
+
// to each container's paths, assertions and annotation coverage.
|
|
718
|
+
let container = match op {
|
|
719
|
+
Op::Array(required, rules) => {
|
|
720
|
+
Some((*required, &rules.header, rules.header_only(), TYPE_ARRAY))
|
|
721
|
+
}
|
|
722
|
+
Op::Object(required, rules) => {
|
|
723
|
+
Some((*required, &rules.header, rules.header_only(), TYPE_OBJECT))
|
|
724
|
+
}
|
|
725
|
+
_ => None,
|
|
726
|
+
};
|
|
727
|
+
if let Some((required, header, header_only, expected_kind)) = container {
|
|
728
|
+
if self.caches.report_continuations_allowed()
|
|
729
|
+
&& !header_only
|
|
730
|
+
&& (kind == TYPE_UNSUPPORTED
|
|
731
|
+
|| self.caches.dynamic_calls()
|
|
732
|
+
|| prior.has_runtime_properties())
|
|
733
|
+
{
|
|
734
|
+
let result = self.caches.container_report(
|
|
735
|
+
node,
|
|
736
|
+
value,
|
|
737
|
+
(source.1, required, expected_kind == TYPE_OBJECT),
|
|
738
|
+
report,
|
|
739
|
+
&prior,
|
|
740
|
+
tracked,
|
|
741
|
+
)?;
|
|
742
|
+
if tracked {
|
|
743
|
+
prior.merge_diagnostics(self, result)?;
|
|
744
|
+
}
|
|
745
|
+
if report.silent && report.failed {
|
|
746
|
+
break;
|
|
747
|
+
}
|
|
748
|
+
continue;
|
|
749
|
+
}
|
|
750
|
+
if header_only && header.runtime_required(self.caches, kind) {
|
|
751
|
+
if report.collect_header(self.caches, header, required, value, source)? {
|
|
752
|
+
break;
|
|
753
|
+
}
|
|
754
|
+
continue;
|
|
755
|
+
}
|
|
756
|
+
if kind == expected_kind && !self.budget.checkpoint() {
|
|
757
|
+
return Err(Unsupported);
|
|
758
|
+
}
|
|
759
|
+
if required != 0 && kind != expected_kind {
|
|
760
|
+
report.add(self.caches, "type", source, value, 0)?;
|
|
761
|
+
}
|
|
762
|
+
if kind != expected_kind {
|
|
763
|
+
continue;
|
|
764
|
+
}
|
|
765
|
+
if report.silent {
|
|
766
|
+
let status = match op {
|
|
767
|
+
Op::Array(_, rules) => {
|
|
768
|
+
self.array_tracked(rules, value, depth + 1, active, &mut prior)
|
|
769
|
+
}
|
|
770
|
+
Op::Object(_, rules) => {
|
|
771
|
+
self.object_tracked(rules, value, depth + 1, active, &mut prior)
|
|
772
|
+
}
|
|
773
|
+
_ => unreachable!("container entry"),
|
|
774
|
+
};
|
|
775
|
+
if status == Unsupported {
|
|
776
|
+
return Err(Unsupported);
|
|
777
|
+
}
|
|
778
|
+
report.failed |= status == Invalid;
|
|
779
|
+
if report.failed {
|
|
780
|
+
break;
|
|
781
|
+
}
|
|
782
|
+
continue;
|
|
783
|
+
}
|
|
784
|
+
}
|
|
716
785
|
match op {
|
|
717
786
|
Op::Unsupported => return Err(Unsupported),
|
|
718
787
|
Op::UnresolvedRef(message) => {
|
|
@@ -842,62 +911,7 @@ impl Execution<'_> {
|
|
|
842
911
|
}
|
|
843
912
|
}
|
|
844
913
|
}
|
|
845
|
-
Op::Array(
|
|
846
|
-
if self.caches.report_continuations_allowed()
|
|
847
|
-
&& !rules.header_only()
|
|
848
|
-
&& (kind == TYPE_UNSUPPORTED
|
|
849
|
-
|| self.caches.dynamic_calls()
|
|
850
|
-
|| prior.has_runtime_properties())
|
|
851
|
-
{
|
|
852
|
-
let result = self.caches.container_report(
|
|
853
|
-
node,
|
|
854
|
-
value,
|
|
855
|
-
(source.1, *required, false),
|
|
856
|
-
report,
|
|
857
|
-
&prior,
|
|
858
|
-
tracked,
|
|
859
|
-
)?;
|
|
860
|
-
if tracked {
|
|
861
|
-
prior.merge_diagnostics(self, result)?;
|
|
862
|
-
}
|
|
863
|
-
if report.silent && report.failed {
|
|
864
|
-
break;
|
|
865
|
-
}
|
|
866
|
-
continue;
|
|
867
|
-
}
|
|
868
|
-
if rules.header_only() && rules.header.runtime_required(self.caches, kind) {
|
|
869
|
-
if report.collect_header(
|
|
870
|
-
self.caches,
|
|
871
|
-
&rules.header,
|
|
872
|
-
*required,
|
|
873
|
-
value,
|
|
874
|
-
source,
|
|
875
|
-
)? {
|
|
876
|
-
break;
|
|
877
|
-
}
|
|
878
|
-
continue;
|
|
879
|
-
}
|
|
880
|
-
if kind == TYPE_ARRAY && !self.budget.checkpoint() {
|
|
881
|
-
return Err(Unsupported);
|
|
882
|
-
}
|
|
883
|
-
if *required != 0 && kind != TYPE_ARRAY {
|
|
884
|
-
report.add(self.caches, "type", source, value, 0)?;
|
|
885
|
-
}
|
|
886
|
-
if kind != TYPE_ARRAY {
|
|
887
|
-
continue;
|
|
888
|
-
}
|
|
889
|
-
if report.silent {
|
|
890
|
-
let status =
|
|
891
|
-
self.array_tracked(rules, value, depth + 1, active, &mut prior);
|
|
892
|
-
if status == Unsupported {
|
|
893
|
-
return Err(Unsupported);
|
|
894
|
-
}
|
|
895
|
-
report.failed |= status == Invalid;
|
|
896
|
-
if report.failed {
|
|
897
|
-
break;
|
|
898
|
-
}
|
|
899
|
-
continue;
|
|
900
|
-
}
|
|
914
|
+
Op::Array(_, rules) => {
|
|
901
915
|
let mut coverage = Tracked::new(Valid);
|
|
902
916
|
let len = unsafe { sn_len(value) };
|
|
903
917
|
if rules.max.is_some_and(|max| len > max) {
|
|
@@ -1168,62 +1182,7 @@ impl Execution<'_> {
|
|
|
1168
1182
|
prior.merge_diagnostics(self, coverage)?;
|
|
1169
1183
|
}
|
|
1170
1184
|
}
|
|
1171
|
-
Op::Object(
|
|
1172
|
-
if self.caches.report_continuations_allowed()
|
|
1173
|
-
&& !rules.header_only()
|
|
1174
|
-
&& (kind == TYPE_UNSUPPORTED
|
|
1175
|
-
|| self.caches.dynamic_calls()
|
|
1176
|
-
|| prior.has_runtime_properties())
|
|
1177
|
-
{
|
|
1178
|
-
let result = self.caches.container_report(
|
|
1179
|
-
node,
|
|
1180
|
-
value,
|
|
1181
|
-
(source.1, *required, true),
|
|
1182
|
-
report,
|
|
1183
|
-
&prior,
|
|
1184
|
-
tracked,
|
|
1185
|
-
)?;
|
|
1186
|
-
if tracked {
|
|
1187
|
-
prior.merge_diagnostics(self, result)?;
|
|
1188
|
-
}
|
|
1189
|
-
if report.silent && report.failed {
|
|
1190
|
-
break;
|
|
1191
|
-
}
|
|
1192
|
-
continue;
|
|
1193
|
-
}
|
|
1194
|
-
if rules.header_only() && rules.header.runtime_required(self.caches, kind) {
|
|
1195
|
-
if report.collect_header(
|
|
1196
|
-
self.caches,
|
|
1197
|
-
&rules.header,
|
|
1198
|
-
*required,
|
|
1199
|
-
value,
|
|
1200
|
-
source,
|
|
1201
|
-
)? {
|
|
1202
|
-
break;
|
|
1203
|
-
}
|
|
1204
|
-
continue;
|
|
1205
|
-
}
|
|
1206
|
-
if kind == TYPE_OBJECT && !self.budget.checkpoint() {
|
|
1207
|
-
return Err(Unsupported);
|
|
1208
|
-
}
|
|
1209
|
-
if *required != 0 && kind != TYPE_OBJECT {
|
|
1210
|
-
report.add(self.caches, "type", source, value, 0)?;
|
|
1211
|
-
}
|
|
1212
|
-
if kind != TYPE_OBJECT {
|
|
1213
|
-
continue;
|
|
1214
|
-
}
|
|
1215
|
-
if report.silent {
|
|
1216
|
-
let status =
|
|
1217
|
-
self.object_tracked(rules, value, depth + 1, active, &mut prior);
|
|
1218
|
-
if status == Unsupported {
|
|
1219
|
-
return Err(Unsupported);
|
|
1220
|
-
}
|
|
1221
|
-
report.failed |= status == Invalid;
|
|
1222
|
-
if report.failed {
|
|
1223
|
-
break;
|
|
1224
|
-
}
|
|
1225
|
-
continue;
|
|
1226
|
-
}
|
|
1185
|
+
Op::Object(_, rules) => {
|
|
1227
1186
|
let mut coverage = Tracked::new(Valid);
|
|
1228
1187
|
let len = unsafe { sn_len(value) };
|
|
1229
1188
|
if rules.max.is_some_and(|max| len > max) {
|
|
@@ -1721,8 +1680,8 @@ pub unsafe extern "C" fn sn_diagnose(
|
|
|
1721
1680
|
) -> *mut Report {
|
|
1722
1681
|
let result = catch_unwind(AssertUnwindSafe(|| {
|
|
1723
1682
|
let engine = unsafe { &*engine };
|
|
1724
|
-
let local =
|
|
1725
|
-
let caches = unsafe { caches.as_ref() }
|
|
1683
|
+
let mut local = None;
|
|
1684
|
+
let caches = runtime::Caches::supplied_or_default(unsafe { caches.as_ref() }, &mut local);
|
|
1726
1685
|
let execution = Execution {
|
|
1727
1686
|
engine,
|
|
1728
1687
|
caches,
|
|
@@ -1759,8 +1718,8 @@ pub unsafe extern "C" fn sn_diagnose_with_limits(
|
|
|
1759
1718
|
outcome: *mut budget::Outcome,
|
|
1760
1719
|
) -> *mut Report {
|
|
1761
1720
|
let result = catch_unwind(AssertUnwindSafe(|| {
|
|
1762
|
-
let local =
|
|
1763
|
-
let caches = unsafe { caches.as_ref() }
|
|
1721
|
+
let mut local = None;
|
|
1722
|
+
let caches = runtime::Caches::supplied_or_default(unsafe { caches.as_ref() }, &mut local);
|
|
1764
1723
|
let limits = unsafe { *limits };
|
|
1765
1724
|
let execution = Execution {
|
|
1766
1725
|
engine: unsafe { &*engine },
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
//! Ruby runs with the GVL held. Evaluation calls only non-allocating C adapters;
|
|
3
3
|
//! Ruby callbacks during compilation are protected on the C side.
|
|
4
4
|
use std::collections::HashMap;
|
|
5
|
-
use std::ffi::
|
|
5
|
+
use std::ffi::c_void;
|
|
6
6
|
use std::hash::{BuildHasherDefault, Hasher};
|
|
7
7
|
use std::panic::{AssertUnwindSafe, catch_unwind};
|
|
8
8
|
mod budget;
|
|
@@ -108,7 +108,7 @@ unsafe extern "C" {
|
|
|
108
108
|
context: *mut c_void,
|
|
109
109
|
callback: unsafe extern "C" fn(*mut c_void, *const u8, usize, Value) -> i32,
|
|
110
110
|
) -> i32;
|
|
111
|
-
fn sn_field(object: Value, name:
|
|
111
|
+
fn sn_field(object: Value, name: i32, value: *mut Value) -> i32;
|
|
112
112
|
fn sn_pairs(hash: Value, value: *mut Value) -> i32;
|
|
113
113
|
fn sn_key_copy(key: Value, value: *mut Value) -> i32;
|
|
114
114
|
fn sn_opcode(symbol: Value) -> i32;
|
|
@@ -733,9 +733,9 @@ impl Engine {
|
|
|
733
733
|
unsafe { &mut *self.roots }.values.push(value);
|
|
734
734
|
value
|
|
735
735
|
}
|
|
736
|
-
fn field(&mut self, value: Value, name:
|
|
736
|
+
fn field(&mut self, value: Value, name: i32) -> Result<Value, Value> {
|
|
737
737
|
let mut result = 0;
|
|
738
|
-
if unsafe { sn_field(value, name
|
|
738
|
+
if unsafe { sn_field(value, name, &mut result) } != 0 {
|
|
739
739
|
return Err(result);
|
|
740
740
|
}
|
|
741
741
|
Ok(self.retain(result))
|
|
@@ -786,7 +786,7 @@ impl Engine {
|
|
|
786
786
|
.map(|p| (p[0], p[1]))
|
|
787
787
|
.collect())
|
|
788
788
|
}
|
|
789
|
-
fn size_field(&mut self, value: Value, name:
|
|
789
|
+
fn size_field(&mut self, value: Value, name: i32) -> Result<Option<usize>, Value> {
|
|
790
790
|
let n = self.field(value, name)?;
|
|
791
791
|
Ok(if unsafe { sn_same(n, sn_nil()) } != 0 {
|
|
792
792
|
None
|
|
@@ -802,7 +802,7 @@ impl Engine {
|
|
|
802
802
|
None // The only non-integral bound is maxContains' +Infinity.
|
|
803
803
|
})
|
|
804
804
|
}
|
|
805
|
-
fn child(&mut self, value: Value, name:
|
|
805
|
+
fn child(&mut self, value: Value, name: i32) -> Result<Option<usize>, Value> {
|
|
806
806
|
let child = self.field(value, name)?;
|
|
807
807
|
if unsafe { sn_same(child, sn_nil()) } != 0 {
|
|
808
808
|
Ok(None)
|
|
@@ -886,7 +886,7 @@ impl Engine {
|
|
|
886
886
|
self.tracks.push(false);
|
|
887
887
|
self.kind_demand.push(KindDemand::None);
|
|
888
888
|
self.metadata.push(scope::Metadata::default());
|
|
889
|
-
let code = self.field(program,
|
|
889
|
+
let code = self.field(program, FIELD_CODE)?;
|
|
890
890
|
let flags = unsafe { sn_integer(sn_entry(code, 0)) };
|
|
891
891
|
self.tracks[index] = flags & i64::from(TRACKS_EVALUATION) != 0;
|
|
892
892
|
self.compile_scope(program, index, flags)?;
|
|
@@ -906,7 +906,7 @@ impl Engine {
|
|
|
906
906
|
OP_TYPE_INTEGER => Op::Type(TYPE_INTEGER, false),
|
|
907
907
|
OP_TYPE_STRING => Op::Type(TYPE_STRING, false),
|
|
908
908
|
OP_TYPES => {
|
|
909
|
-
let mask = self.field(operand,
|
|
909
|
+
let mask = self.field(operand, FIELD_MASK)?;
|
|
910
910
|
Op::Type(unsafe { sn_integer(mask) } as i32, true)
|
|
911
911
|
}
|
|
912
912
|
OP_CONST => Op::Const(operand),
|
|
@@ -920,11 +920,11 @@ impl Engine {
|
|
|
920
920
|
OP_ONE_OF => Op::One(self.branches(operand)?),
|
|
921
921
|
OP_NOT => Op::Not(self.compile(operand)?),
|
|
922
922
|
OP_CONDITIONAL => {
|
|
923
|
-
let condition = self.field(operand,
|
|
923
|
+
let condition = self.field(operand, FIELD_CONDITION)?;
|
|
924
924
|
Op::Conditional(
|
|
925
925
|
self.compile(condition)?,
|
|
926
|
-
self.child(operand,
|
|
927
|
-
self.child(operand,
|
|
926
|
+
self.child(operand, FIELD_THEN_BRANCH)?,
|
|
927
|
+
self.child(operand, FIELD_ELSE_BRANCH)?,
|
|
928
928
|
)
|
|
929
929
|
}
|
|
930
930
|
OP_NUMBER | OP_TYPED_NUMBER | OP_TYPED_INTEGER => {
|
|
@@ -944,10 +944,10 @@ impl Engine {
|
|
|
944
944
|
}
|
|
945
945
|
}
|
|
946
946
|
OP_STRING | OP_TYPED_STRING => {
|
|
947
|
-
let pattern = self.field(operand,
|
|
948
|
-
let format = self.field(operand,
|
|
949
|
-
let base64 = self.field(operand,
|
|
950
|
-
let json = self.field(operand,
|
|
947
|
+
let pattern = self.field(operand, FIELD_PATTERN)?;
|
|
948
|
+
let format = self.field(operand, FIELD_FORMAT)?;
|
|
949
|
+
let base64 = self.field(operand, FIELD_DECODE_BASE64)?;
|
|
950
|
+
let json = self.field(operand, FIELD_PARSE_JSON)?;
|
|
951
951
|
{
|
|
952
952
|
let content = if self.validate_content
|
|
953
953
|
&& unsafe { sn_true(base64) | sn_true(json) } != 0
|
|
@@ -959,12 +959,12 @@ impl Engine {
|
|
|
959
959
|
} else {
|
|
960
960
|
None
|
|
961
961
|
};
|
|
962
|
-
let assertion = self.field(operand,
|
|
962
|
+
let assertion = self.field(operand, FIELD_FORMAT_ASSERTION)?;
|
|
963
963
|
let runtime_format = (self.validate_format
|
|
964
964
|
|| unsafe { sn_true(assertion) } != 0)
|
|
965
965
|
&& unsafe { sn_same(format, sn_nil()) } == 0;
|
|
966
966
|
let format = if runtime_format {
|
|
967
|
-
let name = self.field(format,
|
|
967
|
+
let name = self.field(format, FIELD_NAME)?;
|
|
968
968
|
if unsafe { sn_same(name, sn_nil()) } != 0 {
|
|
969
969
|
None
|
|
970
970
|
} else {
|
|
@@ -973,8 +973,8 @@ impl Engine {
|
|
|
973
973
|
} else {
|
|
974
974
|
None
|
|
975
975
|
};
|
|
976
|
-
let max_length = self.field(operand,
|
|
977
|
-
let min_length = self.field(operand,
|
|
976
|
+
let max_length = self.field(operand, FIELD_MAX_LENGTH)?;
|
|
977
|
+
let min_length = self.field(operand, FIELD_MIN_LENGTH)?;
|
|
978
978
|
let length_flags = (unsafe { sn_truthy(max_length) } << 2)
|
|
979
979
|
| (unsafe { sn_truthy(min_length) } << 3);
|
|
980
980
|
Op::String(
|
|
@@ -991,8 +991,8 @@ impl Engine {
|
|
|
991
991
|
runtime_format,
|
|
992
992
|
format,
|
|
993
993
|
content,
|
|
994
|
-
min: self.size_field(operand,
|
|
995
|
-
max: self.size_field(operand,
|
|
994
|
+
min: self.size_field(operand, FIELD_MIN_LENGTH)?,
|
|
995
|
+
max: self.size_field(operand, FIELD_MAX_LENGTH)?,
|
|
996
996
|
pattern: if unsafe { sn_truthy(pattern) } == 0 {
|
|
997
997
|
None
|
|
998
998
|
} else {
|
|
@@ -1006,11 +1006,11 @@ impl Engine {
|
|
|
1006
1006
|
}
|
|
1007
1007
|
}
|
|
1008
1008
|
OP_ARRAY | OP_TYPED_ARRAY => {
|
|
1009
|
-
let unique = self.field(operand,
|
|
1010
|
-
let prefix = self.field(operand,
|
|
1009
|
+
let unique = self.field(operand, FIELD_UNIQUE)?;
|
|
1010
|
+
let prefix = self.field(operand, FIELD_PREFIX_ITEMS)?;
|
|
1011
1011
|
let prefix = self.children(prefix)?;
|
|
1012
|
-
let items = self.field(operand,
|
|
1013
|
-
let list = self.field(operand,
|
|
1012
|
+
let items = self.field(operand, FIELD_ITEMS)?;
|
|
1013
|
+
let list = self.field(operand, FIELD_ITEMS_LIST)?;
|
|
1014
1014
|
let list = unsafe { sn_true(list) } != 0;
|
|
1015
1015
|
let items = if list {
|
|
1016
1016
|
self.children(items)?
|
|
@@ -1028,8 +1028,8 @@ impl Engine {
|
|
|
1028
1028
|
Box::new(Array {
|
|
1029
1029
|
header: self.container_header(
|
|
1030
1030
|
operand,
|
|
1031
|
-
|
|
1032
|
-
|
|
1031
|
+
FIELD_MAX_ITEMS,
|
|
1032
|
+
FIELD_MIN_ITEMS,
|
|
1033
1033
|
false,
|
|
1034
1034
|
(if unsafe { sn_truthy(unique) } != 0 {
|
|
1035
1035
|
4
|
|
@@ -1038,25 +1038,27 @@ impl Engine {
|
|
|
1038
1038
|
}) | (if list { 8 } else { 0 }),
|
|
1039
1039
|
)?,
|
|
1040
1040
|
unique: unsafe { sn_truthy(unique) } != 0,
|
|
1041
|
-
min: self.size_field(operand,
|
|
1042
|
-
max: self.size_field(operand,
|
|
1041
|
+
min: self.size_field(operand, FIELD_MIN_ITEMS)?,
|
|
1042
|
+
max: self.size_field(operand, FIELD_MAX_ITEMS)?,
|
|
1043
1043
|
prefix,
|
|
1044
1044
|
items,
|
|
1045
1045
|
list,
|
|
1046
|
-
additional: self.child(operand,
|
|
1047
|
-
contains: self.child(operand,
|
|
1048
|
-
min_contains: self
|
|
1049
|
-
|
|
1046
|
+
additional: self.child(operand, FIELD_ADDITIONAL)?,
|
|
1047
|
+
contains: self.child(operand, FIELD_CONTAINS)?,
|
|
1048
|
+
min_contains: self
|
|
1049
|
+
.size_field(operand, FIELD_MIN_CONTAINS)?
|
|
1050
|
+
.unwrap_or(1),
|
|
1051
|
+
max_contains: self.size_field(operand, FIELD_MAX_CONTAINS)?,
|
|
1050
1052
|
count_contains: unsafe {
|
|
1051
|
-
sn_true(self.field(operand,
|
|
1053
|
+
sn_true(self.field(operand, FIELD_COUNT_CONTAINS)?)
|
|
1052
1054
|
} != 0,
|
|
1053
|
-
unevaluated: self.child(operand,
|
|
1055
|
+
unevaluated: self.child(operand, FIELD_UNEVALUATED)?,
|
|
1054
1056
|
}),
|
|
1055
1057
|
)
|
|
1056
1058
|
}
|
|
1057
1059
|
OP_OBJECT | OP_TYPED_OBJECT => {
|
|
1058
|
-
let patterns = self.field(operand,
|
|
1059
|
-
let dependencies = self.field(operand,
|
|
1060
|
+
let patterns = self.field(operand, FIELD_PATTERNS)?;
|
|
1061
|
+
let dependencies = self.field(operand, FIELD_DEPENDENCIES)?;
|
|
1060
1062
|
{
|
|
1061
1063
|
let patterns = self.compile_map(patterns)?;
|
|
1062
1064
|
let pattern_names: Vec<_> = patterns.iter().map(|&(key, _)| key).collect();
|
|
@@ -1071,7 +1073,7 @@ impl Engine {
|
|
|
1071
1073
|
.collect();
|
|
1072
1074
|
let pattern_group =
|
|
1073
1075
|
pattern::PatternGroup::compile(&pattern_names, &patterns);
|
|
1074
|
-
let required = self.field(operand,
|
|
1076
|
+
let required = self.field(operand, FIELD_REQUIRED)?;
|
|
1075
1077
|
let inspect_required = unsafe { sn_truthy(required) } != 0
|
|
1076
1078
|
&& !(unsafe { sn_kind(required) } == TYPE_ARRAY
|
|
1077
1079
|
&& unsafe { sn_len(required) } == 0);
|
|
@@ -1082,7 +1084,7 @@ impl Engine {
|
|
|
1082
1084
|
.filter(|key| key.ordinary_string)
|
|
1083
1085
|
.map(|key| key.name)
|
|
1084
1086
|
.collect();
|
|
1085
|
-
let properties = self.field(operand,
|
|
1087
|
+
let properties = self.field(operand, FIELD_PROPERTIES)?;
|
|
1086
1088
|
let properties = self.compile_map(properties)?;
|
|
1087
1089
|
if properties
|
|
1088
1090
|
.iter()
|
|
@@ -1157,7 +1159,7 @@ impl Engine {
|
|
|
1157
1159
|
}
|
|
1158
1160
|
})
|
|
1159
1161
|
.collect();
|
|
1160
|
-
let dependent = self.field(operand,
|
|
1162
|
+
let dependent = self.field(operand, FIELD_DEPENDENT_REQUIRED)?;
|
|
1161
1163
|
let mut dependent_required = vec![];
|
|
1162
1164
|
let mut dependent_schemas = vec![];
|
|
1163
1165
|
let mut diagnostic_dependencies = vec![];
|
|
@@ -1192,7 +1194,7 @@ impl Engine {
|
|
|
1192
1194
|
));
|
|
1193
1195
|
dependent_required.push((name, names));
|
|
1194
1196
|
}
|
|
1195
|
-
let dependent = self.field(operand,
|
|
1197
|
+
let dependent = self.field(operand, FIELD_DEPENDENT_SCHEMAS)?;
|
|
1196
1198
|
let schemas = self.compile_map(dependent)?;
|
|
1197
1199
|
diagnostic_dependencies.extend(schemas.iter().map(|&(name, child)| {
|
|
1198
1200
|
DiagnosticDependency::Schema(name, child, "dependentSchemas")
|
|
@@ -1211,15 +1213,15 @@ impl Engine {
|
|
|
1211
1213
|
let mut object = Object {
|
|
1212
1214
|
header: self.container_header(
|
|
1213
1215
|
operand,
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
+
FIELD_MAX_PROPERTIES,
|
|
1217
|
+
FIELD_MIN_PROPERTIES,
|
|
1216
1218
|
true,
|
|
1217
1219
|
0,
|
|
1218
1220
|
)?,
|
|
1219
1221
|
inspect_required,
|
|
1220
1222
|
record: None,
|
|
1221
|
-
min: self.size_field(operand,
|
|
1222
|
-
max: self.size_field(operand,
|
|
1223
|
+
min: self.size_field(operand, FIELD_MIN_PROPERTIES)?,
|
|
1224
|
+
max: self.size_field(operand, FIELD_MAX_PROPERTIES)?,
|
|
1223
1225
|
required,
|
|
1224
1226
|
required_order,
|
|
1225
1227
|
properties,
|
|
@@ -1231,12 +1233,12 @@ impl Engine {
|
|
|
1231
1233
|
required_property_indices,
|
|
1232
1234
|
property_keys,
|
|
1233
1235
|
property_indices,
|
|
1234
|
-
additional: self.child(operand,
|
|
1235
|
-
names: self.child(operand,
|
|
1236
|
+
additional: self.child(operand, FIELD_ADDITIONAL)?,
|
|
1237
|
+
names: self.child(operand, FIELD_PROPERTY_NAMES)?,
|
|
1236
1238
|
dependent_required,
|
|
1237
1239
|
dependent_schemas,
|
|
1238
1240
|
diagnostic_dependencies,
|
|
1239
|
-
unevaluated: self.child(operand,
|
|
1241
|
+
unevaluated: self.child(operand, FIELD_UNEVALUATED)?,
|
|
1240
1242
|
}
|
|
1241
1243
|
.with_record();
|
|
1242
1244
|
if let Some(record) = &mut object.record {
|
|
@@ -1289,11 +1291,11 @@ impl Engine {
|
|
|
1289
1291
|
}
|
|
1290
1292
|
}
|
|
1291
1293
|
OP_REF | OP_RECURSIVE_REF | OP_DYNAMIC_REF => {
|
|
1292
|
-
let reference = self.field(operand,
|
|
1294
|
+
let reference = self.field(operand, FIELD_VALUE)?;
|
|
1293
1295
|
let mut target = 0;
|
|
1294
1296
|
if unsafe { sn_resolve(self.compiler, program, reference, &mut target) } != 0 {
|
|
1295
1297
|
if unsafe { sn_resolution_error(target) } != 0 {
|
|
1296
|
-
let message = self.field(target,
|
|
1298
|
+
let message = self.field(target, FIELD_MESSAGE)?;
|
|
1297
1299
|
Op::UnresolvedRef(message)
|
|
1298
1300
|
} else {
|
|
1299
1301
|
return Err(target);
|
|
@@ -3586,8 +3588,8 @@ pub unsafe extern "C" fn sn_valid(
|
|
|
3586
3588
|
) -> i32 {
|
|
3587
3589
|
catch_unwind(AssertUnwindSafe(|| {
|
|
3588
3590
|
let e = unsafe { &*engine };
|
|
3589
|
-
let local =
|
|
3590
|
-
let caches = unsafe { caches.as_ref() }
|
|
3591
|
+
let mut local = None;
|
|
3592
|
+
let caches = runtime::Caches::supplied_or_default(unsafe { caches.as_ref() }, &mut local);
|
|
3591
3593
|
caches.admit(e, root);
|
|
3592
3594
|
let execution = Execution {
|
|
3593
3595
|
engine: e,
|
|
@@ -3614,8 +3616,8 @@ pub unsafe extern "C" fn sn_valid_with_limits(
|
|
|
3614
3616
|
outcome: *mut budget::Outcome,
|
|
3615
3617
|
) -> i32 {
|
|
3616
3618
|
let result = catch_unwind(AssertUnwindSafe(|| {
|
|
3617
|
-
let local =
|
|
3618
|
-
let caches = unsafe { caches.as_ref() }
|
|
3619
|
+
let mut local = None;
|
|
3620
|
+
let caches = runtime::Caches::supplied_or_default(unsafe { caches.as_ref() }, &mut local);
|
|
3619
3621
|
let e = unsafe { &*engine };
|
|
3620
3622
|
caches.admit(e, root);
|
|
3621
3623
|
let execution = Execution {
|