Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parametric and mutually recursive datatypes #275

Open
wants to merge 50 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
48e6395
Encodes most functionality for generic sorts to work with inductive d…
Jun 24, 2021
2c76b83
Cleaned up the code, removed erroneous print statements, eliminated t…
Jun 25, 2021
6e2d3aa
Updated tweaks to match pr feedback
Jun 25, 2021
73091eb
Made the requested tweaks and created a generic_datatype.h file. The …
Jun 28, 2021
f404a60
Present version contains tweaks in response to the pull request as we…
Jun 28, 2021
186c44b
Contains PR tweaks, non-compiling file, as well as consistent style.
Jun 28, 2021
8222f9d
Contains all the revisions in response to the last pr (like moving th…
Jul 2, 2021
932e72e
Completely reworked generic_datatype.h and cpp. Should still work wit…
Jul 3, 2021
4edb86e
Completely reworked generic_datatype.h and cpp. Should still work wit…
Jul 3, 2021
29821d9
Commit for git clang reformatting
Jul 6, 2021
c235259
Responded to most requested changes in the last pr. Due to weirdness …
Jul 6, 2021
524b305
Added fixes for the generic datatype implementation, and made generic…
Jul 7, 2021
9656480
First iteration of response to requested changes.
Jul 8, 2021
107c61c
Added responses to most requested changes and removed commented lines
Jul 8, 2021
9112316
Additional tweaks, refined testing for the datatype sorts.
Jul 9, 2021
be07ff9
MAde additional tweaks, fleshed out testing.
Jul 9, 2021
8b138d9
Reworked add_selector_self to work with the new file framework. Added…
Jul 10, 2021
23741f5
Another round of responses to requested changes.
Jul 13, 2021
a7092b0
Properly functional add_selector_self as well as style fixes.
Jul 14, 2021
b348d61
Added style tweaks and self selector functionality.
Jul 14, 2021
f85666c
Response to another wave of revisions. Still needs to surmount undefi…
Jul 15, 2021
0ea3911
PR revision requests. Mostly style tweaks.
Jul 16, 2021
e2cf3d4
PR tweaks.
Jul 16, 2021
29779b9
PR tweaks and style adjustements.
Jul 16, 2021
00ddb30
PR tweaks
Jul 16, 2021
f806fc8
Extensive documentation added
Jul 17, 2021
51766d1
Added extensive comments and documentation.
Jul 17, 2021
55377b1
Relevant to current PR
Jul 21, 2021
f212c02
New branch
Jul 21, 2021
013a0ed
test
Jul 23, 2021
84fdf16
functionality changes
Jul 23, 2021
ea37bbc
Working get_constructor, tester functions. I'm struggling with how to…
Jul 24, 2021
e4f86bb
Fully functioning representation of datatype components as terms
Jul 28, 2021
32791ac
Clang formatted
Jul 28, 2021
cb59ed9
Addtl. files to commit
Jul 28, 2021
c436995
Merge remote-tracking branch 'upstream/master' into dt_sort_inf
Jul 28, 2021
7f2c0ca
PR revisions
Aug 1, 2021
1e55c49
clang formatted
Aug 1, 2021
84b121f
forgot to add the type checking
Aug 2, 2021
5c4fb58
clang formatted
Aug 2, 2021
630c193
pr revisions
Aug 4, 2021
dbbf72b
clang formatted
Aug 4, 2021
450158a
test proven parametric datatypes
Aug 18, 2021
d001672
working tests for parametric datatypes
Aug 18, 2021
ca5c402
partial recursive functionality
Aug 20, 2021
35c73b5
Merge remote-tracking branch 'upstream/master' into par_dt
Aug 20, 2021
d6bf1fa
Fully working mutually recursive datatypes
Aug 21, 2021
cff090b
clang formatted
Aug 21, 2021
86f90d4
add some style tweaks
Aug 24, 2021
632ad9e
Merge remote-tracking branch 'upstream/master' into par_dt
Aug 24, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion include/generic_datatype.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,16 @@ class GenericDatatypeDecl : public AbsDatatypeDecl
public:
GenericDatatypeDecl(const std::string name);
virtual ~GenericDatatypeDecl(){};
std::string get_name();
std::string get_name() const;
int get_param_count() const;
std::vector<Sort> get_param_sorts();
void register_param_sort(std::string param_name);

protected:
friend class GenericSolver;
std::string dt_name;
int param_count;
std::vector<Sort> param_sorts;
};

