Skip to content

Commit a683156

Browse files
authored
feat(docs/stdlib): split and reorder Core libraries (#2391)
* ci(docs): check links in doc comments of stdlib
1 parent f263f4a commit a683156

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+3859
-3680
lines changed

.github/workflows/tact-docs-test.yml

+21-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ on:
1414
"review_requested",
1515
]
1616
branches: ["main"]
17-
# Only start the workflow if anything inside the docs has changed
18-
paths: ["docs/**"]
17+
# Only start the workflow if anything inside the docs or std/internal has changed
18+
paths: ["docs/**", "src/stdlib/stdlib/std/internal/**"]
1919

2020
# Allows to run this workflow manually from the Actions tab
2121
workflow_dispatch:
@@ -67,6 +67,25 @@ jobs:
6767
fail: true
6868
failIfEmpty: false
6969

70+
# That way, when building the docs in the next step,
71+
# their link checker will be able to validate the links in stdlib
72+
- name: Save a file with all the links in stdlib
73+
if: runner.os == 'Linux'
74+
run: |
75+
stdlib_path="src/stdlib/stdlib/std/internal"
76+
linkfile='std-internal-link-test.mdx'
77+
pushd "$stdlib_path"
78+
echo -e '---\ntitle: "std/internal link test"\n---\n' > "$linkfile"
79+
grep 'https://docs.tact.*$' *.tact >> "$linkfile"
80+
# remove possible brackets, since they can interfere
81+
sed -E 's|(\[\|\])||g' -i "$linkfile"
82+
# remove some punctuation characters after the links
83+
sed -E 's|(https://docs.tact-lang.org.*)[.,;]$|\1|g' -i "$linkfile"
84+
# proceed with replacements
85+
sed -E 's|https://docs.tact-lang.org(.*)$|[link](\1)|g' -i "$linkfile"
86+
popd
87+
mv "${stdlib_path}/${linkfile}" docs/src/content/docs/
88+
7089
- name: Build the site
7190
working-directory: docs
7291
run: yarn build

