Skip to content

Commit

Permalink
Report ControlMark during evaluation (#21)
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Cruz Viotti <[email protected]>
  • Loading branch information
jviotti authored Oct 17, 2024
1 parent e150395 commit 012b106
Show file tree
Hide file tree
Showing 4 changed files with 225 additions and 137 deletions.
2 changes: 1 addition & 1 deletion src/compiler/compile_describe.cc
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ struct DescribeVisitor {
}

auto operator()(const ControlMark &) const -> std::string {
return describe_reference(this->target);
return "The schema location was marked for future use";
}

auto operator()(const ControlEvaluate &) const -> std::string {
Expand Down
28 changes: 24 additions & 4 deletions src/evaluator/evaluator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,16 @@ auto evaluate_step(const sourcemeta::blaze::Template::value_type &step,
} \
bool result{false};

#define EVALUATE_BEGIN_NO_PRECONDITION_AND_NO_PUSH(step_category, step_type) \
SOURCEMETA_TRACE_END(trace_dispatch_id, "Dispatch"); \
SOURCEMETA_TRACE_START(trace_id, STRINGIFY(step_type)); \
const auto &step_category{std::get<step_type>(step)}; \
if (step_category.report && callback.has_value()) { \
callback.value()(EvaluationType::Pre, true, step, context.evaluate_path(), \
context.instance_location(), context.null); \
} \
bool result{true};

#define EVALUATE_END(step_category, step_type) \
if (step_category.report && callback.has_value()) { \
callback.value()(EvaluationType::Post, result, step, \
Expand All @@ -130,6 +140,15 @@ auto evaluate_step(const sourcemeta::blaze::Template::value_type &step,
SOURCEMETA_TRACE_END(trace_id, STRINGIFY(step_type)); \
return result;

#define EVALUATE_END_NO_POP(step_category, step_type) \
if (step_category.report && callback.has_value()) { \
callback.value()(EvaluationType::Post, result, step, \
context.evaluate_path(), context.instance_location(), \
context.null); \
} \
SOURCEMETA_TRACE_END(trace_id, STRINGIFY(step_type)); \
return result;

// As a safety guard, only emit the annotation if it didn't exist already.
// Otherwise we risk confusing consumers

Expand Down Expand Up @@ -621,14 +640,13 @@ auto evaluate_step(const sourcemeta::blaze::Template::value_type &step,
}

case IS_STEP(ControlMark): {
SOURCEMETA_TRACE_START(trace_id, "ControlMark");
const auto &control{std::get<ControlMark>(step)};
EVALUATE_BEGIN_NO_PRECONDITION_AND_NO_PUSH(control, ControlMark);
context.mark(control.value, control.children);
SOURCEMETA_TRACE_END(trace_id, "ControlMark");
return true;
EVALUATE_END_NO_POP(control, ControlMark);
}

case IS_STEP(ControlEvaluate): {
SOURCEMETA_TRACE_END(trace_dispatch_id, "Dispatch");
SOURCEMETA_TRACE_START(trace_id, "ControlEvaluate");
const auto &control{std::get<ControlEvaluate>(step)};
context.evaluate(control.value);
Expand Down Expand Up @@ -1026,7 +1044,9 @@ auto evaluate_step(const sourcemeta::blaze::Template::value_type &step,
#undef EVALUATE_BEGIN_NO_TARGET
#undef EVALUATE_BEGIN_TRY_TARGET
#undef EVALUATE_BEGIN_NO_PRECONDITION
#undef EVALUATE_BEGIN_NO_PRECONDITION_AND_NO_PUSH
#undef EVALUATE_END
#undef EVALUATE_END_NO_POP
#undef EVALUATE_ANNOTATION
#undef EVALUATE_ANNOTATION_NO_PRECONDITION

Expand Down
Loading

5 comments on commit 012b106

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark (macos/llvm)

Benchmark suite Current: 012b106 Previous: e150395 Ratio
Compiler_Draft6_AdaptiveCard 3063184999.9999757 ns/iter 2797583374.999931 ns/iter 1.09
Evaluator_Draft4_Meta_1_No_Callback 740.2954219862007 ns/iter 739.9160002437139 ns/iter 1.00
Evaluator_Draft4_Required_Properties 925.9385475522297 ns/iter 950.5409377316741 ns/iter 0.97
Evaluator_Draft4_Many_Optional_Properties_Minimal_Match 155.46500055327053 ns/iter 155.0020715936181 ns/iter 1.00
Evaluator_Draft4_Few_Optional_Properties_Minimal_Match 107.7466426231151 ns/iter 101.67821729673167 ns/iter 1.06
Evaluator_Draft4_Items_Schema 2734.9825857317087 ns/iter 2626.6809721467516 ns/iter 1.04
Evaluator_Draft4_Nested_Object 22.431563943196686 ns/iter 21.498736260770173 ns/iter 1.04
Evaluator_Draft4_Properties_Triad_Optional 1312.6204262056372 ns/iter 1262.0675916063283 ns/iter 1.04
Evaluator_Draft4_Properties_Triad_Closed 1001.9050848562284 ns/iter 957.4814075083616 ns/iter 1.05
Evaluator_Draft4_Properties_Triad_Required 1342.8019870719356 ns/iter 1289.8074813572575 ns/iter 1.04
Evaluator_Draft4_Non_Recursive_Ref 215.6203470884329 ns/iter 211.0406381823207 ns/iter 1.02
Evaluator_Draft4_Pattern_Properties_True 1352.5478739080866 ns/iter 1333.6844586762984 ns/iter 1.01
Evaluator_Draft4_Ref_To_Single_Property 104.41017136727727 ns/iter 104.83666651744358 ns/iter 1.00
Evaluator_Draft4_Additional_Properties_Type 405.2340133925259 ns/iter 404.56023777660107 ns/iter 1.00
Evaluator_Draft4_Nested_Oneof 376.6261606741372 ns/iter 365.88129633033884 ns/iter 1.03
Evaluator_Draft6_Property_Names 772.4640717464985 ns/iter 759.1624615344009 ns/iter 1.02
Evaluator_Draft7_If_Then_Else 167.49189828860284 ns/iter 165.93666979724202 ns/iter 1.01
Evaluator_2019_09_Unevaluated_Properties 626.549382461172 ns/iter 631.670020792663 ns/iter 0.99
Evaluator_2020_12_Dynamic_Ref 1404.7558526691007 ns/iter 1395.5049559438398 ns/iter 1.01

This comment was automatically generated by workflow using github-action-benchmark.

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark (linux/llvm)

Benchmark suite Current: 012b106 Previous: e150395 Ratio
Compiler_Draft6_AdaptiveCard 5323986226.000045 ns/iter 5254180197.000039 ns/iter 1.01
Evaluator_Draft4_Meta_1_No_Callback 971.4845561079401 ns/iter 976.1014188065781 ns/iter 1.00
Evaluator_Draft4_Required_Properties 1579.7818899552367 ns/iter 1623.2832061085678 ns/iter 0.97
Evaluator_Draft4_Many_Optional_Properties_Minimal_Match 182.39994249150078 ns/iter 180.9178308527149 ns/iter 1.01
Evaluator_Draft4_Few_Optional_Properties_Minimal_Match 128.6042121212366 ns/iter 127.93555269921643 ns/iter 1.01
Evaluator_Draft4_Items_Schema 3542.6553320772223 ns/iter 3456.432265111202 ns/iter 1.02
Evaluator_Draft4_Nested_Object 29.126339756112678 ns/iter 28.471068147142578 ns/iter 1.02
Evaluator_Draft4_Properties_Triad_Optional 1794.8141747305197 ns/iter 1760.7334752583683 ns/iter 1.02
Evaluator_Draft4_Properties_Triad_Closed 1492.9644251859966 ns/iter 1470.9895736058181 ns/iter 1.01
Evaluator_Draft4_Properties_Triad_Required 1867.982890850692 ns/iter 1846.0975707651314 ns/iter 1.01
Evaluator_Draft4_Non_Recursive_Ref 476.2840263631875 ns/iter 474.03149485191074 ns/iter 1.00
Evaluator_Draft4_Pattern_Properties_True 2464.1954229862336 ns/iter 2468.4193180127168 ns/iter 1.00
Evaluator_Draft4_Ref_To_Single_Property 130.7826949982183 ns/iter 132.31357958256896 ns/iter 0.99
Evaluator_Draft4_Additional_Properties_Type 588.6369346416967 ns/iter 592.7102308864778 ns/iter 0.99
Evaluator_Draft4_Nested_Oneof 466.9342918122981 ns/iter 456.55738632136405 ns/iter 1.02
Evaluator_Draft6_Property_Names 1227.9339994786692 ns/iter 1270.5081702689877 ns/iter 0.97
Evaluator_Draft7_If_Then_Else 205.76822562816238 ns/iter 201.92798042247443 ns/iter 1.02
Evaluator_2019_09_Unevaluated_Properties 796.4612249313353 ns/iter 765.3364313625099 ns/iter 1.04
Evaluator_2020_12_Dynamic_Ref 1895.6047070918214 ns/iter 1900.9828154174338 ns/iter 1.00

This comment was automatically generated by workflow using github-action-benchmark.

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark (linux/gcc)

Benchmark suite Current: 012b106 Previous: e150395 Ratio
Evaluator_2020_12_Dynamic_Ref 1758.8194661205812 ns/iter 1767.0105047893703 ns/iter 1.00
Evaluator_2019_09_Unevaluated_Properties 792.8727064491544 ns/iter 764.0782082242223 ns/iter 1.04
Evaluator_Draft7_If_Then_Else 198.18064272659143 ns/iter 199.85894687947408 ns/iter 0.99
Evaluator_Draft6_Property_Names 1565.2434424718017 ns/iter 1638.7174816665506 ns/iter 0.96
Evaluator_Draft4_Meta_1_No_Callback 1065.001315555872 ns/iter 1066.0083704243593 ns/iter 1.00
Evaluator_Draft4_Required_Properties 2252.200140627724 ns/iter 2258.2184725374377 ns/iter 1.00
Evaluator_Draft4_Many_Optional_Properties_Minimal_Match 193.61635424309046 ns/iter 193.41619073905866 ns/iter 1.00
Evaluator_Draft4_Few_Optional_Properties_Minimal_Match 136.2882553807749 ns/iter 136.39589212489975 ns/iter 1.00
Evaluator_Draft4_Items_Schema 3076.225042575645 ns/iter 3082.585946065188 ns/iter 1.00
Evaluator_Draft4_Nested_Object 24.28688768622522 ns/iter 23.925558313593733 ns/iter 1.02
Evaluator_Draft4_Properties_Triad_Optional 1766.7102511196656 ns/iter 1706.4366174618622 ns/iter 1.04
Evaluator_Draft4_Properties_Triad_Closed 1447.0215147794147 ns/iter 1401.51182581941 ns/iter 1.03
Evaluator_Draft4_Properties_Triad_Required 1851.0578187012075 ns/iter 1770.0121914223243 ns/iter 1.05
Evaluator_Draft4_Non_Recursive_Ref 469.8315277991517 ns/iter 466.1606305968139 ns/iter 1.01
Evaluator_Draft4_Pattern_Properties_True 2330.454139163103 ns/iter 2268.0232556624433 ns/iter 1.03
Evaluator_Draft4_Ref_To_Single_Property 138.94665862756628 ns/iter 143.85632013525603 ns/iter 0.97
Evaluator_Draft4_Additional_Properties_Type 1110.1979548916847 ns/iter 1097.1593304383032 ns/iter 1.01
Evaluator_Draft4_Nested_Oneof 434.1856557690243 ns/iter 457.995981691783 ns/iter 0.95
Compiler_Draft6_AdaptiveCard 5800702870.00001 ns/iter 5969355952.99999 ns/iter 0.97

This comment was automatically generated by workflow using github-action-benchmark.

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark (windows/msvc)

Benchmark suite Current: 012b106 Previous: e150395 Ratio
Compiler_Draft6_AdaptiveCard 10205197199.99993 ns/iter 10519977499.99998 ns/iter 0.97
Evaluator_Draft4_Meta_1_No_Callback 2362.2546428571563 ns/iter 2322.552206972939 ns/iter 1.02
Evaluator_Draft4_Required_Properties 1972.5540095473903 ns/iter 1992.7871364171601 ns/iter 0.99
Evaluator_Draft4_Many_Optional_Properties_Minimal_Match 506.97869999999057 ns/iter 508.37133928567374 ns/iter 1.00
Evaluator_Draft4_Few_Optional_Properties_Minimal_Match 365.02238906354677 ns/iter 374.84843306278475 ns/iter 0.97
Evaluator_Draft4_Items_Schema 6348.625000001107 ns/iter 6321.058928571281 ns/iter 1.00
Evaluator_Draft4_Nested_Object 120.26329687500949 ns/iter 117.55162499998815 ns/iter 1.02
Evaluator_Draft4_Properties_Triad_Optional 5340.673000000606 ns/iter 5358.0589999990025 ns/iter 1.00
Evaluator_Draft4_Properties_Triad_Closed 4373.959999999499 ns/iter 4413.800625000164 ns/iter 0.99
Evaluator_Draft4_Properties_Triad_Required 5596.351785714302 ns/iter 5492.572321428619 ns/iter 1.02
Evaluator_Draft4_Non_Recursive_Ref 528.4308928569966 ns/iter 520.6627000000026 ns/iter 1.01
Evaluator_Draft4_Pattern_Properties_True 8161.097098212825 ns/iter 8133.434151785325 ns/iter 1.00
Evaluator_Draft4_Ref_To_Single_Property 370.0942522321274 ns/iter 381.9187889430721 ns/iter 0.97
Evaluator_Draft4_Additional_Properties_Type 738.7994419644375 ns/iter 743.8309151785053 ns/iter 0.99
Evaluator_Draft4_Nested_Oneof 1037.379999999999 ns/iter 1061.3320312499397 ns/iter 0.98
Evaluator_Draft6_Property_Names 1761.7350033028167 ns/iter 1758.3360546856622 ns/iter 1.00
Evaluator_Draft7_If_Then_Else 513.4992999999213 ns/iter 509.7210714285642 ns/iter 1.01
Evaluator_2019_09_Unevaluated_Properties 2187.447499999706 ns/iter 2193.6712499996956 ns/iter 1.00
Evaluator_2020_12_Dynamic_Ref 4742.038251819591 ns/iter 4699.488391714837 ns/iter 1.01

This comment was automatically generated by workflow using github-action-benchmark.

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark (macos/gcc)

Benchmark suite Current: 012b106 Previous: e150395 Ratio
Compiler_Draft6_AdaptiveCard 4186587095.26062 ns/iter 4117516756.0577393 ns/iter 1.02
Evaluator_Draft4_Meta_1_No_Callback 768.8004915483799 ns/iter 947.9302963988943 ns/iter 0.81
Evaluator_Draft4_Required_Properties 1033.3281453214481 ns/iter 1083.0688695092133 ns/iter 0.95
Evaluator_Draft4_Many_Optional_Properties_Minimal_Match 178.9956374995767 ns/iter 187.97929393926745 ns/iter 0.95
Evaluator_Draft4_Few_Optional_Properties_Minimal_Match 124.4484572298337 ns/iter 128.11798595505243 ns/iter 0.97
Evaluator_Draft4_Items_Schema 2462.036738689145 ns/iter 2584.8281708436543 ns/iter 0.95
Evaluator_Draft4_Nested_Object 25.12929065246058 ns/iter 26.965898901034723 ns/iter 0.93
Evaluator_Draft4_Properties_Triad_Optional 1504.9767171337178 ns/iter 1616.4172393375939 ns/iter 0.93
Evaluator_Draft4_Properties_Triad_Closed 1304.115731020665 ns/iter 1423.3041449569134 ns/iter 0.92
Evaluator_Draft4_Properties_Triad_Required 1571.9038114938364 ns/iter 1701.7418027158164 ns/iter 0.92
Evaluator_Draft4_Non_Recursive_Ref 418.9114752029646 ns/iter 472.74581595465224 ns/iter 0.89
Evaluator_Draft4_Pattern_Properties_True 1991.9919314317626 ns/iter 2105.2053138741185 ns/iter 0.95
Evaluator_Draft4_Ref_To_Single_Property 119.30752555566185 ns/iter 126.75238230652717 ns/iter 0.94
Evaluator_Draft4_Additional_Properties_Type 482.18212116044634 ns/iter 516.8398079622392 ns/iter 0.93
Evaluator_Draft4_Nested_Oneof 369.86024409793527 ns/iter 390.13052306477675 ns/iter 0.95
Evaluator_Draft6_Property_Names 976.3967314983381 ns/iter 982.1958274608397 ns/iter 0.99
Evaluator_Draft7_If_Then_Else 182.9492682782845 ns/iter 194.694989101538 ns/iter 0.94
Evaluator_2019_09_Unevaluated_Properties 638.1857680964579 ns/iter 671.7654659991397 ns/iter 0.95
Evaluator_2020_12_Dynamic_Ref 1602.928664177985 ns/iter 1698.5951313636685 ns/iter 0.94

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.