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

Remove Freeze #12683

Closed
nikomatsakis opened this issue Mar 4, 2014 · 12 comments
Closed

Remove Freeze #12683

nikomatsakis opened this issue Mar 4, 2014 · 12 comments
Labels
E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. P-medium Medium priority
Milestone

Comments

@nikomatsakis
Copy link
Contributor

In the discussion on #11781, it has become clear that there is still a role for Freeze, but likely not the Freeze kind we have today. Today Freeze is a property based on reachability, but this should likely change.

See comment here for details:

#11781 (comment)

@nikomatsakis nikomatsakis added this to the 1.0 milestone Mar 4, 2014
@nikomatsakis
Copy link
Contributor Author

Copying tags and labels from #11781. I can mentor.

@nikomatsakis
Copy link
Contributor Author

cc @flaper87

@nikomatsakis
Copy link
Contributor Author

cc @alexcrichton @thestinger

@flaper87 flaper87 self-assigned this Mar 4, 2014
@flaper87
Copy link
Contributor

flaper87 commented Mar 4, 2014

Since I'm working on the Share kind already, I'll stab this one too. (Although they are quite independent)

@nikomatsakis
Copy link
Contributor Author

Some more details and differences from today:

  • &mut T should be Freeze, I believe, since &&mut T doesn't permit mutations.
  • Similarly, closures and procs can be freeze, since they should not be callable from a & reference.

@alexcrichton
Copy link
Member

I believe that to remain sound we will have to simultaneously change the Freeze definition and add the Share bound (Freeze will no longer be sound for Arc)

@bill-myers
Copy link
Contributor

Maybe we should have both a shallow Freeze and a deep Freeze?

A deep Freeze trait is essential if one wants to have enforced pure functions (along with a way to dynamically disable TLS and global state).

Also, maybe HashMap should require keys to be deeply Freeze, since otherwise their hash might change unexpectedly (theoretically, another kind might be best here, but Freeze should work in practice).

But OTOH a shallow Freeze is useful for optimization and allowing to place data in read-only memory.

@thestinger
Copy link
Contributor

If you're not allowed to hide internal mutation as an implementation detail, then reference counting isn't the only thing you're unable to do. You can't use memory allocation at all. There's no working around the fact that free needs to mutate memory. There needs to be a clear definition of what is meant by this kind of immutability rather than just how it relates to reachability.

@zkamsler
Copy link
Contributor

zkamsler commented Mar 4, 2014

@thestinger @nikomatsakis's proposed definition (or my interpretation thereof) is fairly narrow. T can be Freeze iff the memory directly pointed at by &T cannot be changed. It is shallow and does not imply any logical immutability as the current definition might (although I am not entirely clear on the specifics of that). As such, the Freeze bound probably wouldn't be used in many places other than those that have already been enumerated.

@thestinger
Copy link
Contributor

What's a use case of Freeze then? After Share lands, the only use case I can think of is type-based alias analysis and it won't want this change of definition. The current definition isn't about a logical immutability - it's about shallow immutability.

Deep immutability seems almost meaningless, as I/O and memory allocation break the invariant. The concept does not exist in GCC or LLVM. It doesn't seem useful for enforcing purity, because the methods would already need to be marked as pure or they might be performing I/O without a handle from the object.

@zkamsler
Copy link
Contributor

zkamsler commented Mar 4, 2014

I think the major one was the initialization of static variables, and the aforementioned optimizations.
#11781 (comment)

@nikomatsakis
Copy link
Contributor Author

Today we decided to kill Freeze and instead rely on an Unsafe<T> type. Closing as dup of #12577.

flip1995 pushed a commit to flip1995/rust that referenced this issue May 2, 2024
…l, r=Manishearth

[`non_canonical_partial_ord_impl`]: Fix emitting warnings which conflict with `needless_return`

fixes rust-lang#12683

---

changelog: fix [`non_canonical_partial_ord_impl`] emitting warnings which conflict with `needless_return`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. P-medium Medium priority
Projects
None yet
Development

No branches or pull requests

6 participants