cspell.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
"\\b[xB]\\{[a-fA-F0-9]*_?\\}", // binary literals in Fift-asm
2222
"\\b0[xX][a-fA-F0-9_]*\\b", // hexadecimal numbers
2323
"\\b(?:address|crc32|cell|slice|rawSlice)\\(\".+?\"\\)", // some comptime functions
24-
"ince Tact " // regex in RELEASE.md
24+
"ince Tact ", // regex in RELEASE.md
25+
"core-contextstate"
2526
],
2627
"flagWords": [],
2728
"ignorePaths": [

dev-docs/CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1818
### Docs
1919

2020
- Removed the "gas-expensive" badge from `checkSignature()` and `checkDataSignature()` functions and added a caution note when they do become expensive (from 11th call): PR [#2380](https://github.com/tact-lang/tact/pull/2380)
21+
- Fixed descriptions of `Slice.asString()` and `String.asSlice()` functions: PR [#2391](https://github.com/tact-lang/tact/pull/2391)
22+
- Split Core libraries in the reference: `core-common` and `core-advanced` were removed, and their contents distributed across other libraries; `core-crypto`, `core-contextstate`, `core-send`, `core-gas`, and `core-addresses` were introduced: PR [#2391](https://github.com/tact-lang/tact/pull/2391)
2123

2224
### Release contributors
2325

docs/astro.config.mjs

+10-5
Original file line numberDiff line numberDiff line change
@@ -256,14 +256,17 @@ export default defineConfig({
256256
link: 'ref/core-base#',
257257
},
258258
{ slug: 'ref/core-base' },
259-
{ slug: 'ref/core-common' },
259+
{ slug: 'ref/core-send' },
260+
{ slug: 'ref/core-contextstate' },
260261
{ slug: 'ref/core-comptime' },
262+
{ slug: 'ref/core-cells' },
263+
{ slug: 'ref/core-addresses' },
264+
{ slug: 'ref/core-strings' },
261265
{ slug: 'ref/core-debug' },
262-
{ slug: 'ref/core-random' },
266+
{ slug: 'ref/core-gas' },
267+
{ slug: 'ref/core-crypto' },
263268
{ slug: 'ref/core-math' },
264-
{ slug: 'ref/core-strings' },
265-
{ slug: 'ref/core-cells' },
266-
{ slug: 'ref/core-advanced' },
269+
{ slug: 'ref/core-random' },
267270
{
268271
label: 'Standard libraries',
269272
translations: { 'zh-CN': '标准库' },
@@ -322,5 +325,7 @@ export default defineConfig({
322325
'/ecosystem/tools/jetbrains': '/ecosystem/jetbrains',
323326
'/ecosystem/tools/vscode': '/ecosystem/vscode',
324327
'/ecosystem/tools/misti': '/ecosystem/misti',
328+
'/ref/core-common': '/ref/core-send',
329+
'/ref/core-advanced': '/ref/core-contextstate',
325330
},
326331
});

docs/src/content/docs/book/assembly-functions.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ The [TVM][tvm] places a couple of values onto its stack upon initialization, and
426426

427427
:::
428428

429-
Therefore, to access details such as the amount of [nanoToncoins](/book/integers#nanotoncoin) in a message or the [`Address{:tact}`][p] of the sender, it's strongly recommended to call the [`context(){:tact}`](/ref/core-common#context) or [`sender(){:tact}`](/ref/core-common#sender) functions instead of attempting to look for those values on the stack.
429+
Therefore, to access details such as the amount of [nanoToncoins](/book/integers#nanotoncoin) in a message or the [`Address{:tact}`][p] of the sender, it's strongly recommended to call the [`context(){:tact}`](/ref/core-contextstate#context) or [`sender(){:tact}`](/ref/core-contextstate#sender) functions instead of attempting to look for those values on the stack.
430430

431431
### Don't rely on the order of fields in structures in the standard library {#caveats-stdlib-structures}
432432

docs/src/content/docs/book/debug.mdx

+4-4
Original file line numberDiff line numberDiff line change
@@ -630,13 +630,13 @@ it('your test clause title', async () => {
630630

631631
## Logging via `emit` {#logging}
632632

633-
A [global static function](/book/functions#global-static-functions) [`emit(){:tact}`](/ref/core-common#emit) sends a message to the outer world — it doesn't have a specific recipient.
633+
A [global static function](/book/functions#global-static-functions) [`emit(){:tact}`](/ref/core-send#emit) sends a message to the outer world — it doesn't have a specific recipient.
634634

635635
This function is very handy for logging and analyzing data off-chain — one just has to look at [external messages](/book/external) produced by the contract.
636636

637637
### Logs in local Sandbox tests {#logging-local}
638638

639-
When deploying in the [Sandbox][sb], you may call [`emit(){:tact}`](/ref/core-common#emit) from a [receiver function](/book/contracts#receiver-functions) and then observe the list of sent [external messages](/book/external):
639+
When deploying in the [Sandbox][sb], you may call [`emit(){:tact}`](/ref/core-send#emit) from a [receiver function](/book/contracts#receiver-functions) and then observe the list of sent [external messages](/book/external):
640640

641641
```typescript {9-10}
642642
it('emits', async () => {
@@ -656,7 +656,7 @@ it('emits', async () => {
656656

657657
Every transaction on TON Blockchain [contains `out_msgs`](https://docs.ton.org/develop/data-formats/transaction-layout#transaction) — a dictionary that holds the list of outgoing messages created during the transaction execution.
658658

659-
To see logs from [`emit(){:tact}`](/ref/core-common#emit) in that dictionary, look for external messages without a recipient. In various TON Blockchain explorers, such transactions will be marked as `external-out` with the destination specified as `-` or `empty`.
659+
To see logs from [`emit(){:tact}`](/ref/core-send#emit) in that dictionary, look for external messages without a recipient. In various TON Blockchain explorers, such transactions will be marked as `external-out` with the destination specified as `-` or `empty`.
660660

661661
Note that some explorers deserialize the message body sent for you, while others don't. However, you can always [parse it yourself](#logging-parsing) locally.
662662

@@ -697,7 +697,7 @@ it('emits', async () => {
697697
});
698698
```
699699

700-
Here, the `res` object would contain the list of sent [external messages](/book/external) as its `externals` field. Let's access it to parse the first message sent via a call to [`emit(){:tact}`](/ref/core-common#emit) in Tact code (or _emitted_ for short):
700+
Here, the `res` object would contain the list of sent [external messages](/book/external) as its `externals` field. Let's access it to parse the first message sent via a call to [`emit(){:tact}`](/ref/core-send#emit) in Tact code (or _emitted_ for short):
701701

702702
```typescript /body/
703703
it('emits', async () => {

docs/src/content/docs/book/exit-codes.mdx

+2-2
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ Here are some of the functions in Tact which can throw an error with this exit c
617617

618618
1. [`Int.toFloatString(digits){:tact}`](/ref/core-strings#inttofloatstring): if `digits` is not in the interval $0 < digits < 78$.
619619

620-
2. [`String.fromBase64(){:tact}`](/ref/core-strings#stringfrombase64) and [`Slice.fromBase64(){:tact}`](/ref/core-strings#slicefrombase64): if the given [`String{:tact}`][p] or [`Slice{:tact}`][slice] contains non-Base64 characters.
620+
2. [`String.fromBase64(){:tact}`](/ref/core-strings#stringfrombase64) and [`Slice.fromBase64(){:tact}`](/ref/core-cells#slicefrombase64): if the given [`String{:tact}`][p] or [`Slice{:tact}`][slice] contains non-Base64 characters.
621621

622622
```tact
623623
try {
@@ -680,7 +680,7 @@ try {
680680

681681
The value of type [`Address{:tact}`][p] belongs to a basechain, when its [chain ID](https://docs.ton.org/learn/overviews/addresses#workchain-id) is equal to 0.
682682

683-
Such check is currently only performed in the [`forceBasechain(){:tact}`](/ref/core-advanced#forcebasechain) function. If the address does not belong to a basechain, i.e., its chain ID isn't 0, the function throws an error with exit code 138: `Not a basechain address`.
683+
Such check is currently only performed in the [`forceBasechain(){:tact}`](/ref/core-addresses#forcebasechain) function. If the address does not belong to a basechain, i.e., its chain ID isn't 0, the function throws an error with exit code 138: `Not a basechain address`.
684684

685685
```tact
686686
let someBasechainAddress: Address =

docs/src/content/docs/book/expressions.mdx

+3-3
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ Field | Type | Description
282282

283283
:::note
284284

285-
For workchain 0, the [`Address{:tact}`][p] of the current contract obtained by calling the [`myAddress(){:tact}`](/ref/core-common#myaddress) function is identical to the one that can be obtained by calling the [`contractAddress(){:tact}`](/ref/core-common#contractaddress) function with the initial state of the current contract computed via `initOf{:tact}`:
285+
For workchain 0, the [`Address{:tact}`][p] of the current contract obtained by calling the [`myAddress(){:tact}`](/ref/core-contextstate#myaddress) function is identical to the one that can be obtained by calling the [`contractAddress(){:tact}`](/ref/core-addresses#contractaddress) function with the initial state of the current contract computed via `initOf{:tact}`:
286286

287287
```tact {6}
288288
contract TheKingPrawn {
@@ -295,7 +295,7 @@ Field | Type | Description
295295
}
296296
```
297297

298-
However, if you only need the address of the current contract at runtime and not its `StateInit{:tact}`, use the [`myAddress(){:tact}`](/ref/core-common#myaddress) function, as it consumes **significantly** less gas.
298+
However, if you only need the address of the current contract at runtime and not its `StateInit{:tact}`, use the [`myAddress(){:tact}`](/ref/core-contextstate#myaddress) function, as it consumes **significantly** less gas.
299299

300300
:::
301301

@@ -314,7 +314,7 @@ codeOf ExampleContract; // a Cell with ExampleContract code
314314
// name of the contract
315315
```
316316

317-
If `codeOf{:tact}` is used for the current contract, its result is equivalent to calling [`myCode(){:tact}`](/ref/core-advanced#mycode).
317+
If `codeOf{:tact}` is used for the current contract, its result is equivalent to calling [`myCode(){:tact}`](/ref/core-contextstate#mycode).
318318

319319
```tact
320320
contract ExampleContract {

docs/src/content/docs/book/gas-best-practices.mdx

+6-6
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,9 @@ If your contract method does not access any of its persistent state variables, m
161161

162162
### Use `sender()` over `context().sender`
163163

164-
When you receive an internal message, you can obtain the address of the contract that has sent it. This can be done by calling the [`sender()`](/ref/core-common#sender) function or by accessing the `.sender` field of the `Context{:tact}` [struct][struct] after calling the [`context()`](/ref/core-common#context) function.
164+
When you receive an internal message, you can obtain the address of the contract that has sent it. This can be done by calling the [`sender()`](/ref/core-contextstate#sender) function or by accessing the `.sender` field of the `Context{:tact}` [struct][struct] after calling the [`context()`](/ref/core-contextstate#context) function.
165165

166-
If you only need the sender's address and no additional context on the incoming message that is contained in the `Context{:tact}` struct, then use the [`sender()`](/ref/core-common#sender) function as it is less gas-consuming.
166+
If you only need the sender's address and no additional context on the incoming message that is contained in the `Context{:tact}` struct, then use the [`sender()`](/ref/core-contextstate#sender) function as it is less gas-consuming.
167167

168168
```tact /sender\\(\\)/
169169
message(MessageParameters{
@@ -194,9 +194,9 @@ fun example() {
194194

195195
Every [contract](/book/contracts) in Tact implicitly [inherits](/book/contracts#traits) the `BaseTrait{:tact}` trait, which contains a number of [internal functions](/book/contracts#internal-functions) for any contract. Those internal functions are gas-expensive for the same reasons as stated earlier.
196196

197-
Calls to `self.forward(){:tact}`, `self.reply(){:tact}` and `self.notify(){:tact}` can be replaced with respective calls to the [`send(){:tact}`](/ref/core-common#send) or [`message(){:tact}`](/ref/core-common#message) functions with suitable values.
197+
Calls to `self.forward(){:tact}`, `self.reply(){:tact}` and `self.notify(){:tact}` can be replaced with respective calls to the [`send(){:tact}`](/ref/core-send#send) or [`message(){:tact}`](/ref/core-send#message) functions with suitable values.
198198

199-
Moreover, if all you want is to forward the remaining value back to the sender, it is best to use the [`cashback(){:tact}`](/ref/core-common#cashback) function instead of `self.notify(){:tact}` function.
199+
Moreover, if all you want is to forward the remaining value back to the sender, it is best to use the [`cashback(){:tact}`](/ref/core-send#cashback) function instead of `self.notify(){:tact}` function.
200200

201201
```tact
202202
// This
@@ -234,7 +234,7 @@ cashback(sender());
234234

235235
### Use `deploy()` function for on-chain deployments
236236

237-
There are many [message-sending functions](/book/send#message-sending-functions), and the [`deploy(){:tact}`](/ref/core-common#deploy) function is optimized for cheaper on-chain deployments compared to the [`send(){:tact}`](/ref/core-common#send) function.
237+
There are many [message-sending functions](/book/send#message-sending-functions), and the [`deploy(){:tact}`](/ref/core-send#deploy) function is optimized for cheaper on-chain deployments compared to the [`send(){:tact}`](/ref/core-send#send) function.
238238

239239
```tact
240240
deploy(DeployParameters{
@@ -247,7 +247,7 @@ deploy(DeployParameters{
247247

248248
### Use `message()` function for non-deployment messages
249249

250-
There are many [message-sending functions](/book/send#message-sending-functions), and the [`message(){:tact}`](/ref/core-common#message) function is optimized for cheaper non-deployment regular messages compared to the [`send(){:tact}`](/ref/core-common#send) function.
250+
There are many [message-sending functions](/book/send#message-sending-functions), and the [`message(){:tact}`](/ref/core-send#message) function is optimized for cheaper non-deployment regular messages compared to the [`send(){:tact}`](/ref/core-send#send) function.
251251

252252
```tact
253253
message(MessageParameters{

docs/src/content/docs/book/message-mode.mdx

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: "Messages are sent with the mode param of the struct SendParameters
55

66
import { Badge } from '@astrojs/starlight/components';
77

8-
As previously mentioned, messages sent via the [`send(){:tact}`](/ref/core-common#send) function utilize the `mode` parameter of the `SendParameters{:tact}` structure. The `mode` is an [`Int{:tact}`][int] value, which is combined from base modes and optional flags, which are also [`Int{:tact}`][int] values.
8+
As previously mentioned, messages sent via the [`send(){:tact}`](/ref/core-send#send) function utilize the `mode` parameter of the `SendParameters{:tact}` structure. The `mode` is an [`Int{:tact}`][int] value, which is combined from base modes and optional flags, which are also [`Int{:tact}`][int] values.
99

1010
It's possible to use raw [`Int{:tact}`][int] values and manually provide them for the `mode`, but for your convenience there is a set of constants you may use to easily construct the compound `mode`. Take a look at the following tables for more information on base modes and optional flags.
1111

@@ -68,7 +68,7 @@ Note that there can be only **one** [base mode](#base-modes), but the number of
6868

6969
Some [message-sending functions](/book/send#message-sending-functions) do not allow setting a mode by passing an argument. This is because their internal logic requires a specific fixed set of modes to be used instead:
7070

71-
* [`emit(){:tact}`](/ref/core-common#emit) sends a message with the `SendDefaultMode{:tact}` ($0$).
71+
* [`emit(){:tact}`](/ref/core-send#emit) sends a message with the `SendDefaultMode{:tact}` ($0$).
7272
* [`self.reply(){:tact}`](/ref/core-base#self-reply), [`self.notify(){:tact}`](/ref/core-base#self-notify), and [`self.forward(){:tact}`](/ref/core-base#self-forward) all use the `SendRemainingValue{:tact}` mode unless the [`self.storageReserve{:tact}`](/ref/core-base#self-storagereserve) constant is overridden to be greater than $0$, in which case they attempt to use the `SendRemainingBalance{:tact}` mode.
7373

7474
[int]: /book/integers

docs/src/content/docs/book/security-best-practices.mdx

+2-2
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ A message cascade can be processed over many blocks. Assume that while one messa
299299

300300
## Handle/Send bounced messages
301301

302-
Send messages with the bounce flag set to `true{:tact}`, which is the default for the [`send(){:tact}`](/ref/core-common#send) function. Messages bounce when the execution of a contract fails. You may want to handle this by rolling back the state of the contract using [`try...catch{:tact}`](/book/statements#try-catch) statements and performing additional processing depending on your logic.
302+
Send messages with the bounce flag set to `true{:tact}`, which is the default for the [`send(){:tact}`](/ref/core-send#send) function. Messages bounce when the execution of a contract fails. You may want to handle this by rolling back the state of the contract using [`try...catch{:tact}`](/book/statements#try-catch) statements and performing additional processing depending on your logic.
303303

304304
##### Do's ✅
305305

@@ -356,7 +356,7 @@ From the [Sending messages page](/book/send#outbound-message-processing) of the
356356

357357
> Each transaction on TON Blockchain consists of multiple phases. Outbound messages are evaluated in the compute phase but are **not** sent in that phase. Instead, they're queued in order of appearance for the action phase, where all actions listed in the compute phase, such as outbound messages or reserve requests, are executed.
358358
359-
Hence, if the compute phase fails, [registers](https://docs.ton.org/v3/documentation/tvm/tvm-overview#control-registers) `c4` (persistent data) and `c5` (actions) won't be updated. However, it is possible to manually save their state using the [`commit(){:tact}`](/ref/core-advanced/#commit) function.
359+
Hence, if the compute phase fails, [registers](https://docs.ton.org/v3/documentation/tvm/tvm-overview#control-registers) `c4` (persistent data) and `c5` (actions) won't be updated. However, it is possible to manually save their state using the [`commit(){:tact}`](/ref/core-contextstate#commit) function.
360360

361361
## Return gas excesses carefully
362362

0 commit comments

Comments
 (0)