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/rust-compile-expr.cc | |
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/rust-compile-expr.cc')
-rw-r--r-- | gcc/rust/backend/rust-compile-expr.cc | 40 |
1 files changed, 40 insertions, 0 deletions
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) { |