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<DB_IMPORTED_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.

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?

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?

Jason

Reply via email to