Skip to content

Commit e9e4cc5

Browse files
authored
Allow precompilation to happen on meta-schemas (#537)
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
1 parent a02a187 commit e9e4cc5

5 files changed

Lines changed: 16 additions & 23 deletions

File tree

src/compiler/compile.cc

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -225,13 +225,6 @@ auto compile(const sourcemeta::core::JSON &schema,
225225
.precompile_static_references_maximum_schemas),
226226
sorted_precompile_references.end());
227227
}
228-
229-
// We do not apply this pre-compilation optimisation on meta-schemas
230-
if (sourcemeta::core::schema_official_resolver(base).has_value() ||
231-
(uses_dynamic_scopes && schema.is_object() &&
232-
schema.defines("$vocabulary"))) {
233-
sorted_precompile_references.clear();
234-
}
235228
}
236229

237230
assert(sorted_precompile_references.size() <=

src/compiler/include/sourcemeta/blaze/compiler.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,19 +85,19 @@ enum class Mode : std::uint8_t {
8585
/// Advanced knobs that you can tweak for higher control and optimisations
8686
struct Tweaks {
8787
/// Attempt to precompile static references to speed up compilation
88-
const bool precompile_static_references{true};
88+
bool precompile_static_references{true};
8989
/// Consider static references that are not circular when precompiling static
9090
/// references
91-
const bool precompile_static_references_non_circular{false};
91+
bool precompile_static_references_non_circular{false};
9292
/// The maximum amount of static references to precompile
93-
const std::size_t precompile_static_references_maximum_schemas{10};
93+
std::size_t precompile_static_references_maximum_schemas{10};
9494
/// The minimum amount of references to a destination before considering it
9595
/// for precompilation
96-
const std::size_t precompile_static_references_minimum_reference_count{10};
96+
std::size_t precompile_static_references_minimum_reference_count{10};
9797
/// Always unroll `properties` in a logical AND operation
98-
const bool properties_always_unroll{false};
98+
bool properties_always_unroll{false};
9999
/// Attempt to re-order `properties` subschemas to evaluate cheaper ones first
100-
const bool properties_reorder{true};
100+
bool properties_reorder{true};
101101
};
102102

103103
/// @ingroup compiler

test/evaluator/evaluator_draft4_test.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ TEST(Evaluator_draft4, metaschema_1) {
1414
EXPECT_TRUE(metaschema.has_value());
1515

1616
const sourcemeta::core::JSON instance{sourcemeta::core::parse_json("{}")};
17-
EVALUATE_WITH_TRACE_FAST_SUCCESS(metaschema.value(), instance, 3);
17+
EVALUATE_WITH_TRACE_FAST_SUCCESS(metaschema.value(), instance, 4);
1818
}
1919

2020
TEST(Evaluator_draft4, metaschema_2) {
@@ -31,22 +31,22 @@ TEST(Evaluator_draft4, metaschema_2) {
3131
}
3232
})JSON")};
3333

34-
EVALUATE_WITH_TRACE_FAST_SUCCESS(metaschema.value(), instance, 16);
34+
EVALUATE_WITH_TRACE_FAST_SUCCESS(metaschema.value(), instance, 17);
3535
}
3636

3737
TEST(Evaluator_draft4, metaschema_hyper_self) {
3838
const auto metaschema{sourcemeta::core::schema_official_resolver(
3939
"http://json-schema.org/draft-04/hyper-schema#")};
4040
EXPECT_TRUE(metaschema.has_value());
41-
EVALUATE_WITH_TRACE_FAST_SUCCESS(metaschema.value(), metaschema.value(), 741);
41+
EVALUATE_WITH_TRACE_FAST_SUCCESS(metaschema.value(), metaschema.value(), 787);
4242
}
4343

4444
TEST(Evaluator_draft4, metaschema_hyper_self_exhaustive) {
4545
const auto metaschema{sourcemeta::core::schema_official_resolver(
4646
"http://json-schema.org/draft-04/hyper-schema#")};
4747
EXPECT_TRUE(metaschema.has_value());
4848
EVALUATE_WITH_TRACE_EXHAUSTIVE_SUCCESS(metaschema.value(), metaschema.value(),
49-
957);
49+
959);
5050
}
5151

5252
TEST(Evaluator_draft4, unknown_keyword) {

test/evaluator/evaluator_draft6_test.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,22 @@ TEST(Evaluator_draft6, metaschema) {
1414
EXPECT_TRUE(metaschema.has_value());
1515

1616
const sourcemeta::core::JSON instance{sourcemeta::core::parse_json("{}")};
17-
EVALUATE_WITH_TRACE_FAST_SUCCESS(metaschema.value(), instance, 2);
17+
EVALUATE_WITH_TRACE_FAST_SUCCESS(metaschema.value(), instance, 3);
1818
}
1919

2020
TEST(Evaluator_draft6, metaschema_hyper_self) {
2121
const auto metaschema{sourcemeta::core::schema_official_resolver(
2222
"http://json-schema.org/draft-06/hyper-schema#")};
2323
EXPECT_TRUE(metaschema.has_value());
24-
EVALUATE_WITH_TRACE_FAST_SUCCESS(metaschema.value(), metaschema.value(), 842);
24+
EVALUATE_WITH_TRACE_FAST_SUCCESS(metaschema.value(), metaschema.value(), 894);
2525
}
2626

2727
TEST(Evaluator_draft6, metaschema_hyper_self_exhaustive) {
2828
const auto metaschema{sourcemeta::core::schema_official_resolver(
2929
"http://json-schema.org/draft-06/hyper-schema#")};
3030
EXPECT_TRUE(metaschema.has_value());
3131
EVALUATE_WITH_TRACE_EXHAUSTIVE_SUCCESS(metaschema.value(), metaschema.value(),
32-
1103);
32+
1105);
3333
}
3434

3535
TEST(Evaluator_draft6, unknown_keyword) {

test/evaluator/evaluator_draft7_test.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,22 @@ TEST(Evaluator_draft7, metaschema) {
1414
EXPECT_TRUE(metaschema.has_value());
1515

1616
const sourcemeta::core::JSON instance{sourcemeta::core::parse_json("{}")};
17-
EVALUATE_WITH_TRACE_FAST_SUCCESS(metaschema.value(), instance, 2);
17+
EVALUATE_WITH_TRACE_FAST_SUCCESS(metaschema.value(), instance, 3);
1818
}
1919

2020
TEST(Evaluator_draft7, metaschema_hyper_self) {
2121
const auto metaschema{sourcemeta::core::schema_official_resolver(
2222
"http://json-schema.org/draft-07/hyper-schema#")};
2323
EXPECT_TRUE(metaschema.has_value());
24-
EVALUATE_WITH_TRACE_FAST_SUCCESS(metaschema.value(), metaschema.value(), 441);
24+
EVALUATE_WITH_TRACE_FAST_SUCCESS(metaschema.value(), metaschema.value(), 476);
2525
}
2626

2727
TEST(Evaluator_draft7, metaschema_hyper_self_exhaustive) {
2828
const auto metaschema{sourcemeta::core::schema_official_resolver(
2929
"http://json-schema.org/draft-07/hyper-schema#")};
3030
EXPECT_TRUE(metaschema.has_value());
3131
EVALUATE_WITH_TRACE_EXHAUSTIVE_SUCCESS(metaschema.value(), metaschema.value(),
32-
566);
32+
568);
3333
}
3434

3535
TEST(Evaluator_draft7, if_1) {

0 commit comments

Comments
 (0)