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

Small code refactor #6263

Merged
merged 5 commits into from
Jul 13, 2024
Merged
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
31 changes: 11 additions & 20 deletions sway-core/src/abi_generation/abi_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,17 @@ impl TypeId {
resolved_type_id: TypeId,
) -> String {
let type_engine = engines.te();
let self_abi_str = type_engine.get(*self).abi_str(ctx, engines);
if self.is_generic_parameter(engines, resolved_type_id) {
format!("generic {}", type_engine.get(*self).abi_str(ctx, engines))
format!("generic {}", self_abi_str)
} else {
match (
&*type_engine.get(*self),
&*type_engine.get(resolved_type_id),
) {
(TypeInfo::Custom { .. }, TypeInfo::Struct { .. }) => {
type_engine.get(resolved_type_id).abi_str(ctx, engines)
}
(TypeInfo::Custom { .. }, TypeInfo::Enum { .. }) => {
type_engine.get(resolved_type_id).abi_str(ctx, engines)
}
(TypeInfo::Custom { .. }, TypeInfo::Alias { .. }) => {
(TypeInfo::Custom { .. }, TypeInfo::Struct { .. })
| (TypeInfo::Custom { .. }, TypeInfo::Enum { .. })
| (TypeInfo::Custom { .. }, TypeInfo::Alias { .. }) => {
type_engine.get(resolved_type_id).abi_str(ctx, engines)
}
(TypeInfo::Tuple(fields), TypeInfo::Tuple(resolved_fields)) => {
Expand All @@ -57,7 +54,7 @@ impl TypeId {
format!("[{}; {}]", inner_type, count.val())
}
(TypeInfo::Custom { .. }, _) => {
format!("generic {}", type_engine.get(*self).abi_str(ctx, engines))
format!("generic {}", self_abi_str)
}
_ => type_engine.get(resolved_type_id).abi_str(ctx, engines),
}
Expand Down Expand Up @@ -185,19 +182,13 @@ fn call_path_display(ctx: &AbiStrContext, call_path: &CallPath) -> String {
return call_path.suffix.as_str().to_string();
}
let mut buf = String::new();
let root_name = ctx.program_name.as_deref();
for (index, prefix) in call_path.prefixes.iter().enumerate() {
let mut skip_prefix = false;
if index == 0 {
if let Some(root_name) = &ctx.program_name {
if prefix.as_str() == root_name.as_str() {
skip_prefix = true;
}
}
}
if !skip_prefix {
buf.push_str(prefix.as_str());
buf.push_str("::");
if index == 0 && Some(prefix.as_str()) == root_name {
continue;
}
buf.push_str(prefix.as_str());
buf.push_str("::");
}
buf.push_str(&call_path.suffix.to_string());

Expand Down
Loading