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

Rename "Const" trait to "Freeze" #3949

Closed
bblum opened this Issue Nov 12, 2012 · 8 comments

Comments

Projects
None yet
7 participants
@bblum
Contributor

bblum commented Nov 12, 2012

The word const currently means three things:

  • &const as a mutability qualifier, supertype of "mut" and "" (immut). Directly analogous to C/C++'s meaning.
  • const x: ty = val; for constant globals. Same as the meaning in C/C++/Java/etc.
  • T: Const as a trait, which indicates "no embedded mutability". Corresponds to nothing in any other language, as far as I know.

I propose we change the third one, and leave the other two as they are. Const doesn't even mean the data is constant (it can be borrowed as mutable). In working on the regions paper, I figured this is always used, conceptually, to indicate a "freezable" data structure -- one which becomes deeply constant only when borrowed from immutably. Let's call it that.

related #3542 #3529

@nikomatsakis

This comment has been minimized.

Show comment
Hide comment
@nikomatsakis

nikomatsakis Nov 13, 2012

Contributor

Copying a comment I accidentally wrote in #3542:

I strongly agree with not having const have so many overloaded meanings. To be honest, I think const-the-mutability-qualifier is the odd man out here, and I would like to change it to something else, but I don't know what (read? too valuable to use as a keyword. mut?? looks funny, can't pronounce it. rd or ro? Eh.). I think there is another issue to this effect. I know @jruderman has raised the issue before (and rightly so).

That said, I think Freeze may not be the right name for the trait we currently call Const. Here is my reasoning: a freezable data structure is one which is based purely on owned data and with no explicit mutable qualifiers. This is currently described by Send Const---the Const captures the lack of mutability qualifiers and the Send captures the "relies purely on owned data". So it seems to me that Freeze, if it exists, should be a "subtrait" of Send and Const.

Now, it is not clear to me whether a trait that means "immutable" is necessary on its own. @pcwalton and I have talked about some ideas for removing pure functions and replacing them with closures with a "Const" bound, so it'd be important then. The best name I can come up for to replace Const is Imm (for Immutable, which seems a touch long), even though it is true that an instance of an Imm type, when placed in a mutable local variable (or other mutable context), is in fact mutable. But somehow NoMut doesn't seem to have the same ring!

Contributor

nikomatsakis commented Nov 13, 2012

Copying a comment I accidentally wrote in #3542:

I strongly agree with not having const have so many overloaded meanings. To be honest, I think const-the-mutability-qualifier is the odd man out here, and I would like to change it to something else, but I don't know what (read? too valuable to use as a keyword. mut?? looks funny, can't pronounce it. rd or ro? Eh.). I think there is another issue to this effect. I know @jruderman has raised the issue before (and rightly so).

That said, I think Freeze may not be the right name for the trait we currently call Const. Here is my reasoning: a freezable data structure is one which is based purely on owned data and with no explicit mutable qualifiers. This is currently described by Send Const---the Const captures the lack of mutability qualifiers and the Send captures the "relies purely on owned data". So it seems to me that Freeze, if it exists, should be a "subtrait" of Send and Const.

Now, it is not clear to me whether a trait that means "immutable" is necessary on its own. @pcwalton and I have talked about some ideas for removing pure functions and replacing them with closures with a "Const" bound, so it'd be important then. The best name I can come up for to replace Const is Imm (for Immutable, which seems a touch long), even though it is true that an instance of an Imm type, when placed in a mutable local variable (or other mutable context), is in fact mutable. But somehow NoMut doesn't seem to have the same ring!

@pcwalton

This comment has been minimized.

Show comment
Hide comment
@pcwalton

pcwalton Nov 13, 2012

Contributor

&any int?

Contributor

pcwalton commented Nov 13, 2012

&any int?

@bblum

This comment has been minimized.

Show comment
Hide comment
@bblum

bblum Nov 13, 2012

Contributor

"any what?"

not to reject any, but it might also conflict with the any type which I believe is in the far-future plans.

Contributor

bblum commented Nov 13, 2012

"any what?"

not to reject any, but it might also conflict with the any type which I believe is in the far-future plans.

@pnkfelix

This comment has been minimized.

Show comment
Hide comment
@pnkfelix

pnkfelix May 2, 2013

Member
  • I believe &const is going away in the future
  • const x: ty = val has been replaced by static x: ty = val

so I don't think we need to get rid of Const as a trait at this point. Closing bug.

Member

pnkfelix commented May 2, 2013

  • I believe &const is going away in the future
  • const x: ty = val has been replaced by static x: ty = val

so I don't think we need to get rid of Const as a trait at this point. Closing bug.

@pnkfelix pnkfelix closed this May 2, 2013

@brson

This comment has been minimized.

Show comment
Hide comment
@brson

brson May 7, 2013

Contributor

I am still interested in renaming both Const and Owned

Contributor

brson commented May 7, 2013

I am still interested in renaming both Const and Owned

@brson brson reopened this May 7, 2013

@thestinger

This comment has been minimized.

Show comment
Hide comment
@thestinger

thestinger May 7, 2013

Contributor

+1 for renaming Const to Freeze

The word Const doesn't really get across the meaning, which is that something can be statically frozen by the compiler (either it inherits mutability, or it's immutable).

Contributor

thestinger commented May 7, 2013

+1 for renaming Const to Freeze

The word Const doesn't really get across the meaning, which is that something can be statically frozen by the compiler (either it inherits mutability, or it's immutable).

@toddaaro

This comment has been minimized.

Show comment
Hide comment
@toddaaro

toddaaro Jul 3, 2013

Contributor

Visiting for triage. Whatever happens, this should be settled by milestone "maturity number 2 - backwards compatible".

Contributor

toddaaro commented Jul 3, 2013

Visiting for triage. Whatever happens, this should be settled by milestone "maturity number 2 - backwards compatible".

@thestinger

This comment has been minimized.

Show comment
Hide comment
@thestinger

thestinger Jul 3, 2013

Contributor

This landed as part of #7451.

Contributor

thestinger commented Jul 3, 2013

This landed as part of #7451.

@thestinger thestinger closed this Jul 3, 2013

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