Skip to content
This repository has been archived by the owner on Sep 5, 2023. It is now read-only.

InferType-changes #903

Draft
wants to merge 36 commits into
base: cairo-1.0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
01f4a01
generateTypeStr does not show location for default pointers
AlejandroLabourdette Feb 6, 2023
70a6127
getParameterTypes for struct constructor use new type pattern
AlejandroLabourdette Feb 6, 2023
e762048
create identifier do not specialize the nodeType
AlejandroLabourdette Feb 6, 2023
dbd437f
TypeNameRemover pass after BuiltinHandler
AlejandroLabourdette Feb 9, 2023
e140676
lint
AlejandroLabourdette Feb 9, 2023
e52fd8b
Merge branch 'TypeNameRemover-after-BuilinHandler' into inferType-cha…
AlejandroLabourdette Feb 9, 2023
4492129
after abi builtins pass instead of builtinHandler
AlejandroLabourdette Feb 10, 2023
ceeb7a1
Merge branch 'TypeNameRemover-after-BuilinHandler' into inferType-cha…
AlejandroLabourdette Feb 10, 2023
25e13d2
skip visitIndexAccess to TypeNames that are before abiBuiltin
AlejandroLabourdette Feb 10, 2023
8e5bf39
Merge branch 'TypeNameRemover-after-BuilinHandler' into inferType-cha…
AlejandroLabourdette Feb 10, 2023
7a80e99
generalize type in argBoundChecker visitFuncCall pass
AlejandroLabourdette Feb 10, 2023
85bb001
lint
AlejandroLabourdette Feb 10, 2023
2702eaa
don't flat typeNames single tuple at TupleFlattener
AlejandroLabourdette Feb 10, 2023
67c4364
Merge branch 'TypeNameRemover-after-BuilinHandler' into inferType-cha…
AlejandroLabourdette Feb 10, 2023
e945a7b
WarpInferType created
AlejandroLabourdette Feb 10, 2023
a6101ca
lint
AlejandroLabourdette Feb 10, 2023
b2ed49c
Merge branch 'create-WarpInferType' into inferType-changes
AlejandroLabourdette Feb 10, 2023
25e74b9
generalize type in memoryToCalldata.ts
AlejandroLabourdette Feb 10, 2023
8162700
remove warpInferType
AlejandroLabourdette Feb 10, 2023
0ef3f91
Merge branch 'develop' into inferType-changes
AlejandroLabourdette Mar 13, 2023
775d383
Fix cairo-lang dependencies issues after major upgrades (#995)
Hyodar Mar 20, 2023
d76b610
fix abiDecode from merge
AlejandroLabourdette Mar 21, 2023
15ef093
fix: typos (#991)
julio4 Mar 21, 2023
54b6f1e
create WarpInferType, override Literal and MemberAccess TypeOf
AlejandroLabourdette Mar 22, 2023
80662e6
try to compute member access type first using inferType
AlejandroLabourdette Mar 22, 2023
bf06220
convert int literal to intType when needed
AlejandroLabourdette Mar 24, 2023
9caa683
Bump @sideway/formula from 3.0.0 to 3.0.1 in /docs (#990)
dependabot[bot] Mar 24, 2023
6d4c6f7
infertype computes literal type using typeString parser
AlejandroLabourdette Mar 27, 2023
d4f35ca
refactor
AlejandroLabourdette Mar 27, 2023
653cb00
case typo in import
AlejandroLabourdette Mar 27, 2023
e9bc773
Merge branch 'refactor-bytesConverter' into inferType-changes
AlejandroLabourdette Mar 27, 2023
adce827
generalize type on return var init
AlejandroLabourdette Mar 27, 2023
4a27842
generalize specialized types
AlejandroLabourdette Mar 27, 2023
4bae6b1
include eventType in generate expression typeString
AlejandroLabourdette Mar 27, 2023
cd406ac
Merge branch 'cairo-1.0' into inferType-changes
AlejandroLabourdette May 29, 2023
efbf418
remove bytes converter
AlejandroLabourdette May 29, 2023
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
4 changes: 2 additions & 2 deletions src/ast/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { printNode } from '../utils/astPrinter';
import { TranspileFailedError } from '../utils/errors';
import { createBlock } from '../utils/nodeTemplates';
import { createImport } from '../utils/importFuncGenerator';
import { safeGetNodeType } from '../utils/nodeTypeProcessing';
import { safeGetNodeType, WarpInferType } from '../utils/nodeTypeProcessing';
import { getContainingSourceUnit, isExternalCall } from '../utils/utils';
import { CairoImportFunctionDefinition } from './cairoNodes';
import { ParameterInfo } from '../export';
Expand Down Expand Up @@ -73,7 +73,7 @@ export class AST {
'All contexts should be the same, otherwise they are from separate solc-typed-ast compiles and they will have no relationship to each other.',
);
this.context = roots[0].requiredContext;
this.inference = new InferType(compilerVersion);
this.inference = new WarpInferType(compilerVersion);
assert(
this.context.locate(this.tempId) === undefined,
`Attempted to create an AST with a context that already has ${this.tempId} registered`,
Expand Down
2 changes: 1 addition & 1 deletion src/cairoUtilFuncGen/calldata/calldataToMemory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ export class CallDataToMemoryGen extends StringIndexedFuncGen {

const [copyCode, funcCalls] = structDef.vMembers.reduce(
([copyCode, funcCalls, offset], decl) => {
const type = safeGetNodeType(decl, this.ast.inference);
const type = generalizeType(safeGetNodeType(decl, this.ast.inference))[0];

if (isReferenceType(type)) {
const recursiveFunc = this.getOrCreateFuncDef(type);
Expand Down
9 changes: 5 additions & 4 deletions src/cairoUtilFuncGen/memory/memoryToCalldata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,13 @@ export class MemoryToCallDataGen extends StringIndexedFuncGen {
`Copying ${printTypeNode(type)} from memory to calldata not implemented yet`,
);
};
const generalizedType = generalizeType(type)[0];

return delegateBasedOnType<GeneratedFunctionInfo>(
type,
(type) => this.createDynamicArrayCopyFunction(type),
(type) => this.createStaticArrayCopyFunction(type),
(type) => this.createStructCopyFunction(type),
generalizedType,
(generalizedType) => this.createDynamicArrayCopyFunction(generalizedType),
(generalizedType) => this.createStaticArrayCopyFunction(generalizedType),
(generalizedType) => this.createStructCopyFunction(generalizedType),
unexpectedTypeFunc,
unexpectedTypeFunc,
);
Expand Down
2 changes: 1 addition & 1 deletion src/cairoUtilFuncGen/memory/memoryToStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export class MemoryToStorageGen extends StringIndexedFuncGen {
const funcName = `wm_to_storage_struct_${def.name}`;

const [copyInstructions, funcsCalled] = this.generateTupleCopyInstructions(
def.vMembers.map((decl) => safeGetNodeType(decl, this.ast.inference)),
def.vMembers.map((decl) => generalizeType(safeGetNodeType(decl, this.ast.inference))[0]),
);
return {
name: funcName,
Expand Down
4 changes: 3 additions & 1 deletion src/cairoUtilFuncGen/storage/copyToStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ export class StorageToStorageGen extends StringIndexedFuncGen {
}

private createStructCopyFunction(def: StructDefinition): GeneratedFunctionInfo {
const members = def.vMembers.map((decl) => safeGetNodeType(decl, this.ast.inference));
const members = def.vMembers.map(
(decl) => generalizeType(safeGetNodeType(decl, this.ast.inference))[0],
);
const [copyCode, funcsCalled] = members.reduce(
([copyCode, funcsCalled, offset], memberType) => {
const width = CairoType.fromSol(
Expand Down
2 changes: 1 addition & 1 deletion src/cairoUtilFuncGen/utils/encodeToFelt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ export class EncodeAsFelt extends StringIndexedFuncGenWithAuxiliar {

const [encodeCode, encodeCalls] = type.definition.vMembers.reduce(
([encodeCode, encodeCalls], varDecl, index) => {
const varType = safeGetNodeType(varDecl, this.ast.inference);
const varType = generalizeType(safeGetNodeType(varDecl, this.ast.inference))[0];
const [memberEncodeCode, memberEncodeCalls] = this.generateEncodeCode(
varType,
`member_${index}`,
Expand Down
3 changes: 2 additions & 1 deletion src/passes/argBoundChecker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
FunctionCallKind,
EnumDefinition,
IntType,
generalizeType,
} from 'solc-typed-ast';
import { ASTMapper } from '../ast/mapper';
import { isExternallyVisible } from '../utils/utils';
Expand All @@ -30,7 +31,7 @@ export class ArgBoundChecker extends ASTMapper {
visitFunctionDefinition(node: FunctionDefinition, ast: AST): void {
if (isExternallyVisible(node) && node.vBody !== undefined) {
node.vParameters.vParameters.forEach((decl) => {
const type = safeGetNodeType(decl, ast.inference);
const type = generalizeType(safeGetNodeType(decl, ast.inference))[0];
if (checkableType(type)) {
const functionCall = ast.getUtilFuncGen(node).boundChecks.inputCheck.gen(decl, type);
this.insertFunctionCall(node, functionCall, ast);
Expand Down
184 changes: 0 additions & 184 deletions src/passes/bytesConverter.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/passes/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ export * from './abiBuiltins';
export * from './annotateImplicits';
export * from './argBoundChecker';
export * from './builtinHandler/export';
export * from './bytesConverter';
export * from './cairoStubProcessor';
export * from './cairoUtilImporter';
export * from './conditionalSplitter/export';
Expand Down
7 changes: 6 additions & 1 deletion src/passes/implicitConversionToExplicit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,12 @@ export class ImplicitConversionToExplicit extends ASTMapper {
visitIndexAccess(node: IndexAccess, ast: AST): void {
this.commonVisit(node, ast);

if (node.vIndexExpression === undefined) return;
if (
safeGetNodeType(node, ast.inference) instanceof TypeNameType ||
node.vIndexExpression === undefined
) {
return;
}

const [baseType, location] = generalizeType(
safeGetNodeType(node.vBaseExpression, ast.inference),
Expand Down
1 change: 0 additions & 1 deletion src/passes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ export * from './annotateImplicits';
export * from './argBoundChecker';
export * from './builtinHandler';
export * from './builtinHandler/require';
export * from './bytesConverter';
export * from './cairoStubProcessor';
export * from './cairoUtilImporter';
export * from './conditionalSplitter/conditionalSplitter';
Expand Down
4 changes: 2 additions & 2 deletions src/passes/returnVariableInitializer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FunctionDefinition, VariableDeclarationStatement } from 'solc-typed-ast';
import { FunctionDefinition, generalizeType, VariableDeclarationStatement } from 'solc-typed-ast';
import { AST } from '../ast/ast';
import { ASTMapper } from '../ast/mapper';
import { cloneASTNode } from '../utils/cloning';
Expand Down Expand Up @@ -27,7 +27,7 @@ export class ReturnVariableInitializer extends ASTMapper {
'',
[newDecl.id],
[newDecl],
getDefaultValue(safeGetNodeType(decl, ast.inference), newDecl, ast),
getDefaultValue(generalizeType(safeGetNodeType(decl, ast.inference))[0], newDecl, ast),
);
identifiers.forEach((identifier) => {
identifier.referencedDeclaration = newDecl.id;
Expand Down
3 changes: 3 additions & 0 deletions src/passes/staticArrayIndexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
Mutability,
PointerType,
StateVariableVisibility,
TypeNameType,
TypeNode,
VariableDeclaration,
VariableDeclarationStatement,
Expand Down Expand Up @@ -58,6 +59,8 @@ export class StaticArrayIndexer extends ASTMapper {
}

visitIndexAccess(node: IndexAccess, ast: AST): void {
if (safeGetNodeType(node, ast.inference) instanceof TypeNameType)
return this.commonVisit(node, ast);
this.staticIndexToMemory(node, ast);
}

Expand Down
6 changes: 5 additions & 1 deletion src/passes/tupleFixes/tupleFlattener.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { TupleExpression } from 'solc-typed-ast';
import { TupleExpression, TypeNameType } from 'solc-typed-ast';
import { AST } from '../../ast/ast';
import { ASTMapper } from '../../ast/mapper';
import { safeGetNodeType } from '../../export';
import { WillNotSupportError } from '../../utils/errors';

export class TupleFlattener extends ASTMapper {
Expand All @@ -18,6 +19,9 @@ export class TupleFlattener extends ASTMapper {
node.vOriginalComponents[0].typeString === node.typeString &&
!node.isInlineArray
) {
if (safeGetNodeType(node.vOriginalComponents[0], ast.inference) instanceof TypeNameType) {
return this.commonVisit(node, ast);
}
const parent = node.parent;
ast.replaceNode(node, node.vOriginalComponents[0], parent);
this.dispatchVisit(node.vOriginalComponents[0], ast);
Expand Down
9 changes: 8 additions & 1 deletion src/passes/typeNameRemover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ import { safeGetNodeType } from '../utils/nodeTypeProcessing';
export class TypeNameRemover extends ASTMapper {
// Function to add passes that should have been run before this pass
addInitialPassPrerequisites(): void {
const passKeys: Set<string> = new Set<string>([]);
const passKeys: Set<string> = new Set<string>([
// ABI Builtin needs to be handled first because some builtin
// functions like abi.decode uses TypeNames as arguments, otherwise,
// they will be removed before use
// Eg:
// abi.decode(data, (uint[7][]));
'Abi',
]);
passKeys.forEach((key) => this.addPassPrerequisite(key));
}

Expand Down
Loading