docs: deprecate init_module, document explicit initialize pattern#477
docs: deprecate init_module, document explicit initialize pattern#477gregnazario wants to merge 8 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
8cad133 to
f560c52
Compare
|
|
||
| - Solidity declares contracts with the `contract` keyword. Move declares modules as `address::module_name`. | ||
| - Solidity constructors run once at deployment. Move initialization logic typically lives in `init_module`. | ||
| - Solidity constructors run once at deployment. In Move, run initialization logic from an explicit `public entry fun initialize` that the publisher calls after publishing (see [Modules on Aptos](/build/smart-contracts/modules-on-aptos#recommended-explicit-initialize-entry-function)). |
There was a problem hiding this comment.
nit: I would say, "In move, initialization is an explicit action invoked by developer, giving them more control. An explicit public entry fun initialize needs to be called..."
basically adding some motivation that explicit init is not too bad: it gives you control on the order of initialization, and aligns with decoupled code-data paradigm in Move.
There was a problem hiding this comment.
Nit2:
No need for public, let's use entry fun initialize
| The MoonCoin module defines the `MoonCoin` struct, or the distinct type of coin type. In addition, it contains a function called `init_module`. The `init_module` function is called when the module is published. In this case, MoonCoin initializes the `MoonCoin` coin type as a `ManagedCoin`, which is maintained by the owner of the account. | ||
|
|
||
| <Aside type="danger" title="`init_module` is deprecated"> | ||
| `init_module` is deprecated and being removed because it causes issues in the VM. New modules should initialize state with an explicit `public entry fun initialize` called by the publisher after publishing — see [Modules on Aptos](/build/smart-contracts/modules-on-aptos#recommended-explicit-initialize-entry-function). This example still uses `init_module` to match the on-chain example module; it will be updated once that example is migrated. |
There was a problem hiding this comment.
Also it has no ordering semantics which inits run first? "Adds complexity for the VM"?
| The `ManagedFungibleAsset` standard helps keep track of which permissions this Module is allowed to use. | ||
|
|
||
| <Aside type="danger" title="`init_module` is deprecated"> | ||
| `init_module` is deprecated and being removed because it causes issues in the VM. New modules should initialize state with an explicit `public entry fun initialize` called by the publisher after publishing — see [Modules on Aptos](/build/smart-contracts/modules-on-aptos#recommended-explicit-initialize-entry-function). This example still uses `init_module` to match the on-chain example module; it will be updated once that example is migrated. |
There was a problem hiding this comment.
Same as for src/content/docs/build/guides/first-coin.mdx
| - Create resource accounts or other module-specific setup tasks | ||
|
|
||
| <Aside type="danger" title="`init_module` is deprecated"> | ||
| The `init_module` function is **deprecated** and is being removed because it causes issues in the VM. Do not use it in new modules. Initialize modules with an explicit `public entry fun initialize` that the publisher calls after publishing the package (see below). |
There was a problem hiding this comment.
Can we list more reasons here:
- No clear linking semantics (old or new code?)
- No initialization order
- Adds significant complexity to the VM
- Remove `public` from `entry fun initialize` throughout (entry fun is sufficient; the publisher calls it via a transaction, not from another module) - Expand init_module deprecation rationale with specific reasons: no clear linking semantics, no initialization order, adds VM complexity - Rephrase billboard guide bullet to convey that explicit initialization is a feature — gives developer control over init order and aligns with Move's code/data separation paradigm - Sync all changes to zh translations
Summary
Deprecates the Move
init_modulefunction across the docs and steers readers to a guardedpublic entry fun initializepattern.init_moduleis being removed because it causes issues in the VM.Changes
initializeentry function" section documenting the replacement with both guards (publisher-address authorization assert +!exists<>once-guard) and the separate-transaction operational caveat.module-initialization.mdx, dutch-auctioninitialization.mdx, both EN+ZH):init_modulefully scrubbed and replaced withinitialize; frontmatter descriptions and prose updated. The dutch-auction sample uses the guide's existingerror::permission_denied(ENOT_OWNER)convention.init_modulecode samples are intentionally kept because they mirror runnable examples inaptos-labs/aptos-core(moon_coin.move,fa_coin.move) — see follow-ups.Replacement pattern
The two guards recover the once-only and publisher-only guarantees that
init_moduleprovided automatically.Verification
pnpm lintclean;pnpm check0 errors / 0 warnings (2 pre-existing unrelated hints)pnpm test tests/agent-discovery.test.ts tests/markdown-negotiation.test.ts→ 42/42 passastro check, full build, and link validation all greeninit_modulenow appears only in the reference (as legacy/deprecated) and the two tutorials (samples + callouts); both ethereum-to-aptos guides are fully scrubbedFollow-ups (out of scope, noted in the plan)
moon_coin.move/fa_coin.movemigrate toinitialize, swap the tutorial samples and drop the "will be updated once that example is migrated" line from both callouts.Note
This branch also contains the design spec and implementation plan under
docs/superpowers/(commitse0c4253,9c3f55d). If you don't want those planning artifacts in the repo, I can drop those two commits before merge.