Skip to content

Write symbolic value at symbolic index #151

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 19 commits into from
Jul 9, 2025

Conversation

Stevengre
Copy link
Contributor

No description provided.

@Stevengre Stevengre requested a review from tothtamas28 June 23, 2025 14:39
@Stevengre Stevengre self-assigned this Jun 23, 2025
@Stevengre Stevengre requested a review from jberthold June 23, 2025 14:46
…ing a boolean wrapper for symbolic writes. This update includes detailed explanations of termination control, reordering for optimization, and write consolidation strategies. Adjusted comments for clarity and improved documentation.
rule #WB(true, I, V, NUM, EF:SparseBytesEF) => writeBytesEF(I, V, NUM, EF) [simplification, concrete(I)]

// Reordering for Optimization
rule #WB(false, I0, V0, NUM0, #WB(true, I1, V1, NUM1, B:SparseBytes)) => #WB(true, I1, V1, NUM1, #WB(false, I0, V0, NUM0, B)) [simplification]
Copy link
Contributor

Choose a reason for hiding this comment

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

Is a requires clause missing here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't need requires clause there. It push uncompleted #WB down to the completed one with true as its first argument.

Copy link
Contributor

Choose a reason for hiding this comment

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

If so, why is it sound to reorder writes unconditionally, in particular, to the same index but with different values?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because the Write Consolidation simplification rules have higher priority.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In that case, I feel there might be some issues. If we add requires here, there could be situations where we cannot determine whether I0 and I1 are equal. This could lead to #WB that can never be completed. Because simplification rules also don't generate branches.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In fact, I want this rule to work like owise to tackle uninterpreted cases. Even though this cannot be the default case, we still need an owise to cover all situations.

Copy link
Contributor Author

@Stevengre Stevengre Jul 3, 2025

Choose a reason for hiding this comment

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

Suggested change
rule #WB(false, I0, V0, NUM0, #WB(true, I1, V1, NUM1, B:SparseBytes)) => #WB(true, I1, V1, NUM1, #WB(false, I0, V0, NUM0, B)) [simplification]
rule #WB(false, I0, V0, NUM0, #WB(true, I1, V1, NUM1, B:SparseBytes)) => #WB(true, I1, V1, NUM1, #WB(false, I0, V0, NUM0, B)) [simplification]
requires I0 =/=Int I1

Copy link
Member

Choose a reason for hiding this comment

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

As discussed on slack, the rule here is probably unsound when the written bytes overlap.
Example:
#WB(false, 0, 65535, 2, #WB( true, 1, 0, 1, bytes(b"\x00\x00")))
I can evaluate this directly to #WB(false, 0, 65535, 2, bytes(b"\x00\x00")) and then bytes(b"\xFF\xFF").
However, I could apply the simplification and get
#WB( true, 1, 0, 1, #WB(false, 0, 65535, 2, bytes(b"\x00\x00")))
but that would be #WB(true, 1, 0, 1, bytes(b"\xFF\xFF")) and then bytes(b"\xFF\x00")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added the suggested constraints on this rule.

…termination control, reordering for optimization, and write consolidation strategies. Update code examples for better understanding and consistency.
… Update documentation to emphasize the reordering optimization and the specific rule for merging operations with identical indices. Improve code examples for better clarity.
…ed the placement of the `requires` clause for clarity and consistency in simplification rules.
@Stevengre Stevengre requested a review from tothtamas28 July 7, 2025 02:45
@Stevengre
Copy link
Contributor Author

Hi @tothtamas28!

I tried adding the I0 =/= Int I1 constraints to that simp rule, but it caused src/tests/integration/test-data/specs/store-symbolic-index-value.k to fail. This indicates that the test effectively captures the simp rule's behavior. If the backend's handling of this situation changes in the future, we'll be able to catch it during our version update CI.

…ration rule for better handling of overlapping writes. Update test data to ensure no overlapping writes between different indices, improving clarity and correctness in the specifications.
@Stevengre Stevengre requested a review from jberthold July 8, 2025 07:12
…s. Update documentation to clarify the edge case for identical indices, ensuring operations are marked complete to prevent infinite rewriting cycles. Adjust simplification annotation for improved clarity.
Copy link
Member

@jberthold jberthold left a comment

Choose a reason for hiding this comment

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

Overall LGTM.
I left a few suggestions for improvements, but not necessarily on this same PR, could be done later if there are good reasons to merge this quickly.
I leave the approval to @tothtamas28 as I am unfamiliar with the surrounding code.

Comment on lines 28 to 30
(4 <=Int I0 orBool I0 +Int 4 <=Int 0) andBool
(4 <=Int I1 orBool I1 +Int 4 <=Int 0) andBool
(4 <=Int I2 orBool I2 +Int 4 <=Int 0) andBool
Copy link
Member

Choose a reason for hiding this comment

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

I think it is not very common to have so many orBool in the path condition.
Maybe you can make a few more tests, positive and negative (e.g. one like the counterexample I had) and replace the orBool conditions by more tests with one condition each?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

f8f74fd

The rule below handles a termination edge case: it immediately marks the operation as complete with reduced priority to avoid infinite rewriting cycles.

```k
rule #WB(false, I0, V0, NUM0, #WB(true, I1, V1, NUM1, B:SparseBytes)) => #WB(true, I0, V0, NUM0, #WB(true, I1, V1, NUM1, B)) [simplification(60)]
Copy link
Member

Choose a reason for hiding this comment

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

This rule might fire if the one above is not applied for random reasons, for instance SMT solver timeout. However, it will just cut the simplification short so it is sound.

Stevengre and others added 3 commits July 8, 2025 19:58
…to ensure truly non-overlapping writes. Update comments for improved clarity on index constraints and their relationships.
Co-authored-by: Jost Berthold <jost.berthold@gmail.com>
…-counter specification to clarify handling of perfect overlapping writes. Ensure that only the covering write is retained in the output, enhancing clarity on index relationships.
@automergerpr-permission-manager automergerpr-permission-manager bot merged commit 4df33d3 into master Jul 9, 2025
3 checks passed
@automergerpr-permission-manager automergerpr-permission-manager bot deleted the jh/sym-write-mem branch July 9, 2025 08:02
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.

4 participants