class GenericDatatypeConstructorDecl : public AbsDatatypeConstructorDecl
Expand All @@ -46,10 +51,13 @@ class GenericDatatypeConstructorDecl : public AbsDatatypeConstructorDecl
int get_selector_count() const;
bool compare(const DatatypeConstructorDecl & d) const override;
std::string get_dt_name() const;
void add_selector_param(const std::string & name, int param_num);

protected:
std::vector<SelectorComponents> selector_vector;
std::string cons_name;
bool contains_param;

DatatypeDecl dt_decl;
// Setter for the dt_decl member. Only to be used when a constructor
// is added to a datatype. datatype_decl: The DatatypeDecl of the datatype.
Expand Down Expand Up @@ -85,6 +93,7 @@ class GenericDatatype : public AbsDatatype

protected:
DatatypeDecl dt_decl;

std::vector<DatatypeConstructorDecl> cons_decl_vector;

friend class GenericSolver;
Expand Down
8 changes: 8 additions & 0 deletions include/generic_solver.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ class GenericSolver : public AbsSmtSolver
Sort make_sort(const Sort & sort_con, const SortVec & sorts) const override;
// Mutually recursive datatypes are currently not supported.
Sort make_sort(const DatatypeDecl & d) const override;

DatatypeDecl make_datatype_decl(const std::string & s) override;

DatatypeConstructorDecl make_datatype_constructor_decl(
const std::string s) override;
void add_constructor(DatatypeDecl & dt,
Expand All @@ -60,11 +62,16 @@ class GenericSolver : public AbsSmtSolver
const Sort & s) const override;
void add_selector_self(DatatypeConstructorDecl & dt,
const std::string & name) const override;
Sort get_unresolved_sort(DatatypeDecl dt_decl);

Term get_constructor(const Sort & s, std::string name) const override;
Term get_tester(const Sort & s, std::string name) const override;
Term get_selector(const Sort & s,
std::string con,
std::string name) const override;
SortVec make_datatype_sorts(
const std::vector<DatatypeDecl> & decls,
const UnorderedSortSet & uninterp_sorts) const override;

/***************************************************************/
/* methods from AbsSmtSolver that are implemented */
Expand Down Expand Up @@ -266,6 +273,7 @@ class GenericSolver : public AbsSmtSolver
std::unique_ptr<
std::unordered_map<std::shared_ptr<GenericDatatype>, std::string>>
datatype_name_map;
std::unique_ptr<std::unordered_map<int, std::string>> par_map;
};

} // namespace smt
32 changes: 32 additions & 0 deletions include/generic_sort.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
namespace smt {

class GenericDatatye;

/* Helper functions for creating generic sorts */
Sort make_uninterpreted_generic_sort(std::string name, uint64_t arity);
Sort make_uninterpreted_generic_sort(Sort sort_cons, const SortVec& sorts);
Expand All @@ -37,6 +38,9 @@ Sort make_generic_sort(SortKind sk, Sort sort1, Sort sort2, Sort sort3);
Sort make_generic_sort(SortKind sk, SortVec sorts);
Sort make_generic_sort(Datatype dt);
Sort make_generic_sort(SortKind sk, std::string cons_name, Sort dt);
Sort make_generic_param_sort(std::string param_name);
Sort make_generic_datatype_sort(Datatype dt);
Sort make_generic_unresolved_sort(DatatypeDecl dt);
/* smtlib representation of sort kinds */
std::string to_smtlib(SortKind);

Expand Down Expand Up @@ -232,4 +236,32 @@ class DatatypeComponentSort : public GenericSort
Sort selector_sort;
};

class ParamSort : public GenericSort
{
public:
ParamSort(std::string param_name);
~ParamSort(){};
std::string get_uninterpreted_name() const override;
std::string compute_string() const override;

protected:
std::string name;
};

