From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id C2A263858CD1 for ; Tue, 9 Apr 2024 02:37:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C2A263858CD1 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C2A263858CD1 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712630226; cv=none; b=cPdFvINWnlDSO8marSLXaPV38jJQztFH1Q/kDYcZOwVGeVJQBJy9EEkj236FnD3r/2Dr0XylD4dJp9uiVwfyC60EaYYt/JyMap+cYPY3AJZabaGbROMsEQ6CqJJ3o8QUtRhRRZcqLrM2FnR6YpGlmJl/mdlvS2GD5zqS1WTKLCI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712630226; c=relaxed/simple; bh=4iwilOHWvoj2D71Cwoqy7xPvabz0ycX+Q5H0enkz2r8=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=Og6/VBDLbWJXfpxF3l1xlgtqrFHz3BlhmVP6f3ACirIj8gCeG7iUcuuB81vGGLB/BF77u8UYbfkiVNNwhzXVOntVf7y2anXd6VaTXDD12mTer6Q+ILZIVXFp1F/QfC7RiUuZ/KgUSQpHKs2RA5Jz+ok3/DBAmnX+yaVTrbdtoiM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712630224; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BCOTbrzdEJdJdwoy6p5fDq3r3QRQuhzUdCb3EtQGs6I=; b=UgTP5we/jzbzq0fH9b1o2gRnd2DDX8N6U8ODygAiFYOFDDmfi6Q1tCPVU4wNlYuZK0jZSc s0yoOsj667046ujCXEI5FAJdgW1ez5/Q6QkUDv9RLQD606AXV8GESQ7m68H0Ri92AukFdK mJlqIY2L2wb8Vh37s5XbO96AoxhTJzI= Received: from mail-vk1-f197.google.com (mail-vk1-f197.google.com [209.85.221.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-580-298gwZkwPSaBulRgeyeJUw-1; Mon, 08 Apr 2024 22:37:02 -0400 X-MC-Unique: 298gwZkwPSaBulRgeyeJUw-1 Received: by mail-vk1-f197.google.com with SMTP id 71dfb90a1353d-4da7b800983so2118251e0c.2 for ; Mon, 08 Apr 2024 19:37:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712630222; x=1713235022; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=BCOTbrzdEJdJdwoy6p5fDq3r3QRQuhzUdCb3EtQGs6I=; b=EFbZAKgRrIHHhe3Sm/5Ha6MfyDcVOV52Wf7gSCVL2sRDLcjLnvDHsAhvEBBHO573t4 oNzCsMm0RvYYE90eOtddFX8SJMPdisyjKHtlQspwisLjsYvimz7jqeeP5xuTEhmhPGAh WXGWqbbXYz7btueyVzDPurxUMB+TbwTexhbLfduSaAGeN95TwHYhJYYzcg+TdgwFu6FM LnoCFKidLBwLlwAzBCL5cPZlM4zDRb1eM3LTrefG8o0lQuNxlfT4pVBmxV3mnEjqjicr o1VRc4aoZfNh2DuLbQo5W9Pictjyk/mUssXSqXyTSn0WHlYMb/JMtUVZJj2qfpF15szb 3iWQ== X-Gm-Message-State: AOJu0YwoxDmeK4WJCMx17naapCWXy/+DAlSemObnAq6StaZGak4CSYKA OOOyKT0TEHgZb0iPGbSClPPvW0+spWgeIxjQJpbrTjbZIVqGqY0Vyj7Q2wMgxOb9BVV3/bLGa8f tS9J6RZYoWnRJovI5qkixv4FTTWzm1HW/6V2qBLA6Bx2zgXhZyYRVVyc= X-Received: by 2002:ac5:c963:0:b0:4d1:34a1:c892 with SMTP id t3-20020ac5c963000000b004d134a1c892mr6640161vkm.13.1712630222401; Mon, 08 Apr 2024 19:37:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGxw3K+QarNLSteh+18oUXf66bcmK95w61FkOM5Ob68eXlXaQ3ZVyWshwZglZiYOLzVJ2VNkg== X-Received: by 2002:ac5:c963:0:b0:4d1:34a1:c892 with SMTP id t3-20020ac5c963000000b004d134a1c892mr6640154vkm.13.1712630222060; Mon, 08 Apr 2024 19:37:02 -0700 (PDT) Received: from [192.168.1.130] (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id b19-20020a0ccd13000000b0068c8be959a0sm3632412qvm.111.2024.04.08.19.37.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 08 Apr 2024 19:37:01 -0700 (PDT) Message-ID: Date: Mon, 8 Apr 2024 22:37:00 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] c++/modules: Track declarations imported from partitions [PR99377] To: Nathaniel Shead Cc: gcc-patches@gcc.gnu.org, Nathan Sidwell , Patrick Palka References: <66056128.050a0220.c7f0.2cc8@mx.google.com> <660e9cbd.620a0220.e9163.84e7@mx.google.com> From: Jason Merrill In-Reply-To: <660e9cbd.620a0220.e9163.84e7@mx.google.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-7.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,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: On 4/4/24 08:27, Nathaniel Shead wrote: > On Wed, Apr 03, 2024 at 02:16:25PM -0400, Jason Merrill wrote: >> On 3/28/24 08:22, Nathaniel Shead wrote: >>> Bootstrapped and regtested on x86_64-pc-linux-gnu, OK for trunk? >>> >>> -- >8 -- >>> >>> The testcase in comment 15 of the linked PR is caused because the >>> following assumption in depset::hash::make_dependency doesn't hold: >>> >>> if (DECL_LANG_SPECIFIC (not_tmpl) >>> && DECL_MODULE_IMPORT_P (not_tmpl)) >>> { >>> /* Store the module number and index in cluster/section, >>> so we don't have to look them up again. */ >>> unsigned index = import_entity_index (decl); >>> module_state *from = import_entity_module (index); >>> /* Remap will be zero for imports from partitions, which >>> we want to treat as-if declared in this TU. */ >>> if (from->remap) >>> { >>> dep->cluster = index - from->entity_lwm; >>> dep->section = from->remap; >>> dep->set_flag_bit (); >>> } >>> } >>> >>> This is because at least for template specialisations, we first see the >>> declaration in the header unit imported from the partition, and then the >>> instantiation provided by the partition itself. This means that the >>> 'import_entity_index' lookup doesn't report that the specialisation was >>> declared in the partition and thus should be considered as-if it was >>> part of the TU, and get exported. >> >> I think "exported" is the wrong term here; IIUC template specializations are >> not themselves exported, just the template itself. > > Yes, sorry; I meant "emitted" here, in terms of whether the definition > is in the CMI (regardless of whether or not that means that importers > can name it). > >> But if the declaration or point of instantiation of the specialization is >> within a module instantiation unit, it is reachable to any importers, >> including the primary module interface unit importing the partition >> interface unit. >> >> Does this work differently if "check" is a separate module rather than a >> partition? > > Yes. When in a non-partition module (say, Bar), then the instantiation > is emitted into Bar's CMI. When a caller imports Foo, it transitively > streams in Bar as well when looking for the entity and imports its > definition from there. > > However, partitions work differently. In the testcase the instantiation > is emitted into Foo:check's CMI, but partition CMIs are only used within > that module: importers don't know that partitions exist, and only read > Foo's CMI. And because make_dependency doesn't realise that the > instantiation came from a partition it hasn't emitted it into Foo's CMI > which means that importers don't see a definition for it at all. > >>> To fix this, this patch allows, as a special case for installing an >>> entity from a partition, to overwrite the entity_map entry with the >>> (later) index into the partition so that this assumption holds again. >> >> Rather than special-casing partitions, would it make sense to override a >> declaration with a definition? > > And so in this case I think that special-casing partitions is exactly > what needs to happen, because the special case is that it came from a > partition (rather than just it was a definition). > > That said, on further reflection I don't think I like the way I did > this, since it means that for this instantiation, errors will refer to > it as belonging to Foo:check instead of pr99377-3_a.H, which seems > wrong (or at least inconsistent with existing behaviour). Hmm, I don't think it's wrong; that's where the point of instantiation is, and this problem is about that same distinction. So I think I prefer the first patch, just correcting the use of "exported" as discussed above. OK with that change. Jason