Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove "remainder" from error messages and TL-B schemes #1699

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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
1 change: 1 addition & 0 deletions dev-docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Incorrect call generation to a mutation function: PR [#1608](https://github.com/tact-lang/tact/pull/1608)
- Allow constant/trait constants depend on each other: PR [#1622](https://github.com/tact-lang/tact/pull/1622)
- Combine all generated FunC code into a single file: PR [#1698](https://github.com/tact-lang/tact/pull/1698)
- Remove "remainder" from error messages and TL-B schemes: PR [#1699](https://github.com/tact-lang/tact/pull/1699)

### Docs

Expand Down
4 changes: 2 additions & 2 deletions docs/src/content/docs/book/cells.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,12 @@ struct TwoCell {

struct TwoBuilder {
bRef: Builder; // ^builder in TL-B
bRem: Builder as remaining; // builder in TL-B
bRem: Builder as remaining; // cell in TL-B
}

struct TwoSlice {
sRef: Slice; // ^slice in TL-B
sRem: Slice as remaining; // slice in TL-B
sRem: Slice as remaining; // cell in TL-B
}

contract SerializationExample {
Expand Down
8 changes: 4 additions & 4 deletions docs/src/content/docs/zh-cn/book/cells.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ description: Cells、Builders 和 Slices 是 TON 区块链的底层单元

标准 [`Cell{:tact}`](#cells) 表示法是 [tvm.pdf](https://docs.ton.org/tvm.pdf) 中首次描述的 cells 通用序列化格式。 它的算法以八进制(字节)序列表示cell,首先将称为描述符的第一个 $2$ 字节序列化:

- _引用描述符_(Refs descriptor)根据以下公式计算:$r + 8 _ k + 32 _ l$,其中 $r$ 是 cell 中包含的引用数量(介于 $0$ 和 $4$ 之间),$k$ 是 cell 类型的标志($0$ 表示[普通](#cells-kinds),$1$ 表示[特殊](#cells-kinds)),$l$ 是
- _引用描述符_(Refs descriptor)根据以下公式计算:$r + 8 _ k + 32 _ l$,其中 $r$ 是 cell 中包含的引用数量(介于 $0$ 和 $4$ 之间),$k$ 是 cell 类型的标志($0$ 表示[普通](#cells-kinds),$1$ 表示[特殊](#cells-kinds)),$l$ 是
cell 的[层级](#cells-levels)(介于 $0$ 和 $3$ 之间)。
- _位描述符_(Bits descriptor)根据以下公式计算:$\lfloor\frac{b}{8}\rfloor + \lceil\frac{b}{8}\rceil$,其中 $b$ 是 cell 中的位数(介于 $0$ 和 $1023$ 之间)。

Expand Down Expand Up @@ -159,9 +159,9 @@ contract SerializationExample {
sRef: Slice; // ^slice in TL-B

// With `remaining`
cRem: Cell as remaining; // remainder<cell> in TL-B
bRem: Builder as remaining; // remainder<builder> in TL-B
sRem: Slice as remaining; // remainder<slice> in TL-B
cRem: Cell as remaining; // cell in TL-B
bRem: Builder as remaining; // cell in TL-B
sRem: Slice as remaining; // cell in TL-B

// Constructor function,
// necessary for this example contract to compile
Expand Down
2 changes: 1 addition & 1 deletion src/storage/allocator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function getOperationSize(src: AllocationOperationType): {
case "remainder": {
if (src.optional) {
throwInternalCompilerError(
"Remainder cell cannot be optional",
`"as remaining" cell cannot be optional`,
);
}
return { bits: 0, refs: 0 };
Expand Down
16 changes: 8 additions & 8 deletions src/types/__snapshots__/resolveDescriptors.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ exports[`resolveDescriptors should fail descriptors for contract-const-override-
`;

exports[`resolveDescriptors should fail descriptors for contract-decl-remainder-in-the-middle 1`] = `
"<unknown>:8:5: The "remainder" field can only be the last field of the contract
"<unknown>:8:5: The "as remaining" field can only be the last field of the contract
7 | a: Int = 0;
> 8 | s: Cell as remaining;
^~~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -402,7 +402,7 @@ exports[`resolveDescriptors should fail descriptors for init-self-reassign-in-if
`;

exports[`resolveDescriptors should fail descriptors for message-decl-remainder-in-the-middle 1`] = `
"<unknown>:8:5: The "remainder" field can only be the last field of the message
"<unknown>:8:5: The "as remaining" field can only be the last field of the message
7 | a: Int;
> 8 | s: Cell as remaining;
^~~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -754,7 +754,7 @@ exports[`resolveDescriptors should fail descriptors for struct-decl-mutually-rec
`;

exports[`resolveDescriptors should fail descriptors for struct-decl-remainder-in-the-middle 1`] = `
"<unknown>:8:5: The "remainder" field can only be the last field of the struct
"<unknown>:8:5: The "as remaining" field can only be the last field of the struct
7 | a: Int;
> 8 | s: Cell as remaining;
^~~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -13590,7 +13590,7 @@ exports[`resolveDescriptors should resolve descriptors for message-decl-remainde
"id": 0,
"kind": "number",
"loc": ,
"value": 3344478825n,
"value": 1872381133n,
},
"init": null,
"interfaces": [],
Expand All @@ -13599,8 +13599,8 @@ exports[`resolveDescriptors should resolve descriptors for message-decl-remainde
"origin": "user",
"partialFieldCount": 0,
"receivers": [],
"signature": "Test{a:int257,b:int257,s:remainder<cell>}",
"tlb": "test#c758b269 a:int257 b:int257 s:remainder<cell> = Test",
"signature": "Test{a:int257,b:int257,s:cell}",
"tlb": "test#6f9a44cd a:int257 b:int257 s:cell = Test",
"traits": [],
"uid": 44104,
},
Expand Down Expand Up @@ -25276,8 +25276,8 @@ exports[`resolveDescriptors should resolve descriptors for struct-decl-remainder
"origin": "user",
"partialFieldCount": 0,
"receivers": [],
"signature": "Test{a:int257,b:int257,s:remainder<cell>}",
"tlb": "_ a:int257 b:int257 s:remainder<cell> = Test",
"signature": "Test{a:int257,b:int257,s:cell}",
"tlb": "_ a:int257 b:int257 s:cell = Test",
"traits": [],
"uid": 44104,
},
Expand Down
12 changes: 6 additions & 6 deletions src/types/resolveSignatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export function resolveSignatures(ctx: CompilerContext, Ast: FactoryAst) {
return "address";
} else if (type === "cell") {
if (format === "remainder") {
return "remainder<cell>";
return "cell";
} else if (format === "ref") {
return "^cell";
}
Expand All @@ -85,7 +85,7 @@ export function resolveSignatures(ctx: CompilerContext, Ast: FactoryAst) {
return "^cell";
} else if (type === "slice") {
if (format === "remainder") {
return "remainder<slice>";
return "cell";
} else if (format === "ref") {
return "^slice";
} else if (format !== null) {
Expand All @@ -96,7 +96,7 @@ export function resolveSignatures(ctx: CompilerContext, Ast: FactoryAst) {
return "^slice";
} else if (type === "builder") {
if (format === "remainder") {
return "remainder<builder>";
return "cell";
} else if (format === "ref") {
return "^slice";
} else if (format !== null) {
Expand Down Expand Up @@ -186,13 +186,13 @@ export function resolveSignatures(ctx: CompilerContext, Ast: FactoryAst) {
throwInternalCompilerError(`Unsupported type: ${name}`);
}

// Check for no "remainder" in the middle of the struct
// Check for no "as remaining" in the middle of the struct
for (const field of t.fields.slice(0, -1)) {
if (field.as === "remaining") {
const kind =
t.ast.kind === "message_decl" ? "message" : "struct";
throwCompilationError(
`The "remainder" field can only be the last field of the ${kind}`,
`The "as remaining" field can only be the last field of the ${kind}`,
field.loc,
);
}
Expand Down Expand Up @@ -422,7 +422,7 @@ function checkContractFields(t: TypeDescription) {
for (const field of t.fields.slice(0, -1)) {
if (field.as === "remaining") {
throwCompilationError(
`The "remainder" field can only be the last field of the contract`,
`The "as remaining" field can only be the last field of the contract`,
field.ast.loc,
);
}
Expand Down