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

[WIP] Metrics for Sanctuary #1186

Draft
wants to merge 91 commits into
base: main
Choose a base branch
from
Draft

[WIP] Metrics for Sanctuary #1186

wants to merge 91 commits into from

Conversation

beta-ziliani
Copy link
Contributor

@beta-ziliani beta-ziliani commented Dec 11, 2024

This PR adds stats to sanctuary. Collected stats are at the moment:

file,   # the complete path at the moment, likely to change
bytes,  # total bytes of file
locs,  # a simple count of lines
number_of_contracts,  # number of hits of the query `[ContractDefinition]`,
total_inheritance_count,  # How many times contracts are inherited
max_inheritance_count,  # the max grade of the contract inheritance graph
cst_height,  # the height of the nodes tree
number_of_nodes, # the sum of nodes
without_trivia,  # same as previous one, but filtering out `.is_trivia?`
number_of_refs, # number of binding refereces
parsing_time,  # in µsec
bindings_time, # in µsec
memory_usage, # in bytes

These are collected with --collect-metrics, and if a file is specified with --metrics-file, it will write the csv tabulated file. Otherwise, it spits it in stdout.

Memory is only profiled if compiled with feature mem_profiler. This is because we're instrumentating Rust's allocator, and I figured it's a bold movement when not profiling. We can then instead remove the --collect-metrics to just check this feature.

Built on top of #1170

- `string` and `bytes` are exported as built-in variables resolving to types
that provide a `concat` function
- `address` can be used as a function to cast a parameter to `address` to eg.
retrieve the balance
This makes resolving to attached functions on types even when the reference of
those types happen in a different lexical scope.
And also provide alternative paths with and without propagating the dynamic
scope. Otherwise, since scope accumulate on the stack it's possible we'll need
to resolve an attached function with the wrong dynamic scope at the top of the
scope stack.
Both contracts and libraries can optionally push the dynamics scope when
traversing to the parent lexical scope (ie. the source unit). But for libraries,
they can also optionally push their name to correctly bind internal types which
were extended (with `using`) by their qualified name (ie. `Lib.Type`).
Applying a function call with a type will always return a value of that type, so
a symbol stack `type,()` is equivalent to `type,@typeof`. Reflect on the binding
entry point of the using clause.
These are parsed as modifiers, and they need a similar treatment as parent
constructor calls in new constructor definitions.
ggiraldez and others added 24 commits November 26, 2024 20:08
The ResolverCandidates will insert arbitrary edges to the graph connecting to
the extension scopes determined available at the beginning of resolution (these
are context dependent) when reaching nodes marked as extension hooks (usually
the source unit's lexical scope).
There's an initial dual purpose:
- make resolution reentrant-safe, as some of the resolution tweaks require
resolving references themselves
- enable recursive lookup of extension scopes for Solidity < 0.7.0
Since extensions are now injected during the resolution phases, it's no longer
needed to have a separate extended scope. This simplifies the existing rules
quite a bit.

Also removes all previous commented out rules that dealt with pushing the
extension scope to the scope stack, since that mechanism is no longer used.
Instead of having to manually customize the resolver. Also, simplify
`ResolveOptions` to an enum with two possible values: `Full` and `NonRecursive`.
`NonRecursive` is used internally from `simple_resolve` to disable code paths
that could lead to infinite recursions when attempting to resolve a reference.
Since the built-ins file needs to be pre-processed to transform the symbols as
to ensure no conflicts can occur with user code, adding the built-ins requires a
couple of manual steps that were replicated in every construction of Solidity
bindings API. By encapsulating this functionality in the `slang_solidity` crate
we remove a source of user error and make it easier to make changes to the
built-ins ingestion code.
@beta-ziliani beta-ziliani requested review from a team as code owners December 11, 2024 12:36
Copy link

changeset-bot bot commented Dec 11, 2024

⚠️ No Changeset found

Latest commit: 873c856

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@beta-ziliani beta-ziliani marked this pull request as draft December 11, 2024 12:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants