mirror of
https://github.com/Z3Prover/z3
synced 2026-08-04 21:23:36 +00:00
`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>
76 lines
1.7 KiB
C++
76 lines
1.7 KiB
C++
/*++
|
|
Copyright (c) 2015 Microsoft Corporation
|
|
|
|
Module Name:
|
|
|
|
ast_pp_util.h
|
|
|
|
Abstract:
|
|
|
|
Utilities for printing SMT2 declarations and assertions.
|
|
|
|
Author:
|
|
|
|
Nikolaj Bjorner (nbjorner) 2015-8-6.
|
|
|
|
Revision History:
|
|
|
|
--*/
|
|
#pragma once
|
|
|
|
#include "ast/decl_collector.h"
|
|
#include "ast/ast_smt2_pp.h"
|
|
#include "util/obj_hashtable.h"
|
|
#include "util/stacked_value.h"
|
|
|
|
class ast_pp_util {
|
|
ast_manager& m;
|
|
obj_hashtable<func_decl> m_removed;
|
|
smt2_pp_environment_dbg m_env;
|
|
stacked_value<unsigned> m_rec_decls;
|
|
stacked_value<unsigned> m_decls;
|
|
stacked_value<unsigned> m_sorts;
|
|
stacked_value<unsigned> m_type_vars;
|
|
expr_mark m_is_defined;
|
|
expr_ref_vector m_defined;
|
|
unsigned_vector m_defined_lim;
|
|
|
|
public:
|
|
|
|
decl_collector coll;
|
|
|
|
ast_pp_util(ast_manager& m): m(m), m_env(m), m_rec_decls(0), m_decls(0), m_sorts(0), m_type_vars(0), m_defined(m), coll(m) {}
|
|
|
|
void reset();
|
|
|
|
void collect(expr* e);
|
|
|
|
void collect(unsigned n, expr* const* es);
|
|
|
|
void collect(expr_ref_vector const& es);
|
|
|
|
void remove_decl(func_decl* f);
|
|
|
|
void display_decls(std::ostream& out);
|
|
|
|
void display_skolem_decls(std::ostream& out);
|
|
|
|
void display_asserts(std::ostream& out, expr_ref_vector const& fmls, bool neat = true);
|
|
|
|
void display_assert(std::ostream& out, expr* f, bool neat = true);
|
|
|
|
void display_assert_and_track(std::ostream& out, expr* f, expr* t, bool neat = true);
|
|
|
|
std::ostream& display_expr(std::ostream& out, expr* f, bool neat = true);
|
|
|
|
std::ostream& define_expr(std::ostream& out, expr* f);
|
|
|
|
std::ostream& display_expr_def(std::ostream& out, expr* f);
|
|
|
|
void push();
|
|
|
|
void pop(unsigned n);
|
|
|
|
smt2_pp_environment& env() { return m_env; }
|
|
};
|
|
|