diff options
author | Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com> | 2024-03-08 14:42:10 +0100 |
---|---|---|
committer | P-E-P <32375388+P-E-P@users.noreply.github.com> | 2024-11-20 13:36:42 +0000 |
commit | 6b5039f20e8827549e7946a280a80bb5db0b10ce (patch) | |
tree | 56a66151171d975efcd9439ad0fa4175417986cc /gcc/rust/backend | |
parent | 2d6d91a776ebd26d3bad128cfec00a60540a659b (diff) | |
download | gcc-6b5039f20e8827549e7946a280a80bb5db0b10ce.zip gcc-6b5039f20e8827549e7946a280a80bb5db0b10ce.tar.gz gcc-6b5039f20e8827549e7946a280a80bb5db0b10ce.tar.bz2 |
Refactor HIR with optionals, references & newtypes
The HIR made heavy use of pair and other unamed types which can be
difficult to read.
gcc/rust/ChangeLog:
* backend/rust-compile-base.cc: Use FnParam getter.
* backend/rust-compile-expr.cc (CompileExpr::visit): Likewise.
* backend/rust-compile-intrinsic.cc: Likewise.
* backend/rust-compile-type.cc: Likewise.
* checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::visit):
Only visit childrens if not missing.
* checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): Use
a reference instead of a raw pointer.
* hir/tree/rust-hir-expr.h: Add presence function for return
expression.
* hir/tree/rust-hir-item.h: Remove take_param_name.
* hir/tree/rust-hir.h: Make mapping getter const.
* typecheck/rust-hir-dot-operator.cc (MethodResolver::Select): Use
getter.
* typecheck/rust-hir-type-check-expr.cc: Likewise.
* typecheck/rust-hir-type-check-implitem.cc: Use FnParam vector instead
of std::pair of Pattern and BaseType.
* typecheck/rust-hir-type-check-item.cc: Likewise.
* typecheck/rust-hir-type-check.cc: Likewise.
* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): Use getters.
(TypeCheckMethodCallExpr::check): Likewise.
* typecheck/rust-tyty-cmp.h: Likewise.
* typecheck/rust-tyty.cc: Use FnParam.
* typecheck/rust-tyty.h (class FnParam): Add FnParam to handle function
parameters instead of handling std::pairs.
* typecheck/rust-unify.cc (UnifyRules::expect_fndef): Use getters.
(UnifyRules::expect_fnptr): Likewise.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Diffstat (limited to 'gcc/rust/backend')
-rw-r--r-- | gcc/rust/backend/rust-compile-base.cc | 2 | ||||
-rw-r--r-- | gcc/rust/backend/rust-compile-expr.cc | 4 | ||||
-rw-r--r-- | gcc/rust/backend/rust-compile-intrinsic.cc | 17 | ||||
-rw-r--r-- | gcc/rust/backend/rust-compile-type.cc | 4 |
4 files changed, 14 insertions, 13 deletions
diff --git a/gcc/rust/backend/rust-compile-base.cc b/gcc/rust/backend/rust-compile-base.cc index 966ff52..d272374 100644 --- a/gcc/rust/backend/rust-compile-base.cc +++ b/gcc/rust/backend/rust-compile-base.cc @@ -711,7 +711,7 @@ HIRCompileBase::compile_function ( for (auto &referenced_param : function_params) { auto &tyty_param = fntype->param_at (i++); - auto param_tyty = tyty_param.second; + auto param_tyty = tyty_param.get_type (); auto compiled_param_type = TyTyResolveCompile::compile (ctx, param_tyty); location_t param_locus = referenced_param.get_locus (); diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc index 7d41f63..35a6f704 100644 --- a/gcc/rust/backend/rust-compile-expr.cc +++ b/gcc/rust/backend/rust-compile-expr.cc @@ -1267,7 +1267,7 @@ CompileExpr::visit (HIR::CallExpr &expr) const TyTy::FnType *fn = static_cast<const TyTy::FnType *> (base); auto ¶m = fn->param_at (index); - *result = param.second; + *result = param.get_type (); return true; }; @@ -1401,7 +1401,7 @@ CompileExpr::visit (HIR::MethodCallExpr &expr) // assignments are coercion sites so lets convert the rvalue if // necessary, offset from the already adjusted implicit self bool ok; - TyTy::BaseType *expected = fntype->param_at (i + 1).second; + TyTy::BaseType *expected = fntype->param_at (i + 1).get_type (); TyTy::BaseType *actual = nullptr; ok = ctx->get_tyctx ()->lookup_type ( diff --git a/gcc/rust/backend/rust-compile-intrinsic.cc b/gcc/rust/backend/rust-compile-intrinsic.cc index 0ffc363..08b64439 100644 --- a/gcc/rust/backend/rust-compile-intrinsic.cc +++ b/gcc/rust/backend/rust-compile-intrinsic.cc @@ -315,13 +315,13 @@ compile_fn_params (Context *ctx, TyTy::FnType *fntype, tree fndecl, { for (auto &parm : fntype->get_params ()) { - auto &referenced_param = parm.first; - auto ¶m_tyty = parm.second; + auto &referenced_param = parm.get_pattern (); + auto param_tyty = parm.get_type (); auto compiled_param_type = TyTyResolveCompile::compile (ctx, param_tyty); - location_t param_locus = referenced_param->get_locus (); + location_t param_locus = referenced_param.get_locus (); Bvariable *compiled_param_var - = CompileFnParam::compile (ctx, fndecl, *referenced_param, + = CompileFnParam::compile (ctx, fndecl, referenced_param, compiled_param_type, param_locus); compiled_param_variables->push_back (compiled_param_var); @@ -496,9 +496,10 @@ transmute_handler (Context *ctx, TyTy::FnType *fntype) rust_error_at (fntype->get_locus (), "cannot transmute between types of different sizes, or " "dependently-sized types"); - rust_inform (fntype->get_ident ().locus, "source type: %qs (%lu bits)", - fntype->get_params ().at (0).second->as_string ().c_str (), - (unsigned long) source_size); + rust_inform ( + fntype->get_ident ().locus, "source type: %qs (%lu bits)", + fntype->get_params ().at (0).get_type ()->as_string ().c_str (), + (unsigned long) source_size); rust_inform (fntype->get_ident ().locus, "target type: %qs (%lu bits)", fntype->get_return_type ()->as_string ().c_str (), (unsigned long) target_size); @@ -1226,7 +1227,7 @@ assume_handler (Context *ctx, TyTy::FnType *fntype) // TODO: make sure this is actually helping the compiler optimize rust_assert (fntype->get_params ().size () == 1); - rust_assert (fntype->param_at (0).second->get_kind () + rust_assert (fntype->param_at (0).get_type ()->get_kind () == TyTy::TypeKind::BOOL); tree lookup = NULL_TREE; diff --git a/gcc/rust/backend/rust-compile-type.cc b/gcc/rust/backend/rust-compile-type.cc index e013352..c6d249e 100644 --- a/gcc/rust/backend/rust-compile-type.cc +++ b/gcc/rust/backend/rust-compile-type.cc @@ -208,12 +208,12 @@ TyTyResolveCompile::visit (const TyTy::FnType &type) for (auto ¶m_pair : type.get_params ()) { - auto param_tyty = param_pair.second; + auto param_tyty = param_pair.get_type (); auto compiled_param_type = TyTyResolveCompile::compile (ctx, param_tyty, trait_object_mode); auto compiled_param = Backend::typed_identifier ( - param_pair.first->as_string (), compiled_param_type, + param_pair.get_pattern ().as_string (), compiled_param_type, ctx->get_mappings ().lookup_location (param_tyty->get_ref ())); parameters.push_back (compiled_param); |