-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Imported types should be added to IDL #1972
Comments
What does listing the types within the Thinking about external types two things come to mind:
|
@kklas the purpose of using something like
Correct...but what about the case of developers importing the types via a renamed There is also There are lots of little edge cases like this that make crate deduction difficult. but if there was an expandable-to-nothing macro to provide a syntactical identifier around verbose type paths, we could then do the IDL parsing of the external programs to get the types we need to merge into the local IDL. |
Fair enough, thanks for clarifying. To me it feels like we're re-implementing the compiler a bit with the IDL parsing. |
Problem
At present, if you
use
anenum
orstruct
from another crate that meets the criteria for a (de)serializable type as an instruction argument, that type gets listed as adefined
entry in the instruction's argument list but doesn't get it's buffer-layout translations embedded into the IDL on program parsing.While this is simply not implemented to be supported, it's also a natural limitation of Rust due to the lack of reflection/introspection. Creating a wrapper type doesn't work either because the inner field of the struct still won't be inspectable in order to get the list of fields of the foreign type.
Possible Solution
A new functional macro to act as a syntactical wrapper around defining the list of external types that need to be parsed and imported into the program's IDL, but expands to an empty
TokenStream
on build (since IDL parsing is over a static file read and doesn't require builds)Example
When the new local program's IDL is parsed, this would cause the equivalent of
anchor idl parse
on the program entry points (likely from the local cargo cache copies) for each of the enumerated external types and merge their IDL type object with the array of types in the local program's IDL.This has become a cross-program composability issue is several cases and would be a huge improvement in the IDL parsing processes to unblock the use of imported types in programs.
(cc @suscd)
The text was updated successfully, but these errors were encountered: