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

Support for Solidity 0.8.26 #271

Merged
merged 3 commits into from
Jul 20, 2024
Merged
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 src/ast/implementation/declaration/contract_definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export class ContractDefinition
usedErrors: number[];

/**
* Used error definition ids (including external definition ids)
* Used events definition ids (including external definition ids)
*/
usedEvents: number[];

Expand Down
3 changes: 2 additions & 1 deletion src/compile/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ export const CompilerVersions08 = [
"0.8.22",
"0.8.23",
"0.8.24",
"0.8.25"
"0.8.25",
"0.8.26"
];

export const CompilerSeries = [
Expand Down
12 changes: 12 additions & 0 deletions src/types/ast/error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { TypeNode } from "./type";
import { Range } from "../../misc";

export class BuiltinErrorType extends TypeNode {
constructor(src?: Range) {
super(src);
}

pp(): string {
return `error`;
}
}
1 change: 1 addition & 0 deletions src/types/ast/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ export * from "./tuple_type";
export * from "./type";
export * from "./typename_type";
export * from "./user_defined_type";
export * from "./error";
19 changes: 16 additions & 3 deletions src/types/infer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,19 @@ export const builtinTypes: { [key: string]: (arg: ASTNode) => TypeNode } = {
},

require: (arg: ASTNode) => {
const hasMsg = arg.parent instanceof FunctionCall && arg.parent.vArguments.length === 2;
const argTs = hasMsg ? [types.bool, types.stringMemory] : [types.bool];
let argTs: TypeNode[];

if (arg.parent instanceof FunctionCall && arg.parent.vArguments.length === 2) {
const secondArg = arg.parent.vArguments[1];

if (secondArg.typeString === "error") {
argTs = [types.bool, types.error];
} else {
argTs = [types.bool, types.stringMemory];
}
} else {
argTs = [types.bool];
}

return new BuiltinFunctionType("require", argTs, []);
},
Expand Down Expand Up @@ -817,8 +828,10 @@ export class InferType {
}
} else if (resolvedCalleeT instanceof BuiltinFunctionType) {
rets = resolvedCalleeT.returns;
} else if (resolvedCalleeT instanceof EventType || resolvedCalleeT instanceof ErrorType) {
} else if (resolvedCalleeT instanceof EventType) {
rets = [];
} else if (resolvedCalleeT instanceof ErrorType) {
rets = [types.error];
} else {
throw new SolTypeError(
`Unexpected unresolved calele type in function call ${pp(node)}`
Expand Down
6 changes: 4 additions & 2 deletions src/types/reserved.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
AddressType,
IntType,
TupleType,
BuiltinFunctionType
BuiltinFunctionType,
BuiltinErrorType
} from "./ast";

// Helper with some singleton types to avoid unnecessary allocations
Expand All @@ -27,5 +28,6 @@ export const types = {
address: new AddressType(false),
addressPayable: new AddressType(true),
noType: new TupleType([]),
typeOfType: new BuiltinFunctionType(undefined, [], [])
typeOfType: new BuiltinFunctionType(undefined, [], []),
error: new BuiltinErrorType()
};
3 changes: 2 additions & 1 deletion test/integration/compile/kinds.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ describe(`Native and WASM compilers produce the same results for all files`, ()
defaultCompilationOutput,
defaultCompilerSettings
]
]
],
["test/samples/solidity/latest_08.sol", [{}, defaultCompilationOutput, { viaIR: true }]]
]);

