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

refactor: add optimization phase #1047

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
bf955e7
First version of the expression simplification phase. Still a couple of
jeshecdom Nov 6, 2024
b297ab2
Further fixes to computing the new AST after expression simplifications.
jeshecdom Nov 15, 2024
50af1d5
Merge branch 'main' into closes970
jeshecdom Nov 15, 2024
c5d8678
Added positive tests.
jeshecdom Nov 18, 2024
e9f02f5
Lint, prettier, spell, knip check
jeshecdom Nov 18, 2024
34b82b6
Merge branch 'main' into closes970
jeshecdom Nov 18, 2024
90bcde3
Addressed issues in review.
jeshecdom Dec 16, 2024
39ce816
Merge branch 'main' into closes970
jeshecdom Jan 16, 2025
d0e55d7
Merge branch 'main' into closes970
jeshecdom Jan 19, 2025
274182e
fix: Failures in tests and yarn gen after merging the refactoring of …
jeshecdom Jan 21, 2025
0c47ed9
Merge branch 'main' into closes970
jeshecdom Jan 21, 2025
c9e02f3
fix(CLI): Optimization phase was showing stack trace in non-verbose m…
jeshecdom Jan 21, 2025
deb9e74
fix: Undo cspell version change.
jeshecdom Jan 21, 2025
d9e7549
fix(CLI): renamed skipTactOptimizationPhase for skipPartialEval. Also…
jeshecdom Jan 21, 2025
e33d97e
fix: Use path.join and VirtualFileSystem.
jeshecdom Jan 21, 2025
21578bc
fix: use Boolean(t).
jeshecdom Jan 21, 2025
9fb7586
refactor: Move all ensureX functions to ast.ts.
jeshecdom Jan 21, 2025
4ee15ce
Merge branch 'main' into closes970
jeshecdom Jan 21, 2025
d60dd12
fix: undo cspell version number.
jeshecdom Jan 21, 2025
270b867
Merge branch 'main' into closes970
jeshecdom Jan 21, 2025
f859692
Merge branch 'main' into closes970
jeshecdom Jan 23, 2025
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",
Copy link
Member

Choose a reason for hiding this comment

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

irrelevant change

"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."
},
"dumpOptimizedTactCode": {
"type": "boolean",
"default": false,
"description": "False by default. If set to true, dumps the code produced by the Tact code optimization phase. In case the optimization phase is skipped, this option is ignored."
Copy link
Contributor

Choose a reason for hiding this comment

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

"Smooth" (in math sense) behavior would be to dump the code anyway, yet unoptimized. "Dump the optimized code" is just another separate optional compilation step that happens to be in the list after "optimize" step.

},
"experimental": {
"type": "object",
"description": "Experimental options that might be removed in the future. Use with caution!",
Expand Down
9 changes: 9 additions & 0 deletions src/config/parseConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ 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 by the Tact code optimization phase.
* In case the optimization phase is skipped, this option is ignored.
*/
dumpOptimizedTactCode: z.boolean().optional(),
/**
* Experimental options that might be removed in the future. Use with caution!
*/
Expand Down
7 changes: 6 additions & 1 deletion src/grammar/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,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
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