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

Add UnliftedRef #198

Open
treeowl opened this issue Aug 15, 2018 · 6 comments
Open

Add UnliftedRef #198

treeowl opened this issue Aug 15, 2018 · 6 comments

Comments

@treeowl
Copy link
Collaborator

treeowl commented Aug 15, 2018

I believe we should be able to unsafeCoerce# our way into references containing TYPE 'UnliftedRep. This is horrible, of course, but also useful. We can support all the usual MutVar operations except atomicModifyMutVar* ones.

@andrewthad
Copy link
Collaborator

I don’t quite understand what you mean. Would this just be backed by an UnliftedArray of length 1?

@treeowl
Copy link
Collaborator Author

treeowl commented Aug 16, 2018

I mean backed by a MutVar# for now. But what I really want to do is fix RuntimeRep so we won't need UnliftedArray#. I want

data RuntimeRep
  = PtrRep Levity
  | ...
data Levity = Lifted | Unlifted
type Type = TYPE ('PtrRep 'Lifted)
data MutableArray# :: Type -> TYPE ('PtrRep levity) -> TYPE ('PtrRep 'Unlifted)
data MutVar# :: Type -> TYPE ('PtrRep levity) -> TYPE ('PtrRep 'Unlifted)
...

In that regime, most MutVar# operations would be levity-polymorphic, but atomicModifyMutVar2# and atomicModifyMutVar_# would only be available for lifted types.

@andrewthad
Copy link
Collaborator

Ah, thanks for clarifying. Now I get it. This seems reasonable, and it should work. It would be nice to fix RuntimeRep as you suggest. The documentation of mkWeak# even hints at this shortcoming of the current system.

@treeowl
Copy link
Collaborator Author

treeowl commented Aug 16, 2018

OTOH, maybe that doesn't help much. We still couldn't write user functions that didn't care about levity....

@andrewthad
Copy link
Collaborator

True. We could unify the types but we would still need an extra copy of all the functions. Unless someone finds a good way to allow levity polymorphism in binding positions.

@konsumlamm
Copy link
Contributor

Since GHC 9.4, MutVar# is levity polymorphic, so this can be now implemented by just making MutVar levity polymorphic too - no unsafeCoerce# needed. See #356.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants