Skip to content

Commit

Permalink
Merge branch 'main' of github.com:pixelplex/tact into docs/cookbook-s…
Browse files Browse the repository at this point in the history
…tonfi
  • Loading branch information
novusnota committed Nov 24, 2024
2 parents 0aeb00f + 6320faa commit 967caff
Show file tree
Hide file tree
Showing 70 changed files with 5,080 additions and 1,461 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/comment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Comment
on:
issue_comment:
types: [created]
pull_request_review_comment:
types: [created]

jobs:
build:
name: Telegram
runs-on: ubuntu-latest
if: ${{ github.event.issue.pull_request }}
steps:
- name: Send telegram message on push
uses: appleboy/[email protected]
with:
to: ${{ secrets.TELEGRAM_ISSUE_CHAT_ID }}
token: ${{ secrets.TELEGRAM_ISSUE_TOKEN }}
format: Markdown
# this might go wrong, because `title` and `body` can have arbitrary markdown
message: |
✏️ [${{ github.event.comment.user.login }}](${{ github.event.comment.html_url }}): ${{ github.event.comment.body }}
🔀 ${{ github.event.issue.title }}
23 changes: 23 additions & 0 deletions .github/workflows/pull.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Pull request
on:
pull_request:
types: [opened, reopened]

jobs:
build:
name: Telegram
runs-on: ubuntu-latest
steps:
- name: Send telegram message on push
uses: appleboy/[email protected]
continue-on-error: true
with:
to: ${{ secrets.TELEGRAM_ISSUE_CHAT_ID }}
token: ${{ secrets.TELEGRAM_ISSUE_TOKEN }}
format: Markdown
# this might go wrong, because `title` can have arbitrary markdown
message: |
🍰 [${{ github.event.pull_request.title }}](${{ github.event.pull_request.html_url }})
🌲 ${{ github.repository }}
👤 ${{ github.actor }}
🔀 ${{ github.event.pull_request.base.label }} <- ${{ github.event.pull_request.head.label }}
23 changes: 23 additions & 0 deletions .github/workflows/tact.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,29 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup Node.js 18 for backwards compat tests
uses: actions/setup-node@v3
with:
node-version: 18
# without caching

