From patchwork Tue Feb 21 12:01:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 59999 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1833561wrn; Tue, 21 Feb 2023 04:29:51 -0800 (PST) X-Google-Smtp-Source: AK7set8EpF9meEKHyTlTZxoNBZFrkFzbkf06JG8/RCh/M9pF9lsLKCJ04r/6+JIo2voDkKsaDYGf X-Received: by 2002:a17:906:304e:b0:8aa:be1a:c4bf with SMTP id d14-20020a170906304e00b008aabe1ac4bfmr10357368ejd.16.1676982591113; Tue, 21 Feb 2023 04:29:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676982591; cv=none; d=google.com; s=arc-20160816; b=GX0bOeLax8d/9xphCg/wJIYRYqMSwnKTwEMqqwL6MoiuXnb27vD0v2KNYjz4ggMEf3 9K2TYcg1FA5+uPumP2q3oLWbqBBZkEyi8dUeJIqGlZfDgbAYxwtJNG8OXiHg5SpdS7QG mM2vrGbW163ymcQ+Cfu8+Hrkxbd5FZGZpUjAGLH/YaZKrs+2aY0tghl06Ou4Wi81gzDJ rTd6aZi6qhPK7/Zq1gdl50JtGchlIQtivZJT8g2QMOCfKHylBa0OgLqkf8F4xwF4FC0h 5ZZu2i0vRHMU6w6ELhq9XrYaWdDNSlxGceJf/oYmFe+hxUNiECS4ch5BILa/ryrA474Z 8zDQ== 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=RnXwxXJcMqT0unhfwV0db+jGuzoB00BPT1OUeIgVUSQ=; b=WhLcr8V+9uGaCOrTL+GDIuyPO4W07l5AOg/Z+ERQRM1FsJAoofPAyKNQzhobYeyLEZ VjFFxwXOnxXXoJre8qIfgjZdF5KGinLcGon0mBGae25LuJfeewD9K2ynDDWT0BPozajH XpuhsbHVLHV2OZxUlN6+/4PFhoZ9gWf9V2Frf2Qk9b0tJ7qVoKZ9Aq4Tg8MTqo6sy3va OH/LgbmJ5mYUE+pEhJewk/HVpuYQ55i63zZ2iTf9h0MMNl4lzObzeLsX2hJA2h8c7SE4 9PeNwJFTi+ycSAAekOs/VdV8WN5VrQD0NwFQczPrWzA+LMQT9Gc9wV3EjzD/BlgmGYYC 5LwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=MXUsdwHR; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id fw37-20020a170907502500b008d21d51c307si7215733ejc.383.2023.02.21.04.29.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:29:51 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=MXUsdwHR; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 B3B953873BE0 for ; Tue, 21 Feb 2023 12:11:20 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by sourceware.org (Postfix) with ESMTPS id A8FF3384DD3C for ; Tue, 21 Feb 2023 12:04:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A8FF3384DD3C 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-x431.google.com with SMTP id r7so3992032wrz.6 for ; Tue, 21 Feb 2023 04:04:07 -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=Va+HSvtaLSn/JOJ5WLCWfiVrsp41XegG32iSuGLEqXm0XqOz3zR+AwJrLXPGZM9RVJ qcPXOE8XM5hiIB55sczpitG3rbBQXFldfJS++0C+Iw6ueoYO9EAHJ8FEfRmRiz4lojha DJUZ82CiRGt/FEqy3s2eJ5foR2ldNAEsvOFFwe/WXg0H6TEj7sTl9lvBvRxO3A09yaWE m6Smt3wZKHu0BCWWPrNFSMUs6k1woCRr+pPAwbCmYu4mCbiU4uY+MFo9zcRxAWa7j4Mn Lu1BOIDu9WE7dxnb7z/q6p5yqbBWDsSbnZvQv4xUMZBIZynFg1vvruzyDk48KB/Jl47f AI5w== X-Gm-Message-State: AO0yUKUPq8EisRfo8mo7e/XpF2YV35LAgCtpsAPYwFGmzN2CgFd6XQTw j+m68zGH4OFdmAf9NTqdKrgpLM2Dnu8eNGY2xw== 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> MIME-Version: 1.0 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=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?1758443697437472252?= X-GMAIL-MSGID: =?utf-8?q?1758443697437472252?= 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