diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2022-08-19 21:06:50 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-19 21:06:50 +0000 |
commit | 0f4ec11e8c2399ca20f80b4006e294794f9b2e0f (patch) | |
tree | 9631c8dd4a6aeaa85ed2248faae9af02ba370023 /gcc/rust/backend | |
parent | abfd358d756b409ce657761d320b04b9383cbfd8 (diff) | |
parent | fdbf789c2bb93baebd449744309d7c42bf2b36b8 (diff) | |
download | gcc-0f4ec11e8c2399ca20f80b4006e294794f9b2e0f.zip gcc-0f4ec11e8c2399ca20f80b4006e294794f9b2e0f.tar.gz gcc-0f4ec11e8c2399ca20f80b4006e294794f9b2e0f.tar.bz2 |
Merge #1492
1492: Redo coercion site code r=philberty a=philberty
This gets rid of the old visitor method and brings us much closer to the
Rustc rules which from the algo mentioned in the comment's do the checks
in a very specific order which we need to match.
Co-authored-by: Philip Herron <philip.herron@embecosm.com>
Diffstat (limited to 'gcc/rust/backend')
-rw-r--r-- | gcc/rust/backend/rust-compile-base.h | 7 | ||||
-rw-r--r-- | gcc/rust/backend/rust-compile-expr.cc | 40 | ||||
-rw-r--r-- | gcc/rust/backend/rust-compile.cc | 10 |
3 files changed, 47 insertions, 10 deletions
diff --git a/gcc/rust/backend/rust-compile-base.h b/gcc/rust/backend/rust-compile-base.h index 5a0ac8f..4c20933 100644 --- a/gcc/rust/backend/rust-compile-base.h +++ b/gcc/rust/backend/rust-compile-base.h @@ -48,7 +48,6 @@ protected: Location rvalue_locus); tree coerce_to_dyn_object (tree compiled_ref, const TyTy::BaseType *actual, - const TyTy::BaseType *expected, const TyTy::DynamicObjectType *ty, Location locus); tree compute_address_for_trait_item ( @@ -78,6 +77,12 @@ protected: tree resolve_unsized_adjustment (Resolver::Adjustment &adjustment, tree expression, Location locus); + tree resolve_unsized_slice_adjustment (Resolver::Adjustment &adjustment, + tree expression, Location locus); + + tree resolve_unsized_dyn_adjustment (Resolver::Adjustment &adjustment, + tree expression, Location locus); + static void setup_fndecl (tree fndecl, bool is_main_entry_point, bool is_generic_fn, HIR::Visibility &visibility, const HIR::FunctionQualifiers &qualifiers, diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc index 9a8b779..412ca09 100644 --- a/gcc/rust/backend/rust-compile-expr.cc +++ b/gcc/rust/backend/rust-compile-expr.cc @@ -2514,6 +2514,27 @@ tree HIRCompileBase::resolve_unsized_adjustment (Resolver::Adjustment &adjustment, tree expression, Location locus) { + bool expect_slice + = adjustment.get_expected ()->get_kind () == TyTy::TypeKind::SLICE; + bool expect_dyn + = adjustment.get_expected ()->get_kind () == TyTy::TypeKind::DYNAMIC; + + // assumes this is an array + tree expr_type = TREE_TYPE (expression); + if (expect_slice) + { + rust_assert (TREE_CODE (expr_type) == ARRAY_TYPE); + return resolve_unsized_slice_adjustment (adjustment, expression, locus); + } + + rust_assert (expect_dyn); + return resolve_unsized_dyn_adjustment (adjustment, expression, locus); +} + +tree +HIRCompileBase::resolve_unsized_slice_adjustment ( + Resolver::Adjustment &adjustment, tree expression, Location locus) +{ // assumes this is an array tree expr_type = TREE_TYPE (expression); rust_assert (TREE_CODE (expr_type) == ARRAY_TYPE); @@ -2542,6 +2563,25 @@ HIRCompileBase::resolve_unsized_adjustment (Resolver::Adjustment &adjustment, {data, size}, -1, locus); } +tree +HIRCompileBase::resolve_unsized_dyn_adjustment ( + Resolver::Adjustment &adjustment, tree expression, Location locus) +{ + tree rvalue = expression; + Location rvalue_locus = locus; + + const TyTy::BaseType *actual = adjustment.get_actual (); + const TyTy::BaseType *expected = adjustment.get_expected (); + + const TyTy::DynamicObjectType *dyn + = static_cast<const TyTy::DynamicObjectType *> (expected); + + rust_debug ("resolve_unsized_dyn_adjustment actual={%s} dyn={%s}", + actual->debug_str ().c_str (), dyn->debug_str ().c_str ()); + + return coerce_to_dyn_object (rvalue, actual, dyn, rvalue_locus); +} + void CompileExpr::visit (HIR::RangeFromToExpr &expr) { diff --git a/gcc/rust/backend/rust-compile.cc b/gcc/rust/backend/rust-compile.cc index 6913144..0ccb98d 100644 --- a/gcc/rust/backend/rust-compile.cc +++ b/gcc/rust/backend/rust-compile.cc @@ -161,13 +161,6 @@ HIRCompileBase::coercion_site1 (tree rvalue, const TyTy::BaseType *rval, lvalue_locus, rvalue_locus)) return error_mark_node; } - else if (expected->get_kind () == TyTy::TypeKind::DYNAMIC - && actual->get_kind () != TyTy::TypeKind::DYNAMIC) - { - const TyTy::DynamicObjectType *dyn - = static_cast<const TyTy::DynamicObjectType *> (expected); - return coerce_to_dyn_object (rvalue, actual, expected, dyn, rvalue_locus); - } else if (expected->get_kind () == TyTy::TypeKind::SLICE) { // bad coercion @@ -182,7 +175,7 @@ HIRCompileBase::coercion_site1 (tree rvalue, const TyTy::BaseType *rval, // return an unsized coercion Resolver::Adjustment unsize_adj ( - Resolver::Adjustment::AdjustmentType::UNSIZE, expected); + Resolver::Adjustment::AdjustmentType::UNSIZE, actual, expected); return resolve_unsized_adjustment (unsize_adj, rvalue, rvalue_locus); } @@ -192,7 +185,6 @@ HIRCompileBase::coercion_site1 (tree rvalue, const TyTy::BaseType *rval, tree HIRCompileBase::coerce_to_dyn_object (tree compiled_ref, const TyTy::BaseType *actual, - const TyTy::BaseType *expected, const TyTy::DynamicObjectType *ty, Location locus) { |