This is an archive of the discontinued LLVM Phabricator instance.

[C++20] [Modules] [Concepts] Recognize same concepts more precisely in Serialization
ClosedPublic

Authored by ChuanqiXu on Nov 29 2021, 10:13 PM.

Details

Summary

When we use concept in modules, we would meet a curious error. For example:

C++
// foo.h
#ifndef FOO_H
#define FOO_H

template< class T >
concept Range = requires(T& t) {
  t.begin();
};

namespace workspace {
    struct A {
        public:
            template <Range T>
            using range_type = T;
    };
}

#endif
// A.cppm
module;
#include "foo.h"
export module A;
// B.cppm
module;
#include "foo.h"
export module B;
import A;

The compiler would tell us that the definition of workspace::A::range_type in B.cppm is not the same with the one in A.cppm!
The reason here is that the implementation would judge two concepts is same by their addresses. However, when we use modules, the addresses wouldn't be the same all the time since one is parsed in their TU and another is imported in another TU.
This patch fixes this by using isSameEntity to judge the two concepts. I think it should be a good fix.

Test Plan: check-all

Diff Detail

Event Timeline

ChuanqiXu requested review of this revision.Nov 29 2021, 10:13 PM
ChuanqiXu created this revision.

Clean code.

ChuanqiXu planned changes to this revision.Nov 30 2021, 3:55 AM
ChuanqiXu updated this revision to Diff 390668.Nov 30 2021, 5:09 AM

Fix tests under Debug mode. I need to remember run debug tests : (

ChuanqiXu updated this revision to Diff 390878.Nov 30 2021, 6:02 PM

Format codes.

rsmith accepted this revision.Dec 7 2021, 6:34 PM
This revision is now accepted and ready to land.Dec 7 2021, 6:34 PM