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 flip for changing import statement semantics #277

Merged
merged 3 commits into from
Jun 24, 2024
Merged

Conversation

SupunS
Copy link
Member

@SupunS SupunS commented Jun 12, 2024

Work towards #278

@SupunS SupunS force-pushed the supun/import-semantics branch 2 times, most recently from f90486c to 3869d1d Compare June 12, 2024 19:05
@SupunS SupunS force-pushed the supun/import-semantics branch 2 times, most recently from cf05f6d to a7baef2 Compare June 12, 2024 19:40

## Related Issues

None
Copy link
Contributor

Choose a reason for hiding this comment

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

This is obviously beyond the scope of this current FLIP (and would be a new feature that can be added after Cadence 1.0), but I think that changing imports to create an unentitled reference to the contract value does suggest that it may be useful to also be able to import an entitled reference to the contract as well. There would need to be some kind of way to guarantee that only certain people can do this, and syntax for it as well.

Copy link
Collaborator

@bluesign bluesign Jun 13, 2024

Choose a reason for hiding this comment

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

I think easiest solution is to disallow entitlements on contract functions. ( which can be relaxed later if needed )

Copy link
Member

Choose a reason for hiding this comment

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

@SupunS SupunS force-pushed the supun/import-semantics branch from a7baef2 to 88fd57b Compare June 12, 2024 23:03
@SupunS SupunS force-pushed the supun/import-semantics branch from 88fd57b to 5ba4d0c Compare June 12, 2024 23:08
@SupunS SupunS marked this pull request as ready for review June 13, 2024 17:05
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.

LGTM! Just a few minor suggestions for phrasing

cadence/20240612-import-contract-as-reference.md Outdated Show resolved Hide resolved
cadence/20240612-import-contract-as-reference.md Outdated Show resolved Hide resolved
cadence/20240612-import-contract-as-reference.md Outdated Show resolved Hide resolved
cadence/20240612-import-contract-as-reference.md Outdated Show resolved Hide resolved
cadence/20240612-import-contract-as-reference.md Outdated Show resolved Hide resolved
```
### Drawbacks

This is a breaking change. Certain users may have to update their code.
Copy link
Contributor

Choose a reason for hiding this comment

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

So code that would need to be changed here is if you directly use a imported contracts fields and mutate them right?

Copy link
Member Author

@SupunS SupunS Jun 17, 2024

Choose a reason for hiding this comment

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

yes, but in addition, if you use a field of a imported inside a function (say for example return as is), then the type annotation would change.
e.g:

fun someFunction(): T {
    return ImportedContract.foo
}

then this would change to

fun someFunction(): &T {  // <-- reference type
    return ImportedContract.foo
}

(This is also the change needed for those three contracts that breaks)


### Alternatives Considered

A non-breaking alternative solution is to keep current language semantics as-is, and warn about contract fields that
Copy link
Contributor

Choose a reason for hiding this comment

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

Personally I think this is very dangerous. Cadence-1.0 is already breaking so this is just one more thing that we need to do.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agree!

@bluesign
Copy link
Collaborator

bluesign commented Jun 17, 2024

What are the breaking examples for this on staged contracts ? I can think of access(account) var cases as most critical ( will require setter I suppose in the current model ) , structs as references can be pretty easy to fix.

@SupunS
Copy link
Member Author

SupunS commented Jun 17, 2024

@bluesign Like mentioned in the impact section, there were three contracts affected by this, and all of them were returning an imported-contract field (a dictionary) as-is, so the type annotation of the function would needed to be changed. e.g: similar to #277 (comment). I don't quite know what the use-case of those functions are; They were not used anywhere AFAIU (did a string search in all staged contracts, but came empty).

@turbolent
Copy link
Member

I can think of access(account) var cases as most critical ( will require setter I suppose in the current model )

Yeah, that's one of the downsides, but IMHO probably not a big deal, given the workaround is adding a setter. Adding special rules to the language for treating access(account) differently is not worth it (more rules increase the burden for users and implementors, and there is little benefit over an explicit setter function)

@bluesign
Copy link
Collaborator

Yeah, that's one of the downsides, but IMHO probably not a big deal, given the workaround is adding a setter.

Yeah I checked mainnet contracts now, it seems it is rarely used to modify, often used to just read.

@bjartek
Copy link
Contributor

bjartek commented Jun 20, 2024

LGTM, this is a no brainer.

@austinkline
Copy link
Contributor

Proposal is pretty straight-forward, a bit surprised it didn't work this way already!

👍

@bluesign
Copy link
Collaborator

LGTM

@SupunS
Copy link
Member Author

SupunS commented Jun 20, 2024

For additional information, these are the fixes needed for the three breaking contracts: https://gist.github.com/SupunS/c732360df3fa969e09a161776a1af0ab

@SupunS
Copy link
Member Author

SupunS commented Jun 20, 2024

We discussed this FLIP during today's developer office hours / working group call, and the sentiment was very positive, and there have not been any concerns so far.
If it continues to have no any further concerns, we will consider this FLIP as approved by the EOW.

@SupunS
Copy link
Member Author

SupunS commented Jun 24, 2024

Thanks everyone for the feedback! This FLIP has been open for a while, and had multiple breakout sessions for discussing the details. There has been no concerns and the feedback has been very positive.
Thus, I'll consider this FLIP as approved! 🎉

You can follow the implementation progress at onflow/cadence#3417

@SupunS SupunS merged commit e77c63c into main Jun 24, 2024
@SupunS SupunS deleted the supun/import-semantics branch June 24, 2024 17:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants