3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2026-02-19 23:14:40 +00:00
z3/src/ast
Copilot 0d85b86334 Update Z3_mk_datatype_sort API to accept array of sort parameters and add Z3_mk_polymorphic_datatype (#7966)
* Initial plan

* Update Z3_mk_datatype_sort API to accept array of parameters

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>

* Update language bindings for parametric datatype sort API

- Python: Updated DatatypeSort() to accept optional params list
- OCaml: Added mk_sort_ref_p/mk_sort_ref_ps for parametric datatypes
- .NET: Added MkDatatypeSortRef() methods with optional params
- Java: Added mkDatatypeSortRef() methods with optional params
- All changes maintain backward compatibility

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>

* Fix .NET build error - rename params to parameters

The 'params' keyword is reserved in C#, causing compilation errors.
Renamed parameter from 'params' to 'parameters' in MkDatatypeSortRef methods.

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>

* Add unit test for parametric datatypes

Added test_parametric_datatype.cpp to demonstrate polymorphic datatypes.
The test creates two concrete instantiations of a generic pair concept:
- pair_int_real with fields (first:Int, second:Real)
- pair_real_int with fields (first:Real, second:Int)
Then verifies that accessors work correctly and type checking is enforced.

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>

* Implement polymorphic type variables support for parametric datatypes

- Modified datatype_decl_plugin to allow type variables as parameters
- Updated mk_datatype_decl to extract type variables from field sorts
- Type variables are collected in order of first appearance
- Revised unit test to use Z3_mk_type_variable for polymorphic datatypes
- Test creates pair datatype with type variables alpha and beta
- Successfully instantiates with concrete types (pair Int Real) and (pair Real Int)
- Verifies accessor types match and equality terms are well-typed
- All tests pass

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>

* Add Z3_mk_polymorphic_datatype API and refactor datatype creation

- Added new API Z3_mk_polymorphic_datatype to z3_api.h
- Renamed static mk_datatype_decl to api_datatype_decl in api_datatype.cpp
- Modified api_datatype_decl to accept explicit type parameters
- Updated all callers to use renamed function
- Added test_polymorphic_datatype_api demonstrating new API usage
- Both tests pass successfully

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>

* Remove type variable collection logic from constructors

Removed the logic for collecting type variables from field sorts based on constructors.

* Update comments on parameter handling in api_datatype.cpp

Clarify usage of parameters in API documentation.

* Fix OCaml build error - use list instead of array for mk_datatype_sort

Changed mk_sort_ref to pass empty list [] instead of empty array [||].
Changed mk_sort_ref_p to pass params list directly instead of converting to array.
Z3native.mk_datatype_sort expects a list, not an array.

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>

* Add polymorphic datatype example to C++ examples

Added polymorphic_datatype_example() demonstrating:
- Creating type variables alpha and beta with Z3_mk_type_variable
- Defining parametric Pair datatype with fields of type alpha and beta
- Instantiating with concrete types (Pair Int Real) and (Pair Real Int)
- Getting constructors and accessors from instantiated datatypes
- Creating constants and expressions using the polymorphic types
- Verifying type correctness with equality (= (first p1) (second p2))

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>
Co-authored-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2025-10-26 15:32:21 +01:00
..
converters test 2025-10-14 18:01:41 +02:00
euf Fix compilation warning: add missing is_passive_eq case to switch statement (#7785) 2025-08-15 09:50:45 -07:00
fpa fix #7661 2025-05-29 17:46:51 +01:00
macros Centralize and document TRACE tags using X-macros (#7657) 2025-05-28 14:31:25 +01:00
normal_forms fixing the order 2025-10-13 21:00:54 +02:00
pattern Centralize and document TRACE tags using X-macros (#7657) 2025-05-28 14:31:25 +01:00
proofs Centralize and document TRACE tags using X-macros (#7657) 2025-05-28 14:31:25 +01:00
rewriter parameter eval order 2025-10-26 15:32:20 +01:00
simplifiers Par (#7945) 2025-09-21 10:11:04 +03:00
sls move smt params to params directory, update release.yml 2025-06-09 10:47:22 -07:00
substitution nits 2025-06-30 08:37:39 -07:00
act_cache.cpp
act_cache.h booyah 2020-07-04 15:56:30 -07:00
arith_decl_plugin.cpp Centralize and document TRACE tags using X-macros (#7657) 2025-05-28 14:31:25 +01:00
arith_decl_plugin.h Sls (#7439) 2024-11-02 12:32:48 -07:00
array_decl_plugin.cpp add -> as another array sort constructor 2025-06-22 21:35:23 -07:00
array_decl_plugin.h fixes to ho-matcher 2025-07-05 16:24:45 -07:00
array_peq.cpp code simplification 2025-02-18 19:07:58 -08:00
array_peq.h code simplification 2025-02-18 19:07:58 -08:00
ast.cpp base implementation for cardinality constraints 2025-10-26 10:35:37 +01:00
ast.h base implementation for cardinality constraints 2025-10-26 10:35:37 +01:00
ast_ll_pp.cpp added API to monitor clause inferences 2022-10-19 08:34:55 -07:00
ast_ll_pp.h remove '#include <iostream>' from headers and from unneeded places 2022-06-17 14:10:19 +01:00
ast_lt.cpp remove unnecessary parameter copies 2023-12-22 16:11:06 +00:00
ast_lt.h booyah 2020-07-04 15:56:30 -07:00
ast_pp.h remove a few string copies 2023-12-20 16:55:09 +00:00
ast_pp_dot.cpp Centralize and document TRACE tags using X-macros (#7657) 2025-05-28 14:31:25 +01:00
ast_pp_dot.h remove '#include <iostream>' from headers and from unneeded places 2022-06-17 14:10:19 +01:00
ast_pp_util.cpp fixes to mbqi in the new core based on #6575 2023-02-10 16:56:06 -08:00
ast_pp_util.h wip - proof hints 2022-10-08 20:12:57 +02:00
ast_printer.cpp Remove empty leaf destructors. (#6211) 2022-07-30 10:07:03 +01:00
ast_printer.h Use = default for virtual constructors. 2022-08-05 18:11:46 +03:00
ast_smt2_pp.cpp patch definitions, add pretty print support 2025-10-13 22:39:32 +02:00
ast_smt2_pp.h patch definitions, add pretty print support 2025-10-13 22:39:32 +02:00
ast_smt_pp.cpp remove debug output 2025-10-13 22:40:21 +02:00
ast_smt_pp.h Add and fix a few general compiler warnings. (#5628) 2021-10-29 15:42:32 +02:00
ast_trail.h remove default destructors 2024-10-02 22:20:12 +01:00
ast_translation.cpp Centralize and document TRACE tags using X-macros (#7657) 2025-05-28 14:31:25 +01:00
ast_translation.h revert my mess with the ast hashtable 2021-02-17 14:29:07 +00:00
ast_util.cpp bug in flatten/and/or introduced when skipping sub-expressions 2021-12-22 07:43:37 -08:00
ast_util.h convert reduce-args to a simplifier 2023-01-28 20:12:14 -08:00
bv_decl_plugin.cpp Centralize and document TRACE tags using X-macros (#7657) 2025-05-28 14:31:25 +01:00
bv_decl_plugin.h fix #7572 and fix #7574 2025-03-07 10:46:29 -08:00
char_decl_plugin.cpp Typo Fixes (#6803) 2023-07-09 11:56:10 -07:00
char_decl_plugin.h Typo Fixes (#6803) 2023-07-09 11:56:10 -07:00
CMakeLists.txt Implement finite_set_decl_plugin with complete operator support and polymorphism infrastructure (#7961) 2025-10-13 10:58:53 +02:00
cost_evaluator.cpp add priority queue to instantiation 2021-01-31 16:17:52 -08:00
cost_evaluator.h add priority queue to instantiation 2021-01-31 16:17:52 -08:00
datatype_decl_plugin.cpp Update Z3_mk_datatype_sort API to accept array of sort parameters and add Z3_mk_polymorphic_datatype (#7966) 2025-10-26 15:32:21 +01:00
datatype_decl_plugin.h Fix O(n²) performance issue in CLI datatype declaration processing (#7712) 2025-07-02 09:54:36 -07:00
decl_collector.cpp fixes to mbqi in the new core based on #6575 2023-02-10 16:56:06 -08:00
decl_collector.h fixes to mbqi in the new core based on #6575 2023-02-10 16:56:06 -08:00
display_dimacs.cpp fixes for #6577 2023-02-11 09:33:42 -08:00
display_dimacs.h enable wcnf output for weighted maxsat problems 2021-02-28 09:59:36 -08:00
dl_decl_plugin.cpp Centralize and document TRACE tags using X-macros (#7657) 2025-05-28 14:31:25 +01:00
dl_decl_plugin.h Remove empty leaf destructors. (#6211) 2022-07-30 10:07:03 +01:00
expr2polynomial.cpp Centralize and document TRACE tags using X-macros (#7657) 2025-05-28 14:31:25 +01:00
expr2polynomial.h remove default destructors 2024-10-02 22:20:12 +01:00
expr2var.cpp Centralize and document TRACE tags using X-macros (#7657) 2025-05-28 14:31:25 +01:00
expr2var.h booyah 2020-07-04 15:56:30 -07:00
expr_abstract.cpp Centralize and document TRACE tags using X-macros (#7657) 2025-05-28 14:31:25 +01:00
expr_abstract.h wip - throttle AC completion, enable congruences over bound bodies 2025-07-11 12:48:27 +02:00
expr_delta_pair.h booyah 2020-07-04 15:56:30 -07:00
expr_functors.cpp call it data instead of c_ptr for approaching C++11 std::vector convention. 2021-04-13 18:17:35 -07:00
expr_functors.h Use = default for virtual constructors. 2022-08-05 18:11:46 +03:00
expr_map.cpp
expr_map.h booyah 2020-07-04 15:56:30 -07:00
expr_stat.cpp
expr_stat.h booyah 2020-07-04 15:56:30 -07:00
expr_substitution.cpp bugfix to elim_uncnstr to ensure nodes are created. Prepare smt_internalizer to replay unit literals 2024-12-04 15:32:15 -08:00
expr_substitution.h wip - testing solve-eqs2, added as tactic 2022-11-05 22:42:59 -07:00
finite_set_decl_plugin.cpp Fix finite_set sort cardinality computation for finite base sorts (#7997) 2025-10-23 17:30:17 +02:00
finite_set_decl_plugin.h add interpretations when there are ranges 2025-10-20 23:21:30 +02:00
for_each_ast.cpp
for_each_ast.h Centralize and document TRACE tags using X-macros (#7657) 2025-05-28 14:31:25 +01:00
for_each_expr.cpp remove unneeded iterator functions 2024-09-23 12:59:04 +01:00
for_each_expr.h remove unneeded iterator functions 2024-09-23 12:59:04 +01:00
format.cpp fix #6530 2023-01-10 13:43:17 -08:00
format.h call it data instead of c_ptr for approaching C++11 std::vector convention. 2021-04-13 18:17:35 -07:00
fpa_decl_plugin.cpp Centralize and document TRACE tags using X-macros (#7657) 2025-05-28 14:31:25 +01:00
fpa_decl_plugin.h remove default destructors 2024-10-02 22:20:12 +01:00
func_decl_dependencies.cpp
func_decl_dependencies.h booyah 2020-07-04 15:56:30 -07:00
has_free_vars.cpp fixup std-order / inv-order 2024-10-03 19:35:16 -07:00
has_free_vars.h tune q-eval and q-ematch 2021-09-28 13:41:37 -07:00
is_variable_test.h Add and fix a few general compiler warnings. (#5628) 2021-10-29 15:42:32 +02:00
justified_expr.h move from justified_expr to dependent_expr by aligning datatypes 2025-01-22 11:46:10 -08:00
macro_substitution.cpp remove using insert_if_not_there2 2020-04-25 15:08:51 -07:00
macro_substitution.h booyah 2020-07-04 15:56:30 -07:00
num_occurs.cpp build warning 2020-05-02 15:51:12 -07:00
num_occurs.h Add and fix a few general compiler warnings. (#5628) 2021-10-29 15:42:32 +02:00
occurs.cpp wip - alpha support for polymorphism 2023-07-12 18:09:02 -07:00
occurs.h #6805 2023-07-11 09:41:29 -07:00
pb_decl_plugin.cpp working on python make for arm 2022-04-07 13:36:23 +02:00
pb_decl_plugin.h Remove empty leaf destructors. (#6211) 2022-07-30 10:07:03 +01:00
polymorphism_inst.cpp fix #7049 2023-12-08 13:05:21 -08:00
polymorphism_inst.h wip - alpha support for polymorphism 2023-07-12 18:09:02 -07:00
polymorphism_util.cpp Implement finite_set_decl_plugin with complete operator support and polymorphism infrastructure (#7961) 2025-10-13 10:58:53 +02:00
polymorphism_util.h Implement finite_set_decl_plugin with complete operator support and polymorphism infrastructure (#7961) 2025-10-13 10:58:53 +02:00
pp.cpp Centralize and document TRACE tags using X-macros (#7657) 2025-05-28 14:31:25 +01:00
pp.h booyah 2020-07-04 15:56:30 -07:00
pp_params.pyg print lemmas2console faster 2023-03-20 17:07:04 +01:00
quantifier_stat.cpp move common routines for quantifiers 2021-01-28 13:23:40 -08:00
quantifier_stat.h move common routines for quantifiers 2021-01-28 13:23:40 -08:00
recfun_decl_plugin.cpp Centralize and document TRACE tags using X-macros (#7657) 2025-05-28 14:31:25 +01:00
recfun_decl_plugin.h remove default destructors 2024-10-02 22:20:12 +01:00
recurse_expr.h booyah 2020-07-04 15:56:30 -07:00
recurse_expr_def.h call it data instead of c_ptr for approaching C++11 std::vector convention. 2021-04-13 18:17:35 -07:00
reg_decl_plugins.cpp Implement finite_set_decl_plugin with complete operator support and polymorphism infrastructure (#7961) 2025-10-13 10:58:53 +02:00
reg_decl_plugins.h booyah 2020-07-04 15:56:30 -07:00
scoped_proof.h overhaul of proof format for new solver 2022-08-28 17:44:33 -07:00
seq_decl_plugin.cpp Centralize and document TRACE tags using X-macros (#7657) 2025-05-28 14:31:25 +01:00
seq_decl_plugin.h Performance improvements for seq-sls (#7519) 2025-01-21 08:01:59 -08:00
shared_occs.cpp fix #4112 2020-04-26 21:04:28 -07:00
shared_occs.h cleanup 2022-11-24 22:46:35 +07:00
special_relations_decl_plugin.cpp add EUF plugin framework. 2023-11-30 13:58:30 -08:00
special_relations_decl_plugin.h add EUF plugin framework. 2023-11-30 13:58:30 -08:00
static_features.cpp Centralize and document TRACE tags using X-macros (#7657) 2025-05-28 14:31:25 +01:00
static_features.h disable new code until pre-condition gets fixed 2022-11-30 22:29:59 -08:00
used_symbols.h booyah 2020-07-04 15:56:30 -07:00
used_vars.cpp #5259 - the Ranjit 2s shave 2021-05-12 10:43:16 -07:00
used_vars.h #5259 - the Ranjit 2s shave 2021-05-12 10:43:16 -07:00
value_generator.cpp Mark override methods appropriately. (#6207) 2022-07-29 23:29:15 +02:00
value_generator.h Use = default for virtual constructors. 2022-08-05 18:11:46 +03:00
well_sorted.cpp Centralize and document TRACE tags using X-macros (#7657) 2025-05-28 14:31:25 +01:00
well_sorted.h booyah 2020-07-04 15:56:30 -07:00