-
Notifications
You must be signed in to change notification settings - Fork 45
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
Add partial string support #327
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for doing this! We have been wanting this for a while...
Some general comments:
- We don't have a strict clang-format policy, we still some lines look too long, it is better to try keep it under 80 characters per line. Also, clang-formatting of course wouldn't hurt (but not necessary).
- You might want to split this PR to 2 PRs -- the string related stuff and the other stuff. But up to you.
- While the implementation generally looks fine to me, it is really hard to tell if it works without tests. It would be great if you could add tests that exercise every function that you've implemented. You can find examples in the
tests
directory.
contrib/setup-cvc5.sh
Outdated
# echo "$DEPS/cvc5 already exists. If you want to rebuild, please remove it manually." | ||
cd $DEPS | ||
cd cvc5 | ||
cd build | ||
make -j$NUM_CORES | ||
cd $DIR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure this is what we want to do.
If the directory already exists, then this would probably mean that cvc5
is already built in it, no?
include/solver.h
Outdated
@@ -210,6 +210,28 @@ class AbsSmtSolver | |||
*/ | |||
virtual Term make_term(int64_t i, const Sort & sort) const = 0; | |||
|
|||
/* Make a string value term | |||
* @param s is the value | |||
* @param useEscSequences is the useEscSequences in String constructor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment is not very clear. What is the string constructor? And what does useEscSequences
mean? It might be the case that this documentation line is too specific to cvc5
, while it should be more general.
include/solver.h
Outdated
*/ | ||
virtual Term make_term(const std::wstring& s, const Sort & sort) const{ | ||
throw NotImplementedException("Strings not supported for this solver."); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cvc5/src/cvc5_term.cpp
Outdated
@@ -50,6 +50,7 @@ const std::unordered_map<::cvc5::Kind, PrimOp> kind2primop( | |||
{ ::cvc5::NEG, Negate }, | |||
{ ::cvc5::MULT, Mult }, | |||
{ ::cvc5::DIVISION, Div }, | |||
{ ::cvc5::INTS_DIVISION, IntDiv }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder -- integer division is already tested, including with cvc5:
Line 49 in f2d7d3d
Term div = s->make_term(IntDiv, five, two); |
How come we need to add it now?
src/generic_solver.cpp
Outdated
{ | ||
Term value_term = make_value(s, useEscSequences, sort); | ||
return store_term(value_term); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} | |
} | |
src/generic_solver.cpp
Outdated
assert(sk == STRING); | ||
string repr; | ||
repr = std::to_string(s); | ||
Term term = std::make_shared<GenericTerm>(sort, Op(), TermVec{}, repr); //figure out how to handle useEscSequences |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this figured out yet? :)
If not -- what exactly is the issue?
If so, the comment can be removed.
src/generic_solver.cpp
Outdated
SortKind sk = sort->get_sort_kind(); | ||
assert(sk == STRING); | ||
string repr; | ||
repr = std::to_string(s); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will that always work? Is it always possible to convert a wstring
to a string
?
…t for strings in generic solver in this PR
…o add-strings The changes are caused by resolving conflict with main.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, a few final minor comments.
cvc5/src/cvc5_solver.cpp
Outdated
std::string msg = "Can't create constant with string and useEscSequences"; | ||
msg += useEscSequences; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::string msg = "Can't create constant with string and useEscSequences"; | |
msg += useEscSequences; | |
std::string msg = "Can't create a string constant |
cvc5/src/cvc5_solver.cpp
Outdated
} | ||
else | ||
{ | ||
std::string msg = "Can't create constant with wstring for sort "; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::string msg = "Can't create constant with wstring for sort "; | |
std::string msg = "Can't create string constant for sort "; |
cvc5/src/cvc5_solver.cpp
Outdated
// Indexed Op | ||
{ Int_To_BV, ::cvc5::Kind::INT_TO_BITVECTOR }, | ||
{ StrLt, ::cvc5::Kind::STRING_LT }, | ||
{ StrLeq, ::cvc5::Kind::STRING_LEQ }, | ||
{ StrLen, ::cvc5::Kind::STRING_LENGTH }, | ||
{ StrConcat, ::cvc5::Kind::STRING_CONCAT }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Indexed Op | |
{ Int_To_BV, ::cvc5::Kind::INT_TO_BITVECTOR }, | |
{ StrLt, ::cvc5::Kind::STRING_LT }, | |
{ StrLeq, ::cvc5::Kind::STRING_LEQ }, | |
{ StrLen, ::cvc5::Kind::STRING_LENGTH }, | |
{ StrConcat, ::cvc5::Kind::STRING_CONCAT }, | |
// String Op | |
{ StrLt, ::cvc5::Kind::STRING_LT }, | |
{ StrLeq, ::cvc5::Kind::STRING_LEQ }, | |
{ StrLen, ::cvc5::Kind::STRING_LENGTH }, | |
{ StrConcat, ::cvc5::Kind::STRING_CONCAT }, | |
// Indexed Op | |
{ Int_To_BV, ::cvc5::Kind::INT_TO_BITVECTOR }, |
|
||
return res; | ||
} | ||
Term LoggingSolver::make_term(const std::wstring& s, const Sort & sort) const{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Term LoggingSolver::make_term(const std::wstring& s, const Sort & sort) const{ | |
Term LoggingSolver::make_term(const std::wstring& s, const Sort & sort) const{ |
tests/cvc5/cvc5-str.cpp
Outdated
** directory for licensing information.\endverbatim | ||
** | ||
** \brief | ||
** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
** | |
** Tests for strings in the cvc5 backend. |
tests/cvc5/cvc5-str.cpp
Outdated
{ | ||
SmtSolver s = Cvc5SolverFactory::create(false); | ||
s->set_opt("produce-models", "true"); | ||
//s->set_opt("strings-exp", "true"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
//s->set_opt("strings-exp", "true"); |
tests/test-str.cpp
Outdated
// use this line for printing wstrings | ||
//#include <locale> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// use this line for printing wstrings | |
//#include <locale> |
tests/test-str.cpp
Outdated
// an example of printing wstrx1 | ||
//std::cout << x1 << " = "; | ||
//std::wcout << wstrx1 << std::endl; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// an example of printing wstrx1 | |
//std::cout << x1 << " = "; | |
//std::wcout << wstrx1 << std::endl; |
Co-authored-by: yoni206 <yoni206@users.noreply.github.com>
…o add-strings Minor change
Added string support for StrLt "str.<", StrLeq "str.<=", StrLen "str.len", StrConcat, "str.++". |
Added string support for StrLt "str.<", StrLeq "str.<=", StrLen "str.len", StrConcat, "str.++".
Also, added support for IntDiv, ::cvc5::INTS_DIVISION, FLOAT parsing, and made changes to TermTranslator::infixize_rational.