class UnresolvedSort : public GenericSort
{
public:
UnresolvedSort(DatatypeDecl dt_decl);
~UnresolvedSort(){};
std::string compute_string() const override;
std::string to_string() const override;
DatatypeDecl get_datatype_decl();
std::vector<std::string> get_params();
void insert_param(std::string new_param);

protected:
DatatypeDecl datatype_decl;
std::vector<std::string> params_vector;
};

} // namespace smt
14 changes: 7 additions & 7 deletions include/solver.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,15 +239,15 @@ class AbsSmtSolver
* If no symbol of that name has been declared, throws
* IncorrectUsageException
*
* Allows a user to look up a symbol by name. This can be very useful for term
* translation, since we can look up symbols instead of keeping track of the
* mapping via externally populated caches (in the case where the target
* Allows a user to look up a symbol by name. This can be very useful for
* term translation, since we can look up symbols instead of keeping track of
* the mapping via externally populated caches (in the case where the target
* solver has already been used).
*
* Note, solver backend deals with the implementation. The main motivation for
* this is that each backend solver has to own the symbol table. If the symbol
* table were stored in AbsSmtSolver then it would get destructed after the
* backend solver which has bad refcounting implications for many solvers.
* Note, solver backend deals with the implementation. The main motivation
* for this is that each backend solver has to own the symbol table. If the
* symbol table were stored in AbsSmtSolver then it would get destructed after
* the backend solver which has bad refcounting implications for many solvers.
*
* @param name the name of the symbol to look up
* @return the Term representation of the corresponding symbol
Expand Down
2 changes: 2 additions & 0 deletions include/sort.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ enum SortKind
CONSTRUCTOR,
SELECTOR,
TESTER,
PARAM,
UNRESOLVED,

/** IMPORTANT: This must stay at the bottom.
It's only use is for sizing the kind2str array
Expand Down
43 changes: 40 additions & 3 deletions src/generic_datatype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,37 @@ using namespace std;

namespace smt {

GenericDatatypeDecl::GenericDatatypeDecl(const std::string name) : dt_name(name)
GenericDatatypeDecl::GenericDatatypeDecl(const std::string name)
: dt_name(name), param_count(0)
{
}

std::string GenericDatatypeDecl::get_name() { return dt_name; }
std::string GenericDatatypeDecl::get_name() const { return dt_name; }

int GenericDatatypeDecl::get_param_count() const { return param_count; }

std::vector<Sort> GenericDatatypeDecl::get_param_sorts() { return param_sorts; }

void GenericDatatypeDecl::register_param_sort(std::string param_name)
{
for (unsigned int i = 0; i < param_count; ++i)
{
// Checks if the selector has already been added
if (param_sorts[i]->to_string() == param_name)
{
// throw "Can't add selector. It already exists in this
// datatype!";
return;
}
}
Sort new_param = make_generic_param_sort(param_name);
param_sorts.push_back(new_param);
param_count += 1;
}

GenericDatatypeConstructorDecl::GenericDatatypeConstructorDecl(
const std::string & name)
: cons_name(name)
: cons_name(name), contains_param(false)
{
}

Expand Down Expand Up @@ -87,6 +109,21 @@ void GenericDatatype::add_constructor(
}
shared_ptr<GenericDatatypeConstructorDecl> gdt_cons =
static_pointer_cast<GenericDatatypeConstructorDecl>(dt_cons_decl);

if (gdt_cons->contains_param == true)
{
for (int i = 0; i < gdt_cons->get_selector_count(); ++i)
{
if (gdt_cons->get_selector_vector()[i].sort->get_sort_kind()
== SortKind::PARAM)
{
static_pointer_cast<GenericDatatypeDecl>(dt_decl)->register_param_sort(
static_pointer_cast<ParamSort>(
gdt_cons->get_selector_vector()[i].sort)
->to_string());
}
}
}
// Links the constructor to the datatype_decl of the datatype
gdt_cons->update_stored_dt(dt_decl);
// Links the datatype to the new constructor
Expand Down
Loading