Skip to content

Commit

Permalink
fix: typechecker checks if message opcode fits into 32 bits
Browse files Browse the repository at this point in the history
  • Loading branch information
anton-trunov committed Aug 31, 2024
1 parent acfb175 commit 8c7be12
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 46 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix code generation bug for maps from unsigned integers to Boolean values: PR [#725](https://github.com/tact-lang/tact/pull/725)
- Compiler failure when `toString` gets called as a static function and not a method: PR [#745](https://github.com/tact-lang/tact/pull/745)
- Tact AST keeps the original format of integer literals (hex/dec/oct/bin): PR [#771](https://github.com/tact-lang/tact/pull/771)
- Message opcodes are now checked if they fit into 32 bits: PR [#771](https://github.com/tact-lang/tact/pull/771)

## [1.4.4] - 2024-08-18

Expand Down
93 changes: 47 additions & 46 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,58 @@
"alnum",
"assgn",
"augmentedassign",
"BBITS",
"blockstore",
"bounceable",
"BREFS",
"Brujin",
"CHKSIGNS",
"CHKSIGNU",
"cleanall",
"codegen",
"CONFIGOPTPARAM",
"CTOS",
"decompilation",
"decompile",
"Decompiled",
"decompiler",
"decompiles",
"decompilation",
"decompiling",
"dentry",
"Descr",
"disasm",
"divmod",
"dnsresolve",
"elseifnot",
"ENDC",
"Fift",
"forall",
"formedness",
"funs",
"funcfiftlib",
"funcid",
"funs",
"gettest",
"HASHCU",
"HASHEXT",
"HASHSU",
"idict",
"initof",
"infixl",
"infixr",
"initof",
"ipfs",
"ipld",
"jettons",
"jsxdev",
"keccak",
"KECCAK",
"knip",
"Korshakov",
"Laika",
"LDIX",
"langle",
"LDIX",
"LDREF",
"LDSLICEX",
"LDUX",
"LDVARUINT",
"lparen",
"LTIME",
Expand All @@ -54,36 +70,54 @@
"mintable",
"mktemp",
"multiformats",
"Korshakov",
"MYADDR",
"Neovim",
"NEWC",
"nocheck",
"noexcept",
"Nonterminal",
"nonterminal",
"Neovim",
"Nonterminal",
"Offchain",
"Parens",
"pinst",
"PLDIX",
"PLDREF",
"PLDSLICEX",
"PLDUX",
"POSIX",
"postpack",
"prando",
"PUSHREF",
"PUSHSLICE",
"RANDU",
"rangle",
"RAWRESERVE",
"renamer",
"rparen",
"rugpull",
"rugpulled",
"SBITS",
"sctx",
"STIX",
"STUX",
"STVARUINT",
"STREF",
"SDBEGINSQ",
"SDEMPTY",
"SDSKIPFIRST",
"SEMPTY",
"SENDRAWMSG",
"seqno",
"SETINDEXVARQ",
"shiki",
"SREFS",
"SREMPTY",
"Stateinit",
"STDICT",
"stdlib",
"STIX",
"STREF",
"struct",
"structs",
"STSLICER",
"STUX",
"STVARUINT",
"subtyping",
"Tarjan",
"testdata",
Expand All @@ -97,41 +131,8 @@
"uninit",
"unixfs",
"workchain",
"привет",
"PUSHREF",
"PUSHSLICE",
"renamer",
"Brujin",
"dentry",
"SETINDEXVARQ",
"gettest",
"LDREF",
"STSLICER",
"ENDC",
"BREFS",
"BBITS",
"CTOS",
"PLDREF",
"LDSLICEX",
"PLDSLICEX",
"PLDIX",
"LDUX",
"PLDUX",
"SDSKIPFIRST",
"SREFS",
"SBITS",
"SEMPTY",
"SDEMPTY",
"SREMPTY",
"CONFIGOPTPARAM",
"MYADDR",
"HASHCU",
"HASHSU",
"CHKSIGNU",
"CHKSIGNS",
"RAWRESERVE",
"SENDRAWMSG",
"SDBEGINSQ"
"xffff",
"привет"
],
"flagWords": [],
"ignorePaths": [
Expand Down
10 changes: 10 additions & 0 deletions src/grammar/__snapshots__/grammar.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,16 @@ Line 2, col 13:
"
`;
exports[`grammar should fail message-negative-opcode 1`] = `
"<unknown>:1:9: Parse error: expected "0", "1".."9", "0O", "0o", "0B", "0b", "0X", or "0x"
Line 1, col 9:
> 1 | message(-1) Foo { }
^
2 |
"
`;
exports[`grammar should fail struct-double-semicolon 1`] = `
"<unknown>:2:19: Parse error: expected "}"
Expand Down
1 change: 1 addition & 0 deletions src/grammar/test-failed/message-negative-opcode.tact
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
message(-1) Foo { }
9 changes: 9 additions & 0 deletions src/types/__snapshots__/resolveDescriptors.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,15 @@ Line 8, col 1:
"
`;
exports[`resolveDescriptors should fail descriptors for message-opcode-too-large 1`] = `
"<unknown>:1:9: Opcode of message "Foo" is too large: it must fit into 32 bits
Line 1, col 9:
> 1 | message(0x1_FFFFF_FFFF) Foo { }
^~~~~~~~~~~~~~
2 |
"
`;
exports[`resolveDescriptors should fail descriptors for method-first-param-not-self1 1`] = `
"<unknown>:8:17: Extend function must have first parameter named "self"
Line 8, col 17:
Expand Down
10 changes: 10 additions & 0 deletions src/types/resolveDescriptors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,16 @@ export function resolveDescriptors(ctx: CompilerContext) {
a.loc,
);
}
if (
a.kind === "message_decl" &&
a.opcode &&
a.opcode.value > 0xffff_ffff
) {
throwCompilationError(
`Opcode of message ${idTextErr(a.name)} is too large: it must fit into 32 bits`,
a.opcode.loc,
);
}
}

// Trait
Expand Down
1 change: 1 addition & 0 deletions src/types/test-failed/message-opcode-too-large.tact
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
message(0x1_FFFFF_FFFF) Foo { }

0 comments on commit 8c7be12

Please sign in to comment.