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

extended calculation of info for regexes #4656

Merged
merged 12 commits into from
Aug 22, 2020

Conversation

veanes
Copy link
Collaborator

@veanes veanes commented Aug 21, 2020

Added new fields to the info object and implemented their calculation rules.
In particular, this fixes some earlier issues with
min-length of compl as well as min-length of difference (that was buggy).
Also updated tracing of state_graph with regex info.
Introduced the trace tag "re_info" to trace info calculation of new regex expressions.

@NikolajBjorner
Copy link
Contributor

NikolajBjorner commented Aug 21, 2020

There are build warnings for the initialization order.

You want this list:

	                valid(true), classical(is_classical), standard(is_standard), interpreted(is_interpreted), nonbranching(is_nonbranching),
                normalized(is_normalized), monadic(is_monadic), nullable(is_nullable), singleton(is_singleton), 
                min_length(min_l), star_height(star_h) {}

To have the same order as the appearances in the declarations.
Singleton and nullable are swapped.

             ^
src/smt/smt_context_inv.cpp
src/smt/theory_bv.cpp
src/smt/theory_str_regex.cpp
In file included from ../src/ast/static_features.h:26:0,
                 from ../src/smt/asserted_formulas.h:22,
                 from ../src/smt/smt_context.h:40,
                 from ../src/smt/smt_context_inv.cpp:19:
../src/ast/seq_decl_plugin.h: In constructor ‘seq_util::rex::info::info(bool, bool, bool, bool, bool, bool, bool, lbool, unsigned int, unsigned int)’:
../src/ast/seq_decl_plugin.h:432:19: warning: ‘seq_util::rex::info::nullable’ will be initialized after [-Wreorder]
             lbool nullable;
                   ^
../src/ast/seq_decl_plugin.h:430:18: warning:   ‘bool seq_util::rex::info::singleton’ [-Wreorder]
             bool singleton;
                  ^
../src/ast/seq_decl_plugin.h:446:13: warning:   when initialized here [-Wreorder]
             info(bool is_classical, 
             ^
In file included from ../src/ast/static_features.h:26:0,
                 from ../src/smt/asserted_formulas.h:22,
                 from ../src/smt/smt_context.h:40,
                 from ../src/smt/theory_bv.cpp:19:
../src/ast/seq_decl_plugin.h: In constructor ‘seq_util::rex::info::info(bool, bool, bool, bool, bool, bool, bool, lbool, unsigned int, unsigned int)’:
../src/ast/seq_decl_plugin.h:432:19: warning: ‘seq_util::rex::info::nullable’ will be initialized after [-Wreorder]
             lbool nullable;
                   ^
../src/ast/seq_decl_plugin.h:430:18: warning:   ‘bool seq_util::rex::info::singleton’ [-Wreorder]
             bool singleton;
                  ^
../src/ast/seq_decl_plugin.h:446:13: warning:   when 

/* All bounded loops have a body that is a singleton. */
bool monadic;
/* Positive Boolean combination of ranges or predicates or singleton sequences. */
bool singleton;
Copy link
Contributor

Choose a reason for hiding this comment

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

need to be in same order during initialization

min_length = std::min(i1.min_length, i2.min_length);
nullable = (i1.nullable == i2.nullable ? i1.nullable : l_undef);
//TBD: whether ite is interpreted or not depends on whether the condition is interpreted and both branches are interpreted
return info(false, false, false, false, i1.normalized && i2.normalized, i1.monadic && i2.monadic, i1.singleton && i2.singleton, nullable, min_length, std::max(i1.star_height, i2.star_height));
}
return invalid_info;
Copy link
Contributor

Choose a reason for hiding this comment

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

Since it is possible to return invalid_info, the combiners need to be defined if one of the infos is invalid.
Currently, initialization of invalid infos leave a lot of fields uninitialized. This leads to undefined behavior.

/*
Constructs an invalid info
*/
info() : valid(false) {}
Copy link
Contributor

Choose a reason for hiding this comment

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

better to assign default initialization to all fields.
You can use the syntax

     lbool nullable { l_undef };

in the declarations to indicate default initializers.

case OP_RE_STAR:
i1 = get_info_rec(e->get_arg(0));
return info(i1.classical, i1.classical, i1.interpreted, i1.nonbranching, i1.normalized, i1.monadic, false, l_true, 0, i1.star_height + 1);
Copy link
Contributor

@NikolajBjorner NikolajBjorner Aug 21, 2020

Choose a reason for hiding this comment

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

Seems cleaner if you simply update i1, such as i1.star_height++;

@NikolajBjorner
Copy link
Contributor

Note the build failures

uded from ../src/ast/rewriter/arith_rewriter.h:23:0,
                 from ../src/smt/arith_eq_solver.h:20,
                 from ../src/smt/arith_eq_solver.cpp:17:
../src/ast/seq_decl_plugin.h:488:23: error: expected class-name before ‘(’ token
             info compl() const;
                       ^

and regression failure (on the win64 build)

@veanes
Copy link
Collaborator Author

veanes commented Aug 21, 2020

hopefully fixed regression (forgotten return stmt)
not sure about .."expected class-name before ‘(’ toke"
I believe this was because compl() declaration order did not match definition order?
With VS neither gave any compilation errors.

@NikolajBjorner NikolajBjorner merged commit db65381 into Z3Prover:master Aug 22, 2020
info opt() const;
info complement() const;
info concat(info & rhs, bool lhs_is_concat) const;
info disj(info& rhs) const;
Copy link
Contributor

Choose a reason for hiding this comment

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

info const& rhs ?

};
private:
seq_util& u;
ast_manager& m;
family_id m_fid;
vector<info> mutable m_infos;
expr_ref_vector mutable m_info_pinned;
info invalid_info;
info invalid_info{ info(l_undef) };
Copy link
Contributor

Choose a reason for hiding this comment

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

space after info before {

/* Value is either undefined (known=l_undef) or defined and known (l_true) or defined but unknown (l_false)*/
lbool known{ l_undef };
/* No complement, no intersection, no difference, and no if-then-else is used. Reverse is allowed. */
bool classical{ false };
Copy link
Contributor

Choose a reason for hiding this comment

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

space between classical and {

case OP_RE_UNION:
i1 = get_info_rec(e->get_arg(0));
i2 = get_info_rec(e->get_arg(1));
return info(std::min(i1.min_length, i2.min_length));
return i1.disj(i2);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this was for the better. If you are really into overloading, you can use operator| or operator|| instead of disj.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I did these updates and also updated loop info calculation, worked on the same branch but since the PR was closed, I guess I need to open a new one for these

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.

3 participants