From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1643) id D653B3858C33; Sat, 22 Oct 2022 10:48:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D653B3858C33 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666435711; bh=rm9oivKaJjMWTtTMgOZ1CfceuqQrJxbhIRDCFPG58Y0=; h=From:To:Subject:Date:From; b=OFD1HVrn0DtQ8h54urRd0ZxYXGFjU99S804KyxzP+oNlazXsUNptCu/cHKJZjCWIg fc7RsFSh57XbopPuO+4tasFNUnib19fZ4fhFK2jWmlbNgzN0i0u+dOiirxT14CwpEL ZLT2gTyCjxxlVX0JfZLnUhb3OADPCNtYcssRlAzc= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Thomas Schwinge To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/rust/master] Add missing type resolution for function type segments X-Act-Checkin: gcc X-Git-Author: Philip Herron X-Git-Refname: refs/heads/devel/rust/master X-Git-Oldrev: d396692534019f1e80b821c9e483164f302679bf X-Git-Newrev: f6f87dead4bf2da20bc3a22dc6ca7a373c9ed05c Message-Id: <20221022104831.D653B3858C33@sourceware.org> Date: Sat, 22 Oct 2022 10:48:31 +0000 (GMT) List-Id: https://gcc.gnu.org/g:f6f87dead4bf2da20bc3a22dc6ca7a373c9ed05c commit f6f87dead4bf2da20bc3a22dc6ca7a373c9ed05c Author: Philip Herron Date: Thu Oct 20 18:05:43 2022 +0100 Add missing type resolution for function type segments Diff: --- 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 d7647b75f7a..53eccb79d93 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