Skip to content

introduce goto_programt::instructiont::type() and _nonconst() #6412

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
merged 2 commits into from
Oct 26, 2021

Conversation

kroening
Copy link
Member

This introduces two methods to read and write the type of a GOTO program
instruction, and replaces various direct accesses.

  • 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 Oct 22, 2021

Codecov Report

Merging #6412 (13c2919) into develop (093a216) will increase coverage by 0.00%.
The diff coverage is 84.67%.

Impacted file tree graph

@@           Coverage Diff            @@
##           develop    #6412   +/-   ##
========================================
  Coverage    75.98%   75.98%           
========================================
  Files         1524     1524           
  Lines       164242   164241    -1     
========================================
  Hits        124801   124801           
+ Misses       39441    39440    -1     
Impacted Files Coverage Δ
src/analyses/global_may_alias.cpp 0.00% <0.00%> (ø)
src/goto-instrument/points_to.cpp 0.00% <0.00%> (ø)
src/goto-instrument/uninitialized.cpp 0.00% <0.00%> (ø)
src/goto-programs/remove_unused_functions.cpp 0.00% <0.00%> (ø)
src/goto-symex/symex_main.cpp 85.93% <40.00%> (ø)
src/goto-programs/interpreter.cpp 51.64% <50.00%> (ø)
src/goto-programs/goto_program.cpp 69.74% <75.00%> (ø)
jbmc/src/java_bytecode/remove_exceptions.cpp 95.52% <100.00%> (-0.03%) ⬇️
...rams/remove_virtual_functions_without_fallback.cpp 98.70% <100.00%> (ø)
...a_bytecode_instrument/virtual_call_null_checks.cpp 97.82% <100.00%> (ø)
... and 37 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 e7eff1e...13c2919. Read the comment docs.

Copy link
Member

@peterschrammel peterschrammel left a comment

Choose a reason for hiding this comment

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

💡 I think by introducing turn_into_assume (we've already got turn_into_skip), we can do without type_nonconst().

i1->source_location_nonconst() = instruction.source_location();
i1->code_nonconst() = code_declt(symbol_expr);

i2->type=ASSIGN;
i2->type_nonconst() = ASSIGN;
Copy link
Member

Choose a reason for hiding this comment

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

use the 2-param variant of insert_after?

@@ -120,11 +120,11 @@ void uninitializedt::add_assertions(
id2string(identifier)+"#initialized";

symbol_exprt symbol_expr(new_identifier, bool_typet());
i1->type=DECL;
i1->type_nonconst() = DECL;
Copy link
Member

Choose a reason for hiding this comment

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

use the 2-param variant of insert_after?

@@ -421,7 +421,7 @@ bool remove_exceptionst::instrument_throw(
exc_thrown,
typecast_exprt(exc_expr, exc_thrown.type()));
// now turn the `throw' into `assignment'
instr_it->type=ASSIGN;
instr_it->type_nonconst() = ASSIGN;
Copy link
Member

Choose a reason for hiding this comment

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

swap?

@@ -846,7 +846,7 @@ void disjunctive_polynomial_accelerationt::build_fixed()
{
if(instruction.is_assert())
{
instruction.type = ASSUME;
instruction.type_nonconst() = ASSUME;
Copy link
Member

Choose a reason for hiding this comment

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

turn_into_assume?

This method turns a GOTO or an ASSERT instruction into an ASSUME with the
same condition.  This is a common pattern in the code base, and introducing
the method enables doing so in a way that is guaranteed to preserve the
class invariants.
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.

Seems reasonable.

/// Set the kind of the instruction.
/// This method is best avoided to prevent mal-formed instructions.
/// Consider using the goto_programt::make_X methods instead.
goto_program_instruction_typet &type_nonconst()
Copy link
Collaborator

Choose a reason for hiding this comment

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

As this only has 7 users, would it be better to just refactor those and not have this functionality at all? Alternatively, could this be marked as deprecated?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Aren't we even down to 2 users, one of which can easily be fixed and the other being read_bin_goto_object? I think the latter could be handled by some low-level constructor that likely wants to be private with access only permitted via a friend declaration.

@kroening
Copy link
Member Author

I've added turn_into_assume, which removes some usage of type_nonconst().

This introduces two methods to read and write the type of a GOTO program
instruction, and replaces various direct accesses.
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.

It would be great to figure out a story for the nonconst case right away.

Comment on lines 58 to +59
const auto back_edge = add_instruction(back_edge_location, instructions);
back_edge->type = GOTO;
back_edge->type_nonconst() = GOTO;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can't we use make_goto for this one?

Copy link
Member Author

Choose a reason for hiding this comment

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

add_instruction() in that unit test should be replaced altogether, but this goes beyond this PR.

/// Set the kind of the instruction.
/// This method is best avoided to prevent mal-formed instructions.
/// Consider using the goto_programt::make_X methods instead.
goto_program_instruction_typet &type_nonconst()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Aren't we even down to 2 users, one of which can easily be fixed and the other being read_bin_goto_object? I think the latter could be handled by some low-level constructor that likely wants to be private with access only permitted via a friend declaration.

@kroening
Copy link
Member Author

Changing read_bin_goto_object is a major rejfactoring of that piece of code; much more involved than the initial scope of the PR. I'd do this separately.

@kroening kroening merged commit 6351d3a into develop Oct 26, 2021
@kroening kroening deleted the instructiont_type branch October 26, 2021 20:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants