fe_codegen/yul/legalize/
signature.rs

1use fe_mir::ir::{FunctionSignature, TypeKind};
2
3use crate::db::CodegenDb;
4
5pub fn legalize_func_signature(db: &dyn CodegenDb, sig: &mut FunctionSignature) {
6    // Remove param if the type is contract or zero-sized.
7    let params = &mut sig.params;
8    params.retain(|param| match param.ty.data(db.upcast()).kind {
9        TypeKind::Contract(_) => false,
10        _ => !param.ty.deref(db.upcast()).is_zero_sized(db.upcast()),
11    });
12
13    // Legalize param types.
14    for param in params.iter_mut() {
15        param.ty = db.codegen_legalized_type(param.ty);
16    }
17
18    if let Some(ret_ty) = sig.return_type {
19        // Remove return type  if the type is contract or zero-sized.
20        if ret_ty.is_contract(db.upcast()) || ret_ty.deref(db.upcast()).is_zero_sized(db.upcast()) {
21            sig.return_type = None;
22        } else {
23            // Legalize param types.
24            sig.return_type = Some(db.codegen_legalized_type(ret_ty));
25        }
26    }
27}