Skip to content

Supports nested quantifiers in function contracts #5968

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

Merged

Conversation

ArenBabikian
Copy link
Contributor

This PR adds support for nested quantified expressions in function contracts. It is a direct extension to #5959

  • Each commit message has a non-empty body, explaining why the change was made.
  • Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/
  • Regression or unit tests are included, or existing tests cover the modified code (in this case I have detailed which ones those are in the commit message).
  • My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • White-space or formatting changes outside the feature-related changed lines are in commits of their own.

Copy link
Collaborator

@martin-cs martin-cs left a comment

Choose a reason for hiding this comment

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

Has potential but I think some changes may be needed.

@feliperodri feliperodri added aws Bugs or features of importance to AWS CBMC users Code Contracts Function and loop contracts labels Mar 29, 2021
@ArenBabikian ArenBabikian force-pushed the contracts-quantifiers-nested branch 2 times, most recently from dcfb077 to 202359e Compare April 2, 2021 14:25
@ArenBabikian ArenBabikian marked this pull request as ready for review April 2, 2021 14:40
@codecov
Copy link

codecov bot commented Apr 2, 2021

Codecov Report

Merging #5968 (9c9de7b) into develop (72d84b8) will increase coverage by 0.12%.
The diff coverage is 59.37%.

❗ Current head 9c9de7b differs from pull request most recent head 33b412b. Consider uploading reports for the commit 33b412b to get more accurate results
Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #5968      +/-   ##
===========================================
+ Coverage    74.02%   74.14%   +0.12%     
===========================================
  Files         1444     1444              
  Lines       157307   157341      +34     
===========================================
+ Hits        116441   116656     +215     
+ Misses       40866    40685     -181     
Impacted Files Coverage Δ
src/goto-instrument/code_contracts.h 94.11% <ø> (ø)
src/solvers/smt2/smt2_conv.h 100.00% <ø> (ø)
src/solvers/smt2/smt2_conv.cpp 60.07% <22.22%> (+0.12%) ⬆️
src/goto-harness/goto_harness_parse_options.cpp 68.37% <60.00%> (-0.05%) ⬇️
src/goto-instrument/code_contracts.cpp 84.41% <100.00%> (+0.87%) ⬆️
src/ansi-c/literals/convert_character_literal.cpp 31.70% <0.00%> (-19.52%) ⬇️
src/goto-programs/read_goto_binary.cpp 30.84% <0.00%> (-16.83%) ⬇️
src/ansi-c/c_typecheck_type.cpp 62.96% <0.00%> (-13.43%) ⬇️
src/util/mp_arith.cpp 41.55% <0.00%> (-9.10%) ⬇️
src/util/std_types.cpp 83.95% <0.00%> (-4.94%) ⬇️
... and 29 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d98b56b...33b412b. Read the comment docs.

Copy link
Collaborator

@feliperodri feliperodri left a comment

Choose a reason for hiding this comment

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

LGTM module the requested changes from @SaswatPadhi

Copy link
Collaborator

@martin-cs martin-cs left a comment

Choose a reason for hiding this comment

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

Looks good in principle but please can you use the appropriate exprt types rather than just pulling things out of the operators array.

@ArenBabikian ArenBabikian force-pushed the contracts-quantifiers-nested branch 2 times, most recently from fbeef9e to 9c925b9 Compare April 9, 2021 14:25
Copy link
Contributor

@SaswatPadhi SaswatPadhi left a comment

Choose a reason for hiding this comment

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

Approving since it's not a blocker, but it would be nice to use const references (const T &) in place of copies (T) wherever possible.

@@ -168,23 +169,56 @@ void code_contractst::add_quantified_variable(
replace_symbolt &replace,
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we use const exprt& expression?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently, I do not think that it is possible. But I the medium/long term, we should get rid of this parameter entirely.

Copy link
Collaborator

@martin-cs martin-cs left a comment

Choose a reason for hiding this comment

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

Approve subject to the requested corrections.

Where possible use the named / most specific accessor functions. This is to avoid the need to rummage around in the irept formatting. In most cases it is just stylistic but in the case of quantifiers it is covering a bug.

// 1. get quantified symbol
quantifier_exprt quantifier_expression = to_quantifier_expr(expression);
exprt tuple = quantifier_expression.operands().at(0);
exprt quantified_variable = tuple.operands().at(0);
Copy link
Collaborator

Choose a reason for hiding this comment

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

The other ones I have flagged are style but here it really matters, you should use variables() and where() so that you can handle the case of multiple quantified variables.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have made the modification as requested. However, I would like to point out that currently, it seems like quantifier expressions with multiple variables are not fully handled (or used, at least). This can be fixed in a separate PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, in my experience, most call sites use .symbol() in place of .variables() and expect a quantifier over a single variable. But thanks for the fix here. Looks good to me and we could add a regression test later once we handle multi-variable quantification properly.

@ArenBabikian ArenBabikian force-pushed the contracts-quantifiers-nested branch 3 times, most recently from 7e02564 to 4e6f2a7 Compare April 9, 2021 19:43
This adds support for nested quantifiers in funtion contracts.
We recursively handle quantifiers that are nested within other
quantifiers or within Boolean connectives.
@ArenBabikian ArenBabikian force-pushed the contracts-quantifiers-nested branch from 4e6f2a7 to 33b412b Compare April 9, 2021 19:49
@SaswatPadhi SaswatPadhi merged commit d79e5f0 into diffblue:develop Apr 9, 2021
@ArenBabikian ArenBabikian deleted the contracts-quantifiers-nested branch April 12, 2021 12:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aws Bugs or features of importance to AWS CBMC users Code Contracts Function and loop contracts
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants