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

Add line content to debug prints #563

Merged
merged 3 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `[DEBUG]` prefix was removed from debug prints because a similar prefix was already present: PR [#506](https://github.com/tact-lang/tact/pull/506)
- File paths in debug prints always use POSIX file paths (even on Windows): PR [#523](https://github.com/tact-lang/tact/pull/523)
- The IPFS ABI and supported interfaces getters are not generated by default; to generate those, set to `true` the two newly introduced per-project options in `tact.config.json`: `ipfsAbiGetter` and `interfacesGetter`: PR [#534](https://github.com/tact-lang/tact/pull/534)
- Debug prints now include line content for better debugging experience: PR [#563](https://github.com/tact-lang/tact/pull/563)

### Fixed

Expand Down
35 changes: 23 additions & 12 deletions src/abi/global.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { Address, Cell, toNano } from "@ton/core";
import { enabledDebug, enabledMasterchain } from "../config/features";
import { writeAddress, writeCell } from "../generator/writers/writeConstant";
import { writeExpression } from "../generator/writers/writeExpression";
import {
writeExpression,
writeValue,
} from "../generator/writers/writeExpression";
import { throwCompilationError } from "../errors";
import { evalConstantExpression } from "../constEval";
import { getErrorId } from "../types/resolveErrors";
Expand Down Expand Up @@ -239,35 +242,39 @@ export const GlobalFunctions: Map<string, AbiFunction> = new Map([
? posixNormalize(path.relative(cwd(), ref.file!))
: "unknown";
const lineCol = ref.interval.getLineAndColumn();
const debugPrint = `File ${filePath}:${lineCol.lineNum}:${lineCol.colNum}`;
const debugPrint1 = `File ${filePath}:${lineCol.lineNum}:${lineCol.colNum}:`;
const debugPrint2 = writeValue(
ref.interval.getLineAndColumn().line.trimStart(),
ctx,
);

if (arg0.kind === "map") {
const exp = writeExpression(resolved[0]!, ctx);
return `${ctx.used(`__tact_debug`)}(${exp}, "${debugPrint}")`;
return `${ctx.used(`__tact_debug`)}(${exp}, ${debugPrint2}, "${debugPrint1}")`;
} else if (arg0.kind === "null") {
return `${ctx.used(`__tact_debug_str`)}("null", "${debugPrint}")`;
return `${ctx.used(`__tact_debug_str`)}("null", ${debugPrint2}, "${debugPrint1}")`;
} else if (arg0.kind === "void") {
return `${ctx.used(`__tact_debug_str`)}("void", "${debugPrint}")`;
return `${ctx.used(`__tact_debug_str`)}("void", ${debugPrint2}, "${debugPrint1}")`;
} else if (arg0.kind === "ref") {
if (arg0.name === "Int") {
const exp = writeExpression(resolved[0]!, ctx);
return `${ctx.used(`__tact_debug_str`)}(${ctx.used(`__tact_int_to_string`)}(${exp}), "${debugPrint}")`;
return `${ctx.used(`__tact_debug_str`)}(${ctx.used(`__tact_int_to_string`)}(${exp}), ${debugPrint2}, "${debugPrint1}")`;
} else if (arg0.name === "Bool") {
const exp = writeExpression(resolved[0]!, ctx);
return `${ctx.used(`__tact_debug_bool`)}(${exp}, "${debugPrint}")`;
return `${ctx.used(`__tact_debug_bool`)}(${exp}, ${debugPrint2}, "${debugPrint1}")`;
} else if (arg0.name === "String") {
const exp = writeExpression(resolved[0]!, ctx);
return `${ctx.used(`__tact_debug_str`)}(${exp}, "${debugPrint}")`;
return `${ctx.used(`__tact_debug_str`)}(${exp}, ${debugPrint2}, "${debugPrint1}")`;
} else if (arg0.name === "Address") {
const exp = writeExpression(resolved[0]!, ctx);
return `${ctx.used(`__tact_debug_address`)}(${exp}, "${debugPrint}")`;
return `${ctx.used(`__tact_debug_address`)}(${exp}, ${debugPrint2}, "${debugPrint1}")`;
} else if (
arg0.name === "Builder" ||
arg0.name === "Slice" ||
arg0.name === "Cell"
) {
const exp = writeExpression(resolved[0]!, ctx);
return `${ctx.used(`__tact_debug`)}(${exp}, "${debugPrint}")`;
return `${ctx.used(`__tact_debug`)}(${exp}, ${debugPrint2}, "${debugPrint1}")`;
}
throwCompilationError(
"dump() not supported for type: " + arg0.name,
Expand Down Expand Up @@ -303,8 +310,12 @@ export const GlobalFunctions: Map<string, AbiFunction> = new Map([
? posixNormalize(path.relative(cwd(), ref.file!))
: "unknown";
const lineCol = ref.interval.getLineAndColumn();
const debugPrint = `File ${filePath}:${lineCol.lineNum}:${lineCol.colNum}`;
return `${ctx.used(`__tact_debug_stack`)}("${debugPrint}")`;
const debugPrint1 = `File ${filePath}:${lineCol.lineNum}:${lineCol.colNum}:`;
const debugPrint2 = writeValue(
ref.interval.getLineAndColumn().line.trimStart(),
ctx,
);
return `${ctx.used(`__tact_debug_stack`)}(${debugPrint2}, "${debugPrint1}")`;
},
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ if (flag) {
},
{
"code": {
"code": "asm "STRDUMP" "DROP" "s0 DUMP" "DROP"",
"code": "asm "STRDUMP" "DROP" "STRDUMP" "DROP" "s0 DUMP" "DROP"",
"kind": "asm",
},
"comment": null,
Expand All @@ -375,11 +375,11 @@ if (flag) {
"impure",
},
"name": "__tact_debug",
"signature": "forall X -> () __tact_debug(X value, slice debug_print)",
"signature": "forall X -> () __tact_debug(X value, slice debug_print_1, slice debug_print_2)",
},
{
"code": {
"code": "asm "STRDUMP" "DROP" "STRDUMP" "DROP"",
"code": "asm "STRDUMP" "DROP" "STRDUMP" "DROP" "STRDUMP" "DROP"",
"kind": "asm",
},
"comment": null,
Expand All @@ -389,14 +389,14 @@ if (flag) {
"impure",
},
"name": "__tact_debug_str",
"signature": "() __tact_debug_str(slice value, slice debug_print)",
"signature": "() __tact_debug_str(slice value, slice debug_print_1, slice debug_print_2)",
},
{
"code": {
"code": "if (value) {
__tact_debug_str("true", debug_print);
__tact_debug_str("true", debug_print_1, debug_print_2);
} else {
__tact_debug_str("false", debug_print);
__tact_debug_str("false", debug_print_1, debug_print_2);
}",
"kind": "generic",
},
Expand All @@ -409,7 +409,7 @@ if (flag) {
"impure",
},
"name": "__tact_debug_bool",
"signature": "() __tact_debug_bool(int value, slice debug_print)",
"signature": "() __tact_debug_bool(int value, slice debug_print_1, slice debug_print_2)",
},
{
"code": {
Expand Down Expand Up @@ -523,7 +523,7 @@ return __tact_base64_encode(user_friendly_address_with_checksum);",
},
{
"code": {
"code": "__tact_debug_str(__tact_address_to_user_friendly(address), debug_print);",
"code": "__tact_debug_str(__tact_address_to_user_friendly(address), debug_print_1, debug_print_2);",
"kind": "generic",
},
"comment": null,
Expand All @@ -536,11 +536,11 @@ return __tact_base64_encode(user_friendly_address_with_checksum);",
"impure",
},
"name": "__tact_debug_address",
"signature": "() __tact_debug_address(slice address, slice debug_print)",
"signature": "() __tact_debug_address(slice address, slice debug_print_1, slice debug_print_2)",
},
{
"code": {
"code": "asm "STRDUMP" "DROP" "DUMPSTK"",
"code": "asm "STRDUMP" "DROP" "STRDUMP" "DROP" "DUMPSTK"",
"kind": "asm",
},
"comment": null,
Expand All @@ -550,7 +550,7 @@ return __tact_base64_encode(user_friendly_address_with_checksum);",
"impure",
},
"name": "__tact_debug_stack",
"signature": "() __tact_debug_stack(slice debug_print)",
"signature": "() __tact_debug_stack(slice debug_print_1, slice debug_print_2)",
},
{
"code": {
Expand Down Expand Up @@ -4982,7 +4982,7 @@ if (flag) {
},
{
"code": {
"code": "asm "STRDUMP" "DROP" "s0 DUMP" "DROP"",
"code": "asm "STRDUMP" "DROP" "STRDUMP" "DROP" "s0 DUMP" "DROP"",
"kind": "asm",
},
"comment": null,
Expand All @@ -4992,11 +4992,11 @@ if (flag) {
"impure",
},
"name": "__tact_debug",
"signature": "forall X -> () __tact_debug(X value, slice debug_print)",
"signature": "forall X -> () __tact_debug(X value, slice debug_print_1, slice debug_print_2)",
},
{
"code": {
"code": "asm "STRDUMP" "DROP" "STRDUMP" "DROP"",
"code": "asm "STRDUMP" "DROP" "STRDUMP" "DROP" "STRDUMP" "DROP"",
"kind": "asm",
},
"comment": null,
Expand All @@ -5006,14 +5006,14 @@ if (flag) {
"impure",
},
"name": "__tact_debug_str",
"signature": "() __tact_debug_str(slice value, slice debug_print)",
"signature": "() __tact_debug_str(slice value, slice debug_print_1, slice debug_print_2)",
},
{
"code": {
"code": "if (value) {
__tact_debug_str("true", debug_print);
__tact_debug_str("true", debug_print_1, debug_print_2);
} else {
__tact_debug_str("false", debug_print);
__tact_debug_str("false", debug_print_1, debug_print_2);
}",
"kind": "generic",
},
Expand All @@ -5026,7 +5026,7 @@ if (flag) {
"impure",
},
"name": "__tact_debug_bool",
"signature": "() __tact_debug_bool(int value, slice debug_print)",
"signature": "() __tact_debug_bool(int value, slice debug_print_1, slice debug_print_2)",
},
{
"code": {
Expand Down Expand Up @@ -5140,7 +5140,7 @@ return __tact_base64_encode(user_friendly_address_with_checksum);",
},
{
"code": {
"code": "__tact_debug_str(__tact_address_to_user_friendly(address), debug_print);",
"code": "__tact_debug_str(__tact_address_to_user_friendly(address), debug_print_1, debug_print_2);",
"kind": "generic",
},
"comment": null,
Expand All @@ -5153,11 +5153,11 @@ return __tact_base64_encode(user_friendly_address_with_checksum);",
"impure",
},
"name": "__tact_debug_address",
"signature": "() __tact_debug_address(slice address, slice debug_print)",
"signature": "() __tact_debug_address(slice address, slice debug_print_1, slice debug_print_2)",
},
{
"code": {
"code": "asm "STRDUMP" "DROP" "DUMPSTK"",
"code": "asm "STRDUMP" "DROP" "STRDUMP" "DROP" "DUMPSTK"",
"kind": "asm",
},
"comment": null,
Expand All @@ -5167,7 +5167,7 @@ return __tact_base64_encode(user_friendly_address_with_checksum);",
"impure",
},
"name": "__tact_debug_stack",
"signature": "() __tact_debug_stack(slice debug_print)",
"signature": "() __tact_debug_stack(slice debug_print_1, slice debug_print_2)",
},
{
"code": {
Expand Down Expand Up @@ -9599,7 +9599,7 @@ if (flag) {
},
{
"code": {
"code": "asm "STRDUMP" "DROP" "s0 DUMP" "DROP"",
"code": "asm "STRDUMP" "DROP" "STRDUMP" "DROP" "s0 DUMP" "DROP"",
"kind": "asm",
},
"comment": null,
Expand All @@ -9609,11 +9609,11 @@ if (flag) {
"impure",
},
"name": "__tact_debug",
"signature": "forall X -> () __tact_debug(X value, slice debug_print)",
"signature": "forall X -> () __tact_debug(X value, slice debug_print_1, slice debug_print_2)",
},
{
"code": {
"code": "asm "STRDUMP" "DROP" "STRDUMP" "DROP"",
"code": "asm "STRDUMP" "DROP" "STRDUMP" "DROP" "STRDUMP" "DROP"",
"kind": "asm",
},
"comment": null,
Expand All @@ -9623,14 +9623,14 @@ if (flag) {
"impure",
},
"name": "__tact_debug_str",
"signature": "() __tact_debug_str(slice value, slice debug_print)",
"signature": "() __tact_debug_str(slice value, slice debug_print_1, slice debug_print_2)",
},
{
"code": {
"code": "if (value) {
__tact_debug_str("true", debug_print);
__tact_debug_str("true", debug_print_1, debug_print_2);
} else {
__tact_debug_str("false", debug_print);
__tact_debug_str("false", debug_print_1, debug_print_2);
}",
"kind": "generic",
},
Expand All @@ -9643,7 +9643,7 @@ if (flag) {
"impure",
},
"name": "__tact_debug_bool",
"signature": "() __tact_debug_bool(int value, slice debug_print)",
"signature": "() __tact_debug_bool(int value, slice debug_print_1, slice debug_print_2)",
},
{
"code": {
Expand Down Expand Up @@ -9757,7 +9757,7 @@ return __tact_base64_encode(user_friendly_address_with_checksum);",
},
{
"code": {
"code": "__tact_debug_str(__tact_address_to_user_friendly(address), debug_print);",
"code": "__tact_debug_str(__tact_address_to_user_friendly(address), debug_print_1, debug_print_2);",
"kind": "generic",
},
"comment": null,
Expand All @@ -9770,11 +9770,11 @@ return __tact_base64_encode(user_friendly_address_with_checksum);",
"impure",
},
"name": "__tact_debug_address",
"signature": "() __tact_debug_address(slice address, slice debug_print)",
"signature": "() __tact_debug_address(slice address, slice debug_print_1, slice debug_print_2)",
},
{
"code": {
"code": "asm "STRDUMP" "DROP" "DUMPSTK"",
"code": "asm "STRDUMP" "DROP" "STRDUMP" "DROP" "DUMPSTK"",
"kind": "asm",
},
"comment": null,
Expand All @@ -9784,7 +9784,7 @@ return __tact_base64_encode(user_friendly_address_with_checksum);",
"impure",
},
"name": "__tact_debug_stack",
"signature": "() __tact_debug_stack(slice debug_print)",
"signature": "() __tact_debug_stack(slice debug_print_1, slice debug_print_2)",
},
{
"code": {
Expand Down
Loading
Loading