mirror of
https://github.com/Z3Prover/z3
synced 2026-08-03 04:33:28 +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
2 KiB
C++
76 lines
2 KiB
C++
/*++
|
|
Copyright (c) 2011 Microsoft Corporation
|
|
|
|
Module Name:
|
|
|
|
decl_collector.h
|
|
|
|
Abstract:
|
|
|
|
Collect uninterpreted func_delcs and sorts.
|
|
This class was originally in ast_smt_pp.h
|
|
|
|
Author:
|
|
|
|
Leonardo (leonardo) 2011-10-04
|
|
|
|
Revision History:
|
|
|
|
--*/
|
|
#pragma once
|
|
|
|
#include "util/top_sort.h"
|
|
#include "util/lim_vector.h"
|
|
#include "ast/ast.h"
|
|
#include "ast/datatype_decl_plugin.h"
|
|
#include "ast/array_decl_plugin.h"
|
|
|
|
class decl_collector {
|
|
ast_manager & m;
|
|
lim_svector<sort*> m_sorts;
|
|
lim_svector<sort*> m_type_vars;
|
|
lim_svector<func_decl*> m_decls;
|
|
lim_svector<func_decl*> m_rec_decls;
|
|
ast_mark m_visited;
|
|
ast_ref_vector m_trail;
|
|
unsigned_vector m_trail_lim;
|
|
family_id m_basic_fid;
|
|
family_id m_dt_fid;
|
|
datatype_util m_dt_util;
|
|
array_util m_ar_util;
|
|
family_id m_rec_fid;
|
|
ptr_vector<ast> m_todo;
|
|
|
|
void visit_sort(sort* n);
|
|
bool is_bool(sort* s);
|
|
|
|
typedef obj_hashtable<sort> sort_set;
|
|
sort_set* collect_deps(sort* s);
|
|
void collect_deps(top_sort<sort>& st);
|
|
void collect_deps(sort* s, sort_set& set);
|
|
|
|
public:
|
|
decl_collector(ast_manager & m);
|
|
|
|
bool should_declare(func_decl* f) const;
|
|
|
|
void reset() { m_sorts.reset(); m_type_vars.reset(); m_decls.reset(); m_visited.reset(); m_trail.reset(); }
|
|
void visit_func(func_decl* n);
|
|
void visit(ast * n);
|
|
void visit(unsigned n, expr* const* es);
|
|
void visit(expr_ref_vector const& es);
|
|
|
|
void push();
|
|
void pop(unsigned n);
|
|
|
|
void order_deps(unsigned n);
|
|
|
|
unsigned get_num_sorts() const { return m_sorts.size(); }
|
|
unsigned get_num_decls() const { return m_decls.size(); }
|
|
|
|
lim_svector<sort*> const& get_sorts() const { return m_sorts; }
|
|
lim_svector<sort*> const& get_type_vars() const { return m_type_vars; }
|
|
lim_svector<func_decl*> const& get_func_decls() const { return m_decls; }
|
|
lim_svector<func_decl*> const& get_rec_decls() const { return m_rec_decls; }
|
|
};
|
|
|