Skip to content

Commit f1ecd52

Browse files
committed
Remove legacy lifecycle syntax
1 parent 57d5560 commit f1ecd52

33 files changed

Lines changed: 825 additions & 803 deletions

‎README.md‎

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ verifier obligations, runtime requirements, and target-profile policy flags.
2727

2828
The language is intentionally narrow: it is not a new VM, and it is not an
2929
account-storage contract language. CellScript gives protocol authors a typed
30-
way to describe assets, shared Cell state, receipts, lifecycle transitions,
30+
way to describe assets, shared Cell state, receipts, explicit state transitions,
3131
locks, and transaction-shaped effects — while still mapping directly to the
3232
Cell model used by CKB.
3333

@@ -169,7 +169,8 @@ CellScript programs are written in terms of Cell lifecycle operations:
169169
- **Capability gates** — `has store, transfer, destroy` makes asset permissions
170170
explicit instead of implicit.
171171
- **Declarative state machines** — state remains explicit schema data, while
172-
`state_machine Type.field { A -> B by action; }` declares allowed edges and
172+
`state_machine Name for Type.field { A -> B by action; }` or compact
173+
`state Type.field { A -> B; }` declares allowed edges, and
173174
`action ... moves input.field A -> B` binds an action to the edge it proves.
174175
- **Effect inference** — `action` bodies are classified as `Pure`, `ReadOnly`,
175176
`Mutating`, `Creating`, or `Destroying` based on their Cell operations.
@@ -292,10 +293,10 @@ action burn(token: Token) {
292293
| Example | What it shows |
293294
|---|---|
294295
| `examples/token.cell` | Mint, transfer, burn, guarded same-symbol merge |
295-
| `examples/timelock.cell` | Time-gated state transitions, delayed claim paths |
296+
| `examples/timelock.cell` | Time-gated release checks, delayed claim paths |
296297
| `examples/multisig.cell` | Authorization thresholds, signature-oriented locks |
297298
| `examples/nft.cell` | Unique assets, metadata, ownership transfer |
298-
| `examples/vesting.cell` | Receipt-style grants and claim lifecycle |
299+
| `examples/vesting.cell` | Receipt-style grants and explicit claim state transitions |
299300
| `examples/amm_pool.cell` | Shared pool state, swap/liquidity effects |
300301
| `examples/launch.cell` | Launch/pool composition patterns |
301302

@@ -317,7 +318,7 @@ chain-specific VM:
317318
|---|---|---|---|---|
318319
| Execution target | RISC-V ELF / asm on ckb-vm | EVM bytecode | Move bytecode | FuelVM bytecode |
319320
| State model | Typed Cells, explicit inputs/deps/outputs | Account storage slots | Resources in global storage | UTXO + native assets |
320-
| Asset model | Native `resource`, lifecycle, receipts, shared Cells | Manual token contracts | Native resources | Native assets |
321+
| Asset model | Native `resource`, state transitions, receipts, shared Cells | Manual token contracts | Native resources | Native assets |
321322
| Linear ownership | Compiler-enforced | No | Yes (abilities) | No general user-defined |
322323
| Shared state | Explicit `shared` Cells | Implicit contract storage | Shared objects (some chains) | No shared Cell analogue |
323324
| Reentrancy | No callback-style reentrancy | Common risk surface | Lower by design | Lower predicate risk |
@@ -337,7 +338,7 @@ CellScript includes production-style local language tooling for early users:
337338
- **In-process LSP** — diagnostics, completions, hover, go-to-definition,
338339
references, rename, formatting, and metadata-oriented code actions. The
339340
compiler crate exposes an `LspServer`; `cellc --lsp` provides a full
340-
`tower-lsp` JSON-RPC transport over stdio. Completions include lifecycle
341+
`tower-lsp` JSON-RPC transport over stdio. Completions include state-machine
341342
states after `Type::`.
342343
- **VS Code extension** — syntax highlighting, snippets, on-save diagnostics,
343344
compiler-backed formatting, scratch compilation, metadata/constraints/production
@@ -376,7 +377,7 @@ crate (`cellscript`) with its own `mod.rs` entry point under `src/`.
376377
graph LR
377378
Source["Source (.cell)"] --> Lexer
378379
Lexer --> Parser
379-
Parser --> TypeCheck["Type Checker\n+ Lifecycle"]
380+
Parser --> TypeCheck["Type Checker\n+ State Checks"]
380381
TypeCheck --> IRLower["IR Lowering\n+ Optimize"]
381382
IRLower --> Codegen["Codegen (RISC-V)"]
382383
IRLower --> Metadata["Metadata (JSON)"]
@@ -402,9 +403,9 @@ action `moves` clauses, and all statement/expression forms.
402403
or settled before the action body exits. Also validates shared-state
403404
mutability rules, capability gates, effect classification (`Pure` /
404405
`ReadOnly` / `Mutating` / `Creating` / `Destroying`), and call signatures.
405-
- *Lifecycle checking* — validates explicit state fields, `state_machine`
406-
transition graphs, action `moves` clauses, legal state transitions, and static
407-
create-site checks.
406+
- *State transition checking* — validates explicit state fields,
407+
`state_machine` transition graphs, action `moves` clauses, legal state
408+
transitions, and static create-site checks.
408409

409410
**4. IR lowering** (`ir/` + `optimize/` + `resolve/`)
410411
- *`resolve/`* — builds per-module symbol tables and resolves `use` imports
@@ -482,7 +483,7 @@ treated as deployable.
482483
```mermaid
483484
flowchart TB
484485
Source[".cell source + Cell.toml\n--target-profile ckb"] --> Frontend["Lexer + parser\nstable source spans"]
485-
Frontend --> Semantics["Type + lifecycle checks\nlinear resources, lock-only require,\nprotected/witness/lock_args classification"]
486+
Frontend --> Semantics["Type + state checks\nlinear resources, lock-only require,\nprotected/witness/lock_args classification"]
486487
Semantics --> Policy["CKB policy gate\nfail closed on unsupported runtime or state shapes"]
487488
488489
subgraph Rules["CKB profile rules"]
@@ -509,7 +510,7 @@ flowchart TB
509510

510511
This separates three boundaries:
511512

512-
- **compiler boundary** — parse, type/lifecycle checks, CKB policy rejection, IR,
513+
- **compiler boundary** — parse, type/state checks, CKB policy rejection, IR,
513514
codegen, and metadata;
514515
- **artifact boundary** — `cellc verify-artifact` proves the artifact, sidecar,
515516
source hash, target profile, and selected policy flags agree;

‎README_CH.md‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ action burn(token: Token) {
224224
| `examples/timelock.cell` | 时间门控状态转换、延迟 claim 路径 |
225225
| `examples/multisig.cell` | 授权阈值、签名导向的 lock 逻辑 |
226226
| `examples/nft.cell` | 唯一资产、metadata、所有权转移 |
227-
| `examples/vesting.cell` | Receipt-style grants 和 claim lifecycle |
227+
| `examples/vesting.cell` | Receipt-style grants 和显式 claim 状态转换 |
228228
| `examples/amm_pool.cell` | Shared pool state、swap/liquidity effects |
229229
| `examples/launch.cell` | Launch/pool composition patterns |
230230

@@ -299,7 +299,7 @@ CellScript 是一个多遍编译器,把 `.cell` 源码通过五个定义明确
299299
graph LR
300300
Source["Source (.cell)"] --> Lexer
301301
Lexer --> Parser
302-
Parser --> TypeCheck["Type Checker\n+ Lifecycle"]
302+
Parser --> TypeCheck["Type Checker\n+ State Checks"]
303303
TypeCheck --> IRLower["IR Lowering\n+ Optimize"]
304304
IRLower --> Codegen["Codegen (RISC-V)"]
305305
IRLower --> Metadata["Metadata (JSON)"]
@@ -323,7 +323,7 @@ graph LR
323323
体退出前必须被 consume、transfer、destroy、claim 或 settle。同时验证
324324
shared-state 可变性规则、capability gates、effect 分类(`Pure` /
325325
`ReadOnly` / `Mutating` / `Creating` / `Destroying`)和调用签名。
326-
- *生命周期检查* — 验证显式 state 字段、`state_machine` 转换图、action
326+
- *状态转换检查* — 验证显式 state 字段、`state_machine` 转换图、action
327327
`moves` 子句、合法状态转换和静态 create-site 检查。
328328

329329
**4. IR 降低**(`ir/` + `optimize/` + `resolve/`)
@@ -397,7 +397,7 @@ CKB 假设暴露出来。
397397
```mermaid
398398
flowchart TB
399399
Source[".cell source + Cell.toml\n--target-profile ckb"] --> Frontend["Lexer + parser\n稳定 source span"]
400-
Frontend --> Semantics["Type + lifecycle checks\n线性资源、lock-only require、\nprotected/witness/lock_args 分类"]
400+
Frontend --> Semantics["Type + state checks\n线性资源、lock-only require、\nprotected/witness/lock_args 分类"]
401401
Semantics --> Policy["CKB policy gate\n对不支持的 runtime 或状态形状 fail closed"]
402402
403403
subgraph Rules["CKB profile rules"]
@@ -424,7 +424,7 @@ flowchart TB
424424

425425
这里分成三条边界:
426426

427-
- **编译器边界** — parse、type/lifecycle checks、CKB policy rejection、IR、
427+
- **编译器边界** — parse、type/state checks、CKB policy rejection、IR、
428428
codegen 和 metadata;
429429
- **artifact 边界** — `cellc verify-artifact` 证明 artifact、sidecar、源码
430430
hash、target profile 和选定 policy flags 一致;

‎docs/CELLSCRIPT_0_13_RELEASE_NOTES_DRAFT.md‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,20 +198,26 @@ New in 0.13:
198198
local witness buffer before decoding dynamic payload lengths, and reject
199199
trailing payload bytes after all static or dynamic witness arguments are
200200
consumed.
201-
- Lifecycle receipts now fail compilation unless they declare a scalar unsigned
202-
`state` field, matching the runtime verifier's lifecycle state contract.
203-
- Lifecycle state storage remains explicit cell data: the compiler does not
201+
- Legacy `#[lifecycle(...)]` receipt syntax has been removed. State remains
202+
explicit schema data, and transition policy is declared with `state` /
203+
`state_machine` plus action-level `moves`.
204+
- State-machine storage remains explicit cell data: the compiler does not
204205
inject hidden state fields or mutate Molecule layout. `create` initializers
205-
may now use declared lifecycle state names such as `state: Created`, while
206+
may now use declared state names such as `state: Created`, while
206207
guards and computed expressions can use qualified names such as
207208
`Ticket::Active` instead of numeric state indexes. The LSP now completes
208-
those qualified lifecycle states after `Type::`.
209+
those qualified state-machine states after `Type::`.
209210
- Declarative state machines can now be expressed without hidden layout changes:
210211
`state_machine Name for Type.field { A -> B by action; }` and compact
211212
`state Type.field { A -> B; }` declare the graph, while action signatures can
212213
bind the edge they prove with `moves input.field A -> B`. The type checker,
213-
lifecycle static checks, IR metadata, runtime verifier, formatter, docs
214+
state static checks, IR metadata, runtime verifier, formatter, docs
214215
generator, and LSP all carry the explicit state field name.
216+
- State-machine checking no longer treats enum or declaration order as a hidden
217+
linear state sequence: initial creates may use any declared state, and declared
218+
edges may return to the first state. `moves` and `by action` edges now fail at
219+
compile time unless the action consumes the corresponding owned input and
220+
creates exactly one replacement output.
215221
- Mutate preserved-field verification now fails closed when not every preserved
216222
field is verifier-addressable; metadata no longer classifies oversized
217223
data-except fallback paths as checked-runtime.

‎docs/CELLSCRIPT_EXAMPLE_BUSINESS_FLOWS.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ are no lock entries in this example.
127127

128128
## `multisig.cell`
129129

130-
Business purpose: threshold wallet creation, proposal lifecycle, signature
130+
Business purpose: threshold wallet creation, proposal records, signature
131131
collection, execution, cancellation, and signer/threshold governance proposals.
132132

133133
```mermaid

‎docs/CELLSCRIPT_RUNTIME_ERROR_CODES.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ When a CLI failure can be tied to this registry, stderr uses the same
2626
| 3 | `cell-load-failed` | Cell data or field loading failed or returned an unusable result. | Check that the expected input, output, or dep cell exists and is reachable by the generated script. |
2727
| 4 | `exact-size-mismatch` | Loaded bytes did not match the exact fixed-size schema requirement. | Check fixed-width schema fields and ensure the builder encodes the exact Molecule byte length. |
2828
| 5 | `assertion-failed` | A source-level assert or invariant check evaluated to false. | Inspect the action invariant or assert expression and the transaction values that feed it. |
29-
| 7 | `lifecycle-transition-mismatch` | A lifecycle state transition did not match the declared transition rule. | Compare consumed and produced lifecycle state fields with the declared lifecycle transitions. |
30-
| 8 | `lifecycle-new-state-invalid` | A created or replacement lifecycle state was outside the declared state range. | Check created output lifecycle state values and declared lifecycle states. |
31-
| 9 | `lifecycle-old-state-invalid` | A consumed lifecycle state was outside the declared state range. | Check consumed input lifecycle state values and declared lifecycle states. |
29+
| 7 | `lifecycle-transition-mismatch` | A state-machine transition did not match the declared transition rule. | Compare consumed and produced state fields with the declared state-machine transitions. |
30+
| 8 | `lifecycle-new-state-invalid` | A created or replacement state value was outside the declared state range. | Check created output state values and declared state-machine states. |
31+
| 9 | `lifecycle-old-state-invalid` | A consumed state value was outside the declared state range. | Check consumed input state values and declared state-machine states. |
3232
| 10 | `entry-witness-magic-mismatch` | Entry witness bytes did not start with the CellScript witness ABI magic. | Encode entry witnesses with `cellc entry-witness` or the documented `CSARGv1\0` wire format. |
3333
| 11 | `type-hash-preservation-mismatch` | A replacement output did not preserve the consumed input type hash. | Check the replacement output type script and builder output ordering. |
3434
| 12 | `lock-hash-preservation-mismatch` | A replacement output did not preserve the consumed input lock hash. | Check the replacement output lock script and builder output ordering. |

‎docs/wiki/Tutorial-04-Packages-and-CLI-Workflow.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ cellc doc --json
133133
```
134134

135135
Generated docs summarize modules, actions, resources, receipts, locks,
136-
lifecycle rules, and lowering metadata.
136+
state-machine rules, and lowering metadata.
137137

138138
## Audit And Evidence Reports
139139

‎docs/wiki/Tutorial-07-LSP-and-Tooling.md‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
You can write CellScript with any text editor and the `cellc` CLI. The LSP and
2-
VS Code extension make that loop shorter. Parse errors, type errors, lifecycle
3-
mistakes, symbols, hovers, formatting, and compiler-backed reports can show up
4-
while you work instead of after a long command sequence.
2+
VS Code extension make that loop shorter. Parse errors, type errors,
3+
state-machine mistakes, symbols, hovers, formatting, and compiler-backed reports
4+
can show up while you work instead of after a long command sequence.
55

66
The useful thing to remember is that editor feedback is not a separate language
7-
implementation. It is tied to the same parser, type checker, lifecycle checks,
7+
implementation. It is tied to the same parser, type checker, state-transition checks,
88
and lowering metadata used by `cellc`.
99

1010
## What You Will Learn
@@ -20,10 +20,10 @@ and lowering metadata used by `cellc`.
2020
The LSP implementation supports the editor features you expect while writing a
2121
contract:
2222

23-
- diagnostics for parse, type, lifecycle, and lowering errors;
24-
- hover information for actions, receipts, fields, local variables, lifecycle
23+
- diagnostics for parse, type, state-machine, and lowering errors;
24+
- hover information for actions, receipts, fields, local variables, state-machine
2525
states, and lowering metadata;
26-
- keyword, type, symbol, field, local, enum variant, and qualified lifecycle
26+
- keyword, type, symbol, field, local, enum variant, and qualified state-machine
2727
state completions such as `Ticket::Active`;
2828
- go-to-definition;
2929
- find-references;

‎docs/wiki/Tutorial-08-Bundled-Example-Contracts.md‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ example.
1212
|---|---|
1313
| `examples/token.cell` | Minting, transfer, burn, and guarded token merge. |
1414
| `examples/nft.cell` | Unique assets, metadata, ownership transitions, and owner locks. |
15-
| `examples/timelock.cell` | Time-gated state transitions, release requests, and approval flow. |
16-
| `examples/multisig.cell` | Threshold policy, proposals, signatures-as-data, and lock-boundary predicates. |
15+
| `examples/timelock.cell` | Time-gated release checks, release requests, and approval flow. |
16+
| `examples/multisig.cell` | Threshold policy, proposal records, signatures-as-data, and lock-boundary predicates. |
1717
| `examples/vesting.cell` | Vesting grants, receipts, claim lifecycle, and admin-boundary comments. |
1818
| `examples/amm_pool.cell` | Shared pool state, swap logic, liquidity receipts, and settlement effects. |
1919
| `examples/launch.cell` | Launch/pool composition patterns. |
@@ -46,8 +46,8 @@ If you are learning the language, read them in this order:
4646
1. `token.cell`: start here. It is the smallest example with a clear resource
4747
lifecycle.
4848
2. `nft.cell`: learn unique assets and ownership-style locks.
49-
3. `timelock.cell`: learn time guards and replacement state.
50-
4. `multisig.cell`: learn proposal lifecycle and threshold logic.
49+
3. `timelock.cell`: learn time guards and release evidence.
50+
4. `multisig.cell`: learn proposal records and threshold logic.
5151
5. `vesting.cell`: learn receipt-style claim flows.
5252
6. `amm_pool.cell`: learn shared pool state after you understand resources.
5353
7. `launch.cell`: read this last because it composes multiple patterns.

‎examples/acceptance/multisig.cell‎

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,7 @@ receipt Proposal has destroy {
4343
signatures: Vec<Signature>,
4444
created_at: u64,
4545
expires_at: u64,
46-
state: u8,
47-
}
48-
49-
state Proposal.state {
50-
Created -> Pending;
51-
Pending -> Executed;
52-
Executed -> Cancelled;
46+
state: ProposalStatus,
5347
}
5448

5549
struct Signature {
@@ -136,7 +130,7 @@ action propose_transfer(
136130
signatures: [],
137131
created_at: current_time,
138132
expires_at: current_time + DEFAULT_TIMEOUT,
139-
state: Created,
133+
state: ProposalStatus::Pending,
140134
};
141135

142136

@@ -265,7 +259,7 @@ action propose_add_signer(
265259
signatures: [],
266260
created_at: current_time,
267261
expires_at: current_time + DEFAULT_TIMEOUT,
268-
state: Created,
262+
state: ProposalStatus::Pending,
269263
};
270264

271265
proposal
@@ -303,7 +297,7 @@ action propose_remove_signer(
303297
signatures: [],
304298
created_at: current_time,
305299
expires_at: current_time + DEFAULT_TIMEOUT,
306-
state: Created,
300+
state: ProposalStatus::Pending,
307301
};
308302

309303
proposal
@@ -342,7 +336,7 @@ action propose_change_threshold(
342336
signatures: [],
343337
created_at: current_time,
344338
expires_at: current_time + DEFAULT_TIMEOUT,
345-
state: Created,
339+
state: ProposalStatus::Pending,
346340
};
347341

348342
proposal

‎examples/acceptance/nft.cell‎

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,6 @@ receipt Listing has destroy {
3939
state: u8,
4040
}
4141

42-
state Listing.state {
43-
Created -> Active;
44-
Active -> Filled;
45-
Filled -> Cancelled;
46-
}
47-
4842
receipt Offer has destroy {
4943
token_id: u64,
5044
buyer: Address,
@@ -53,12 +47,6 @@ receipt Offer has destroy {
5347
state: u8,
5448
}
5549

56-
state Offer.state {
57-
Created -> Active;
58-
Active -> Accepted;
59-
Accepted -> Expired;
60-
}
61-
6250
receipt RoyaltyPayment {
6351
token_id: u64,
6452
recipient: Address,
@@ -112,7 +100,7 @@ action create_listing(
112100
seller: nft.owner,
113101
price,
114102
created_at: current_time,
115-
state: Created,
103+
state: 0,
116104
};
117105

118106
listing
@@ -174,7 +162,7 @@ action create_offer(
174162
buyer,
175163
price,
176164
expires_at,
177-
state: Created,
165+
state: 0,
178166
};
179167

180168
offer

0 commit comments

Comments
 (0)