Skip to content

Commit d582b16

Browse files
[refactoring] Remove display for tags (aptos-labs#16747)
- Display implementation of tags is removed - `to_canonical_string()` should be used instead - Fixes conversion of function tags to strings
1 parent 3089ded commit d582b16

File tree

46 files changed

+328
-337
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+328
-337
lines changed

api/src/accounts.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,8 @@ impl Account {
664664
.find_resource(&state_view, self.address, resource_type)
665665
.context(format!(
666666
"Failed to query DB to check for {} at {}",
667-
resource_type, self.address
667+
resource_type.to_canonical_string(),
668+
self.address
668669
))
669670
.map_err(|err| {
670671
BasicErrorWith404::internal_with_code(

api/src/response.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,9 @@ pub fn resource_not_found<E: NotFoundError>(
663663
"Resource",
664664
format!(
665665
"Address({}), Struct tag({}) and Ledger version({})",
666-
address, struct_tag, ledger_version
666+
address,
667+
struct_tag.to_canonical_string(),
668+
ledger_version
667669
),
668670
AptosErrorCode::ResourceNotFound,
669671
ledger_info,
@@ -698,7 +700,10 @@ pub fn struct_field_not_found<E: NotFoundError>(
698700
"Struct Field",
699701
format!(
700702
"Address({}), Struct tag({}), Field name({}) and Ledger version({})",
701-
address, struct_tag, field_name, ledger_version
703+
address,
704+
struct_tag.to_canonical_string(),
705+
field_name,
706+
ledger_version
702707
),
703708
AptosErrorCode::StructFieldNotFound,
704709
ledger_info,

api/src/state.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,8 @@ impl StateApi {
291291
.find_resource(&state_view, address, &tag)
292292
.context(format!(
293293
"Failed to query DB to check for {} at {}",
294-
tag, address
294+
tag.to_canonical_string(),
295+
address
295296
))
296297
.map_err(|err| {
297298
BasicErrorWith404::internal_with_code(

api/types/src/convert.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -573,9 +573,9 @@ impl<'a, S: StateView> MoveConverter<'a, S> {
573573

574574
Ok(Some(DecodedTableData {
575575
key: key.json().unwrap(),
576-
key_type: table_info.key_type.to_string(),
576+
key_type: table_info.key_type.to_canonical_string(),
577577
value: value.json().unwrap(),
578-
value_type: table_info.value_type.to_string(),
578+
value_type: table_info.value_type.to_canonical_string(),
579579
}))
580580
}
581581

@@ -596,7 +596,7 @@ impl<'a, S: StateView> MoveConverter<'a, S> {
596596

597597
Ok(Some(DeletedTableData {
598598
key: key.json().unwrap(),
599-
key_type: table_info.key_type.to_string(),
599+
key_type: table_info.key_type.to_canonical_string(),
600600
}))
601601
}
602602

aptos-move/aptos-gas-profiling/src/aggregate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ impl ExecutionAndIOCosts {
9999
addr: _addr,
100100
ty,
101101
cost,
102-
} => insert_or_add(&mut storage_reads, format!("{}", ty), *cost),
102+
} => insert_or_add(&mut storage_reads, ty.to_canonical_string(), *cost),
103103
CreateTy { cost } => insert_or_add(&mut ops, "create_ty".to_string(), *cost),
104104
}
105105
}

aptos-move/aptos-gas-profiling/src/erased.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,10 @@ impl ExecutionGasEvent {
148148
),
149149
*cost,
150150
),
151-
LoadResource { addr, ty, cost } => {
152-
Node::new(format!("load<{}::{}>", Render(addr), ty), *cost)
153-
},
151+
LoadResource { addr, ty, cost } => Node::new(
152+
format!("load<{}::{}>", Render(addr), ty.to_canonical_string()),
153+
*cost,
154+
),
154155
CreateTy { cost } => Node::new("create_ty", *cost),
155156
}
156157
}
@@ -272,7 +273,7 @@ impl WriteStorage {
272273

273274
impl EventStorage {
274275
fn to_erased(&self) -> Node<StoragePair> {
275-
Node::new(format!("{}", self.ty), (self.cost, Fee::zero()))
276+
Node::new(self.ty.to_canonical_string(), (self.cost, Fee::zero()))
276277
}
277278
}
278279

aptos-move/aptos-gas-profiling/src/flamegraph.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ impl StorageFees {
4747

4848
for event in &self.events {
4949
// TODO: Handle discounts.
50-
lines.push(format!("events;{}", event.ty), event.cost)
50+
lines.push(
51+
format!("events;{}", event.ty.to_canonical_string()),
52+
event.cost,
53+
)
5154
}
5255

5356
lines.into_inner()
@@ -148,7 +151,12 @@ impl ExecutionAndIOCosts {
148151
*cost,
149152
),
150153
LoadResource { addr, ty, cost } => self.lines.push(
151-
format!("{};load<{}::{}>", self.path(), Render(addr), ty),
154+
format!(
155+
"{};load<{}::{}>",
156+
self.path(),
157+
Render(addr),
158+
ty.to_canonical_string()
159+
),
152160
*cost,
153161
),
154162
}

aptos-move/aptos-gas-profiling/src/render.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ impl<'a> Display for Render<'a, (&'a ModuleId, &'a IdentStr, &'a [TypeTag])> {
4545
self.0
4646
.2
4747
.iter()
48-
.map(|ty| format!("{}", ty))
48+
.map(|ty| ty.to_canonical_string())
4949
.collect::<Vec<_>>()
50-
.join(",")
50+
.join(", ")
5151
)?;
5252
}
5353
Ok(())
@@ -75,8 +75,8 @@ impl Display for Render<'_, Path> {
7575
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
7676
match self.0 {
7777
Path::Code(module_id) => write!(f, "{}", Render(module_id)),
78-
Path::Resource(struct_ty) => write!(f, "{}", struct_ty),
79-
Path::ResourceGroup(struct_ty) => write!(f, "{}", struct_ty),
78+
Path::Resource(struct_ty) => write!(f, "{}", struct_ty.to_canonical_string()),
79+
Path::ResourceGroup(struct_ty) => write!(f, "{}", struct_ty.to_canonical_string()),
8080
}
8181
}
8282
}
@@ -130,6 +130,6 @@ impl Display for Render<'_, WriteOpType> {
130130

131131
impl Display for Render<'_, TypeTag> {
132132
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
133-
write!(f, "{}", self.0)
133+
write!(f, "{}", self.0.to_canonical_string())
134134
}
135135
}

aptos-move/aptos-gas-profiling/src/report.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ impl TransactionGasLog {
285285
.iter()
286286
.map(|event| {
287287
json!({
288-
"name": format!("{}", event.ty),
288+
"name": format!("{}", event.ty.to_canonical_string()),
289289
"cost": fmt_storage_fee(event.cost),
290290
"cost-percentage": fmt_storage_fee_percentage(event.cost),
291291
})

aptos-move/aptos-sdk-builder/src/common.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ use std::{
1818
pub(crate) fn type_not_allowed(type_tag: &TypeTag) -> ! {
1919
panic!(
2020
"Transaction scripts cannot take arguments of type {}.",
21-
type_tag
21+
type_tag.to_canonical_string()
2222
);
2323
}
2424

25-
/// Clean up doc comments extracter by the Move prover.
25+
/// Clean up doc comments extracted by the Move prover.
2626
pub(crate) fn prepare_doc_string(doc: &str) -> String {
2727
doc.replace("\n ", "\n").trim().to_string()
2828
}

0 commit comments

Comments
 (0)