Skip to content

Conversation

@Ptival
Copy link

@Ptival Ptival commented Nov 4, 2025

Following the merge of #1219 , it would be nice to scatter the termination module, in such a way that one could require some termination measures without having to include every single instruction in their output.

The main culprit here was compressed_measure, but once that one is scattered (thanks @jn80842), it's a small extra step to just move around the rest of the code and get rid of the termination module altogether.

I tried to remove all references to the module, but may have missed some.

I was also instructed that the termination measures for vmem_read_addr and vmem_write_addr might no longer need to be protected only for the Rocq output, so they get taken out of the $iftarget coq.

I have only tested the Lean output, so I'm hoping the CI will check whether my changes are consistent.

Happy to discuss any of the decisions I made, they could be based on incorrect assumptions on my end.

@jordancarlin
Copy link
Collaborator

Would #905 eliminate the need for compressed_measure? If so, maybe we should get that PR updated and merged first.

@pmundkur
Copy link
Collaborator

pmundkur commented Nov 4, 2025

Would #905 eliminate the need for compressed_measure? If so, maybe we should get that PR updated and merged first.

That's blocked on rems-project/sail#1357, so I'm okay with merging this first and removing compressed_measure later.

@pmundkur
Copy link
Collaborator

pmundkur commented Nov 4, 2025

@Ptival looks like this needs newlines at end-of-file fixes to pass pre-commit.

@Ptival
Copy link
Author

Ptival commented Nov 4, 2025

Looks like I might have broken something on the Lean side too, I'll investigate:

https://github.com/riscv/sail-riscv/actions/runs/19080408022/job/54510837967

@Ptival Ptival marked this pull request as draft November 4, 2025 20:53
@Ptival Ptival force-pushed the vr/scatter-termination branch from ef03dc8 to b3a7375 Compare November 5, 2025 21:23
@github-actions
Copy link

github-actions bot commented Nov 5, 2025

Test Results

2 115 tests  ±0   2 115 ✅ ±0   20m 53s ⏱️ +4s
    1 suites ±0       0 💤 ±0 
    1 files   ±0       0 ❌ ±0 

Results for commit 762e228. ± Comparison against base commit 91178c8.

♻️ This comment has been updated with latest results.

@Ptival Ptival force-pushed the vr/scatter-termination branch 3 times, most recently from f5c10d0 to cd5a62a Compare November 6, 2025 01:11
Copy link
Collaborator

@Timmmm Timmmm left a comment

Choose a reason for hiding this comment

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

This looks much better to me! It would be good to get an explanation of exactly what this is for and how it works for people who aren't formal experts.

@Ptival Ptival force-pushed the vr/scatter-termination branch 2 times, most recently from 647b481 to 83fcead Compare November 6, 2025 18:02
@pmundkur
Copy link
Collaborator

pmundkur commented Nov 6, 2025

FYI, I was able to rebase #905 (as #1382), which removed the measure for execute but also broke Lean in a new way (I think).

@Ptival Ptival force-pushed the vr/scatter-termination branch from 83fcead to 61540a5 Compare November 6, 2025 21:40
@Ptival
Copy link
Author

Ptival commented Nov 6, 2025

FYI, I was able to rebase #905 (as #1382), which removed the measure for execute but also broke Lean in a new way (I think).

Ah interesting, I'm going to have a quick look at why your error happens.

In the meantime, I have updated the currentlyEnabled_measure with working values. I added comment with the dependency chain I witnessed for future reference.

Leaving this as a draft PR until we figure out whether we can remove the whole compressed_measure.

@pmundkur pmundkur added the refactor Code clean up label Nov 7, 2025
@Ptival Ptival force-pushed the vr/scatter-termination branch 4 times, most recently from 8eebf25 to 65d90f2 Compare November 18, 2025 22:18
@Ptival Ptival marked this pull request as ready for review November 18, 2025 22:19
@Ptival
Copy link
Author

Ptival commented Nov 18, 2025

I have followed the removal of compressed_measure, added some comments over the termination measures, and it seems to work well for my purposes.

Copy link
Collaborator

@pmundkur pmundkur left a comment

Choose a reason for hiding this comment

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

LGTM. Since the measures are now appearing in the main code, it would be helpful to have some explanatory comments where previously there weren't any.

Ok(data)
}

termination_measure vmem_read_addr repeat n
Copy link
Collaborator

Choose a reason for hiding this comment

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

It would be helpful to explain the repeat construct here, and refer to it for the vmem_write_addr case below.

Copy link
Author

@Ptival Ptival Nov 19, 2025

Choose a reason for hiding this comment

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

I honestly don't know what this does precisely.

It's not very documented... according to the syntax documentation in the SAIL repo this shouldn't even be valid syntax...
image

@Alasdair I think maybe you added this, could you explain to me what this variant of termination_measure is?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure if I added it, but it's a termination measure for the loop in the function body. In the syntax repeat n is a valid loop_measure.

I think this can be placed inline and attached to the loop itself, which might be more clear.

Copy link
Author

Choose a reason for hiding this comment

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

Ah, I think I saw the syntax for putting it next to the loop, I will give it a try, as I agree it would be more clear.

Copy link
Author

Choose a reason for hiding this comment

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

Alright, I attempted something. It needs magic_hash for some reason. I'll wait for CI to check because I think this is specifically exercised by the Rocq backend.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We shouldn't use that option in the model, it's for debugging generated code that uses internally generated identifiers that can't clash with user identifiers (by allowing it to be passed back into the frontend) . If it doesn't support it we should just keep the termination measure separate for now. I also don't guarantee that debug flags will persist between Sail versions, and that flag has mostly been superseeded by the $sail_internal directive which is file-local and more descriptive, so it is actual risk of being removed.

I'm really not sure why using an inline termination measure would require that option anyway. I'll look into changing that.

Copy link
Author

Choose a reason for hiding this comment

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

Alright I reverted it!

@Ptival Ptival force-pushed the vr/scatter-termination branch 3 times, most recently from 5ddc35b to 762e228 Compare November 19, 2025 19:55
@Ptival Ptival force-pushed the vr/scatter-termination branch from 762e228 to 9714790 Compare November 21, 2025 17:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Code clean up

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants