mirror of
https://github.com/Z3Prover/z3
synced 2026-07-24 16:02:33 +00:00
fix: declare type variables before use in solver display output (#10103)
`decl_collector::visit_sort` did not collect sorts with `poly_family_id`
(type variables created via `mk_type_var` / `declare-type-var`), so
`solver::display` and `ast_pp_util::display_decls` never emitted type
variable declarations before referencing them — producing invalid
SMT-LIB2 output.
## Changes
- **`src/ast/decl_collector.h`**: added a dedicated `lim_svector<sort*>
m_type_vars` field (separate from `m_sorts`) with a `get_type_vars()`
getter; `reset()` clears it; `push()`/`pop()` maintain its scope.
- **`src/ast/decl_collector.cpp` — `visit_sort`**: sorts with
`poly_family_id` are now pushed to `m_type_vars` instead of `m_sorts`,
keeping type variables distinct from uninterpreted sorts:
```cpp
if (m.is_uninterp(n))
m_sorts.push_back(n);
else if (fid == poly_family_id)
m_type_vars.push_back(n);
```
- **`src/ast/ast_pp_util.h`**: added a `stacked_value<unsigned>
m_type_vars` cursor to track which type variables have already been
printed.
- **`src/ast/ast_pp_util.cpp` — `display_decls`**: emits
`(declare-type-var <name>)` for each collected type variable before
other sort declarations; `reset()`/`push()`/`pop()` maintain the new
cursor.
**Example** — given `(declare-type-var A)(declare-fun f (A) A)`, the
dump now correctly produces:
```smt2
(declare-type-var A)
(declare-fun f (A) A)
(assert ...)
```
The output round-trips cleanly through the Z3 parser.
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
This commit is contained in:
parent
087eeaf33c
commit
634b2886ba
4 changed files with 19 additions and 4 deletions
|
|
@ -26,6 +26,8 @@ void decl_collector::visit_sort(sort * n) {
|
|||
family_id fid = n->get_family_id();
|
||||
if (m.is_uninterp(n))
|
||||
m_sorts.push_back(n);
|
||||
else if (fid == poly_family_id)
|
||||
m_type_vars.push_back(n);
|
||||
else if (fid == m_dt_fid) {
|
||||
m_sorts.push_back(n);
|
||||
for (func_decl * cnstr : *m_dt_util.get_datatype_constructors(n)) {
|
||||
|
|
@ -188,6 +190,7 @@ void decl_collector::collect_deps(sort* s, sort_set& set) {
|
|||
void decl_collector::push() {
|
||||
m_trail_lim.push_back(m_trail.size());
|
||||
m_sorts.push_scope();
|
||||
m_type_vars.push_scope();
|
||||
m_decls.push_scope();
|
||||
m_rec_decls.push_scope();
|
||||
}
|
||||
|
|
@ -200,6 +203,7 @@ void decl_collector::pop(unsigned n) {
|
|||
m_trail.shrink(sz);
|
||||
m_trail_lim.shrink(m_trail_lim.size() - n);
|
||||
m_sorts.pop_scope(n);
|
||||
m_type_vars.pop_scope(n);
|
||||
m_decls.pop_scope(n);
|
||||
m_rec_decls.pop_scope(n);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue