From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id rvzMB3Dp2WJ+UxgAWB0awg (envelope-from ) for ; Thu, 21 Jul 2022 20:04:00 -0400 Received: by simark.ca (Postfix, from userid 112) id 122C21E5EA; Thu, 21 Jul 2022 20:04:00 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, NICE_REPLY_A autolearn=ham autolearn_force=no version=3.4.6 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 79C7C1E13B for ; Thu, 21 Jul 2022 20:03:59 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D293038356B1 for ; Fri, 22 Jul 2022 00:03:58 +0000 (GMT) Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) by sourceware.org (Postfix) with ESMTPS id B1F823835839 for ; Fri, 22 Jul 2022 00:03:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B1F823835839 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wm1-f49.google.com with SMTP id c22so1894205wmr.2 for ; Thu, 21 Jul 2022 17:03:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=ZxWSpC1LSmiqxl9q8p+Eo0cozmYc7Xk/GD+xXJIy6nE=; b=f/BDCopIR6CcqbT9C6MuDS6MC3umD0io4NqZIfugvDQwFaPdZp0mf4zxl33giV8kUI mWR7XBnHbN0RxpPF0OtkfxuqSDE2aUGpABwUVLedRlw/VdowavH9QegPH9PL/u0Zoqrj IdnPvLLNglXCK7GSI1O7VeOYgwhN7Y4cb7R+EiHPBb3qKc4dvLOJzVMust39gwUZBUMa 0FFaEUTqM5vwaKGHEsdSLKOTWPhKUzbZfCbSYwwEy6Zz9gU5U3RD5H5g9PS1LfoLAjk9 O5uIHcd6pLtqcg3CjARiGWT9ndU/fYOjGHb0NnYozy19t+Vnthu61iaqqo7KqfOV/+gY VZ4A== X-Gm-Message-State: AJIora+u49IZ1swXiL69Fv2pQBAXa41Ke38F9LZb9kC2QeZt71pWqsQS SNyb2oBWF2A8LQqqxlUEYDw= X-Google-Smtp-Source: AGRyM1ufgTibXXh219/zls8M7D5z9dWeqWpMUc1A/uRYpbrlP9CpsAez5rr658hHUF5hwCr2LNL9bA== X-Received: by 2002:a05:600c:1f16:b0:3a3:214c:a85e with SMTP id bd22-20020a05600c1f1600b003a3214ca85emr365246wmb.95.1658448225375; Thu, 21 Jul 2022 17:03:45 -0700 (PDT) Received: from ?IPv6:2001:8a0:f924:2600:209d:85e2:409e:8726? ([2001:8a0:f924:2600:209d:85e2:409e:8726]) by smtp.gmail.com with ESMTPSA id w7-20020a1cf607000000b003a31f1edfa7sm7014208wmc.41.2022.07.21.17.03.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 21 Jul 2022 17:03:44 -0700 (PDT) Subject: Re: [PATCH][gdbsupport] Use task size in parallel_for_each To: Tom de Vries , gdb-patches@sourceware.org References: <20220718194219.GA16823@delia.home> <4fc23fcd-c15d-7622-8b51-cc48cd3cba16@palves.net> <75931310-5dcd-059d-9221-6c94dbcd231f@suse.de> From: Pedro Alves Message-ID: Date: Fri, 22 Jul 2022 01:03:43 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: <75931310-5dcd-059d-9221-6c94dbcd231f@suse.de> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tom Tromey Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" On 2022-07-21 9:23 p.m., Tom de Vries wrote: > On 7/21/22 19:35, Pedro Alves wrote: >>> diff --git a/gdbsupport/parallel-for.h b/gdbsupport/parallel-for.h >>> index bf40f125f0f..3c9269574df 100644 >>> --- a/gdbsupport/parallel-for.h >>> +++ b/gdbsupport/parallel-for.h >>> @@ -134,7 +134,9 @@ typename gdb::detail::par_for_accumulator< >>>       typename std::result_of::type >>>     >::result_type >>>   parallel_for_each (unsigned n, RandomIt first, RandomIt last, >>> -           RangeFunction callback) >>> +           RangeFunction callback, >>> +           std::function *task_size_ptr >>> +             = (std::function *)nullptr) >> >> That use of a std::function pointer looks odd.  AFAICT, TASK_SIZE_PTR is only ever called >> as a callback by parallel_for_each, for setup, in the calling thread, and isn't stored >> anywhere, right?  If so, gdb::function_view instead should work, is lightweight, and is >> nullable, meaning you don't need a pointer. >> >> And then, at the caller, just using a lambda instead of a std::function should work too: >> >>      auto task_size = [=] (iter_type iter) >>        { >>     dwarf2_per_cu_data *per_cu = iter->get (); >>     return per_cu->length (); >>        }; > > I've tried that (attached) but ran into the usual template error mess, not sure how I could solve that yet. I see. The problem is that here: @@ -134,7 +135,9 @@ typename gdb::detail::par_for_accumulator< typename std::result_of::type >::result_type parallel_for_each (unsigned n, RandomIt first, RandomIt last, - RangeFunction callback) + RangeFunction callback, + gdb::function_view task_size + = nullptr) parallel_for_each is a template, and the function_view parameter's type depends on a template parameter (RandomIt), so we can't rely on implicit conversions, such as when passing a lambda (lambda -> function_view). We need to pass a function_view of the right type already. That's not special about function_view, it's just how templates and overload resolution works. So this would fix it: diff --git c/gdb/dwarf2/read.c w/gdb/dwarf2/read.c index 23c3873cba6..06df773f1e0 100644 --- c/gdb/dwarf2/read.c +++ w/gdb/dwarf2/read.c @@ -7067,11 +7067,12 @@ dwarf2_build_psymtabs_hard (dwarf2_per_objfile *per_objfile) using iter_type = decltype (per_bfd->all_comp_units.begin ()); - auto task_size = [=] (iter_type iter) + auto task_size_ = [=] (iter_type iter) { dwarf2_per_cu_data *per_cu = iter->get (); return per_cu->length (); }; + gdb::function_view task_size = task_size_; Though it's annoying to have to write the function_view type. Note that this instead, is a bad pattern with function_view (similarly to other view types, like string_view), as it immediately dangles the lambda temporary: - auto task_size = [=] (iter_type iter) + gdb::function_view task_size = [=] (iter_type iter) { dwarf2_per_cu_data *per_cu = iter->get (); return per_cu->length (); }; I think the best is to introduce a gdb::make_function_view function, so that you can do this: diff --git c/gdb/dwarf2/read.c w/gdb/dwarf2/read.c index 23c3873cba6..255b955a54c 100644 --- c/gdb/dwarf2/read.c +++ w/gdb/dwarf2/read.c @@ -7101,7 +7101,7 @@ dwarf2_build_psymtabs_hard (dwarf2_per_objfile *per_objfile) } } return result_type (thread_storage.release (), std::move (errors)); - }, task_size); + }, gdb::make_function_view (task_size)); /* Only show a given exception a single time. */ std::unordered_set seen_exceptions; I've got that working here. I'll post it tomorrow. Note: the 'task_size' lambda doesn't actually need to capture anything: @@ -7067,11 +7067,12 @@ dwarf2_build_psymtabs_hard (dwarf2_per_objfile *per_objfile) using iter_type = decltype (per_bfd->all_comp_units.begin ()); - auto task_size = [=] (iter_type iter) + auto task_size = [] (iter_type iter) { dwarf2_per_cu_data *per_cu = iter->get (); return per_cu->length (); };