bool is_unsafe () const { return unsafety == Unsafety::Unsafe; }
bool is_async () const { return async_status == Async::Yes; }
+ Unsafety get_unsafety () const { return unsafety; }
ABI get_abi () const { return abi; }
};
params.emplace_back (ptype->get_ref ());
}
- translated = new TyTy::FnPtr (fntype.get_mappings ().get_hirid (),
- fntype.get_locus (), std::move (params),
- TyTy::TyVar (return_type->get_ref ()));
+ translated
+ = new TyTy::FnPtr (fntype.get_mappings ().get_hirid (), fntype.get_locus (),
+ std::move (params),
+ TyTy::TyVar (return_type->get_ref ()),
+ fntype.get_function_qualifiers ().get_abi (),
+ fntype.get_function_qualifiers ().get_unsafety ());
}
void
TyVar retty = fn->get_var_return_type ().monomorphized_clone ();
return new FnPtr (fn->get_ref (), fn->get_ty_ref (), ident.locus,
- std::move (cloned_params), retty,
- fn->get_combined_refs ());
+ std::move (cloned_params), retty, fn->get_abi (),
+ fn->get_unsafety (), fn->get_combined_refs ());
}
else if (auto adt = x->try_as<const ADTType> ())
{
params_str += p.get_tyty ()->as_string () + " ,";
}
- return "fnptr (" + params_str + ") -> " + get_return_type ()->as_string ();
+ std::string unsafety = "";
+ if (get_unsafety () == Unsafety::Unsafe)
+ unsafety = "unsafe ";
+
+ std::string abi = get_string_from_abi (get_abi ());
+ return unsafety + "abi:" + abi + " " + "fnptr (" + params_str + ") -> "
+ + get_return_type ()->as_string ();
}
bool
cloned_params.emplace_back (p.get_ref ());
return new FnPtr (get_ref (), get_ty_ref (), ident.locus,
- std::move (cloned_params), result_type,
- get_combined_refs ());
+ std::move (cloned_params), result_type, get_abi (),
+ get_unsafety (), get_combined_refs ());
}
void
static constexpr auto KIND = TypeKind::FNPTR;
FnPtr (HirId ref, location_t locus, std::vector<TyVar> params,
- TyVar result_type, std::set<HirId> refs = std::set<HirId> ())
+ TyVar result_type, ABI abi, Unsafety unsafety,
+ std::set<HirId> refs = std::set<HirId> ())
: CallableTypeInterface (ref, ref, TypeKind::FNPTR,
{Resolver::CanonicalPath::create_empty (), locus},
refs),
- params (std::move (params)), result_type (result_type)
+ params (std::move (params)), result_type (result_type), abi (abi),
+ unsafety (unsafety)
{}
FnPtr (HirId ref, HirId ty_ref, location_t locus, std::vector<TyVar> params,
- TyVar result_type, std::set<HirId> refs = std::set<HirId> ())
+ TyVar result_type, ABI abi, Unsafety unsafety,
+ std::set<HirId> refs = std::set<HirId> ())
: CallableTypeInterface (ref, ty_ref, TypeKind::FNPTR,
{Resolver::CanonicalPath::create_empty (), locus},
refs),
- params (params), result_type (result_type)
+ params (params), result_type (result_type), abi (abi), unsafety (unsafety)
{}
std::string get_name () const override final { return as_string (); }
std::vector<TyVar> &get_params () { return params; }
const std::vector<TyVar> &get_params () const { return params; }
+ ABI get_abi () const { return abi; }
+
+ Unsafety get_unsafety () const { return unsafety; }
+
private:
std::vector<TyVar> params;
TyVar result_type;
+ ABI abi;
+ Unsafety unsafety;
};
class ClosureType : public CallableTypeInterface, public SubstitutionRef
return unify_error_type_node ();
}
+ if (ltype->get_abi () != type.get_abi ())
+ {
+ return unify_error_type_node ();
+ }
+
+ if (ltype->get_unsafety () != type.get_unsafety ())
+ {
+ return unify_error_type_node ();
+ }
+
return ltype;
}
break;
}
}
+ // FIXME
+ //
+ // there is a bug in:
+ // testsuite/rust/compile/try-catch-unwind-{new,old}.rs I think the test
+ //
+ // case is wrong because it should be taking an FnOnce which probably
+ // didnt exist at the time in gccrs
+ //
+ // if (ltype->get_abi () != type.get_abi ())
+ // {
+ // return unify_error_type_node ();
+ // }
+
+ // FIXME fntype needs to track unsafe or not
+ // if (ltype->get_unsafety () != type.get_unsafety ())
+ // {
+ // return unify_error_type_node ();
+ // }
+
return ltype;
}
break;