The type T must be defined in the caller's current module.
The move developer also needs this feature to restrict the function's generic type. Still, this feature is hardcode in the verifier, and the developer can not use this feature for their function.
So, if we introduce some verifier annotation, we can provide this feature to the developer.
Pitch
Describe the solution you'd like
Introduce a verifier annotation, such as #[private_generics(T)], indicating the function's generic parameter T is private, which requires the same restriction to T as global storage instructions.
Implement a verifier extension for the annotation, like sui-verifier's private_generics.
UseCase
TypeTable
140 The TypeTable also requires this feature to ensure Type Safety.
Provide bcs::from_bytes
module std::bcs{
#[private_generics(T)]
public fun from_bytes<T>(bytes: vector<u8>): T
}
As described in the issue(https://github.com/rooch-network/rooch/issues/145) mentioned, relying on private_generics alone cannot guarantee type safety. We need two other annotations,#[self_struct] and #[require_self_struct(T)]. The name for the annotations is yet to be determined.
[self_struct]: A struct with this annotation indicates that all its fields are either of primitive type or defined in the current module.
[require_self_struct(T)]: A function with annotation indicates that the generic type T must have #[self_struct] annotation.
module std::bcs{
#[private_generics(T), require_self_struct(T)]
public fun from_bytes<T>(bytes: vector<u8>): T
}
π Feature Request
Motivation
In Move, the verifier ensures that the generic parameters of the global storage instructions must be defined in the caller's module.
Such as
move_to<T>|move_from<T>|borrow_global<T>|borrow_global_mut<T>
The type
T
must be defined in the caller's current module.The move developer also needs this feature to restrict the function's generic type. Still, this feature is hardcode in the verifier, and the developer can not use this feature for their function.
So, if we introduce some verifier annotation, we can provide this feature to the developer.
Pitch
Describe the solution you'd like
#[private_generics(T)]
, indicating the function's generic parameterT
is private, which requires the same restriction toT
as global storage instructions.UseCase
140 The TypeTable also requires this feature to ensure Type Safety.
bcs::from_bytes
As described in the issue(https://github.com/rooch-network/rooch/issues/145) mentioned, relying on
private_generics
alone cannot guarantee type safety. We need two other annotations,#[self_struct]
and#[require_self_struct(T)]
. The name for the annotations is yet to be determined.[self_struct]: A struct with this annotation indicates that all its fields are either of primitive type or defined in the current module.
[require_self_struct(T)]: A function with annotation indicates that the generic type
T
must have#[self_struct]
annotation.Are you willing to open a pull request? (See CONTRIBUTING)
Yes
Additional context