- name: Backwards compat tests
run: |
# Temporarily ignore engines
yarn config set ignore-engines true
# Install dependencies, gen and build the compiler
yarn install
yarn clean
yarn gen
yarn build
# Test some specific things for backwards compatibility.
# It's important to restrain from using too much of Node.js 22+ features
# until it goes into maintenance LTS state and majority of users catches up
yarn jest -t 'isSubsetOf'
# Clean-up
yarn cleanall
yarn config delete ignore-engines
- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
Expand Down
15 changes: 11 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,37 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- New CSpell dictionaries: TVM instructions and adjusted list of Fift words: PR [#881](https://github.com/tact-lang/tact/pull/881)
- Docs: the `description` property to the frontmatter of the each page for better SEO: PR [#916](https://github.com/tact-lang/tact/pull/916)
- Docs: Google Analytics tags per every page: PR [#921](https://github.com/tact-lang/tact/pull/921)
- Docs: Added Ston.fi cookbook: PR [#956](https://github.com/tact-lang/tact/pull/956)
- Docs: Added NFTs cookbook: PR [#958](https://github.com/tact-lang/tact/pull/958)
- Docs: added Ston.fi cookbook: PR [#956](https://github.com/tact-lang/tact/pull/956)
- Docs: added NFTs cookbook: PR [#958](https://github.com/tact-lang/tact/pull/958)
- Ability to specify a compile-time method ID expression for getters: PR [#922](https://github.com/tact-lang/tact/pull/922) and PR [#932](https://github.com/tact-lang/tact/pull/932)
- Destructuring of structs and messages: PR [#856](https://github.com/tact-lang/tact/pull/856)
- Destructuring of structs and messages: PR [#856](https://github.com/tact-lang/tact/pull/856), PR [#964](https://github.com/tact-lang/tact/pull/964), PR [#969](https://github.com/tact-lang/tact/pull/969)
- Docs: automatic links to Web IDE from all code blocks: PR [#994](https://github.com/tact-lang/tact/pull/994)
- The `SendDefaultMode` send mode constant to the standard library: PR [#1010](https://github.com/tact-lang/tact/pull/1010)
- Docs: initial semi-automated Chinese translation of the documentation: PR [#942](https://github.com/tact-lang/tact/pull/942)
- The `replace` and `replaceGet` methods for the `Map` type: PR [#941](https://github.com/tact-lang/tact/pull/941)
- Utility for logging errors in code that was supposed to be unreachable: PR [#991](https://github.com/tact-lang/tact/pull/991)
- Docs: `preloadRef` method for the `Slice` type: PR [#1044](https://github.com/tact-lang/tact/pull/1044)
- Docs: added DeDust cookbook: PR [#954](https://github.com/tact-lang/tact/pull/954)

### Changed

- The `parseImports` function now returns AST import nodes instead of raw strings: PR [#966](https://github.com/tact-lang/tact/pull/966)
- Optional types for `self` argument in `extends mutates` functions are now allowed: PR [#854](https://github.com/tact-lang/tact/pull/854)
- Docs: complete overhaul of the exit codes page: PR [#978](https://github.com/tact-lang/tact/pull/978)
- Docs: enhanced Jettons Cookbook page: PR [#944](https://github.com/tact-lang/tact/pull/944)
- Error codes in the report are now formatted as a list: PR [#1051](https://github.com/tact-lang/tact/pull/1051)

### Fixed

- Collisions in getter method ids are now handled and reported properly: PR [#875](https://github.com/tact-lang/tact/pull/875)
- Collisions in getter method ids are now handled and reported properly: PR [#875](https://github.com/tact-lang/tact/pull/875), PR [#1052](https://github.com/tact-lang/tact/pull/1052)
- Docs: layout of tables, syntax highlighting, Chinese translations of sidebar separators: PR [#916](https://github.com/tact-lang/tact/pull/916)
- Non-null struct fields after null ones are treated correctly in Sandbox tests after updating `@ton/core` to 0.59.0: PR [#933](https://github.com/tact-lang/tact/pull/933)
- Prevent inline code snippets from changing their background color: PR [#935](https://github.com/tact-lang/tact/pull/935)
- Docs: correctly handle next and previous page links at the bottom of the pages when there's a separator item in the sidebar: PR [#949](https://github.com/tact-lang/tact/pull/949)
- Docs: compilation of examples in `data-structures.mdx` and across Cookbook: PR [#917](https://github.com/tact-lang/tact/pull/917)
- `as coins` map value serialization type is now handled correctly: PR [#987](https://github.com/tact-lang/tact/pull/987)
- Type checking for `foreach` loops in trait methods: PR [#1017](https://github.com/tact-lang/tact/pull/1017)
- The `sha256()` function no longer throws on statically known strings of any length: PR [#907](https://github.com/tact-lang/tact/pull/907)

### Release contributors

Expand Down
1 change: 1 addition & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
"uintptr",
"uninit",
"unixfs",
"varuint",
"workchain",
"xffff",
"привет"
Expand Down
2 changes: 1 addition & 1 deletion docs/links-to-web-ide.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export default function remarkLinksToWebIDE() {
// Constructing opening <a> tag
[
// Open the tag
'<a',
'<a data-pagefind-ignore="all"',
// Make links opened in new tab
'target="_blank"',
// Set styles
Expand Down
4 changes: 2 additions & 2 deletions docs/src/content/docs/book/operators.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ Unary here means that they are applied only to one operand of the given expressi

Unary operators can be one of the two types:

* prefix — placed before the expression.
* postfix (or suffix) — placed after the expression.
* Prefix — placed before the expression.
* Postfix (or suffix) — placed after the expression.

### Non-null assert, `!!` {#unary-non-null-assert}

Expand Down
155 changes: 155 additions & 0 deletions docs/src/content/docs/book/statements.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ title: Statements
description: "This page lists all the statements in Tact, which can appear anywhere in the function bodies"
---

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

The following statements can appear anywhere in the [function](/book/functions) body.

## `let` statement {#let}
Expand Down Expand Up @@ -96,6 +98,157 @@ value += 5; // augmented assignment (one of the many, see below)

:::

## Destructuring assignment

<Badge text="Available since Tact 1.6" variant="tip" size="medium"/><p/>

The destructuring assignment is a concise way to unpack [Structs][s] and [Messages][m] into distinct variables. It mirrors the [instantiation syntax](/book/expressions#instantiation), but instead of creating a new [Struct][s] or [Message][m] it binds every field or some of the fields to their respective variables.

The syntax is derived from the [`let` statement](#let), and instead of specifying the variable name directly it involves specifying the structure type on the left side of the [assignment operator `={:tact}`](/book/operators#assignment), which corresponds to the structure type of the value on the right side.

```tact {9}
// Definition of Example
struct Example { number: Int }
// An arbitrary helper function
fun get42(): Example { return Example { number: 42 } }
fun basic() {
// Basic syntax of destructuring assignment (to the left of "="):
let Example { number } = get42();
// ------- ------ -------
// ↑ ↑ ↑
// | | gives the Example Struct
// | definition of "number" variable, derived
// | from the field "number" in Example Struct
// target structure type "Example"
// to destructure fields from
// Same as above, but with an instantiation
// to showcase how destructuring syntax mirrors it:
let Example { number } = Example { number: 42 };
// ----------------------
// ↑
// instantiation of Example Struct
// Above examples of syntax are roughly equivalent
// to the following series of statements:
let example = Example { number: 42 };
let number = example.number;
}
```

Just like in [instantiation](/book/expressions#instantiation), the trailing comma is allowed.

```tact
struct Example { number: Int }
fun trailblazing() {
let Example {
number, // trailing comma inside variable list
} = Example {
number: 42, // trailing comma inside field list
};
}
```

:::note

[Augmented assignment operators](/book/operators#augmented-assignment) do not make sense for such assignments and will therefore be reported as parsing errors:

```tact
struct Example { number: Int }
fun get42(): Example { return Example { number: 42 } }
fun basic() {
let Example { number } += get42();
// ^ this will result in the parse error:
// expected "="
}
```

:::

To create a binding under a different variable name, specify it after the semicolon `:{:tact}`.

```tact
// Similar definition, but this time field is called "field", not "number"
struct Example { field: Int }
fun naming(s: Example) {
let Example { field: varFromField } = s;
// ------------ ↑
// ↑ |
// | instance of Example Struct, received
// | as a parameter of the function "naming"
// definition of "varFromField" variable, derived
// from the field "field" in Example Struct
}
```

Note, that the order of bindings doesn't matter — all the fields retain their values and types under their names no matter the order in which they stand in their definition in the respective [Struct][s] or [Message][m].

```tact
// "first" goes first, then goes "second"
struct Two { first: Int; second: String }
fun order(s: Two) {
let Two { second, first } = s;
// ------ -----
// ↑ ↑
// | this variable will be of type Int,
// | same as the "first" field on Struct Two
// this variable will be of type String,
// same as the "second" field in Struct Two
}
```

Destructuring assignment is exhaustive and requires specifying all the fields as variables. To deliberately ignore some of the fields, use an underscore `_{:tact}`, which discards the considered field's value. Note, that such wildcard variable name `_{:tact}` cannot be accessed:

```tact
// "first" goes first, then goes "second"
struct Two { first: Int; second: String }
fun discard(s: Two) {
let Two { second: _, first } = s;
// ---
// ↑
// discards the "second" field, only taking the "first"
}
```

To completely ignore the rest of the fields, use `..` at the end of the list:

```tact
struct Many { one: Int; two: Int; three: Int; fans: Int }
fun ignore(s: Many) {
let Many { fans, .. } = s;
// --
// ↑
// ignores all the unspecified fields,
// defining only "fans"
}
```

:::caution

At the moment, destructuring of nested [Structs][s] or [Messages][m] isn't allowed. That is, the following won't work:

```tact
struct First { nested: Second }
struct Second { field: Int }
fun example() {
let prep = First { nested: Second { field: 42 } };
let First { nested: { field: thing } } = prep;
// ^ this will result in the parse error:
// expected "_", "A".."Z", or "a".."z"
}
```

:::

## Branches

Control the flow of the code.
Expand Down Expand Up @@ -415,3 +568,5 @@ foreach (_, _ in quartiles) {
:::

[int]: /book/integers
[s]: /book/structs-and-messages#structs
[m]: /book/structs-and-messages#messages
Loading

0 comments on commit 967caff

Please sign in to comment.