From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by sourceware.org (Postfix) with ESMTPS id A82553858C5E for ; Tue, 21 Feb 2023 12:04:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A82553858C5E 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-wr1-x430.google.com with SMTP id t13so4089829wrv.13 for ; Tue, 21 Feb 2023 04:04:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; 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=RnXwxXJcMqT0unhfwV0db+jGuzoB00BPT1OUeIgVUSQ=; b=MXUsdwHRcVYGse3qbma1tj6PiJfuNnte6EUNITOXpXo/i3s8vISPcGPr6ZZlFlwnMa kM494z5yyG+184/hpoAOjAzqOFFYB0/dsYJ4IjpC0/7DBo33x+Q77Fj4Z8kqWeoVjMHk 2d9WoKh5K5i1NM0QYrK9o+GMt1wHyWBmdZyc9JMMWUkkYUj0bPCRCj0kr74iuGy0RjOK eZXSxjUDif1jDCJ9h/aqbWx+FY5hIUnQCAeL8YPXCGSlauNGskjpEsdzIDMJGlXGA9jc AENz9yAxNsUWd29xSFZWGQ/KvMqm8I7+gXInu46HP73WjoH70wdskxRSJi/jovvSc9ta Sa/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=RnXwxXJcMqT0unhfwV0db+jGuzoB00BPT1OUeIgVUSQ=; b=lkOv4GcC2l2bJKhga/4UWFiS9tKxzMrCgKgO8hkBZMejiO6gTttpUtjtYcWFi7ewXi EZJCxupQ203js4gZt/KWCRkSITGClsDZupy06Q4L2rf6RFkqTwc8KNpPAaA1SSEszJC9 MNGGUyFXZHdjE12P2j8O2IeaiIp0iV2V+I7tJuyJcvGjfRMdqpUWffqMj4O8l/yOogaa kTX9Qwd5EyCWJyYyjGHsPlISwoO5YB30JAEdsHZtdEin1rVV82w665NU2eGnhAHVkeCr MZ9yYT04XNo7Pq/zOZpdVpoL0kDV5sldolFB6eUaxiQuIGq7aod1BDM2q4XUPI6r03fQ QaxQ== X-Gm-Message-State: AO0yUKWhWsTxE3evG8nIhpjQtKjhKgr0AhBMZjttegFXRC0TaHGEW4Ia xcZ5RNWFPKPsp8vnLH/LbBrA X-Google-Smtp-Source: AK7set+go4ZQFB8kUFrAYQKuBPMcQFoxmTGpq4fIRTNdxUSU9BB9MhE1KG4V9ru8GaTkYHTllZR/rg== X-Received: by 2002:a05:6000:c2:b0:2c5:55a1:c7fe with SMTP id q2-20020a05600000c200b002c555a1c7femr2971891wrx.8.1676981046245; Tue, 21 Feb 2023 04:04:06 -0800 (PST) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id c15-20020adffb4f000000b002c55b0e6ef1sm5013811wrs.4.2023.02.21.04.04.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:04:05 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 053/103] gccrs: Add missing type resolution for function type segments Date: Tue, 21 Feb 2023 13:01:43 +0100 Message-Id: <20230221120230.596966-54-arthur.cohen@embecosm.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230221120230.596966-1-arthur.cohen@embecosm.com> References: <20230221120230.596966-1-arthur.cohen@embecosm.com> Reply-To: arthur.cohen@embecosm.com MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-14.8 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=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: From: Philip Herron gcc/rust/ChangeLog: * typecheck/rust-tyty-bounds.cc (TypeCheckBase::get_predicate_from_bound): Add missing implementation. --- gcc/rust/typecheck/rust-tyty-bounds.cc | 69 +++++++++++++++++++++++--- 1 file changed, 62 insertions(+), 7 deletions(-) diff --git a/gcc/rust/typecheck/rust-tyty-bounds.cc b/gcc/rust/typecheck/rust-tyty-bounds.cc index 1a2ed3b7422..20a81ada6c4 100644 --- a/gcc/rust/typecheck/rust-tyty-bounds.cc +++ b/gcc/rust/typecheck/rust-tyty-bounds.cc @@ -84,16 +84,71 @@ TypeCheckBase::get_predicate_from_bound (HIR::TypePath &type_path) = HIR::GenericArgs::create_empty (type_path.get_locus ()); auto &final_seg = type_path.get_final_segment (); - if (final_seg->is_generic_segment ()) + switch (final_seg->get_type ()) { - auto final_generic_seg - = static_cast (final_seg.get ()); - if (final_generic_seg->has_generic_args ()) - { - args = final_generic_seg->get_generic_args (); - } + case HIR::TypePathSegment::SegmentType::GENERIC: { + auto final_generic_seg + = static_cast (final_seg.get ()); + if (final_generic_seg->has_generic_args ()) + { + args = final_generic_seg->get_generic_args (); + } + } + break; + + case HIR::TypePathSegment::SegmentType::FUNCTION: { + auto final_function_seg + = static_cast (final_seg.get ()); + auto &fn = final_function_seg->get_function_path (); + + // we need to make implicit generic args which must be an implicit Tuple + auto crate_num = mappings->get_current_crate (); + HirId implicit_args_id = mappings->get_next_hir_id (); + Analysis::NodeMapping mapping (crate_num, + final_seg->get_mappings ().get_nodeid (), + implicit_args_id, UNKNOWN_LOCAL_DEFID); + + std::vector> params_copy; + for (auto &p : fn.get_params ()) + { + params_copy.push_back (p->clone_type ()); + } + + HIR::TupleType *implicit_tuple + = new HIR::TupleType (mapping, std::move (params_copy), + final_seg->get_locus ()); + + std::vector> inputs; + inputs.push_back (std::unique_ptr (implicit_tuple)); + + args = HIR::GenericArgs ({} /* lifetimes */, + std::move (inputs) /* type_args*/, + {} /* binding_args*/, {} /* const_args */, + final_seg->get_locus ()); + + // resolve the fn_once_output type + TyTy::BaseType *fn_once_output_ty + = fn.has_return_type () + ? TypeCheckType::Resolve (fn.get_return_type ().get ()) + : TyTy::TupleType::get_unit_type ( + final_seg->get_mappings ().get_hirid ()); + context->insert_implicit_type (final_seg->get_mappings ().get_hirid (), + fn_once_output_ty); + + // setup the associated type.. ?? + // fn_once_output_ty->debug (); + } + break; + + default: + /* nothing to do */ + break; } + // FIXME + // I think this should really be just be if the !args.is_empty() because + // someone might wrongly apply generic arguments where they should not and + // they will be missing error diagnostics if (predicate.requires_generic_args ()) { // this is applying generic arguments to a trait reference -- 2.39.1