Skip to content

Commit

Permalink
Merge branch 'pmakhnev/rewrite-address-related-functions-to-tact' of …
Browse files Browse the repository at this point in the history
…github.com:tact-lang/tact into pmakhnev/rewrite-address-related-functions-to-tact
  • Loading branch information
novusnota committed Feb 14, 2025
2 parents 03099fc + e380b2f commit 4427701
Show file tree
Hide file tree
Showing 183 changed files with 1,365 additions and 751 deletions.
8 changes: 8 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ module.exports = {
es2021: true,
},
rules: {
"@typescript-eslint/consistent-type-imports": [
"error",
{
prefer: "type-imports",
fixStyle: "separate-type-imports",
disallowTypeAnnotations: true,
},
],
"@typescript-eslint/no-unused-vars": [
"error",
{
Expand Down
2 changes: 2 additions & 0 deletions dev-docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `nullChecks` config option to disable run-time null checks for the `!!` operator in order to save gas: PR [#1660](https://github.com/tact-lang/tact/pull/1660)
- `loadVarInt16`, `loadVarUint16`, `loadVarInt32`, `loadVarUint32` methods for the `Slice` type: PR [#1667](https://github.com/tact-lang/tact/pull/1667)
- New functions in stdlib from `stdlib.fc` and `math.fc`: `Builder.depth`, `Slice.skipLastBits`, `Slice.firstBits`, `Slice.lastBits`, `Slice.depth`, `Cell.computeDataSize`, `Slice.computeDataSize`, `Cell.depth`, `curLt`, `blockLt`, `setGasLimit`, `getSeed`, `setSeed`, `myCode`, `sign`, `divc`, `muldivc`, `mulShiftRight`, `mulShiftRightRound`, `mulShiftRightCeil`, `sqrt`: PR [#986](https://github.com/tact-lang/tact/pull/986)
- The `--output` CLI flag for specifying custom output directory in single-contract compilation: PR [#1793](https://github.com/tact-lang/tact/pull/1793)
- New functions `Slice.asAddressUnsafe`, `contractHash`, `Builder.hash` in stdlib: PR [#1766](https://github.com/tact-lang/tact/pull/1766)

### Changed
Expand All @@ -48,6 +49,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Better error message for `extend function without parameters` error: PR [#1624](https://github.com/tact-lang/tact/pull/1624)
- Don't generate `lazy_deployment_completed` by default: PR [#1717](https://github.com/tact-lang/tact/pull/1717)
- Optimized `emptyCell()` and `emptySlice()` functions: PR [#1696](https://github.com/tact-lang/tact/pull/1696)
- Internal `crc16` function is now verifiable and covered with tests: PR [#1739](https://github.com/tact-lang/tact/pull/1739)
- Rearrange parameters of some asm methods in order described in `AsmShuffle`: PR [#1702](https://github.com/tact-lang/tact/pull/1702)
- Error message for invalid type for function argument now shows expected type: PR [#1738](https://github.com/tact-lang/tact/pull/1738)

Expand Down
10 changes: 9 additions & 1 deletion docs/src/content/docs/book/compile.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,15 @@ If you want to pin down a specific version of the compiler, run the following co

A number of build artifacts can be produced per compilation of each contract. Some of the artifacts can be omitted using [configuration settings](/book/config).

The location of the artifacts depends on the [`output`](/book/config#projects-output) field of the [`tact.config.json`](/book/config). In [Blueprint][bp]-based projects, `output` is not used and all generated files are always placed in `build/ProjectName/`.
The location of the artifacts depends on the compilation method:
- For projects using `tact.config.json`, use the [`output`](/book/config#projects-output) field in the config file
- For single contract compilation, you can specify the output directory using the `-o` or `--output` flag:
```shell
tact contract.tact --output ./custom-output
```
If not specified, the files will be generated in the same directory as the input file.

In [Blueprint][bp]-based projects, `output` is not used and all generated files are always placed in `build/ProjectName/`.

### Compilation report, `.md` {#report}

Expand Down
3 changes: 2 additions & 1 deletion examples/increment.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { IncrementContract } from "./output/increment_IncrementContract";
import { Blockchain, SandboxContract, TreasuryContract } from "@ton/sandbox";
import type { SandboxContract, TreasuryContract } from "@ton/sandbox";
import { Blockchain } from "@ton/sandbox";
import { toNano } from "@ton/core";
import "@ton/test-utils";

Expand Down
3 changes: 2 additions & 1 deletion examples/multisig-3.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { toNano } from "@ton/core";
import { Blockchain, SandboxContract, TreasuryContract } from "@ton/sandbox";
import type { SandboxContract, TreasuryContract } from "@ton/sandbox";
import { Blockchain } from "@ton/sandbox";
import { MultisigContract } from "./output/multisig-3_MultisigContract";
import "@ton/test-utils";

Expand Down
8 changes: 5 additions & 3 deletions examples/verify.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import normalize from "path-normalize";
import { Cell } from "@ton/core";
import { Config, Options } from "../src/config/parseConfig";
import { ILogger, Logger } from "../src/context/logger";
import { PackageFileFormat, run } from "../src";
import type { Config, Options } from "../src/config/parseConfig";
import type { ILogger } from "../src/context/logger";
import { Logger } from "../src/context/logger";
import type { PackageFileFormat } from "../src";
import { run } from "../src";
import { fileFormat } from "../src/packaging/fileFormat";
import { getCompilerVersion } from "../src/pipeline/version";

Expand Down
6 changes: 4 additions & 2 deletions examples/wallet.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { storeTransfer, Transfer, Wallet } from "./output/wallet_Wallet";
import { Blockchain, SandboxContract, TreasuryContract } from "@ton/sandbox";
import type { Transfer } from "./output/wallet_Wallet";
import { storeTransfer, Wallet } from "./output/wallet_Wallet";
import type { SandboxContract, TreasuryContract } from "@ton/sandbox";
import { Blockchain } from "@ton/sandbox";
import { beginCell, toNano } from "@ton/core";
import { sign } from "@ton/crypto";
import { randomKey } from "../src/test/utils/random-utils";
Expand Down
2 changes: 2 additions & 0 deletions spell/cspell-list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ cheatsheet
Cheatsheet
cheatsheets
Cheatsheets
CCITT
cleanall
codegen
compilables
Expand Down Expand Up @@ -167,5 +168,6 @@ vogons
workchain
workchains
xffff
XMODEM
xtwitter
привет
10 changes: 5 additions & 5 deletions src/abi/AbiFunction.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { AstExpression } from "../ast/ast";
import { CompilerContext } from "../context/context";
import { WriterContext } from "../generator/Writer";
import { TypeRef } from "../types/types";
import { SrcInfo } from "../grammar";
import type { AstExpression } from "../ast/ast";
import type { CompilerContext } from "../context/context";
import type { WriterContext } from "../generator/Writer";
import type { TypeRef } from "../types/types";
import type { SrcInfo } from "../grammar";

export type AbiFunction = {
name: string;
Expand Down
2 changes: 1 addition & 1 deletion src/abi/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import { writeExpression } from "../generator/writers/writeExpression";
import { throwCompilationError } from "../error/errors";
import { getErrorId } from "../types/resolveErrors";
import { AbiFunction } from "./AbiFunction";
import type { AbiFunction } from "./AbiFunction";
import path from "path";
import { cwd } from "process";
import { posixNormalize } from "../utils/filePath";
Expand Down
13 changes: 7 additions & 6 deletions src/abi/map.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { CompilerContext } from "../context/context";
import { SrcInfo } from "../grammar";
import { printTypeRef, TypeRef } from "../types/types";
import { WriterContext } from "../generator/Writer";
import type { CompilerContext } from "../context/context";
import type { SrcInfo } from "../grammar";
import type { TypeRef } from "../types/types";
import { printTypeRef } from "../types/types";
import type { WriterContext } from "../generator/Writer";
import { ops } from "../generator/writers/ops";
import { writeExpression } from "../generator/writers/writeExpression";
import { throwCompilationError } from "../error/errors";
import { getType } from "../types/resolveDescriptors";
import { AbiFunction } from "./AbiFunction";
import { AstExpression } from "../ast/ast";
import type { AbiFunction } from "./AbiFunction";
import type { AstExpression } from "../ast/ast";
import { isAssignable } from "../types/subtyping";

// Helper functions to avoid redundancy
Expand Down
2 changes: 1 addition & 1 deletion src/abi/struct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ops } from "../generator/writers/ops";
import { writeExpression } from "../generator/writers/writeExpression";
import { throwCompilationError } from "../error/errors";
import { getType } from "../types/resolveDescriptors";
import { AbiFunction } from "./AbiFunction";
import type { AbiFunction } from "./AbiFunction";

export const StructFunctions: Map<string, AbiFunction> = new Map([
[
Expand Down
2 changes: 1 addition & 1 deletion src/ast/ast-constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { keys } from "../utils/tricks";
import {
import type {
AstAugmentedAssignOperation,
AstBinaryOperation,
AstFunctionAttributeName,
Expand Down
4 changes: 2 additions & 2 deletions src/ast/ast-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as A from "./ast";
import { AstId } from "./ast";
import type * as A from "./ast";
import type { AstId } from "./ast";
import { throwInternalCompilerError } from "../error/errors";
import { dummySrcInfo } from "../grammar";

Expand Down
2 changes: 1 addition & 1 deletion src/ast/ast-printer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as A from "./ast";
import type * as A from "./ast";
import { groupBy, intercalate, isUndefined } from "../utils/array";
import { makeVisitor } from "../utils/tricks";
import { astNumToString, idText } from "./ast-helpers";
Expand Down
8 changes: 4 additions & 4 deletions src/ast/ast.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Address, Cell, Slice } from "@ton/core";
import { SrcInfo } from "../grammar/src-info";
import { RelativePath } from "../imports/path";
import { Language } from "../imports/source";
import type { Address, Cell, Slice } from "@ton/core";
import type { SrcInfo } from "../grammar/src-info";
import type { RelativePath } from "../imports/path";
import type { Language } from "../imports/source";

export type AstModule = {
readonly kind: "module";
Expand Down
4 changes: 2 additions & 2 deletions src/ast/clone.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AstNode } from "./ast";
import { FactoryAst } from "./ast-helpers";
import type { AstNode } from "./ast";
import type { FactoryAst } from "./ast-helpers";
import { throwInternalCompilerError } from "../error/errors";

export function cloneNode<T extends AstNode>(
Expand Down
8 changes: 4 additions & 4 deletions src/ast/getAstSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
* We have this file so that the "current id" state would not be stored globally
*/

import { Loc } from "@tonstudio/parser-runtime";
import * as A from "./ast";
import { FactoryAst } from "../ast/ast-helpers";
import { SrcInfo } from "../grammar/src-info";
import type { Loc } from "@tonstudio/parser-runtime";
import type * as A from "./ast";
import type { FactoryAst } from "../ast/ast-helpers";
import type { SrcInfo } from "../grammar/src-info";

export const getAstSchema = (
factory: FactoryAst,
Expand Down
2 changes: 1 addition & 1 deletion src/ast/iterators.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AstNode } from "./ast";
import type { AstNode } from "./ast";

/**
* Recursively iterates over each node in an AstNode and applies a callback to each AST element.
Expand Down
2 changes: 1 addition & 1 deletion src/ast/random.infra.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fc from "fast-check";
import * as A from "./ast";
import type * as A from "./ast";
import { dummySrcInfo } from "../grammar/src-info";
import { diffJson } from "diff";
import { astBinaryOperations, astUnaryOperations } from "./ast-constants";
Expand Down
10 changes: 6 additions & 4 deletions src/ast/util.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Address, Cell, Slice } from "@ton/core";
import * as A from "./ast";
import { isLiteral, FactoryAst } from "./ast-helpers";
import { dummySrcInfo, SrcInfo } from "../grammar";
import type { Address, Cell, Slice } from "@ton/core";
import type * as A from "./ast";
import type { FactoryAst } from "./ast-helpers";
import { isLiteral } from "./ast-helpers";
import type { SrcInfo } from "../grammar";
import { dummySrcInfo } from "../grammar";

export const getAstUtil = ({ createNode }: FactoryAst) => {
function makeUnaryExpression(
Expand Down
4 changes: 2 additions & 2 deletions src/bindings/typescript/serializers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ABITypeRef } from "@ton/core";
import { Writer } from "../../utils/Writer";
import type { ABITypeRef } from "@ton/core";
import type { Writer } from "../../utils/Writer";
import { throwInternalCompilerError } from "../../error/errors";

const primitiveTypes = [
Expand Down
9 changes: 6 additions & 3 deletions src/bindings/typescript/writeStruct.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { ABIType, ABITypeRef } from "@ton/core";
import type { ABIType, ABITypeRef } from "@ton/core";
import { serializers } from "./serializers";
import { AllocationCell, AllocationOperation } from "../../storage/operation";
import type {
AllocationCell,
AllocationOperation,
} from "../../storage/operation";
import { throwInternalCompilerError } from "../../error/errors";
import { Writer } from "../../utils/Writer";
import type { Writer } from "../../utils/Writer";

export const maxTupleSize = 15;

Expand Down
4 changes: 2 additions & 2 deletions src/bindings/writeTypescript.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as changeCase from "change-case";
import { Writer } from "../utils/Writer";
import { ABIArgument, ABIType, ContractABI } from "@ton/core";
import type { ABIArgument, ABIType, ContractABI } from "@ton/core";
import {
writeArgumentToStack,
writeDictParser,
Expand All @@ -13,7 +13,7 @@ import {
writeTupleParser,
writeTupleSerializer,
} from "./typescript/writeStruct";
import { AllocationCell } from "../storage/operation";
import type { AllocationCell } from "../storage/operation";
import { throwInternalCompilerError } from "../error/errors";
import { topologicalSort } from "../utils/utils";
import {
Expand Down
5 changes: 3 additions & 2 deletions src/browser.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Config, verifyConfig } from "./config/parseConfig";
import { ILogger } from "./context/logger";
import type { Config } from "./config/parseConfig";
import { verifyConfig } from "./config/parseConfig";
import type { ILogger } from "./context/logger";
import { build } from "./pipeline/build";
import { createVirtualFileSystem } from "./vfs/createVirtualFileSystem";

Expand Down
2 changes: 1 addition & 1 deletion src/cli/arg-consumer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Intersect } from "../utils/tricks";
import type { Intersect } from "../utils/tricks";

type ArgConsumerErrors = {
duplicateArgument: (name: string) => void;
Expand Down
4 changes: 2 additions & 2 deletions src/cli/logger.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-confusing-void-expression */
import { throwInternal } from "../error/errors";
import { Logger, SourceLogger } from "../error/logger-util";
import { Range } from "../error/range";
import type { Logger, SourceLogger } from "../error/logger-util";
import type { Range } from "../error/range";
import { getAnsiMarkup } from "./colors";
import { TerminalLogger } from "./logger";
import pathWindows from "path/win32";
Expand Down
8 changes: 5 additions & 3 deletions src/cli/logger.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { Logger, LoggerHandlers, makeLogger } from "../error/logger-util";
import type { Logger, LoggerHandlers } from "../error/logger-util";
import { makeLogger } from "../error/logger-util";
import {
printError,
showExpectedText,
showTemplate,
} from "../error/string-util";
import { cwd } from "process";
import { throwInternal } from "../error/errors";
import { AnsiMarkup } from "./colors";
import type { AnsiMarkup } from "./colors";
import type * as path from "path";

export const CliLogger = () => {
let hadErrors = false;
Expand All @@ -24,7 +26,7 @@ export const CliLogger = () => {

export type Verbosity = "error" | "warn" | "info";

type PathApi = typeof import("path");
type PathApi = typeof path;

export const TerminalLogger = <T>(
pathApi: PathApi,
Expand Down
16 changes: 15 additions & 1 deletion src/cli/tact/e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { stat } from "fs/promises";
import { makeCodegen, runCommand } from "../test-util.build";
import { join, normalize } from "path";
import { join, normalize, dirname } from "path";

// disable tests on windows
const testWin =
Expand Down Expand Up @@ -101,6 +101,20 @@ describe("tact foo.tact", () => {
expect(result).toMatchObject({ kind: "exited", code: 0 });
});

testWin(
"Check single-contract compilation with custom output directory",
async () => {
const path = await codegen.contract(`single-output`, goodContract);
const customOutput = "custom-output";
const result = await tact(`${path} --output ${customOutput}`);

expect(result).toMatchObject({ kind: "exited", code: 0 });

const statPromise = stat(join(dirname(path), customOutput));
await expect(statPromise).resolves.not.toThrow();
},
);

testWin("Check single-contract compilation with --check", async () => {
const path = await codegen.contract(`single-check`, goodContract);
const result = await tact(`--check ${path}`);
Expand Down
Loading

0 comments on commit 4427701

Please sign in to comment.