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

Decide on name for Freeze #131401

Open
traviscross opened this issue Oct 8, 2024 · 25 comments
Open

Decide on name for Freeze #131401

traviscross opened this issue Oct 8, 2024 · 25 comments
Labels
C-discussion Category: Discussion or questions that doesn't represent real issues. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. I-lang-bikeshed This item needs lang to commit to finishing a bikeshed. I-lang-radar Items that are on lang's radar and will need eventual work or consideration. proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@traviscross
Copy link
Contributor

We still need to pick a name for Freeze (which may still be Freeze) so that we can proceed with:

Thoughts?

cc @rust-lang/lang

@rustbot labels +T-lang +I-lang-nominated

@rustbot rustbot added needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. I-lang-nominated Nominated for discussion during a lang team meeting. T-lang Relevant to the language team, which will review and decide on the PR/issue. labels Oct 8, 2024
@traviscross traviscross added C-discussion Category: Discussion or questions that doesn't represent real issues. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Oct 8, 2024
@p-avital
Copy link

p-avital commented Oct 8, 2024

I'm reiterating my proposal from Zulip: keeping Freeze, and instead giving llvm's freeze a more explicit name. To quote myself from there:

I might just be misunderstanding the docs for the intrinsic, but it feels like it'd translate well to a MaybeUninit::read (as opposed to assume_init_read), or maybe deterministic_read or something alike to avoid it looking simpler than the current assume_init set

@traviscross
Copy link
Contributor Author

Let's see whether we have consensus to simply call it Freeze.

@rfcbot fcp merge

@rfcbot
Copy link

rfcbot commented Oct 8, 2024

Team member @traviscross has proposed to merge this. The next step is review by the rest of the tagged team members:

Concerns:

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns.
See this document for info about what commands tagged team members can give me.

@rfcbot rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Oct 8, 2024
@joshtriplett
Copy link
Member

I'm reiterating my proposal from Zulip: keeping Freeze, and instead giving llvm's freeze a more explicit name. To quote myself from there:

I might just be misunderstanding the docs for the intrinsic, but it feels like it'd translate well to a MaybeUninit::read (as opposed to assume_init_read), or maybe deterministic_read or something alike to avoid it looking simpler than the current assume_init set

I don't know if Freeze is the best name for this trait, but I definitely agree that freeze is not the best name for the the LLVM concept.

@joshtriplett
Copy link
Member

@rfcbot concern should-be-self-documenting-about-interior-mutability

I think we should use a name that's self-documenting and evokes the concept of interior mutability in some way.

@Scripter17
Copy link
Contributor

Would Frozen work?

@Amanieu
Copy link
Member

Amanieu commented Oct 23, 2024

I'm partial to the name InteriorImmutable for the Freeze trait (which was actually one of the alternatives listed in the RFC). All of the cell-related documentation already uses the term "interior mutability" and the trait name makes it clear that it means that the type does not contain a cell.

@traviscross
Copy link
Contributor Author

Stylistically, we don't end trait names with "-able". We have Copy and not Copyable, e.g. We just leaned on this principle in deciding to go with derive(CoercePointee) rather than various "-able" options in:

That is, trait names imply the capability to do the thing named in the trait.

What would be the version of an "interior immutable"-style name that matches that?

@Amanieu
Copy link
Member

Amanieu commented Oct 23, 2024

While "mutable" has a verb form "mutate", there isn't any verb equivalent of "immutable" ("not mutate"?). I would therefore argue for an exception to the -able policy for this specific case since "immutable" very clearly captures what this trait is promising.

An alternative that also captures the concept of interior mutability are might be NoInteriorMutate, but that just looks worse than InteriorImmutable since we're just arbitrarily avoiding the -able suffix.

@hkBst
Copy link
Member

hkBst commented Oct 23, 2024

