Rearchitect declaration internals to support UDVTs #114
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Addresses #113 and partially addresses #42
This PR adds support for user-defined value types by redoing the internals of how abi-to-sol finds all the declared types it needs to emit.
Previously, abi-to-sol was built only to emit
struct
s, and it relied heavily on the ABI schema's idea of a tuple signature (e.g.(uint256,address)
) to organize all the known struct declarations. Struct signatures were used both during declaration collection and during code generation. This caused problems in #42 because signatures lose names, and the old format couldn't collect more than one struct for a given signature. This also prevented any kind of UDVT support, because everything was struct-based.So this PR replaces that with several very-explicit-but-kind-of-messy modules for kinds, identifiers, etc.... and a new explicit bind step, whew! This explicit bind step is helpful and long overdue. In the spirit of structuring these new internals as an IR, things get complicated with ABI JSON parameter's
type
field, which is standard, andinternalType
, which is Solidity-specific. This PR includes a bunch of type guards for taking atype
and classifying it as elementary/array/tuple/etc., and similarly classifying parameter type references as structs and UDVTs and whatnot.To decouple code generation from struct signature based lookups, the new declarations collection system also provides corresponding search logic, so that when the code generator must output an ABI parameter, there's a first-class mechanism for finding the right declaration to use.
This PR also includes some unrelated changes:
Notes:
internalType
, so if Vyper ever adds those, this feature will likely need revisiting.internalType
also, so the system still might not be smart enough to pick the right struct if the input ABI doesn't haveinternalType
s. Fixing this limitation should now be doable thanks to the better organization scheme and search logic, but figured it wasn't urgent enough to include here.