Skip to content

introduce __CPROVER_map type #7096

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

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft

introduce __CPROVER_map type #7096

wants to merge 1 commit into from

Conversation

kroening
Copy link
Member

@kroening kroening commented Sep 2, 2022

This introduces C syntax for a type

__CPROVER_map( domain , codomain )

where domain is a list of types and codomain is a type. The type is
internal, for modeling purposes. It replaces arrays with size
__CPROVER_constant_infinity_uint, which are now deprecated.

  • 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.
  • n/a 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).
  • n/a 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.

@codecov
Copy link

codecov bot commented Sep 2, 2022

Codecov Report

Merging #7096 (14cf4a9) into develop (381b34d) will increase coverage by 0.01%.
The diff coverage is 86.39%.

@@             Coverage Diff             @@
##           develop    #7096      +/-   ##
===========================================
+ Coverage    77.85%   77.86%   +0.01%     
===========================================
  Files         1574     1576       +2     
  Lines       181245   181541     +296     
===========================================
+ Hits        141109   141358     +249     
- Misses       40136    40183      +47     
Impacted Files Coverage Δ
src/ansi-c/c_typecheck_base.h 100.00% <ø> (ø)
src/ansi-c/parser.y 80.11% <0.00%> (-0.37%) ⬇️
src/ansi-c/scanner.l 63.29% <0.00%> (-0.06%) ⬇️
..._incremental/smt2_incremental_decision_procedure.h 75.00% <ø> (ø)
src/solvers/smt2_incremental/smt_solver_process.h 100.00% <ø> (ø)
src/ansi-c/c_typecheck_type.cpp 76.61% <14.28%> (-0.50%) ⬇️
src/goto-instrument/contracts/inlining_decorator.h 34.78% <34.78%> (ø)
...c/goto-instrument/contracts/inlining_decorator.cpp 62.29% <62.29%> (ø)
...lvers/smt2_incremental/smt_response_validation.cpp 95.58% <86.48%> (-2.30%) ⬇️
src/ansi-c/expr2c.cpp 67.33% <100.00%> (+0.16%) ⬆️
... and 13 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@tautschnig
Copy link
Collaborator

Could we please include some documentation of this, especially as there also is an intent to deprecate existing functionality?

@tautschnig
Copy link
Collaborator

Also, could we please have some tests?

@remi-delmas-3000
Copy link
Collaborator

Hi, some questions regarding the feature:

  • how do you define the value of the map for a given input (__CPROVER_assume or assignment ?)
  • what's the syntax like for indexing into/calling the map ?
  • are these usable with DECL or can we also __CPROVER_allocate these maps ?
  • is it possible to have pointers to such maps ?
  • how are they modelled under the hood (axioms ? how does this get translated to SAT, what is the complexity of the SAT encoding ?)

Thanks

@kroening kroening force-pushed the map_type branch 3 times, most recently from 5b58406 to f718eb4 Compare December 11, 2024 21:07
@kroening
Copy link
Member Author

Hi, some questions regarding the feature:

  • how do you define the value of the map for a given input (__CPROVER_assume or assignment ?)

Using a lambda.

  • what's the syntax like for indexing into/calling the map ?

It's a function, so f(args).

  • are these usable with DECL or can we also __CPROVER_allocate these maps ?

DECL only. These do not have an in-memory representation.

  • is it possible to have pointers to such maps ?

No. But you can have maps of maps.

  • how are they modelled under the hood (axioms ? how does this get translated to SAT, what is the complexity of the SAT encoding ?)

It's the existing Ackermann reduction.

@kroening kroening force-pushed the map_type branch 2 times, most recently from 82f715e to 48e4eb8 Compare December 12, 2024 02:56
Comment on lines 1 to 6
CORE
basic1.c

^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
Copy link
Collaborator

Choose a reason for hiding this comment

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

Somewhat random place for comment: I'd also like to see a failing test.

@@ -2534,6 +2534,7 @@ void c_typecheck_baset::typecheck_side_effect_function_call(
function_application_exprt function_application(f_op, expr.arguments());

function_application.add_source_location() = expr.source_location();
function_application.type() = mathematical_function_type.codomain();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Was this a bug? Did we not bump into this before?

{
const mathematical_function_typet &function_type =
to_mathematical_function_type(src);
std::string dest = CPROVER_PREFIX "map(";
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 really the only case of a mathematical function?

Comment on lines 5 to 13
my_map = __CPROVER_lambda
{
int i;
i == 1 ? 10 : 20
};

__CPROVER_assert(my_map(1) == 10, "(1)");
__CPROVER_assert(my_map(2) == 20, "(2)");
Copy link
Collaborator

Choose a reason for hiding this comment

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

  1. Can one also use assumptions to have values in a map?
  2. Is there any (other) way to incrementally populate a map?

This introduces C syntax for a type

  __CPROVER_map(domain, codomain)

where domain is a list of types and codomain is a type.  The type is
internal, for modeling purposes within our own library only, and hence not
added to user-facing documentation.  It replaces arrays with size
__CPROVER_infinity, which are now deprecated.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants