Skip to content

Commit 28881f2

Browse files
committed
Add experimental ABI alias metadata support.
1 parent 380c640 commit 28881f2

File tree

30 files changed

+1556
-64
lines changed

30 files changed

+1556
-64
lines changed

forc-pkg/src/pkg.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1811,6 +1811,7 @@ pub fn compile(
18111811
abi_with_callpaths: true,
18121812
type_ids_to_full_type_str: HashMap::<String, String>::new(),
18131813
unique_names: HashMap::new(),
1814+
experimental,
18141815
},
18151816
engines,
18161817
if experimental.new_encoding {

sway-core/src/abi_generation/abi_str.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pub struct AbiStrContext {
1111
pub abi_with_callpaths: bool,
1212
pub abi_with_fully_specified_types: bool,
1313
pub abi_root_type_without_generic_type_parameters: bool,
14+
pub abi_type_aliases: bool,
1415
}
1516

1617
impl TypeId {
@@ -26,7 +27,7 @@ impl TypeId {
2627
let self_abi_str = type_engine
2728
.get(*self)
2829
.abi_str(handler, ctx, engines, true)?;
29-
if self.is_generic_parameter(engines, resolved_type_id) {
30+
if self.is_generic_parameter(engines, resolved_type_id, ctx.abi_type_aliases) {
3031
Ok(format!("generic {self_abi_str}"))
3132
} else {
3233
match (
@@ -37,9 +38,10 @@ impl TypeId {
3738
| (TypeInfo::Custom { .. }, TypeInfo::Enum { .. }) => type_engine
3839
.get(resolved_type_id)
3940
.abi_str(handler, ctx, engines, true),
40-
(_, TypeInfo::Alias { ty, .. }) => ty
41+
(_, TypeInfo::Alias { ty, .. }) if !ctx.abi_type_aliases => ty
4142
.type_id
4243
.get_abi_type_str(handler, ctx, engines, ty.type_id),
44+
(_, TypeInfo::Alias { .. }) => Ok(self_abi_str),
4345
(TypeInfo::Tuple(fields), TypeInfo::Tuple(resolved_fields)) => {
4446
assert_eq!(fields.len(), resolved_fields.len());
4547
let field_strs = resolved_fields
@@ -204,7 +206,13 @@ impl TypeInfo {
204206
"__slice {}",
205207
ty.abi_str(handler, ctx, engines, false)?
206208
)),
207-
Alias { ty, .. } => Ok(ty.abi_str(handler, ctx, engines, false)?),
209+
Alias { name, ty } => {
210+
if ctx.abi_type_aliases {
211+
Ok(name.to_string())
212+
} else {
213+
ty.abi_str(handler, ctx, engines, false)
214+
}
215+
}
208216
TraitType {
209217
name,
210218
implemented_in: _,

sway-core/src/abi_generation/evm_abi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub fn generate_abi_program(program: &TyProgram, engines: &Engines) -> EvmAbiRes
2525
/// Gives back a string that represents the type, considering what it resolves to
2626
fn get_type_str(type_id: &TypeId, engines: &Engines, resolved_type_id: TypeId) -> String {
2727
let type_engine = engines.te();
28-
if type_id.is_generic_parameter(engines, resolved_type_id) {
28+
if type_id.is_generic_parameter(engines, resolved_type_id, false) {
2929
format!("generic {}", abi_str(&type_engine.get(*type_id), engines))
3030
} else {
3131
match (

0 commit comments

Comments
 (0)