-
Notifications
You must be signed in to change notification settings - Fork 69
replace function calls by operators and removed imports and input checks #1041
replace function calls by operators and removed imports and input checks #1041
Conversation
@@ -41,33 +33,26 @@ export class MathsOperationToFunction extends ASTMapper { | |||
|
|||
visitBinaryOperation(node: BinaryOperation, ast: AST): void { | |||
this.commonVisit(node, ast); | |||
const isUnchecked = this.inUncheckedBlock; | |||
if ( | |||
!((isUnchecked && (node.operator === '-' || node.operator === '+')) || node.operator === '**') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's easier to understand non-negated conditions (especially when it's so complex). Could you modify the condition?
src/passes/argBoundChecker.ts
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the whole pass can be removed. WYT @cicr99 ?
if (node.vInitialValue instanceof FunctionCall) { | ||
if ((node.vInitialValue as FunctionCall).vExpression instanceof Identifier) { | ||
const funcName = writer.write(node.vInitialValue); | ||
if (funcName.includes('_overflow_') || funcName.includes('_overflowing_')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add TODO here and an issue to change it after its fixed in corelib
if (node.vInitialValue instanceof FunctionCall) { | ||
if ((node.vInitialValue as FunctionCall).vExpression instanceof Identifier) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (node.vInitialValue instanceof FunctionCall) { | |
if ((node.vInitialValue as FunctionCall).vExpression instanceof Identifier) { | |
if (node.vInitialValue instanceof FunctionCall && node.vInitialValue.vExpression instanceof Identifier) { |
); | ||
const width = getIntOrFixedByteBitWidth(retType); | ||
|
||
const fullName = `u${width}_overflow${width === 256 && name === 'sub' ? '' : `ing`}_${name}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add a TODO here too
|
||
const fullName = `u${width}_overflow${width === 256 && name === 'sub' ? '' : `ing`}_${name}`; | ||
|
||
const importName = ['integer']; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make a function in importPaths.ts
which returns the import path of overflowing functions based on the width. This way we can easily inspect cairo functions used in warp
Merge conflicts need to be solved |
I've added a sibling issue #1079 to this one. It won't be using the old system of input checks though so I don't see any benefit in implementing it in the same PR |
33f14f3
to
2aa4d95
Compare
This PR do three things:
1 - deal with unsafe operations inside unchecked blocks.
2 - remove unnecessary warplib functions and replace it for their respective operations.
3 - remove input checks.
given the following function:
old transpilation:
new transpilation:
new transpilation for when the operation is bellow than 256 bits
In the case of an operation outside an unchecked block like the following:
old transpilation:
new transpilation: