Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions dev-docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Code generation

- Optimized optional global variables initialization: PR [#3327](https://github.com/tact-lang/tact/pull/3327)

### Docs

- Described off-chain calls and mention exit code 11 for getters: PR [#3314](https://github.com/tact-lang/tact/pull/3314)
Expand Down
10 changes: 10 additions & 0 deletions src/benchmarks/wallet-v5/gas.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,16 @@
"internalTransfer": "5724",
"extensionTransfer": "4656"
}
},
{
"label": "1.6.13 with optimized optional globals",
"pr": "https://github.com/tact-lang/tact/pull/3327",
"gas": {
"externalTransfer": "4965",
"addExtension": "5628",
"internalTransfer": "5722",
"extensionTransfer": "4654"
}
}
]
}
15 changes: 13 additions & 2 deletions src/generator/writeProgram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
writeSerializer,
} from "@/generator/writers/writeSerialization";
import { writeStdlib } from "@/generator/writers/writeStdlib";
import { enabledOptimizedChildCode } from "@/config/features";
import { writeAccessors } from "@/generator/writers/writeAccessors";
import type { ContractABI } from "@ton/core";
import { writeFunction } from "@/generator/writers/writeFunction";
Expand Down Expand Up @@ -116,8 +117,18 @@ export async function writeProgram(
globalVariables.push("global slice __tact_context_sender;");
}

globalVariables.push("global cell __tact_child_contract_codes;");
globalVariables.push("global int __tact_randomized;");
const needsChildCodes =
contract.dependsOn.length > 0 && !enabledOptimizedChildCode(ctx);
if (needsChildCodes) {
globalVariables.push("global cell __tact_child_contract_codes;");
}

const needsRandom = functions.some(
(f) => f.name === "__tact_prepare_random",
);
if (needsRandom) {
globalVariables.push("global int __tact_randomized;");
}

if (contract.globalVariables.has("inMsg")) {
globalVariables.push("global slice __tact_in_msg;");
Expand Down
Loading