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

[move-vm] Generalize metadata for attribute parameters #5896

Merged
merged 1 commit into from
Dec 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion aptos-move/aptos-vm/src/verifier/view_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub(crate) fn validate_view_function<S: MoveResolverExt>(
let is_view = if let Some(data) = module_metadata {
data.fun_attributes
.get(fun_name.as_str())
.map(|attrs| attrs.contains(&KnownAttribute::ViewFunction))
.map(|attrs| attrs.contains(&KnownAttribute::view_function()))
.unwrap_or_default()
} else {
false
Expand Down
2 changes: 1 addition & 1 deletion aptos-move/framework/src/extended_checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ impl<'a> ExtendedChecker<'a> {
.fun_attributes
.entry(fun.get_simple_name_string().to_string())
.or_default()
.push(KnownAttribute::ViewFunction);
.push(KnownAttribute::view_function());
}
}
}
Expand Down
22 changes: 21 additions & 1 deletion aptos-move/framework/src/module_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,30 @@ pub struct RuntimeModuleMetadataV1 {

/// Enumeration of known attributes
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
pub enum KnownAttribute {
pub struct KnownAttribute {
kind: KnownAttributeKind,
args: Vec<String>,
}

/// Enumeration of known attributes
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
pub enum KnownAttributeKind {
ViewFunction = 1,
}

impl KnownAttribute {
pub fn view_function() -> Self {
Self {
kind: KnownAttributeKind::ViewFunction,
args: vec![],
}
}

pub fn is_view_function(&self) -> bool {
self.kind == KnownAttributeKind::ViewFunction
}
}

/// Extract metadata from the VM, upgrading V0 to V1 representation as needed
pub fn get_vm_metadata(vm: &MoveVM, module_id: ModuleId) -> Option<RuntimeModuleMetadataV1> {
if let Some(data) = vm.get_module_metadata(module_id.clone(), &APTOS_METADATA_KEY_V1) {
Expand Down