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 RefUnwindSafe StorageHandle #675

Merged
merged 2 commits into from
Feb 17, 2025

Conversation

Veykril
Copy link
Member

@Veykril Veykril commented Feb 6, 2025

David noticed in rust-lang/rust-analyzer#18964 that Storage isn't unwind safe (on a related note it also obviously isn't sync due to the local state). So this is a proposed design at solving this by introducing a non-local state handle (which hence disallows running computations on it). This would allow you to have a non-local state handle, move that across unwind boundaries, threads, etc and once you need todo computations you can turn it into a handle with local state.

In rust-analyzer I would imagine us holding such a non-local state handle in the main global state and whenever we dispatch a request, clone it, move the clone off to the dispatching thread and then materialize it as a local-state hanlde (Storage).

We could directly implement UnwindSafe on Storage (note how we used to implement RefUnwindSafe already, which is the wrong trait at this stage of the setup), given that if we have no references outstanding the query stack will be empty anyways and so we wouldn't run into issues with moving it across an unwind boundary. That doesn't sit quite right with me though so instead I've opted for this setup, as it also feels like a natural extension to the API to me. A side effect of this is that the non-local handle is Sync, though that is likely not too useful as there is no reason to wrap it inside (interior) mutability.

I've added respective RefUnwindSafe implementations where required to make the auto trait impls work as expected with comments explaining the rationale as to why they ought to be correct.

cc @davidbarsky

Copy link

netlify bot commented Feb 6, 2025

Deploy Preview for salsa-rs canceled.

Name Link
🔨 Latest commit 6fef6b2
🔍 Latest deploy log https://app.netlify.com/sites/salsa-rs/deploys/67b32627510587000862cbb1

Copy link

codspeed-hq bot commented Feb 6, 2025

CodSpeed Performance Report

Merging #675 will not alter performance

Comparing Veykril:veykril/push-xsrukmlqwrlm (6fef6b2) with master (1c7a070)

Summary

✅ 9 untouched benchmarks

@Veykril Veykril force-pushed the veykril/push-xsrukmlqwrlm branch from 25154f7 to 4e44751 Compare February 11, 2025 10:56
Copy link
Contributor

@davidbarsky davidbarsky left a comment

Choose a reason for hiding this comment

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

sorry for the delay; approved modulo nits.

@Veykril Veykril force-pushed the veykril/push-xsrukmlqwrlm branch from 4e44751 to 6fef6b2 Compare February 17, 2025 12:05
@Veykril Veykril added this pull request to the merge queue Feb 17, 2025
Merged via the queue into salsa-rs:master with commit 4b74edf Feb 17, 2025
9 checks passed
@Veykril Veykril deleted the veykril/push-xsrukmlqwrlm branch February 17, 2025 12:07
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.

2 participants