-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add performance tests for bindings API (#1100)
This PR adds performance tests to exercise the bindings API: - `create_bindings` creates a blank Bindings object, useful as a baseline and to later measure the cost of adding the built-ins - `bindings` which construct the stack graphs and other related bindings structures for the performance testing dataset files - `resolve_references` attempts to resolve all the references found in the dataset files --------- Co-authored-by: OmarTawfik <[email protected]>
- Loading branch information
1 parent
15c437c
commit 828eff3
Showing
19 changed files
with
275 additions
and
3,584 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,245 +1,36 @@ | ||
use std::collections::BTreeSet; | ||
use std::path::PathBuf; | ||
|
||
use infra_utils::cargo::CargoWorkspace; | ||
use infra_utils::paths::PathExtensions; | ||
use semver::Version; | ||
use slang_solidity::cst::Node; | ||
use slang_solidity::kinds::{EdgeLabel, NonterminalKind}; | ||
use slang_solidity::language::Language; | ||
use slang_solidity::query::Query; | ||
use slang_solidity::text_index::TextIndex; | ||
|
||
const SOLC_VERSION: Version = Version::new(0, 8, 20); | ||
pub const SOLC_VERSION: Version = Version::new(0, 8, 20); | ||
|
||
const SOURCES: &[&str] = &[ | ||
include_str!("./sources/EnumerableMap.sol"), | ||
include_str!("./sources/ERC20.sol"), | ||
include_str!("./sources/ERC721.sol"), | ||
include_str!("./sources/Governor.sol"), | ||
include_str!("./sources/SafeCast.sol"), | ||
"node_modules/@openzeppelin/contracts/governance/Governor.sol", | ||
"node_modules/@openzeppelin/contracts/token/ERC20/ERC20.sol", | ||
"node_modules/@openzeppelin/contracts/token/ERC721/ERC721.sol", | ||
"node_modules/@openzeppelin/contracts/utils/math/SafeCast.sol", | ||
"node_modules/@openzeppelin/contracts/utils/structs/EnumerableMap.sol", | ||
]; | ||
|
||
const FUNCTION_NAMES: &[&str] = &[ | ||
"CLOCK_MODE", | ||
"_approve", | ||
"_baseURI", | ||
"_burn", | ||
"_cancel", | ||
"_castVote", | ||
"_checkAuthorized", | ||
"_checkGovernance", | ||
"_checkOnERC721Received", | ||
"_countVote", | ||
"_defaultParams", | ||
"_encodeStateBitmap", | ||
"_executeOperations", | ||
"_executor", | ||
"_getApproved", | ||
"_getVotes", | ||
"_increaseBalance", | ||
"_isAuthorized", | ||
"_isValidDescriptionForProposer", | ||
"_mint", | ||
"_ownerOf", | ||
"_propose", | ||
"_queueOperations", | ||
"_quorumReached", | ||
"_requireOwned", | ||
"_safeMint", | ||
"_safeTransfer", | ||
"_setApprovalForAll", | ||
"_spendAllowance", | ||
"_transfer", | ||
"_tryHexToUint", | ||
"_update", | ||
"_validateStateBitmap", | ||
"_voteSucceeded", | ||
"allowance", | ||
"approve", | ||
"at", | ||
"balanceOf", | ||
"cancel", | ||
"castVote", | ||
"castVoteBySig", | ||
"castVoteWithReason", | ||
"castVoteWithReasonAndParams", | ||
"castVoteWithReasonAndParamsBySig", | ||
"clock", | ||
"contains", | ||
"decimals", | ||
"execute", | ||
"get", | ||
"getApproved", | ||
"getVotes", | ||
"getVotesWithParams", | ||
"hashProposal", | ||
"isApprovedForAll", | ||
"keys", | ||
"length", | ||
"name", | ||
"onERC1155BatchReceived", | ||
"onERC1155Received", | ||
"onERC721Received", | ||
"ownerOf", | ||
"proposalDeadline", | ||
"proposalEta", | ||
"proposalNeedsQueuing", | ||
"proposalProposer", | ||
"proposalSnapshot", | ||
"proposalThreshold", | ||
"propose", | ||
"queue", | ||
"quorum", | ||
"relay", | ||
"remove", | ||
"safeTransferFrom", | ||
"set", | ||
"setApprovalForAll", | ||
"state", | ||
"supportsInterface", | ||
"symbol", | ||
"toInt104", | ||
"toInt112", | ||
"toInt120", | ||
"toInt128", | ||
"toInt136", | ||
"toInt144", | ||
"toInt152", | ||
"toInt16", | ||
"toInt160", | ||
"toInt168", | ||
"toInt176", | ||
"toInt184", | ||
"toInt192", | ||
"toInt200", | ||
"toInt208", | ||
"toInt216", | ||
"toInt224", | ||
"toInt232", | ||
"toInt24", | ||
"toInt240", | ||
"toInt248", | ||
"toInt256", | ||
"toInt32", | ||
"toInt40", | ||
"toInt48", | ||
"toInt56", | ||
"toInt64", | ||
"toInt72", | ||
"toInt8", | ||
"toInt80", | ||
"toInt88", | ||
"toInt96", | ||
"toUint104", | ||
"toUint112", | ||
"toUint120", | ||
"toUint128", | ||
"toUint136", | ||
"toUint144", | ||
"toUint152", | ||
"toUint16", | ||
"toUint160", | ||
"toUint168", | ||
"toUint176", | ||
"toUint184", | ||
"toUint192", | ||
"toUint200", | ||
"toUint208", | ||
"toUint216", | ||
"toUint224", | ||
"toUint232", | ||
"toUint24", | ||
"toUint240", | ||
"toUint248", | ||
"toUint256", | ||
"toUint32", | ||
"toUint40", | ||
"toUint48", | ||
"toUint56", | ||
"toUint64", | ||
"toUint72", | ||
"toUint8", | ||
"toUint80", | ||
"toUint88", | ||
"toUint96", | ||
"tokenURI", | ||
"totalSupply", | ||
"transfer", | ||
"transferFrom", | ||
"tryGet", | ||
"version", | ||
"votingDelay", | ||
"votingPeriod", | ||
]; | ||
|
||
pub fn run_parser() -> Vec<Node> { | ||
let language = Language::new(SOLC_VERSION).unwrap(); | ||
|
||
let mut trees = vec![]; | ||
|
||
for source in SOURCES { | ||
let parse_output = language.parse(Language::ROOT_KIND, source); | ||
|
||
assert!( | ||
parse_output.is_valid(), | ||
"Found parse errors:\n{0:#?}", | ||
parse_output.errors(), | ||
); | ||
|
||
trees.push(parse_output.tree()); | ||
} | ||
|
||
trees | ||
pub struct SourceFile { | ||
pub path: PathBuf, | ||
pub contents: String, | ||
} | ||
|
||
pub fn run_cursor(trees: &Vec<Node>) { | ||
let mut results = BTreeSet::new(); | ||
impl SourceFile { | ||
pub fn load_all() -> Vec<Self> { | ||
let crate_dir = CargoWorkspace::locate_source_crate("solidity_testing_perf").unwrap(); | ||
|
||
for tree in trees { | ||
let mut cursor = tree.cursor_with_offset(TextIndex::ZERO); | ||
SOURCES | ||
.iter() | ||
.map(|relative_path| { | ||
let path = crate_dir.join(relative_path); | ||
let contents = path.read_to_string().unwrap(); | ||
|
||
while cursor.go_to_next_nonterminal_with_kind(NonterminalKind::FunctionDefinition) { | ||
results.extend( | ||
cursor | ||
.node() | ||
.children() | ||
.iter() | ||
.filter(|edge| edge.label == Some(EdgeLabel::Name)) | ||
.map(|edge| edge.node.clone().unparse().trim().to_owned()), | ||
); | ||
} | ||
Self { path, contents } | ||
}) | ||
.collect() | ||
} | ||
|
||
assert!( | ||
results.iter().eq(FUNCTION_NAMES.iter()), | ||
"Function names don't match: {results:#?}" | ||
); | ||
} | ||
|
||
pub fn run_query(trees: &Vec<Node>) { | ||
let mut results = BTreeSet::new(); | ||
|
||
let queries = vec![Query::parse( | ||
"[FunctionDefinition | ||
@name name: [_] | ||
]", | ||
) | ||
.unwrap()]; | ||
|
||
for tree in trees { | ||
let cursor = tree.cursor_with_offset(TextIndex::ZERO); | ||
|
||
for query_match in cursor.query(queries.clone()) { | ||
assert_eq!(query_match.captures.len(), 1); | ||
|
||
results.extend( | ||
query_match.captures["name"] | ||
.iter() | ||
.map(|cursor| cursor.node().unparse().trim().to_owned()), | ||
); | ||
} | ||
} | ||
|
||
assert!( | ||
results.iter().eq(FUNCTION_NAMES.iter()), | ||
"Function names don't match: {results:#?}" | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.