Some variants to get the juices going:

  • NoInteriorMut / NoInternalMut / InternalNoMut / InternallyNoMut / InteriorNoMut,
  • NoInteriorChange / NoInternalChange / InternalNoChange / InteriorNoChange,
  • InternalConst / InternallyConst / InteriorConst`,
  • NoMut / NoChange
  • Changeless
  • Constant

@RalfJung
Copy link
Member

RalfJung commented Oct 23, 2024 via email

@traviscross
Copy link
Contributor Author

traviscross commented Oct 24, 2024

What @RalfJung said is why I don't hate Freeze, as we can read it as "has the ability to be frozen when taking a reference to it," where "frozen" here means "will not change".

I.e., inventing some notation, we could imagine the trait as:

trait Freeze {
    fn freeze(&self) -> &frozen Self;
}

@thynson
Copy link

thynson commented Nov 11, 2024

Maybe InteriorFreeze or FreezeInterior?

@traviscross
Copy link
Contributor Author

traviscross commented Nov 11, 2024

I could live with FreezeInterior (ed: but probably still prefer Freeze). It has a similar ring to it as what we did with CoercePointee.

@p-avital
Copy link

@traviscross I'd prefer Freeze to FreezeInterior, as I don't feel the addition of interior buys any clarity, while it does come at the cost of renaming which would make split resources for people looking it up; but at this point, I'm just ready to go with anything that grabs enough traction to finally get stabilized 🫠

@p-avital
Copy link

@traviscross This RFC is becoming stale again, with bike-shedding around the trait's name looking like the main blocker.

Do you think setting a deadline on the decision of naming (and possibly a poll with some of the existing options) could help push forward?

@traviscross
Copy link
Contributor Author

It's a good point. We just need to allocate some time for it in a meeting and commit to the bikeshed. There's a meeting in mid December we have scheduled that would probably make sense for that.

@traviscross traviscross added I-lang-radar Items that are on lang's radar and will need eventual work or consideration. I-lang-bikeshed This item needs lang to commit to finishing a bikeshed. and removed I-lang-nominated Nominated for discussion during a lang team meeting. labels Jan 26, 2025
@p-avital
Copy link

@traviscross Any timeline to try to get this sorted? The breaking change that pushed the need for this is still a major thorn in stabby's side :(

@traviscross
Copy link
Contributor Author

traviscross commented Feb 18, 2025

No, unfortunately. What I can say is that clearing the backlog of things like this is high on my priority list, and I have some plans about how we might do that.

@p-avital
Copy link

Is there any way I can be helpful in the process? :)

@hkBst
Copy link
Member

hkBst commented Feb 18, 2025

Would it make sense to instead of the trait Freeze, have its negation NoFreeze, expressing the fact that some type does have an UnsafeCell somewhere in its representation, instead of the absence of that? Name could be InteriorMut(ate) or InternalChange or InnerMut(ate) or InnerChange or something like that...

"core::marker::Freeze is a trait that is implemented for any type whose memory layout doesn't contain any UnsafeCell: it indicates that the memory referenced by &T is guaranteed not to change while the reference is live." -- the RFC

@p-avital
Copy link

The problem with that is that since you can't make negative bounds, such a trait wouldn't have much use, as its usefulness stands from the particular properties Freeze allows you (or the compiler) to tell about a value.

On the other hand, I've wanted negative bounds for so long that if this bikesheding ends up being the final nail in that coffin, I'd wouldn't even be mad; but I somehow doubt that would happen :D

@traviscross
Copy link
Contributor Author

traviscross commented Feb 18, 2025

Is there any way I can be helpful in the process? :)

We may need a design meeting to resolve this, and for that we'll need a design document that collects the options that have been proposed and the arguments that have been made about them and then proposes a plan. If you could put that together, it'd help. I'll reach out separately about this on Zulip.

@bstrie
Copy link
Contributor

bstrie commented Feb 19, 2025

Given that the major caveat of this trait is that it only implies immutability up until some form of indirection, I'm surprised that nobody has proposed Direct as a component of a potential name. Something like DirectFreeze or DirectlyImmutable seem natural and accurate to me.

Aside, one of the reasons that I don't like InteriorFreeze or any use of the word "interior" is that, even if these types prevent interior mutability, they do not prevent interior interior mutability, which seems liable to be surprising. (EDIT: although this objection goes away if we adopt the Direct terminology above, e.g. NoDirectInteriorMutability, to emphasize that we don't cover the case of transitive interior mutability.)

@hkBst
Copy link
Member

hkBst commented Feb 19, 2025

I wanted to brain storm a little about what action this trait enables, so I went back to the RFC:

"Orthogonally to static-promotion, core::marker::Freeze can also be used to ensure that transmuting &T to a reference to an interior-immutable type (such as [u8; core::mem::size_of::<T>()]) is sound (as interior-mutation of a &T may lead to UB in code using the transmuted reference, as it expects that reference's pointee to never change). This is notably a safety requirement for zerocopy and bytemuck"

"static-promotion" seems to be about "previously, const REF: &T = &expr; was (accidentally) accepted even when expr may contain interior mutability. Now this requires that the type of expr satisfies T: core::marker::Freeze" so should perhaps be changed to "const-promotion" (with or without dash), so that gives the first option of ConstPromote.

Then there is the conversion from &T to &[u8; core::mem::size_of::<T>()]. Specifically in the presence of another &T and where T contains an UnsafeCell (not merely points to one), because then the other ref could be used to change the bit pattern of the memory of T, which I believe would be immediate UB in the presence of a converted &[u8; core::mem::size_of::<T>()], because that shared ref implies constancy of the memory of T which would be violated by doing inner mutation. So that gives variations on TransmuteRefToBytesRef.

Then I wondered what the purpose is of this ref transmute. Is it for enabling some optimization? That would give OptimizeX. Bytemuck seems to use Zeroable, NoUninit, AnyBitPattern among other traits, while ZeroCopy has KnownLayout, Immutable, Unaligned, and IntoBytes. Actually it seems not Immutable (as claimed by the RFC) but this IntoBytes is what is used for this transmuting meaning of Freeze: "Any IntoBytes type can be converted to a slice of initialized bytes of the same size. This is useful for efficiently serializing structured data as raw bytes." Why does the RFC (on a very cursory viewing) seem to suggest that Immutable and IntoBytes are the same? Or perhaps, why does zerocopy separate these traits?

Options:

  • ConstPromote
  • variations on transmuting references to T to references to bits:
    • TransmuteRefToBytesRef
    • ConvertRefToMemRef
    • ViewRefAsBitsRef
    • ViewRefAsRefToBits
    • ViewBorrowAsBorrowedBits
    • ViewBorrowAsRawMemoryBorrow
    • ViewAsShared
    • many other options
  • OptimizeX ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-discussion Category: Discussion or questions that doesn't represent real issues. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. I-lang-bikeshed This item needs lang to commit to finishing a bikeshed. I-lang-radar Items that are on lang's radar and will need eventual work or consideration. proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests