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

Introducing built-in mutability entitlements #86

Merged
merged 5 commits into from
Aug 15, 2023

Conversation

SupunS
Copy link
Member

@SupunS SupunS commented May 12, 2023

Depends on #89

@SupunS SupunS self-assigned this May 15, 2023
@dsainati1
Copy link
Contributor

One other suggestion I had to improve this proposal would be to "break" the Mutable entitlement up a little bit more; instead of having one Mutable entitlement that allows any and all mutating operations on arrays and dictionaries, IMO we can have Insertable and Removable entitlements for these types, along with the Mutable entitlement. In this model the Mutable entitlement would allow access to any mutating function, but the Insertable would only allow inserting new values (while Removable would only allow removing). This doesn't need any support for "entitlement inheritance", as it can already be modeled today with entitlement sets; using type definitions for arrays like:

struct Array {
    access(all) let length: Int
    access(all)fun concat(_ array: T): T
    access(all) fun contains(_ element: T): Bool
    // ... other pub functions here 
    access(Mutable | Insertable) fun append(_ element: T): Void
    access(Mutable | Insertable) fun appendAll(_ array: T): Void
    access(Mutable | Insertable) fun insert(at: Int, _ element: T): Void
    
    access(Mutable | Removable) fun remove(at: Int): T
    access(Mutable | Removable) fun removeFirst(): T
    access(Mutable | Removable) fun removeLast(): T
 }

This way it will be possible to give someone only add/remove access to an array, while still also making it simple to give them full edit access as well.

Copy link
Member

@turbolent turbolent left a comment

Choose a reason for hiding this comment

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

Great start! 👌

@SupunS SupunS force-pushed the supun/references-on-member-access branch 2 times, most recently from 16085d0 to 9acd77d Compare May 19, 2023 22:38
@SupunS SupunS changed the title FLIP: Changing member-access semantics Introducing built-in mutability entitlements May 19, 2023
@SupunS SupunS force-pushed the supun/references-on-member-access branch from 9acd77d to 8b576ac Compare May 19, 2023 22:45
@SupunS SupunS marked this pull request as ready for review May 19, 2023 22:49
@dsainati1 dsainati1 mentioned this pull request May 31, 2023
@turbolent
Copy link
Member

👍 for the idea

We still might want to find consensus on the naming scheme. As Dete pointed out, it'll set a precedent, so we might want to discuss the naming scheme separately, as it also is a question/blocker for e.g. #92

@bjartek
Copy link
Contributor

bjartek commented Jun 20, 2023

I think it is a good idea to discuss naming scheme in more general and just have a documented way on how it is done. Naming things is hard.

@turbolent
Copy link
Member

@SupunS given the alignment on naming in #86 (comment), maybe the proposed entitlements should be renamed to Insert, Remove, and Mutate?

Also, is setting with indexing going to require Insert | Mutate?

@SupunS
Copy link
Member Author

SupunS commented Jul 6, 2023

given the alignment on naming in #86 (comment), maybe the proposed entitlements should be renamed to Insert, Remove, and Mutate?

Yea, I was waiting till we reach a conclusion to update the naming. Will update once we have a consensus (looks like we are almost there).

Also, is setting with indexing going to require Insert | Mutate?

Yes, this is explained in assigment section

Copy link
Member

@turbolent turbolent left a comment

Choose a reason for hiding this comment

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

👍

@turbolent
Copy link
Member

@SupunS Approved in the Cadence Language Design Meeting, let's merge this FLIP and the implementation 👏 🎉

@SupunS SupunS merged commit 942dca5 into main Aug 15, 2023
@SupunS SupunS deleted the supun/references-on-member-access branch August 15, 2023 18:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Proposed
Development

Successfully merging this pull request may close these issues.

7 participants