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

Refactor assert orders #699

Merged
merged 39 commits into from
Dec 17, 2024
Merged

Refactor assert orders #699

merged 39 commits into from
Dec 17, 2024

Conversation

schuessf
Copy link
Contributor

@schuessf schuessf commented Dec 3, 2024

This PR aims to refactor the assert orders. Currently the situation is as follows:

  • We have several assert orders (see AssertCodeBlockOrderType). NOT_INCREMENTALLY is handled in the class AnnotateAndAsserter, while all the others are handled in the subclass AnnotateAndAsserterWithStmtOrderPrioritization (that hardly makes use of the methods of the superclass).
  • The assert orders in AnnotateAndAsserterWithStmtOrderPrioritization are just methods (e.g. annotateAndAssertOutsideLoopFirst1) that doe not only the partitioning of the trace, but also asserts the SSA directly and thus returns a LBool.

This situation is not nice for several reasons:

  • NOT_INCREMENTALLY does not need any special handling, it can be also seen as an assert order that partitions the trace into a single partition.
  • AnnotateAndAsserterWithStmtOrderPrioritization contains many methods that just belong to a single assertion order.
  • We were thinking to combine two assertion order, which is not possible for now, as the methods are not really modular.

Therefore the following changes were made:

  • Assert orders are now an implementation of the new interface IAssertOrder with a single methods that performs the partitioning, but not the assertion itself.
  • Code that is shared between different assert orders was moved from AnnotateAndAsserterWithStmtOrderPrioritization to the new class AssertOrderUtils
  • For NOT_INCREMENTALLY there exists also an implementation of IAssertOrder, AssertOrderNotIncrementally. Therefore AnnotateAndAsserter is no more required and thus was deleted and AnnotateAndAsserterWithStmtOrderPrioritization was renamed to AnnotateAndAsserter
  • In AnnotateAndAsserter we first create an instance of the desired IAssertOrder in getAssertOrder, perform the partioning and then assert the partioned SSA in annotateAndAssert (which was previosuly performed by every assert order itself).

Note: I ran already the nightly build, but there was a small bug (connected to #692). I just fixed it and re-ran the nightly build.

Copy link
Member

@danieldietsch danieldietsch left a comment

Choose a reason for hiding this comment

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

Looks very good and is a really nice change!

Copy link
Contributor

@maul-esel maul-esel left a comment

Choose a reason for hiding this comment

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

Nice :)


/**
* Partition the statement positions between lowerIndex and upperIndex according to their depth. (See documentation
* for the meaning of 'depth'). The result is stored in the map 'depth2Statements'. The partitioning is done
Copy link
Contributor

Choose a reason for hiding this comment

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

Where is this documentation regarding the meaning of "depth"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should be fixed, this part was removed and some documentation added to partitionStatementsAccordingDepth.

mAnnotSSA.setFormulaAtNonCallPos(i, mAnnotateAndAssertCodeBlocks.annotateAndAssertNonCall(i));
}
}

assert callPositions.containsAll(mTrace.getCallPositions());
assert mTrace.getCallPositions().containsAll(callPositions);
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you intend to remove these checks?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, that's interesting: These checks were not present in AnnotateAndAsserterWithStmtOrderPrioritization (which is the basis for the new AnnotateAndAsserter). Therefore I also removed the variable callPositions, because it was unused. But I think it does not hurt to add these checks again.

Copy link
Contributor Author

@schuessf schuessf Dec 3, 2024

Choose a reason for hiding this comment

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

Wait, these assertions state that all calls of the trace are already asserted. This is only reasonable, if the whole SSA is asserted here. We could keep the second assertion, but it would be trivially satisfied, since for all i, if trace.isCallPosition(i) is true, then i is element of trace.getCallPositions(). So I think it is reasonable to remove these assertions.

@schuessf schuessf merged commit 3ddba7f into dev Dec 17, 2024
2 checks passed
@schuessf schuessf deleted the wip/fs/assert-orders branch December 17, 2024 14:03
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