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

introduce index_type and element_type for arrays and vectors #6552

Merged
merged 1 commit into from
Jan 12, 2022

Conversation

kroening
Copy link
Member

This commit introduces convenience methods for retrieving the type of the
elements and of the indices for array and vector types. This avoids using a
global, architecture-dependent function to generate the index type.

  • 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.
  • n/a White-space or formatting changes outside the feature-related changed lines are in commits of their own.

@codecov
Copy link

codecov bot commented Dec 28, 2021

Codecov Report

Merging #6552 (5ba2935) into develop (e4c5999) will decrease coverage by 0.00%.
The diff coverage is 56.75%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #6552      +/-   ##
===========================================
- Coverage    75.98%   75.98%   -0.01%     
===========================================
  Files         1578     1578              
  Lines       181058   181070      +12     
===========================================
+ Hits        137579   137585       +6     
- Misses       43479    43485       +6     
Impacted Files Coverage Δ
src/goto-cc/gcc_cmdline.cpp 74.80% <ø> (ø)
src/goto-instrument/goto_program2code.cpp 68.32% <0.00%> (ø)
src/util/std_expr.h 92.04% <ø> (ø)
src/solvers/flattening/boolbv_get.cpp 82.03% <23.07%> (-0.72%) ⬇️
src/util/std_types.cpp 85.71% <50.00%> (-1.65%) ⬇️
src/util/std_types.h 95.01% <50.00%> (-0.57%) ⬇️
src/goto-symex/field_sensitivity.cpp 90.96% <100.00%> (ø)
src/goto-symex/symex_builtin_functions.cpp 93.35% <100.00%> (ø)
src/util/pointer_offset_size.cpp 92.18% <100.00%> (+0.02%) ⬆️

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 9b72a5c...5ba2935. Read the comment docs.

Copy link
Collaborator

@tautschnig tautschnig left a comment

Choose a reason for hiding this comment

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

Shouldn't we rather strive towards a situation where an array index can be of an arbitrary numeric type?

src/goto-instrument/goto_program2code.cpp Outdated Show resolved Hide resolved
src/solvers/flattening/boolbv_get.cpp Outdated Show resolved Hide resolved
/// The type of the elements of the array.
const typet &element_type() const
{
return subtype();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we actually hide subtype() for array_typet and vector_typet?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, that will improve readability.

@@ -768,6 +768,15 @@ class array_typet:public type_with_subtypet
add(ID_size, std::move(_size));
}

/// The type of the index expressions into any instance of this type.
typet index_type() const;
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 concerned that this may be confusing: we could end up in a situation where array.index().type() != array.index_type()!

Copy link
Member Author

Choose a reason for hiding this comment

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

I'd like to enforce that, going forward, using a precondition.

@kroening
Copy link
Member Author

Shouldn't we rather strive towards a situation where an array index can be of an arbitrary numeric type?

I did consider it, but I don't think it's a good idea.

  1. It would be problematic to use the SMT-LIB array theory, which is basically a map type.
  2. Expressions that one would expect to be identical are not. Say a[1] and a[1l] would be different.

@kroening kroening force-pushed the index_type branch 2 times, most recently from bd9f103 to de7ed5b Compare December 29, 2021 17:18
@tautschnig
Copy link
Collaborator

Shouldn't we rather strive towards a situation where an array index can be of an arbitrary numeric type?

I did consider it, but I don't think it's a good idea.

1. It would be problematic to use the SMT-LIB array theory, which is basically a map type.

2. Expressions that one would expect to be identical are not. Say a[1] and a[1l] would be different.

Will it always be possible to have the same index type, even when linking together objects from different source languages, for example C and Java?

@kroening
Copy link
Member Author

Will it always be possible to have the same index type, even when linking together objects from different source languages, for example C and Java?

The plan is to make the index type part of the array type; you can then mix as you see fit.

Copy link
Collaborator

@tautschnig tautschnig left a comment

Choose a reason for hiding this comment

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

My concerns/comments that I've left unresolved remain in place, but approving nonetheless.

@kroening
Copy link
Member Author

My concerns/comments that I've left unresolved remain in place, but approving nonetheless.

Both of these won't be easy -- look at the branch typet_subtype

This commit introduces convenience methods for retrieving the type of the
elements and of the indices for array and vector types.  This avoids using a
global, architecture-dependent function to generate the index type.
@kroening kroening merged commit 90bcd52 into develop Jan 12, 2022
@kroening kroening deleted the index_type branch January 12, 2022 15:42
@TGWDB TGWDB mentioned this pull request May 31, 2023
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.

4 participants