This is an archive of the discontinued LLVM Phabricator instance.

[Sema] Return primary merged decl as canonical for concepts
ClosedPublic

Authored by ilya-biryukov on Jul 26 2022, 10:08 AM.

Details

Summary

Otherwise we get invalid results for ODR checks. See changed test for an
example: despite the fact that we merge the first concept, its uses
were considered different by Profile, leading to redefinition errors.

After this change, canonical decl for a concept can come from a
different module and may not be visible. This behavior looks suspicious,
but does not break any tests. We might want to add a mechanism to make
the canonical concept declaration visible if we find code that relies on
this invariant.

Also change the order of includes in the test. Importing a moduralized
header before its textual part causes the include guard macro to be
exported and the corresponding #include becomes a no-op.

Diff Detail

Event Timeline

ilya-biryukov created this revision.Jul 26 2022, 10:08 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 26 2022, 10:08 AM
ilya-biryukov requested review of this revision.Jul 26 2022, 10:08 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 26 2022, 10:08 AM

I wonder whether the right fix for this should generalize to Mergeable<T>.
The fact that Mergeable::getFirstDecl checks if the decl is coming from the AST file before looking up its primary merged decl is probably a performance optimization, not a deliberate semantic.

ChuanqiXu added a comment.EditedJul 26 2022, 8:51 PM

I wonder whether the right fix for this should generalize to Mergeable<T>.
The fact that Mergeable::getFirstDecl checks if the decl is coming from the AST file before looking up its primary merged decl is probably a performance optimization, not a deliberate semantic.

Agreed. I think we could omit the isFromASTFile part. But if we want to generalize to Mergeable<T>, we need to add much more tests. I think we could make it in future patches.

This revision is now accepted and ready to land.Jul 26 2022, 10:47 PM
  • set canonical decl as primary merged, add tests for the relevant failure

I wonder whether the right fix for this should generalize to Mergeable<T>.
The fact that Mergeable::getFirstDecl checks if the decl is coming from the AST file before looking up its primary merged decl is probably a performance optimization, not a deliberate semantic.

Agreed. I think we could omit the isFromASTFile part. But if we want to generalize to Mergeable<T>, we need to add much more tests. I think we could make it in future patches.

Totally agree, the Mergable change needs to be tested more thoroughly.
I have incorporated the getCanonicalDecl() call from your patch here and added test for the corresponding failure to merge-concepts.cpp too.
Otherwise my patch did not fix the failure I was encountering in practice (after I double-checked).

This revision was landed with ongoing or failed builds.Jul 27 2022, 3:31 AM
This revision was automatically updated to reflect the committed changes.