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

[move][adapter] Static init rules #1532

Merged
merged 1 commit into from
Apr 22, 2022
Merged

[move][adapter] Static init rules #1532

merged 1 commit into from
Apr 22, 2022

Conversation

tnowacki
Copy link
Contributor

  • Made init rules static
  • The existence of the function is optional
  • The function must be named 'init'
  • The function must be private
  • The function can have a single parameter, &mut TxContext
  • Alternatively, the function can have zero parameters

- Made init rules static
- The existence of the function is optional
- The function must be named 'init'
- The function must be private
- The function can have a single parameter, &mut TxContext
- Alternatively, the function can have zero parameters
@tnowacki
Copy link
Contributor Author

See #1323

@lxfind
Copy link
Contributor

lxfind commented Apr 21, 2022

Cool! Thank you for taking on this!
A few questions for discussion:

  1. Would a more irregular name help distinguish it? like _ _ init _ _?
  2. Why not public? Now that we can verify it statically, we can make it public, and not allow anyone making function calls to any function with this name except in tests. This will make it easier to write tests.

@awelc
Copy link
Contributor

awelc commented Apr 21, 2022

  1. Why not public? Now that we can verify it statically, we can make it public, and not allow anyone making function calls to any function with this name except in tests. This will make it easier to write tests.

The intention was to emphasize the fact that this is not a "regular" (callable) function.

@lxfind
Copy link
Contributor

lxfind commented Apr 21, 2022

The intention was to emphasize the fact that this is not a "regular" (callable) function.

Well, private function only constrains other non-friend modules from calling it. You can still call it from within and friend modules. So I think a verifier that forbids calling it is needed anyway. If so, we can make it public

Copy link
Contributor

@awelc awelc left a comment

Choose a reason for hiding this comment

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

A general comment. At least part of the reason that this was not implemented in the verifier is that when talking to @sblackshear, we were not sure if init should be treated as (practically) a keyword for function naming (a function called init MUST be a module initializer). On the one hand, this makes things more explicit, and on the other - it is somewhat restrictive from programmer's perspective. I am totally cool with the stricter solution, though.

@tnowacki
Copy link
Contributor Author

I feel fine basically keywordifying it for Sui move.

Why not public? Now that we can verify it statically, we can make it public, and not allow anyone making function calls to any function with this name except in tests. This will make it easier to write tests.

It is annoying... but you could always do something like #[test_only] public fun call_init() { init() }

not allow anyone making function calls to any function with this name except in tests.

More on this part, this this rule already in place?
That is, should there be a rule that no one can call init functions? Is that rule already in place?
If not, it will make a followup PR

@lxfind
Copy link
Contributor

lxfind commented Apr 22, 2022

More on this part, this this rule already in place? That is, should there be a rule that no one can call init functions? Is that rule already in place? If not, it will make a followup PR

No there isn't. But I think we should have it?

@tnowacki
Copy link
Contributor Author

I'll land this, with a followup for a "don't call init" init rule

@tnowacki tnowacki merged commit 637f67f into MystenLabs:main Apr 22, 2022
@tnowacki tnowacki deleted the init branch April 22, 2022 16:10
longbowlu added a commit that referenced this pull request Apr 22, 2022
* refactor

* clean up

* refactor
rebase

* rebase

* rebase

* add how-to

* format

* lint

* don't pop key, copy it

* Add a safe client function that augments the follower API with downloading the transactions information (#1446)

Co-authored-by: George Danezis <[email protected]>

* Removing dev-addresses from Move.toml (#1536)

There is no undefined address in the [addresses] section (e.g. AddressToBeFilledIn = "_") so having a [dev-addresses] section is not necessary.

* [move][adapter] Static init rules (#1532)

- Made init rules static
- The existence of the function is optional
- The function must be named 'init'
- The function must be private
- The function can have a single parameter, &mut TxContext
- Alternatively, the function can have zero parameters

* adds a counter example (#1539)

* sui: reorganize binaries

* wallet: log git revision on start

* Refactor Build index by common user workflow (#1530)

* Refactor Build index by common user workflow

* Update index.md

Fix paths missing Markdown file extension

* Update index.md (#1545)

Removing tutorial series until ready

* Update index.md

Remove version from API link
Capitalize REST

* comments and add unwind logic for process

* fix: remove one unneeded instance of key_pair.copy()

* fix: remove three unneeded instances of key_pair.copy()

* fix: remove one unneeded instance of key_pair.copy()

* refactor
rebase

* rebase

* refactor

* rebase

* rebase

* add how-to

* lint

* don't pop key, copy it

* rebase

* Update index.md

Remove version from API link
Capitalize REST

* rebase

Co-authored-by: Lu Zhang <[email protected]>
Co-authored-by: George Danezis <[email protected]>
Co-authored-by: George Danezis <[email protected]>
Co-authored-by: jaredcosulich <[email protected]>
Co-authored-by: Todd Nowacki <[email protected]>
Co-authored-by: Damir S <[email protected]>
Co-authored-by: Brandon Williams <[email protected]>
Co-authored-by: Clay-Mysten <[email protected]>
Co-authored-by: François Garillot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants