synalog 2.7.0__tar.gz → 2.8.0__tar.gz
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.
- {synalog-2.7.0 → synalog-2.8.0}/Cargo.lock +2 -2
- {synalog-2.7.0 → synalog-2.8.0}/Cargo.toml +1 -1
- {synalog-2.7.0 → synalog-2.8.0}/PKG-INFO +1 -1
- {synalog-2.7.0 → synalog-2.8.0}/docs/assertions.md +1 -0
- {synalog-2.7.0 → synalog-2.8.0}/pyproject.toml +1 -1
- {synalog-2.7.0 → synalog-2.8.0}/src/assertion/translate.rs +60 -5
- {synalog-2.7.0 → synalog-2.8.0}/src/compiler/type_inference/builder.rs +26 -1
- {synalog-2.7.0 → synalog-2.8.0}/src/verifier/assertions.rs +132 -4
- {synalog-2.7.0 → synalog-2.8.0}/uv.lock +1 -1
- {synalog-2.7.0 → synalog-2.8.0}/verified/Cargo.toml +1 -1
- {synalog-2.7.0 → synalog-2.8.0}/.gitignore +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/LICENSE +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/NOTICE +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/README.md +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/assets/synalog-dark.svg +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/assets/synalog-light.svg +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/assets/synalog_favicon.png +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/benchmark/results.json +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/benchmark/speedup_by_engine.png +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/benchmark/speedup_distribution.png +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/benchmark/summary.md +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/benchmark/summary.png +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/benchmark/time_comparison.png +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/benchmark/verify_by_engine.png +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/benchmark.md +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/cli.md +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/development.md +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/differences-datalog.md +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/differences.md +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/engines.md +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/examples/aggregation.l +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/examples/aggregation.log +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/examples/directives.l +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/examples/directives.log +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/examples/functions.l +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/examples/functions.log +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/examples/functors.l +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/examples/functors.log +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/examples/getting_started.l +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/examples/getting_started.log +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/examples/knowledge_graphs.l +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/examples/knowledge_graphs.log +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/examples/recursion.l +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/examples/recursion.log +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/examples/run.py +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/examples/shop/concepts/customer.l +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/examples/shop/concepts/order_status.l +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/examples/shop/data/orders.csv +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/examples/shop/layer.toml +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/examples/shop/rules/customer_revenue.l +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/examples/shop/rules/orders_by_status.l +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/examples/shop/rules/top_customers.l +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/examples/shop/tables/orders.l +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/examples/shop.log +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/examples/smoke/concepts/device.l +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/examples/smoke/concepts/test_status.l +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/examples/smoke/data/smoke_tests.csv +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/examples/smoke/layer.toml +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/examples/smoke/rules/failures_by_device.l +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/examples/smoke/rules/runs_per_day.l +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/examples/smoke/tables/smoke_tests.l +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/examples/smoke.log +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/examples/syntax.l +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/examples/syntax.log +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/examples/temporal.l +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/examples/temporal.log +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/examples/temporal_graph.l +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/examples/temporal_graph.log +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/examples/verification.l +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/examples/verification.log +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/getting-started.md +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/index.md +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/javascripts/playground.js +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/javascripts/summarize.js +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/javascripts/synalog-highlight.js +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/knowledge-graphs.md +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/language/aggregation.md +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/language/directives.md +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/language/functions.md +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/language/functors.md +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/language/index.md +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/language/recursion.md +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/language/syntax.md +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/language/temporal.md +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/playground/vendor/codemirror.js +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/playground.md +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/python-api.md +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/stylesheets/extra.css +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/verification.md +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/docs/why.md +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/img/synalog-dark.svg +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/img/synalog-light.svg +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/python/synalog/__init__.py +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/python/synalog/__main__.py +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/python/synalog/checking.py +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/python/synalog/cli.py +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/python/synalog/config.py +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/python/synalog/execution.py +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/python/synalog/introspect.py +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/python/synalog/project.py +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/python/synalog/runners.py +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/python/synalog/writes.py +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/skills/synalog/SKILL.md +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/skills/synalog/examples/company/concepts/department.l +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/skills/synalog/examples/company/concepts/person.l +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/skills/synalog/examples/company/concepts/works_in.l +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/skills/synalog/examples/company/data/departments.csv +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/skills/synalog/examples/company/data/employees.csv +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/skills/synalog/examples/company/layer.toml +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/skills/synalog/examples/company/rules/team_mate.l +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/skills/synalog/examples/company/tables/departments.l +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/skills/synalog/examples/company/tables/employees.l +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/skills/synalog/examples/org/concepts/all_managers.l +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/skills/synalog/examples/org/data/employees.csv +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/skills/synalog/examples/org/layer.toml +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/skills/synalog/examples/org/tables/employees.l +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/skills/synalog/examples/sales/concepts/region.l +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/skills/synalog/examples/sales/data/sales.csv +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/skills/synalog/examples/sales/layer.toml +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/skills/synalog/examples/sales/rules/monthly_sales.l +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/skills/synalog/examples/sales/rules/top_region.l +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/skills/synalog/examples/sales/rules/total_by_region.l +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/skills/synalog/examples/sales/tables/sales.l +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/src/assertion/mod.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/src/assertion/parse.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/src/assertion/report.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/src/compiler/annotations.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/src/compiler/annotations_test.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/src/compiler/dialects.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/src/compiler/dialects_test.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/src/compiler/expr_translate.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/src/compiler/expr_translate_test.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/src/compiler/functors.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/src/compiler/functors_test.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/src/compiler/home_guard.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/src/compiler/home_guard_test.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/src/compiler/mod.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/src/compiler/rule_translate.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/src/compiler/rule_translate_test.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/src/compiler/type_inference/built_in.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/src/compiler/type_inference/edge.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/src/compiler/type_inference/expression.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/src/compiler/type_inference/graph.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/src/compiler/type_inference/inference.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/src/compiler/type_inference/intersection.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/src/compiler/type_inference/mod.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/src/compiler/type_inference/types.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/src/compiler/universe.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/src/compiler/universe_test.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/src/errors.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/src/lib.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/src/parser/json.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/src/parser/json_test.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/src/parser/mod.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/src/parser/names.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/src/parser/parse.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/src/parser/parse_test.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/src/parser/rewrite.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/src/parser/rewrite_test.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/src/parser/span.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/src/parser/span_test.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/src/parser/traverse.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/src/parser/traverse_test.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/src/python.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/src/verifier/arity.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/src/verifier/cast.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/src/verifier/contradiction.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/src/verifier/dependencies.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/src/verifier/directives.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/src/verifier/front_matter.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/src/verifier/functors.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/src/verifier/mod.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/src/verifier/orderby.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/src/verifier/positional.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/src/verifier/recursion.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/src/verifier/reserved.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/src/verifier/safety.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/src/verifier/sqlexpr.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/src/verifier/stratification.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/src/verifier/undefined.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/src/verifier/vars.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/src/wasm.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/verified/src/arity.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/verified/src/cast.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/verified/src/contradiction.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/verified/src/convergence.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/verified/src/home.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/verified/src/lib.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/verified/src/membership.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/verified/src/page.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/verified/src/plan.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/verified/src/quote.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/verified/src/recursion.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/verified/src/safety.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/verified/src/strata.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/verified/src/types.rs +0 -0
- {synalog-2.7.0 → synalog-2.8.0}/zensical.toml +0 -0
|
@@ -300,7 +300,7 @@ dependencies = [
|
|
|
300
300
|
|
|
301
301
|
[[package]]
|
|
302
302
|
name = "synalog"
|
|
303
|
-
version = "2.
|
|
303
|
+
version = "2.8.0"
|
|
304
304
|
dependencies = [
|
|
305
305
|
"anyhow",
|
|
306
306
|
"indexmap",
|
|
@@ -316,7 +316,7 @@ dependencies = [
|
|
|
316
316
|
|
|
317
317
|
[[package]]
|
|
318
318
|
name = "synalog-verified"
|
|
319
|
-
version = "2.
|
|
319
|
+
version = "2.8.0"
|
|
320
320
|
dependencies = [
|
|
321
321
|
"vstd",
|
|
322
322
|
]
|
|
@@ -194,6 +194,7 @@ Each assertion has a status, which `assertions()` reports:
|
|
|
194
194
|
|-------|-------|-----|
|
|
195
195
|
| `Invalid assertion 'P.name': …` | The statement does not parse, or applies a predicate to the wrong number of arguments | Fix the statement; count the predicate's columns |
|
|
196
196
|
| `Invalid assertion 'P.name': variable 'v' is quantified by '∀' but never used …` | A `∀`, `∃` or `∑` names a variable its formula never uses | Remove the variable, or use it where it was meant to appear |
|
|
197
|
+
| `Invalid assertion 'P.name': 'v' appears only after '→' …` | A variable meant for every value (after `∀`, or undeclared) is named only in the conclusion, so nothing gives it values | Say "some value" with `∃ v,` right after `→`, or name it in a premise |
|
|
197
198
|
| `Duplicate assertion 'P.name': …` | The same name is stated twice for a predicate | Give each property its own name |
|
|
198
199
|
| `Malformed @Assert: …` | The annotation is not `@Assert(Predicate, name: "statement", ...)` | One named argument per property |
|
|
199
200
|
| `Assertion 'P.name' is violated: …` | The data holds a counterexample | Fix the rule, or the assertion if it was wrong |
|
|
@@ -125,6 +125,36 @@ pub fn translate(statement: &Expr, schema: &Schema, prefix: &str) -> Result<Tran
|
|
|
125
125
|
// Unbound lowercase names are universally quantified too.
|
|
126
126
|
columns.extend(resolver.implicit);
|
|
127
127
|
|
|
128
|
+
// A universal variable that no premise names has nothing to take its values
|
|
129
|
+
// from: the counterexamples hold the conclusion negated, and no rule added
|
|
130
|
+
// later changes that. Often meant as "some value" (∃ after →). Said in place
|
|
131
|
+
// of the bare "not bound" below, never over a more precise error (a wrong
|
|
132
|
+
// number of arguments) found while emitting.
|
|
133
|
+
let mut premises = Vec::new();
|
|
134
|
+
let mut conclusion = &body;
|
|
135
|
+
while let Expr::Binary(BinOp::Implies, premise, rest) = conclusion {
|
|
136
|
+
premises.push(premise.as_ref());
|
|
137
|
+
conclusion = rest;
|
|
138
|
+
}
|
|
139
|
+
let named: Vec<String> = premises.iter().flat_map(|p| free_vars(p)).collect();
|
|
140
|
+
let only_after: Vec<&str> = if premises.is_empty() {
|
|
141
|
+
Vec::new()
|
|
142
|
+
} else {
|
|
143
|
+
columns.iter().filter(|c| !named.contains(c)).map(String::as_str).collect()
|
|
144
|
+
};
|
|
145
|
+
let conclusion_only = (!only_after.is_empty()).then(|| {
|
|
146
|
+
TranslateError::Invalid(format!(
|
|
147
|
+
"'{}' appear{} only after '→', where nothing gives {} values to check: a name \
|
|
148
|
+
not bound before '→' means 'for every value'. To say 'some value', write \
|
|
149
|
+
'∃ {},' right after '→' (e.g. '… → ∃ {}, …')",
|
|
150
|
+
only_after.join("', '"),
|
|
151
|
+
if only_after.len() == 1 { "s" } else { "" },
|
|
152
|
+
if only_after.len() == 1 { "it" } else { "them" },
|
|
153
|
+
only_after.join(" "),
|
|
154
|
+
only_after.join(" "),
|
|
155
|
+
))
|
|
156
|
+
});
|
|
157
|
+
|
|
128
158
|
let violation = nnf(&body, true);
|
|
129
159
|
let mut emitter = Emitter {
|
|
130
160
|
schema,
|
|
@@ -140,7 +170,12 @@ pub fn translate(statement: &Expr, schema: &Schema, prefix: &str) -> Result<Tran
|
|
|
140
170
|
};
|
|
141
171
|
let mut rules = Vec::new();
|
|
142
172
|
for conjunct in dnf(&violation)? {
|
|
143
|
-
let body = emitter.conjunct(&conjunct, &columns)
|
|
173
|
+
let body = match emitter.conjunct(&conjunct, &columns) {
|
|
174
|
+
Err(TranslateError::Unsupported(_)) if conclusion_only.is_some() => {
|
|
175
|
+
return Err(conclusion_only.unwrap());
|
|
176
|
+
}
|
|
177
|
+
body => body?,
|
|
178
|
+
};
|
|
144
179
|
if body.is_empty() {
|
|
145
180
|
return unsupported("the statement is false whatever the data");
|
|
146
181
|
}
|
|
@@ -911,6 +946,24 @@ mod tests {
|
|
|
911
946
|
rules("∀ x y1 y2, Parent x y1 ∧ Parent x y2 → y1 = y2");
|
|
912
947
|
}
|
|
913
948
|
|
|
949
|
+
#[test]
|
|
950
|
+
fn a_universal_variable_only_the_conclusion_names_is_invalid() {
|
|
951
|
+
// The layer case: `p v` undeclared, named only after →.
|
|
952
|
+
let TranslateError::Invalid(reason) = error("∀ x y, Parent x y → Joint x y p ∧ p ≥ 1") else {
|
|
953
|
+
panic!("expected Invalid");
|
|
954
|
+
};
|
|
955
|
+
assert!(reason.contains("'p' appears only after '→'"), "{reason}");
|
|
956
|
+
assert!(reason.contains("'∃ p,'"), "{reason}");
|
|
957
|
+
// Declared by ∀ but named only after →: the same.
|
|
958
|
+
assert!(matches!(error("∀ x y z, Parent x y → Ancestor x z"), TranslateError::Invalid(_)));
|
|
959
|
+
// Named in a premise, even only in a comparison: checkable as before.
|
|
960
|
+
rules("∀ x y z, Parent x y → z = x → Ancestor z y");
|
|
961
|
+
// Said with ∃: checkable.
|
|
962
|
+
rules("∀ x y, Parent x y → ∃ p, Joint x y p ∧ p ≥ 1");
|
|
963
|
+
// No premise at all: unsupported as before, not this error.
|
|
964
|
+
assert!(matches!(error("∀ x, x > 0"), TranslateError::Unsupported(_)));
|
|
965
|
+
}
|
|
966
|
+
|
|
914
967
|
#[test]
|
|
915
968
|
fn test_implication_chain() {
|
|
916
969
|
assert_eq!(
|
|
@@ -1030,11 +1083,13 @@ mod tests {
|
|
|
1030
1083
|
};
|
|
1031
1084
|
assert!(message.contains("variable 'x' is not bound"), "{message}");
|
|
1032
1085
|
|
|
1033
|
-
// `y` ranges over nothing
|
|
1034
|
-
|
|
1035
|
-
|
|
1086
|
+
// `y` ranges over nothing, and only the conclusion names it: a mistake
|
|
1087
|
+
// in the statement, reported as such (see
|
|
1088
|
+
// `a_universal_variable_only_the_conclusion_names_is_invalid`).
|
|
1089
|
+
let TranslateError::Invalid(message) = error("∀ x y, Ancestor x x → Parent x y") else {
|
|
1090
|
+
panic!("expected an invalid statement");
|
|
1036
1091
|
};
|
|
1037
|
-
assert!(message.contains("
|
|
1092
|
+
assert!(message.contains("'y' appears only after '→'"), "{message}");
|
|
1038
1093
|
}
|
|
1039
1094
|
|
|
1040
1095
|
#[test]
|
|
@@ -336,8 +336,17 @@ impl TypesGraphBuilder {
|
|
|
336
336
|
bounds,
|
|
337
337
|
));
|
|
338
338
|
}
|
|
339
|
+
let bounds = (total_min.unwrap_or(0), total_max.unwrap_or(0));
|
|
339
340
|
|
|
340
|
-
|
|
341
|
+
// Both sides of a comparison, as a condition or a value, are one type:
|
|
342
|
+
// `1 < name` is a number against text, which every engine but SQLite
|
|
343
|
+
// refuses at run time.
|
|
344
|
+
if matches!(predicate_name, "<" | ">" | "<=" | ">=" | "==" | "!=") {
|
|
345
|
+
let side = |field| Expression::predicate_addressing(predicate_name, field, predicate_id);
|
|
346
|
+
graph.connect(Edge::equality(side("left"), side("right"), bounds));
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
bounds
|
|
341
350
|
}
|
|
342
351
|
|
|
343
352
|
/// Convert a parsed expression to a typed expression.
|
|
@@ -666,4 +675,20 @@ mod tests {
|
|
|
666
675
|
let builder = TypesGraphBuilder::new();
|
|
667
676
|
assert!(builder.predicate_usages.is_empty());
|
|
668
677
|
}
|
|
678
|
+
|
|
679
|
+
fn infers(code: &str) -> bool {
|
|
680
|
+
let parsed = crate::parser::parse_file(code, None, &[]).unwrap();
|
|
681
|
+
let rules = parsed.as_object()["rule"].as_array();
|
|
682
|
+
super::super::TypeInference::new(TypesGraphBuilder::new().run_rules(rules.iter())).infer().is_ok()
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
#[test]
|
|
686
|
+
fn test_comparison_sides_are_one_type() {
|
|
687
|
+
let facts = r#"Card(bin: 4017, scheme: "GlobalCard");"#;
|
|
688
|
+
assert!(infers(&format!("{facts}\nHigh(bin:) :- Card(bin:), bin > 4000;")));
|
|
689
|
+
assert!(infers(&format!("{facts}\nNamed(scheme:) :- Card(scheme:), scheme != \"NexPay\";")));
|
|
690
|
+
// Text against a number: refused here, not by the database at run time.
|
|
691
|
+
assert!(!infers(&format!("{facts}\nOdd(scheme:) :- Card(scheme:), 1 <= scheme;")));
|
|
692
|
+
assert!(!infers(&format!("{facts}\nOdd(bin:) :- Card(bin:, scheme:), bin < scheme;")));
|
|
693
|
+
}
|
|
669
694
|
}
|
|
@@ -23,7 +23,8 @@
|
|
|
23
23
|
//! ## What is checked
|
|
24
24
|
//!
|
|
25
25
|
//! Errors are reserved for assertions that can never become valid: a statement that
|
|
26
|
-
//! does not parse or contradicts the program (wrong number of arguments
|
|
26
|
+
//! does not parse or contradicts the program (wrong number of arguments, or
|
|
27
|
+
//! terms of different types compared, often arguments in the wrong order), a
|
|
27
28
|
//! name stated twice, and annotations that are not shaped as
|
|
28
29
|
//! `(Predicate, name: "text", ...)`. A well-formed
|
|
29
30
|
//! statement that cannot be checked on a database is a warning.
|
|
@@ -31,8 +32,9 @@
|
|
|
31
32
|
use std::collections::{HashMap, HashSet};
|
|
32
33
|
|
|
33
34
|
use crate::errors::VerifyError;
|
|
34
|
-
use crate::parser::Json;
|
|
35
|
-
use crate::assertion::{self, Schema, TranslateError, Translation};
|
|
35
|
+
use crate::parser::{parse_file, Json};
|
|
36
|
+
use crate::assertion::{self, Expr, Schema, TranslateError, Translation};
|
|
37
|
+
use crate::compiler::type_inference::{Type, TypeInference, TypesGraphBuilder};
|
|
36
38
|
|
|
37
39
|
use super::reserved::reserved_predicate_names;
|
|
38
40
|
|
|
@@ -175,6 +177,8 @@ pub fn check_assertions(rules: &[&Json]) -> (Vec<AssertionReport>, Vec<Assertion
|
|
|
175
177
|
|
|
176
178
|
let mut reports: Vec<AssertionReport> = Vec::new();
|
|
177
179
|
let mut index: HashMap<(String, String), usize> = HashMap::new();
|
|
180
|
+
// Typed once, and only when an assertion is there to check against it.
|
|
181
|
+
let types = (!assertions.is_empty()).then(|| program_types(rules)).flatten();
|
|
178
182
|
for assertion in assertions {
|
|
179
183
|
let key = (assertion.predicate.clone(), assertion.name.clone());
|
|
180
184
|
if index.contains_key(&key) {
|
|
@@ -185,7 +189,13 @@ pub fn check_assertions(rules: &[&Json]) -> (Vec<AssertionReport>, Vec<Assertion
|
|
|
185
189
|
continue;
|
|
186
190
|
}
|
|
187
191
|
index.insert(key, reports.len());
|
|
188
|
-
let
|
|
192
|
+
let translated = translate_assertion(&assertion, &defined, &schema).and_then(|translation| {
|
|
193
|
+
match types.as_ref().and_then(|types| type_error(rules, &assertion, &translation, &schema, types)) {
|
|
194
|
+
Some(reason) => Err(TranslateError::Invalid(reason)),
|
|
195
|
+
None => Ok(translation),
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
let (status, detail) = match translated {
|
|
189
199
|
Ok(_) => (AssertionStatus::Unchecked, None),
|
|
190
200
|
Err(TranslateError::Missing(missing)) => (
|
|
191
201
|
AssertionStatus::Pending,
|
|
@@ -233,6 +243,93 @@ fn translate_assertion(
|
|
|
233
243
|
Ok(translation)
|
|
234
244
|
}
|
|
235
245
|
|
|
246
|
+
/// Column types of the program's predicates, or None when its own rules do
|
|
247
|
+
/// not type-check (compiling it says why).
|
|
248
|
+
fn program_types(rules: &[&Json]) -> Option<HashMap<String, HashMap<String, Type>>> {
|
|
249
|
+
let mut inference = TypeInference::new(TypesGraphBuilder::new().run_rules(rules.iter().copied()));
|
|
250
|
+
inference.infer().ok()?;
|
|
251
|
+
Some(inference.all_predicate_types())
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/// Why the counterexample rules of `assertion` do not type-check, with what
|
|
255
|
+
/// each of its variables stands for: terms of different types compared are
|
|
256
|
+
/// most often arguments written in another order than the columns'.
|
|
257
|
+
// shortcut: types the whole program again per assertion; type it once with
|
|
258
|
+
// every translation, and only on a failure assertion by assertion, if a large
|
|
259
|
+
// layer makes saving slow.
|
|
260
|
+
fn type_error(
|
|
261
|
+
rules: &[&Json],
|
|
262
|
+
assertion: &Entry,
|
|
263
|
+
translation: &Translation,
|
|
264
|
+
schema: &Schema,
|
|
265
|
+
types: &HashMap<String, HashMap<String, Type>>,
|
|
266
|
+
) -> Option<String> {
|
|
267
|
+
let parsed = parse_file(&translation.rules, None, &[]).ok()?;
|
|
268
|
+
let checks = parsed.as_object()["rule"].as_array();
|
|
269
|
+
let mut inference = TypeInference::new(TypesGraphBuilder::new().run_rules(rules.iter().copied().chain(checks.iter())));
|
|
270
|
+
let error = inference.infer().err()?;
|
|
271
|
+
let statement = assertion::parse(&assertion.text).ok()?;
|
|
272
|
+
let (mut stands, mut columns) = (Vec::new(), Vec::new());
|
|
273
|
+
bindings(&statement, schema, types, &mut stands, &mut columns);
|
|
274
|
+
// Inference meets the two sides in no particular order: name them sorted.
|
|
275
|
+
let mut sides = [error.left.to_string(), error.right.to_string()];
|
|
276
|
+
sides.sort();
|
|
277
|
+
Some(format!(
|
|
278
|
+
"it compares a {} and a {}. Its variables stand for {}. \
|
|
279
|
+
Arguments follow the order of the columns: {}",
|
|
280
|
+
sides[0],
|
|
281
|
+
sides[1],
|
|
282
|
+
stands.join(", "),
|
|
283
|
+
columns.join("; "),
|
|
284
|
+
))
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/// What each variable of `expr` stands for (`p = Sales.amount (number)`), and
|
|
288
|
+
/// the columns of each predicate it applies, in order.
|
|
289
|
+
fn bindings(
|
|
290
|
+
expr: &Expr,
|
|
291
|
+
schema: &Schema,
|
|
292
|
+
types: &HashMap<String, HashMap<String, Type>>,
|
|
293
|
+
stands: &mut Vec<String>,
|
|
294
|
+
columns: &mut Vec<String>,
|
|
295
|
+
) {
|
|
296
|
+
match expr {
|
|
297
|
+
Expr::Forall(_, body) | Expr::Exists(_, body) | Expr::Sum(_, body) | Expr::Not(body) | Expr::Neg(body) => {
|
|
298
|
+
bindings(body, schema, types, stands, columns)
|
|
299
|
+
}
|
|
300
|
+
Expr::Binary(_, left, right) => {
|
|
301
|
+
bindings(left, schema, types, stands, columns);
|
|
302
|
+
bindings(right, schema, types, stands, columns);
|
|
303
|
+
}
|
|
304
|
+
Expr::App(predicate, args) => {
|
|
305
|
+
if let Some(names) = schema.get(predicate) {
|
|
306
|
+
let order = format!("{} ({})", predicate, names.join(", "));
|
|
307
|
+
if !columns.contains(&order) {
|
|
308
|
+
columns.push(order);
|
|
309
|
+
}
|
|
310
|
+
for (arg, column) in args.iter().zip(names) {
|
|
311
|
+
let Expr::App(var, none) = arg else { continue };
|
|
312
|
+
if !none.is_empty() || !var.chars().next().is_some_and(char::is_lowercase) {
|
|
313
|
+
continue;
|
|
314
|
+
}
|
|
315
|
+
let typed = match types.get(predicate).and_then(|t| t.get(column)) {
|
|
316
|
+
Some(t @ (Type::Number | Type::String | Type::Bool)) => format!(" ({t})"),
|
|
317
|
+
_ => String::new(),
|
|
318
|
+
};
|
|
319
|
+
let stand = format!("{var} = {predicate}.{column}{typed}");
|
|
320
|
+
if !stands.contains(&stand) {
|
|
321
|
+
stands.push(stand);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
for arg in args {
|
|
326
|
+
bindings(arg, schema, types, stands, columns);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
Expr::Var(_) | Expr::Num(_) | Expr::Str(_) => {}
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
236
333
|
/// The rules that find the counterexamples of the assertion `name` of `predicate`:
|
|
237
334
|
/// the assertion holds on a database when the translation's predicate is empty
|
|
238
335
|
/// there. `rules` must include the annotation rules.
|
|
@@ -595,4 +692,35 @@ mod tests {
|
|
|
595
692
|
);
|
|
596
693
|
}
|
|
597
694
|
}
|
|
695
|
+
|
|
696
|
+
const DOMINANT: &str = r#"Dominant(card_bin: 4017, total: 10, scheme: "GlobalCard", top: 7);"#;
|
|
697
|
+
|
|
698
|
+
#[test]
|
|
699
|
+
fn test_arguments_out_of_column_order_are_an_error() {
|
|
700
|
+
// `p` lands on `scheme`, text, compared with 1: the columns are
|
|
701
|
+
// (card_bin, total, scheme, top), not (card_bin, scheme, top, total).
|
|
702
|
+
let (reports, errors) = check(&format!(
|
|
703
|
+
"{DOMINANT}\n{}",
|
|
704
|
+
r#"@Assert(Dominant, bounded: "∀ b s p c, Dominant b s p c → 1 ≤ p ∧ p ≤ c");"#
|
|
705
|
+
));
|
|
706
|
+
let [AssertionError::Statement { predicate, name, reason }] = &errors[..] else {
|
|
707
|
+
panic!("{errors:?}")
|
|
708
|
+
};
|
|
709
|
+
assert_eq!((predicate.as_str(), name.as_str()), ("Dominant", "bounded"));
|
|
710
|
+
assert!(reason.contains("compares a"), "{reason}");
|
|
711
|
+
assert!(reason.contains("p = Dominant.scheme (string)"), "{reason}");
|
|
712
|
+
assert!(reason.contains("c = Dominant.top (number)"), "{reason}");
|
|
713
|
+
assert!(reason.contains("Dominant (card_bin, total, scheme, top)"), "{reason}");
|
|
714
|
+
assert_eq!(reports[0].status, AssertionStatus::Unsupported);
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
#[test]
|
|
718
|
+
fn test_arguments_in_column_order_type_check() {
|
|
719
|
+
let (reports, errors) = check(&format!(
|
|
720
|
+
"{DOMINANT}\n{}",
|
|
721
|
+
r#"@Assert(Dominant, bounded: "∀ b c s p, Dominant b c s p → 1 ≤ p ∧ p ≤ c");"#
|
|
722
|
+
));
|
|
723
|
+
assert!(errors.is_empty(), "{errors:?}");
|
|
724
|
+
assert_eq!(reports[0].status, AssertionStatus::Unchecked);
|
|
725
|
+
}
|
|
598
726
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|