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

Add partial string support #327

Merged
merged 13 commits into from
Nov 1, 2023
Merged

Conversation

ntsis
Copy link
Contributor

@ntsis ntsis commented Aug 25, 2023

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.

Copy link
Collaborator

@yoni206 yoni206 left a 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:

  1. 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).
  2. You might want to split this PR to 2 PRs -- the string related stuff and the other stuff. But up to you.
  3. 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.

Comment on lines 29 to 34
# 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
Copy link
Collaborator

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
Copy link
Collaborator

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 Show resolved Hide resolved
include/solver.h Show resolved Hide resolved
include/solver.h Outdated
*/
virtual Term make_term(const std::wstring& s, const Sort & sort) const{
throw NotImplementedException("Strings not supported for this solver.");

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

@@ -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 },
Copy link
Collaborator

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:

Term div = s->make_term(IntDiv, five, two);

How come we need to add it now?

include/ops.h Outdated Show resolved Hide resolved
{
Term value_term = make_value(s, useEscSequences, sort);
return store_term(value_term);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}
}

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
Copy link
Collaborator

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.

SortKind sk = sort->get_sort_kind();
assert(sk == STRING);
string repr;
repr = std::to_string(s);
Copy link
Collaborator

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?

Copy link
Collaborator

@yoni206 yoni206 left a 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.

Comment on lines 207 to 208
std::string msg = "Can't create constant with string and useEscSequences";
msg += useEscSequences;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
std::string msg = "Can't create constant with string and useEscSequences";
msg += useEscSequences;
std::string msg = "Can't create a string constant

}
else
{
std::string msg = "Can't create constant with wstring for sort ";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
std::string msg = "Can't create constant with wstring for sort ";
std::string msg = "Can't create string constant for sort ";

Comment on lines 95 to 100
// 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 },
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// 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{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Term LoggingSolver::make_term(const std::wstring& s, const Sort & sort) const{
Term LoggingSolver::make_term(const std::wstring& s, const Sort & sort) const{

** directory for licensing information.\endverbatim
**
** \brief
**
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
**
** Tests for strings in the cvc5 backend.

{
SmtSolver s = Cvc5SolverFactory::create(false);
s->set_opt("produce-models", "true");
//s->set_opt("strings-exp", "true");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//s->set_opt("strings-exp", "true");

Comment on lines 20 to 21
// use this line for printing wstrings
//#include <locale>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// use this line for printing wstrings
//#include <locale>

Comment on lines 130 to 132
// an example of printing wstrx1
//std::cout << x1 << " = ";
//std::wcout << wstrx1 << std::endl;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// an example of printing wstrx1
//std::cout << x1 << " = ";
//std::wcout << wstrx1 << std::endl;

ntsis and others added 3 commits November 1, 2023 10:10
Co-authored-by: yoni206 <yoni206@users.noreply.github.com>
@yoni206
Copy link
Collaborator

yoni206 commented Nov 1, 2023

Added string support for StrLt "str.<", StrLeq "str.<=", StrLen "str.len", StrConcat, "str.++".

@yoni206 yoni206 merged commit a019770 into stanford-centaur:master Nov 1, 2023
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants