From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7905) id C60D638582A5; Tue, 16 Jan 2024 18:05:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C60D638582A5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1705428309; bh=HINNlr4lv7uC+lIQ042XArAAsO9tdAe+tIuEwNpIeKA=; h=From:To:Subject:Date:From; b=E/NH4fHU+G3zmTxOGo5fzCFA1lzq1oiLlAnRVMHe4fZZ11LCh4571CUgQJuzJgfIZ gL2GDNGuJveZpDAZY1E8+31PWm3GJrFQep5nmGquooLI5xp7qLws/qF6UztfH+K248 0sI/uRFdAtBTUOSIVJDza8EImJCGwr8IEtXAAnI0= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Arthur Cohen To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-7864] gccrs: Track polarity in type bound predicate X-Act-Checkin: gcc X-Git-Author: Philip Herron X-Git-Refname: refs/heads/trunk X-Git-Oldrev: c533a11ae05bae53e4421810f7108aac697ded4e X-Git-Newrev: f84d52a5173c1b432ad07294bc643dc5e8d53bdf Message-Id: <20240116180509.C60D638582A5@sourceware.org> Date: Tue, 16 Jan 2024 18:05:09 +0000 (GMT) List-Id: https://gcc.gnu.org/g:f84d52a5173c1b432ad07294bc643dc5e8d53bdf commit r14-7864-gf84d52a5173c1b432ad07294bc643dc5e8d53bdf Author: Philip Herron Date: Tue Jul 18 16:07:32 2023 +0100 gccrs: Track polarity in type bound predicate Addresses #2443 gcc/rust/ChangeLog: * typecheck/rust-hir-path-probe.cc: track regular polarity * typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_trait): likewise * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): likewise * typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): likewise * typecheck/rust-tyty-bounds.cc (TypeCheckBase::get_predicate_from_bound): likewise (TypeBoundPredicate::TypeBoundPredicate): update ctor (TypeBoundPredicate::operator=): update copy assignment ctor (TypeBoundPredicate::error): update error node * typecheck/rust-tyty.h: add polarity field to predicate Signed-off-by: Philip Herron Diff: --- gcc/rust/typecheck/rust-hir-path-probe.cc | 3 ++- gcc/rust/typecheck/rust-hir-trait-resolve.cc | 1 + gcc/rust/typecheck/rust-hir-type-check-expr.cc | 3 ++- gcc/rust/typecheck/rust-hir-type-check-item.cc | 3 ++- gcc/rust/typecheck/rust-tyty-bounds.cc | 19 ++++++++++++------- gcc/rust/typecheck/rust-tyty.h | 7 +++++-- 6 files changed, 24 insertions(+), 12 deletions(-) diff --git a/gcc/rust/typecheck/rust-hir-path-probe.cc b/gcc/rust/typecheck/rust-hir-path-probe.cc index 2b40f5dd617..85cdc0408a4 100644 --- a/gcc/rust/typecheck/rust-hir-path-probe.cc +++ b/gcc/rust/typecheck/rust-hir-path-probe.cc @@ -344,7 +344,8 @@ PathProbeType::process_associated_trait_for_candidates ( break; } - const TyTy::TypeBoundPredicate p (*trait_ref, UNDEF_LOCATION); + const TyTy::TypeBoundPredicate p (*trait_ref, BoundPolarity::RegularBound, + UNDEF_LOCATION); TyTy::TypeBoundPredicateItem item (&p, trait_item_ref); TyTy::BaseType *trait_item_tyty = item.get_raw_item ()->get_tyty (); diff --git a/gcc/rust/typecheck/rust-hir-trait-resolve.cc b/gcc/rust/typecheck/rust-hir-trait-resolve.cc index 97fec48909a..f2dd191a04a 100644 --- a/gcc/rust/typecheck/rust-hir-trait-resolve.cc +++ b/gcc/rust/typecheck/rust-hir-trait-resolve.cc @@ -214,6 +214,7 @@ TraitResolver::resolve_trait (HIR::Trait *trait_reference) auto self_hrtb = TyTy::TypeBoundPredicate (trait_reference->get_mappings ().get_defid (), std::move (self_subst_copy), + BoundPolarity::RegularBound, trait_reference->get_locus ()); specified_bounds.push_back (self_hrtb); diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc b/gcc/rust/typecheck/rust-hir-type-check-expr.cc index 7a7b3ac7314..b7538abe5db 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-expr.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-expr.cc @@ -1558,7 +1558,8 @@ TypeCheckExpr::visit (HIR::ClosureExpr &expr) TraitReference *trait = TraitResolver::Resolve (*trait_item); rust_assert (!trait->is_error ()); - TyTy::TypeBoundPredicate predicate (*trait, expr.get_locus ()); + TyTy::TypeBoundPredicate predicate (*trait, BoundPolarity::RegularBound, + expr.get_locus ()); // resolve the trait bound where the <(Args)> are the parameter tuple type HIR::GenericArgs args = HIR::GenericArgs::create_empty (expr.get_locus ()); diff --git a/gcc/rust/typecheck/rust-hir-type-check-item.cc b/gcc/rust/typecheck/rust-hir-type-check-item.cc index b329ac13179..1290065f7c7 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-item.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-item.cc @@ -528,7 +528,8 @@ TypeCheckItem::visit (HIR::Trait &trait) RustIdent ident{CanonicalPath::create_empty (), trait.get_locus ()}; infered = new TyTy::DynamicObjectType ( trait.get_mappings ().get_hirid (), ident, - {TyTy::TypeBoundPredicate (*trait_ref, trait.get_locus ())}); + {TyTy::TypeBoundPredicate (*trait_ref, BoundPolarity::RegularBound, + trait.get_locus ())}); } void diff --git a/gcc/rust/typecheck/rust-tyty-bounds.cc b/gcc/rust/typecheck/rust-tyty-bounds.cc index 805028f147a..5947c217707 100644 --- a/gcc/rust/typecheck/rust-tyty-bounds.cc +++ b/gcc/rust/typecheck/rust-tyty-bounds.cc @@ -184,7 +184,8 @@ TypeCheckBase::get_predicate_from_bound (HIR::TypePath &type_path, if (trait->is_error ()) return TyTy::TypeBoundPredicate::error (); - TyTy::TypeBoundPredicate predicate (*trait, type_path.get_locus ()); + TyTy::TypeBoundPredicate predicate (*trait, BoundPolarity::RegularBound, + type_path.get_locus ()); HIR::GenericArgs args = HIR::GenericArgs::create_empty (type_path.get_locus ()); @@ -290,10 +291,11 @@ TypeCheckBase::get_predicate_from_bound (HIR::TypePath &type_path, namespace TyTy { TypeBoundPredicate::TypeBoundPredicate ( - const Resolver::TraitReference &trait_reference, location_t locus) + const Resolver::TraitReference &trait_reference, BoundPolarity polarity, + location_t locus) : SubstitutionRef ({}, SubstitutionArgumentMappings::empty ()), reference (trait_reference.get_mappings ().get_defid ()), locus (locus), - error_flag (false) + error_flag (false), polarity (polarity) { substitutions.clear (); for (const auto &p : trait_reference.get_trait_substs ()) @@ -306,9 +308,10 @@ TypeBoundPredicate::TypeBoundPredicate ( TypeBoundPredicate::TypeBoundPredicate ( DefId reference, std::vector subst, - location_t locus) + BoundPolarity polarity, location_t locus) : SubstitutionRef ({}, SubstitutionArgumentMappings::empty ()), - reference (reference), locus (locus), error_flag (false) + reference (reference), locus (locus), error_flag (false), + polarity (polarity) { substitutions.clear (); for (const auto &p : subst) @@ -322,7 +325,7 @@ TypeBoundPredicate::TypeBoundPredicate ( TypeBoundPredicate::TypeBoundPredicate (const TypeBoundPredicate &other) : SubstitutionRef ({}, SubstitutionArgumentMappings::empty ()), reference (other.reference), locus (other.locus), - error_flag (other.error_flag) + error_flag (other.error_flag), polarity (other.polarity) { substitutions.clear (); for (const auto &p : other.get_substs ()) @@ -358,6 +361,7 @@ TypeBoundPredicate::operator= (const TypeBoundPredicate &other) reference = other.reference; locus = other.locus; error_flag = other.error_flag; + polarity = other.polarity; used_arguments = SubstitutionArgumentMappings::empty (); substitutions.clear (); @@ -396,7 +400,8 @@ TypeBoundPredicate::operator= (const TypeBoundPredicate &other) TypeBoundPredicate TypeBoundPredicate::error () { - auto p = TypeBoundPredicate (UNKNOWN_DEFID, {}, UNDEF_LOCATION); + auto p = TypeBoundPredicate (UNKNOWN_DEFID, {}, BoundPolarity::RegularBound, + UNDEF_LOCATION); p.error_flag = true; return p; } diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h index cb844d71255..341a0e7063f 100644 --- a/gcc/rust/typecheck/rust-tyty.h +++ b/gcc/rust/typecheck/rust-tyty.h @@ -381,11 +381,11 @@ class TypeBoundPredicate : public SubstitutionRef { public: TypeBoundPredicate (const Resolver::TraitReference &trait_reference, - location_t locus); + BoundPolarity polarity, location_t locus); TypeBoundPredicate (DefId reference, std::vector substitutions, - location_t locus); + BoundPolarity polarity, location_t locus); TypeBoundPredicate (const TypeBoundPredicate &other); @@ -432,6 +432,8 @@ public: DefId get_id () const { return reference; } + BoundPolarity get_polarity () const { return polarity; } + std::vector get_associated_type_items (); size_t get_num_associated_bindings () const override final; @@ -445,6 +447,7 @@ private: DefId reference; location_t locus; bool error_flag; + BoundPolarity polarity; }; // https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.VariantDef.html