From patchwork Wed Apr 5 14:03:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 79684 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp352815vqo; Wed, 5 Apr 2023 07:32:18 -0700 (PDT) X-Google-Smtp-Source: AKy350aGuL1r0tJA+L9ipqwjT77+9cqsoBkr9194tIiYo0z3phCI0ZbNgHUd3heFFkbrUXLGrvFB X-Received: by 2002:a17:906:ccc2:b0:92c:16cc:2dcd with SMTP id ot2-20020a170906ccc200b0092c16cc2dcdmr2933949ejb.33.1680705138030; Wed, 05 Apr 2023 07:32:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680705138; cv=none; d=google.com; s=arc-20160816; b=aCBu8AnjdU3eDeSqiDRsFr1mvAgbwf0hP3skxOu3PNEEgXscERH4Kl/DvWqmkIElz2 oqiGhOfJDPJaFK5X64r3uiBn9YcRjCMyehG+Nh/l0ufgggN1HmUcA0BTNkmWY95ZychX KNrf2rb8/AmzTvolpHFWq4/Jt8T9ZX3W+ayF+d2e+IiUREwNl3N+l0MNMtiCJH/q5bhm 43ktmhrkoPhLeMAO0IGRD8+h1t8N8sQNtS2esZAYqFQPGhLQRaIB1QYpYhkisH31MBUu zf+/t7b9xVuwcGMv4dkUOaVJbZHQm6467SI5oK7ANUoZ9aab6HjekZt61dM9TjCQfyAU 3rBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature:dmarc-filter :delivered-to; bh=v8LlfW/dVfH+bREmWfTuMct9EbFkL6ygxutNPMja9do=; b=gp0KO1vUgGJYKi4nqwOS1iqHRcb0lSHtE2nItMxpg7hZnLLzBcAeTfIFkeqOWDWBjf 1MB71xluy3v1wzXaoN63zuq45NIgOnAyTWOymfofs3gV4BJQPkSPKcEoGVZARxm0YGuY 1hfJmsZcelnB0bf1eILlbfKgqQxTLrjCYAYzaHjTBcKPg3wtsVXzh3I2ZA9dHVUDKU9I ReD9EpLn/bwwd498mZHaroGa7GShaZCa3N5YE/298TSHvHwKpH4sU4ZTMJwczeLl4M00 m+pK6nvOSnRDwnKqd/xP75XEmdKBs8ZCOwht343JPF0Yp6+HmERJ5x7j7/uqu5NgjtKl oLDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b="A9/cRi5G"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id ay21-20020a056402203500b005021f0d5753si10478836edb.666.2023.04.05.07.32.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:32:18 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b="A9/cRi5G"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2621D3930C91 for ; Wed, 5 Apr 2023 14:12:50 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by sourceware.org (Postfix) with ESMTPS id 515F4384D197 for ; Wed, 5 Apr 2023 14:05:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 515F4384D197 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embecosm.com Received: by mail-wm1-x333.google.com with SMTP id p34so20958290wms.3 for ; Wed, 05 Apr 2023 07:05:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703556; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=v8LlfW/dVfH+bREmWfTuMct9EbFkL6ygxutNPMja9do=; b=A9/cRi5GMBsTOBhQyHz1fHmGs24WO9TetxvM/xVBg1KoKR8LmxgHVFmOr2qv9b41w0 0Hp32V1opBx5a0eEVbHbFJSBErDwm60gwOQFxeWK+5E9HEfS/XTe03hsE1DZZhbOcuE1 +hPfdfiGHSV2vLbSh6b1YzLLcye9e2FwnPZNNkq1XXqdhjRNmVL6TgVMX31EpEsLGFjq BUPbumChBVhcbutBMyJn2C/TKr6xuVmUXrhB1OII9lmOd//GzyaO/ZkExzH2QEPgPBKM n2cwTvfNZ0D/51CzCp/M7olyIhkVR/riuHhgum2UYFsVT35WJdADiOceYFkVdJ5c60xH RH/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703556; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=v8LlfW/dVfH+bREmWfTuMct9EbFkL6ygxutNPMja9do=; b=GpqmQkbWNGg6UMzVKsx+IvDpNMyhi7tzGHGQglY8j4oIRu88Rzi4UbyfqYYKg8luoe kJfh5/COJiUMjjetDynRuPqWrTWMGYXxrDL/xgKdaDN7kI94KEXL+ofcQuvSPC8+WJ0K QbZL8J4Z1YAemceUBKxb3bnvqJHTz9BmwKETuLYsuq6GjQKQzusQ4/+Im/O04tHLD5Se Ddb2cY6eVdBNVCMKO2MPwtpOoWoDTvQVyeEJTjzipDjAMJYkDxpCaK4oNz8gR5pyry4a hQwCPrLK04xzrwQvWaym2oDQvdWg5uRx654IlI6O+HHHTw+9MmRfhc3D+vEpI07EY70K 89ZA== X-Gm-Message-State: AAQBX9d3NSfBkU/qAmHqxBlSSY0B8MiLLyMiiQIUQv5MafCYeNsRV60m L07sl1aINalideKr2Do09khXn4w4JJWdVIK3uQ== X-Received: by 2002:a1c:7716:0:b0:3ee:67ff:4aad with SMTP id t22-20020a1c7716000000b003ee67ff4aadmr4697692wmi.26.1680703556539; Wed, 05 Apr 2023 07:05:56 -0700 (PDT) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id ay8-20020a05600c1e0800b003edddae1068sm2330150wmb.9.2023.04.05.07.05.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:05:56 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 40/88] gccrs: Refactor BaseType, InferType and ErrorType impl into cc file Date: Wed, 5 Apr 2023 16:03:24 +0200 Message-Id: <20230405140411.3016563-41-arthur.cohen@embecosm.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230405140411.3016563-1-arthur.cohen@embecosm.com> References: <20230405140411.3016563-1-arthur.cohen@embecosm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-14.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: arthur.cohen@embecosm.com Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762347070686302134?= X-GMAIL-MSGID: =?utf-8?q?1762347070686302134?= From: Philip Herron Signed-off-by: Philip Herron gcc/rust/ChangeLog: * typecheck/rust-tyty.cc (BaseType::BaseType): refactor (BaseType::~BaseType): likewise (BaseType::get_ref): likewise (BaseType::set_ref): likewise (BaseType::get_ty_ref): likewise (BaseType::set_ty_ref): likewise (BaseType::is_equal): likewise (BaseType::is_unit): likewise (BaseType::get_kind): likewise (BaseType::get_combined_refs): likewise (BaseType::append_reference): likewise (BaseType::supports_substitutions): likewise (BaseType::has_subsititions_defined): likewise (BaseType::can_substitute): likewise (BaseType::needs_generic_substitutions): likewise (BaseType::contains_type_parameters): likewise (BaseType::get_ident): likewise (BaseType::get_locus): likewise (InferType::InferType): likewise (InferType::get_infer_kind): likewise (InferType::get_name): likewise (InferType::is_concrete): likewise (ErrorType::ErrorType): likewise (ErrorType::is_unit): likewise (ErrorType::is_concrete): likewise (ErrorType::get_name): likewise (ErrorType::monomorphized_clone): likewise * typecheck/rust-tyty.h (class SubstitutionArgumentMappings): likewise --- gcc/rust/typecheck/rust-tyty.cc | 181 ++++++++++++++++++++++++++++++++ gcc/rust/typecheck/rust-tyty.h | 92 ++++++---------- 2 files changed, 211 insertions(+), 62 deletions(-) diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc index b45bd99b1bd..079055e870d 100644 --- a/gcc/rust/typecheck/rust-tyty.cc +++ b/gcc/rust/typecheck/rust-tyty.cc @@ -146,6 +146,122 @@ is_primitive_type_kind (TypeKind kind) } } +// BASE TYPE + +BaseType::BaseType (HirId ref, HirId ty_ref, TypeKind kind, RustIdent ident, + std::set refs) + : TypeBoundsMappings ({}), kind (kind), ref (ref), ty_ref (ty_ref), + combined (refs), ident (ident), mappings (Analysis::Mappings::get ()) +{} + +BaseType::BaseType (HirId ref, HirId ty_ref, TypeKind kind, RustIdent ident, + std::vector specified_bounds, + std::set refs) + : TypeBoundsMappings (specified_bounds), kind (kind), ref (ref), + ty_ref (ty_ref), combined (refs), ident (ident), + mappings (Analysis::Mappings::get ()) +{} + +BaseType::~BaseType () {} + +HirId +BaseType::get_ref () const +{ + return ref; +} + +void +BaseType::set_ref (HirId id) +{ + if (id != ref) + append_reference (ref); + ref = id; +} + +HirId +BaseType::get_ty_ref () const +{ + return ty_ref; +} + +void +BaseType::set_ty_ref (HirId id) +{ + ty_ref = id; +} + +bool +BaseType::is_equal (const BaseType &other) const +{ + return get_kind () == other.get_kind (); +} + +bool +BaseType::is_unit () const +{ + return false; +} + +TypeKind +BaseType::get_kind () const +{ + return kind; +} + +std::set +BaseType::get_combined_refs () const +{ + return combined; +} + +void +BaseType::append_reference (HirId id) +{ + combined.insert (id); +} + +bool +BaseType::supports_substitutions () const +{ + return false; +} + +bool +BaseType::has_subsititions_defined () const +{ + return false; +} + +bool +BaseType::can_substitute () const +{ + return supports_substitutions () && has_subsititions_defined (); +} + +bool +BaseType::needs_generic_substitutions () const +{ + return false; +} + +bool +BaseType::contains_type_parameters () const +{ + return !is_concrete (); +} + +const RustIdent & +BaseType::get_ident () const +{ + return ident; +} + +Location +BaseType::get_locus () const +{ + return ident.locus; +} + bool BaseType::satisfies_bound (const TypeBoundPredicate &predicate) const { @@ -330,6 +446,40 @@ BaseType::debug () const debug_str ().c_str ()); } +// InferType + +InferType::InferType (HirId ref, InferTypeKind infer_kind, Location locus, + std::set refs) + : BaseType (ref, ref, TypeKind::INFER, + {Resolver::CanonicalPath::create_empty (), locus}, refs), + infer_kind (infer_kind) +{} + +InferType::InferType (HirId ref, HirId ty_ref, InferTypeKind infer_kind, + Location locus, std::set refs) + : BaseType (ref, ty_ref, TypeKind::INFER, + {Resolver::CanonicalPath::create_empty (), locus}, refs), + infer_kind (infer_kind) +{} + +InferType::InferTypeKind +InferType::get_infer_kind () const +{ + return infer_kind; +} + +std::string +InferType::get_name () const +{ + return as_string (); +} + +bool +InferType::is_concrete () const +{ + return true; +} + void InferType::accept_vis (TyVisitor &vis) { @@ -435,6 +585,35 @@ InferType::default_type (BaseType **type) const return false; } +// ErrorType + +ErrorType::ErrorType (HirId ref, std::set refs) + : BaseType (ref, ref, TypeKind::ERROR, + {Resolver::CanonicalPath::create_empty (), Location ()}, refs) +{} + +ErrorType::ErrorType (HirId ref, HirId ty_ref, std::set refs) + : BaseType (ref, ty_ref, TypeKind::ERROR, + {Resolver::CanonicalPath::create_empty (), Location ()}, refs) +{} + +bool +ErrorType::is_unit () const +{ + return true; +} +bool +ErrorType::is_concrete () const +{ + return false; +} + +std::string +ErrorType::get_name () const +{ + return as_string (); +} + void ErrorType::accept_vis (TyVisitor &vis) { @@ -477,6 +656,8 @@ ErrorType::monomorphized_clone () const return clone (); } +// Struct Field type + std::string StructFieldType::as_string () const { diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h index cb30a60ae96..1a6bac3f864 100644 --- a/gcc/rust/typecheck/rust-tyty.h +++ b/gcc/rust/typecheck/rust-tyty.h @@ -89,20 +89,15 @@ class TyConstVisitor; class BaseType : public TypeBoundsMappings { public: - virtual ~BaseType () {} + virtual ~BaseType (); - HirId get_ref () const { return ref; } + HirId get_ref () const; - void set_ref (HirId id) - { - if (id != ref) - append_reference (ref); - ref = id; - } + void set_ref (HirId id); - HirId get_ty_ref () const { return ty_ref; } + HirId get_ty_ref () const; - void set_ty_ref (HirId id) { ty_ref = id; } + void set_ty_ref (HirId id); virtual void accept_vis (TyVisitor &vis) = 0; @@ -133,10 +128,7 @@ public: // ty are considered equal if they're of the same kind, and // 1. (For ADTs, arrays, tuples, refs) have the same underlying ty // 2. (For functions) have the same signature - virtual bool is_equal (const BaseType &other) const - { - return get_kind () == other.get_kind (); - } + virtual bool is_equal (const BaseType &other) const; bool satisfies_bound (const TypeBoundPredicate &predicate) const; @@ -148,11 +140,11 @@ public: void inherit_bounds ( const std::vector &specified_bounds); - virtual bool is_unit () const { return false; } + virtual bool is_unit () const; virtual bool is_concrete () const = 0; - TypeKind get_kind () const { return kind; } + TypeKind get_kind () const; /* Returns a pointer to a clone of this. The caller is responsible for * releasing the memory of the returned ty. */ @@ -162,22 +154,19 @@ public: virtual BaseType *monomorphized_clone () const = 0; // get_combined_refs returns the chain of node refs involved in unification - std::set get_combined_refs () const { return combined; } + std::set get_combined_refs () const; - void append_reference (HirId id) { combined.insert (id); } + void append_reference (HirId id); - virtual bool supports_substitutions () const { return false; } + virtual bool supports_substitutions () const; - virtual bool has_subsititions_defined () const { return false; } + virtual bool has_subsititions_defined () const; - virtual bool can_substitute () const - { - return supports_substitutions () && has_subsititions_defined (); - } + virtual bool can_substitute () const; - virtual bool needs_generic_substitutions () const { return false; } + virtual bool needs_generic_substitutions () const; - bool contains_type_parameters () const { return !is_concrete (); } + bool contains_type_parameters () const; std::string mappings_str () const; @@ -192,24 +181,17 @@ public: // Projections if available or error const BaseType *destructure () const; - const RustIdent &get_ident () const { return ident; } + const RustIdent &get_ident () const; - Location get_locus () const { return ident.locus; } + Location get_locus () const; protected: BaseType (HirId ref, HirId ty_ref, TypeKind kind, RustIdent ident, - std::set refs = std::set ()) - : TypeBoundsMappings ({}), kind (kind), ref (ref), ty_ref (ty_ref), - combined (refs), ident (ident), mappings (Analysis::Mappings::get ()) - {} + std::set refs = std::set ()); BaseType (HirId ref, HirId ty_ref, TypeKind kind, RustIdent ident, std::vector specified_bounds, - std::set refs = std::set ()) - : TypeBoundsMappings (specified_bounds), kind (kind), ref (ref), - ty_ref (ty_ref), combined (refs), ident (ident), - mappings (Analysis::Mappings::get ()) - {} + std::set refs = std::set ()); TypeKind kind; HirId ref; @@ -231,18 +213,10 @@ public: }; InferType (HirId ref, InferTypeKind infer_kind, Location locus, - std::set refs = std::set ()) - : BaseType (ref, ref, TypeKind::INFER, - {Resolver::CanonicalPath::create_empty (), locus}, refs), - infer_kind (infer_kind) - {} + std::set refs = std::set ()); InferType (HirId ref, HirId ty_ref, InferTypeKind infer_kind, Location locus, - std::set refs = std::set ()) - : BaseType (ref, ty_ref, TypeKind::INFER, - {Resolver::CanonicalPath::create_empty (), locus}, refs), - infer_kind (infer_kind) - {} + std::set refs = std::set ()); void accept_vis (TyVisitor &vis) override; void accept_vis (TyConstVisitor &vis) const override; @@ -256,13 +230,13 @@ public: BaseType *clone () const final override; BaseType *monomorphized_clone () const final override; - InferTypeKind get_infer_kind () const { return infer_kind; } + InferTypeKind get_infer_kind () const; - std::string get_name () const override final { return as_string (); } + std::string get_name () const override final; bool default_type (BaseType **type) const; - bool is_concrete () const final override { return true; } + bool is_concrete () const final override; private: InferTypeKind infer_kind; @@ -271,20 +245,15 @@ private: class ErrorType : public BaseType { public: - ErrorType (HirId ref, std::set refs = std::set ()) - : BaseType (ref, ref, TypeKind::ERROR, - {Resolver::CanonicalPath::create_empty (), Location ()}, refs) - {} + ErrorType (HirId ref, std::set refs = std::set ()); - ErrorType (HirId ref, HirId ty_ref, std::set refs = std::set ()) - : BaseType (ref, ty_ref, TypeKind::ERROR, - {Resolver::CanonicalPath::create_empty (), Location ()}, refs) - {} + ErrorType (HirId ref, HirId ty_ref, + std::set refs = std::set ()); void accept_vis (TyVisitor &vis) override; void accept_vis (TyConstVisitor &vis) const override; - bool is_unit () const override { return true; } + bool is_unit () const override; std::string as_string () const override; @@ -294,12 +263,11 @@ public: BaseType *clone () const final override; BaseType *monomorphized_clone () const final override; - std::string get_name () const override final { return as_string (); } + std::string get_name () const override final; - bool is_concrete () const final override { return false; } + bool is_concrete () const final override; }; -class SubstitutionArgumentMappings; class ParamType : public BaseType { public: