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: Issue #970: interpreter called only when contract present #1047

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"@typescript-eslint/parser": "^7.0.2",
"ajv-cli": "^5.0.0",
"cross-env": "^7.0.3",
"cspell": "^8.8.3",
"cspell": "^8.16.0",
"eslint": "^8.56.0",
"glob": "^8.1.0",
"husky": "^9.1.5",
Expand Down
10 changes: 10 additions & 0 deletions schemas/configSchema.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@
"default": false,
"description": "False by default. If set to true, enables generation of a getter the information on the interfaces provided by the contract.\n\nRead more about supported interfaces: https://docs.tact-lang.org/ref/evolution/OTP-001."
},
"skipTactOptimizationPhase": {
"type": "boolean",
"default": false,
"description": "False by default. If set to true, skips the Tact code optimization phase."
},
"dumpCodeBeforeAndAfterTactOptimizationPhase": {
"type": "boolean",
"default": false,
"description": "False by default. If set to true, dumps the code produced before and after the Tact code optimization phase."
},
"experimental": {
"type": "object",
"description": "Experimental options that might be removed in the future. Use with caution!",
Expand Down
8 changes: 8 additions & 0 deletions src/config/parseConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ export const optionsSchema = z
* Read more: https://docs.tact-lang.org/book/contracts#interfaces
*/
interfacesGetter: z.boolean().optional(),
/**
* If set to true, skips the Tact code optimization phase.
*/
skipTactOptimizationPhase: z.boolean().optional(),
/**
* If set to true, dumps the code produced before and after the Tact code optimization phase.
*/
dumpCodeBeforeAndAfterTactOptimizationPhase: z.boolean().optional(),
/**
* Experimental options that might be removed in the future. Use with caution!
*/
Expand Down
73 changes: 72 additions & 1 deletion src/grammar/ast.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { throwInternalCompilerError } from "../errors";
import { dummySrcInfo, SrcInfo } from "./grammar";

export type AstModule = {
Expand Down Expand Up @@ -649,7 +650,12 @@ export type AstNull = {
loc: SrcInfo;
};

export type AstValue = AstNumber | AstBoolean | AstNull | AstString;
export type AstValue =
| AstNumber
| AstBoolean
| AstNull
| AstString
| AstStructInstance;

export type AstConstantAttribute =
| { type: "virtual"; loc: SrcInfo }
Expand Down Expand Up @@ -912,6 +918,71 @@ export function isValue(ast: AstExpression): boolean {
case "field_access":
case "static_call":
return false;
default:
throwInternalCompilerError("Unrecognized AstExpression");
}
}

export function isAstExpression(ast: AstNode): ast is AstExpression {
switch (ast.kind) {
case "null":
case "boolean":
case "number":
case "string":
case "id":
case "struct_instance":
case "method_call":
case "init_of":
case "op_unary":
case "op_binary":
case "conditional":
case "field_access":
case "static_call":
return true;

case "asm_function_def":
case "bounced_message_type":
case "constant_decl":
case "constant_def":
case "contract":
case "contract_init":
case "destruct_end":
case "destruct_mapping":
case "field_decl":
case "func_id":
case "function_attribute":
case "function_decl":
case "function_def":
case "import":
case "map_type":
case "message_decl":
case "module":
case "native_function_decl":
case "optional_type":
case "primitive_type_decl":
case "receiver":
case "statement_assign":
case "statement_augmentedassign":
case "statement_condition":
case "statement_destruct":
case "statement_expression":
case "statement_foreach":
case "statement_let":
case "statement_repeat":
case "statement_return":
case "statement_try":
case "statement_try_catch":
case "statement_until":
case "statement_while":
case "struct_decl":
case "struct_field_initializer":
case "trait":
case "type_id":
case "typed_parameter":
return false;

default:
throwInternalCompilerError("Unrecognized AstNode");
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/interpreter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -960,7 +960,7 @@ export class Interpreter {
if (foundContractConst.value !== undefined) {
return foundContractConst.value;
} else {
throwErrorConstEval(
throwNonFatalErrorConstEval(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I don't understand this change, and I suspect a future reader wouldn't either.

When do we throw non-fatal errors in general?

Copy link
Member

@novusnota novusnota Nov 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When do we throw non-fatal errors in general?

When we want to stop the constant evaluation, but continue compiling the rest of the contract. Like, when not being able to compute something at compile-time with ability to fallback to run-time implementation for that something.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stopEvaluation()?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but the current pipeline kinda relies on throwing and catching errors and not on errors as values ¯\_(ツ)_/¯

`cannot evaluate declared contract/trait constant ${idTextErr(ast.field)} as it does not have a body`,
ast.field.loc,
);
Expand Down
Loading
Loading