Skip to content
Draft
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
80 changes: 70 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ sway-ir-macros = { path = "sway-ir/sway-ir-macros", version = "0.69.1" }
#

# Dependencies from the `fuel-abi-types` repository:
fuel-abi-types = "0.12"
fuel-abi-types = "0.15"

# Dependencies from the `fuel-core` repository:
#
Expand Down
10 changes: 5 additions & 5 deletions sway-core/src/abi_generation/abi_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ impl TypeId {
| (TypeInfo::Custom { .. }, TypeInfo::Enum { .. }) => type_engine
.get(resolved_type_id)
.abi_str(handler, ctx, engines, true),
(_, TypeInfo::Alias { ty, .. }) => {
ty.type_id()
.get_abi_type_str(handler, ctx, engines, ty.type_id())
}
(_, TypeInfo::Alias { .. }) => Ok(self_abi_str),
(TypeInfo::Tuple(fields), TypeInfo::Tuple(resolved_fields)) => {
assert_eq!(fields.len(), resolved_fields.len());
let field_strs = resolved_fields
Expand Down Expand Up @@ -200,7 +197,10 @@ impl TypeInfo {
"__slice {}",
ty.abi_str(handler, ctx, engines, false)?
)),
Alias { ty, .. } => Ok(ty.abi_str(handler, ctx, engines, false)?),
Alias { .. } => {
// Aliases are handled specially when processing the ABI, so we should never get here.
unreachable!()
}
TraitType {
name,
trait_type_id: _,
Expand Down
40 changes: 25 additions & 15 deletions sway-core/src/abi_generation/fuel_abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ pub fn generate_program_abi(
messages_types: Some(messages_types),
configurables: Some(configurables),
error_codes: Some(error_codes),
panicking_calls: None,
})
}
TyProgramKind::Script { main_function, .. } => {
Expand Down Expand Up @@ -363,6 +364,7 @@ pub fn generate_program_abi(
messages_types: Some(messages_types),
configurables: Some(configurables),
error_codes: Some(error_codes),
panicking_calls: None,
})
}
TyProgramKind::Predicate { main_function, .. } => {
Expand Down Expand Up @@ -392,6 +394,7 @@ pub fn generate_program_abi(
messages_types: Some(messages_types),
configurables: Some(configurables),
error_codes: Some(error_codes),
panicking_calls: None,
})
}
TyProgramKind::Library { .. } => {
Expand All @@ -411,6 +414,7 @@ pub fn generate_program_abi(
messages_types: Some(messages_types),
configurables: None,
error_codes: Some(error_codes),
panicking_calls: None,
})
}
})?;
Expand Down Expand Up @@ -649,11 +653,31 @@ fn generate_concrete_type_declaration(

let (type_field, concrete_type_id) =
type_id.get_abi_type_field_and_concrete_id(handler, ctx, engines, resolved_type_id)?;

let type_engine = engines.te();
let alias_of = match &*type_engine.get(resolved_type_id) {
TypeInfo::Alias { ty, .. } => {
// Ensure the underlying representation has a declaration first
let target_ctid = generate_concrete_type_declaration(
handler,
ctx,
engines,
metadata_types,
concrete_types,
ty.initial_type_id(),
ty.type_id(),
)?;
Some(target_ctid)
}
_ => None,
};

let concrete_type_decl = TypeConcreteDeclaration {
type_field,
concrete_type_id: concrete_type_id.clone(),
metadata_type_id,
type_arguments,
alias_of,
};

concrete_types.push(concrete_type_decl);
Expand Down Expand Up @@ -814,6 +838,7 @@ fn generate_error_codes(panic_occurrences: &PanicOccurrences) -> BTreeMap<u64, E
*revert_code,
ErrorDetails {
pos: ErrorPosition {
function: String::default(),
pkg: panic_occurrence.loc.pkg.clone(),
file: panic_occurrence.loc.file.clone(),
line: panic_occurrence.loc.loc.line as u64,
Expand Down Expand Up @@ -1150,21 +1175,6 @@ impl TypeId {
None
}
}
TypeInfo::Alias { .. } => {
if let TypeInfo::Alias { ty, .. } = &*type_engine.get(resolved_type_id) {
ty.initial_type_id().get_abi_type_components(
handler,
ctx,
engines,
metadata_types,
concrete_types,
ty.type_id(),
metadata_types_to_add,
)?
} else {
None
}
}
TypeInfo::UnknownGeneric { .. } => {
// avoid infinite recursion
if *self == resolved_type_id {
Expand Down
8 changes: 1 addition & 7 deletions sway-core/src/type_system/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,7 @@ impl TypeId {
},
TypeInfo::Struct(decl_ref),
) => call_path.call_path.suffix != decl_engine.get_struct(decl_ref).call_path.suffix,
(
TypeInfo::Custom {
qualified_call_path: call_path,
..
},
TypeInfo::Alias { name, .. },
) => call_path.call_path.suffix != name.clone(),
(TypeInfo::Custom { .. }, TypeInfo::Alias { .. }) => false,
(TypeInfo::Custom { .. }, _) => true,
_ => false,
}
Expand Down
Loading