for (const sample of samples) {
Expand Down
92 changes: 73 additions & 19 deletions test/integration/compile/latest_08.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,36 +30,36 @@ const encounters = new Map<string, number>([
["PragmaDirective", 2],
["ImportDirective", 1],
["StructDefinition", 1],
["StructuredDocumentation", 5],
["VariableDeclaration", 80],
["ElementaryTypeName", 63],
["StructuredDocumentation", 6],
["VariableDeclaration", 85],
["ElementaryTypeName", 69],
["EnumDefinition", 2],
["EnumValue", 6],
["ContractDefinition", 21],
["FunctionDefinition", 35],
["ParameterList", 94],
["Block", 51],
["ContractDefinition", 22],
["FunctionDefinition", 36],
["ParameterList", 97],
["Block", 52],
["VariableDeclarationStatement", 16],
["Literal", 43],
["UncheckedBlock", 4],
["ExpressionStatement", 22],
["ExpressionStatement", 25],
["UnaryOperation", 6],
["Identifier", 98],
["Identifier", 112],
["Return", 15],
["InheritanceSpecifier", 1],
["IdentifierPath", 36],
["UsingForDirective", 3],
["UserDefinedTypeName", 27],
["ModifierInvocation", 2],
["FunctionCall", 47],
["MemberAccess", 41],
["FunctionCall", 49],
["MemberAccess", 44],
["OverrideSpecifier", 1],
["ElementaryTypeNameExpression", 4],
["NewExpression", 2],
["TryStatement", 2],
["TryCatchClause", 8],
["IfStatement", 3],
["BinaryOperation", 23],
["BinaryOperation", 24],
["EventDefinition", 7],
["ModifierDefinition", 1],
["PlaceholderStatement", 1],
Expand All @@ -71,11 +71,65 @@ const encounters = new Map<string, number>([
["Break", 1],
["ForStatement", 1],
["InlineAssembly", 6],
["ErrorDefinition", 4],
["ErrorDefinition", 5],
["RevertStatement", 3],
["UserDefinedValueTypeDefinition", 5],
["FunctionTypeName", 4],
["Assignment", 3]
["Assignment", 5],
["Mapping", 1],
["IndexAccess", 4],
["SourceUnit", 1],
["PragmaDirective", 2],
["ImportDirective", 1],
["StructDefinition", 1],
["StructuredDocumentation", 6],
["VariableDeclaration", 85],
["ElementaryTypeName", 69],
["EnumDefinition", 2],
["EnumValue", 6],
["ContractDefinition", 22],
["FunctionDefinition", 36],
["ParameterList", 97],
["Block", 52],
["VariableDeclarationStatement", 16],
["Literal", 43],
["UncheckedBlock", 4],
["ExpressionStatement", 25],
["UnaryOperation", 6],
["Identifier", 112],
["Return", 15],
["InheritanceSpecifier", 1],
["IdentifierPath", 36],
["UsingForDirective", 3],
["UserDefinedTypeName", 27],
["ModifierInvocation", 2],
["FunctionCall", 49],
["MemberAccess", 44],
["OverrideSpecifier", 1],
["ElementaryTypeNameExpression", 4],
["NewExpression", 2],
["TryStatement", 2],
["TryCatchClause", 8],
["IfStatement", 3],
["BinaryOperation", 24],
["EventDefinition", 7],
["ModifierDefinition", 1],
["PlaceholderStatement", 1],
["TupleExpression", 9],
["EmitStatement", 6],
["WhileStatement", 1],
["Continue", 1],
["DoWhileStatement", 1],
["Break", 1],
["ForStatement", 1],
["InlineAssembly", 6],
["ErrorDefinition", 5],
["RevertStatement", 3],
["UserDefinedValueTypeDefinition", 5],
["FunctionTypeName", 4],
["Assignment", 5],
["Mapping", 1],
["IndexAccess", 4]
]);

for (const compilerKind of PossibleCompilerKinds) {
Expand All @@ -91,7 +145,7 @@ for (const compilerKind of PossibleCompilerKinds) {
"auto",
undefined,
undefined,
undefined,
{ viaIR: true },
compilerKind as CompilerKind
);

Expand All @@ -118,11 +172,11 @@ for (const compilerKind of PossibleCompilerKinds) {
// console.log(sourceUnit.print());
// console.log(sourceUnit.getChildren().length);

expect(sourceUnit.id).toEqual(829);
expect(sourceUnit.src).toEqual("0:9539:0");
expect(sourceUnit.id).toEqual(878);
expect(sourceUnit.src).toEqual("0:10179:0");
expect(sourceUnit.absolutePath).toEqual(mainSample);
expect(sourceUnit.children.length).toEqual(37);
expect(sourceUnit.getChildren().length).toEqual(819);
expect(sourceUnit.children.length).toEqual(39);
expect(sourceUnit.getChildren().length).toEqual(868);
});

it(`Validate parsed output (${astKind})`, () => {
Expand Down
53 changes: 39 additions & 14 deletions test/integration/factory/copy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,49 @@ import {
detectCompileErrors
} from "../../../src";

const cases: Array<[string, Array<[CompilerKind, string]>]> = [
const cases: Array<[string, Array<[CompilerKind, string, any]>]> = [
[
"./test/samples/solidity/declarations/contract_050.json",
[
[CompilerKind.WASM, "./test/samples/solidity/declarations/contract_050.nodes.wasm.txt"],
[
CompilerKind.WASM,
"./test/samples/solidity/declarations/contract_050.nodes.wasm.txt",
undefined
],
[
CompilerKind.Native,
"./test/samples/solidity/declarations/contract_050.nodes.native.txt"
"./test/samples/solidity/declarations/contract_050.nodes.native.txt",
undefined
]
]
],
[
"./test/samples/solidity/issue_132_fun_kind.sol",
[
[CompilerKind.WASM, "./test/samples/solidity/issue_132_fun_kind.nodes.wasm.txt"],
[CompilerKind.Native, "./test/samples/solidity/issue_132_fun_kind.nodes.native.txt"]
[
CompilerKind.WASM,
"./test/samples/solidity/issue_132_fun_kind.nodes.wasm.txt",
undefined
],
[
CompilerKind.Native,
"./test/samples/solidity/issue_132_fun_kind.nodes.native.txt",
undefined
]
]
],
[
"./test/samples/solidity/different_abi_encoders/v1_imports_v2/v1.sol",
[
[
CompilerKind.WASM,
"./test/samples/solidity/different_abi_encoders/v1_imports_v2/v1.nodes.wasm.txt"
"./test/samples/solidity/different_abi_encoders/v1_imports_v2/v1.nodes.wasm.txt",
undefined
],
[
CompilerKind.Native,
"./test/samples/solidity/different_abi_encoders/v1_imports_v2/v1.nodes.native.txt"
"./test/samples/solidity/different_abi_encoders/v1_imports_v2/v1.nodes.native.txt",
undefined
]
]
],
Expand All @@ -46,33 +61,43 @@ const cases: Array<[string, Array<[CompilerKind, string]>]> = [
[
[
CompilerKind.WASM,
"./test/samples/solidity/different_abi_encoders/v2_imports_v1/v2.nodes.wasm.txt"
"./test/samples/solidity/different_abi_encoders/v2_imports_v1/v2.nodes.wasm.txt",
undefined
],
[
CompilerKind.Native,
"./test/samples/solidity/different_abi_encoders/v2_imports_v1/v2.nodes.native.txt"
"./test/samples/solidity/different_abi_encoders/v2_imports_v1/v2.nodes.native.txt",
undefined
]
]
],
[
"./test/samples/solidity/latest_08.sol",
[
[CompilerKind.WASM, "./test/samples/solidity/latest_08.nodes.wasm.txt"],
[CompilerKind.Native, "./test/samples/solidity/latest_08.nodes.native.txt"]
[
CompilerKind.WASM,
"./test/samples/solidity/latest_08.nodes.wasm.txt",
{ viaIR: true }
],
[
CompilerKind.Native,
"./test/samples/solidity/latest_08.nodes.native.txt",
{ viaIR: true }
]
]
]
];

describe(`ASTNodeFactory.copy() validation`, () => {
for (const [sample, setups] of cases) {
for (const [kind, snapshot] of setups) {
for (const [kind, snapshot, compilerSettings] of setups) {
describe(`[${kind}] ${sample} -> ${snapshot}`, () => {
let data: any = {};

beforeAll(async () => {
const result = await (sample.endsWith(".sol")
? compileSol(sample, "auto", undefined, undefined, undefined, kind)
: compileJson(sample, "auto", undefined, undefined, kind));
? compileSol(sample, "auto", undefined, undefined, compilerSettings, kind)
: compileJson(sample, "auto", undefined, compilerSettings, kind));

const errors = detectCompileErrors(result.data);

Expand Down
Loading