[cfe-dev] Roadmap for a Concepts implementation P0734R0, currently merged into C++20 draft

Hubert Tong via cfe-dev cfe-dev at lists.llvm.org
Sat Nov 18 08:11:27 PST 2017


On Sat, Nov 18, 2017 at 5:02 AM, Saar Raz <saar at raz.email> wrote:

> Great to hear that you're willing to get this going too :)
>
> On Sat, Nov 18, 2017 at 3:41 AM Richard Smith <richard at metafoo.co.uk>
> wrote:
>
>> the result of evaluating a concept with a set of arguments may validly
>> change throughout the compilation of a program, so any notion of tracking /
>> caching concept specializations might not be workable. This needs more
>> analysis.
>>
> Can the value of a concept really change throughout the compilation of a
> program? Doesn't two phase lookup and the guarantee that templates cannot
> be further specialized after they've been instantiated guarantee this not
> to happen? ([temp.spec]p5.3)
>
Concepts are not instantiated. They are evaluated for satisfaction. Much of
the wording to allow "global" knowledge to be used for instantiating
templates relies on point-of-instantiation.

void foo(int, int);

template <typename T>
concept C = requires (T t) { ::foo(t); };

constexpr bool a = C<int>;

void foo(int, int = 0);
constexpr bool b = C<int>;

static_assert(a != b);


>
>
>> * Consider how constraint normalization and subsumption checking will fit
>> into the system. These are probably the two biggest pieces to design and
>> implement.
>>
> Well yes, I see a few challenges with normalization and subsumption -
> please give your input:
> 1. The paper introduces "conjunction" and "disjunction" as their own
> 'operators' that act on constraints. I guess the goal there was to avoid
> people overloading operator&& and operator||. A possible implementation we
> could do is take the expression as parsed, and replace BinaryOperator nodes
> with either the same BinaryOperator with its arguments wrapped with casts
> to bool, or create a new operator opcode and substituting that in. The
> former has the problem that those bool casts weren't really written by the
> user and will be confusing in diagnostics, and frankly do not conform to
> the paper as they would allow 'atomic constraints' to have a type other
> than bool that has a conversion to bool. The latter is probably the more
> correct solution but IDK how much work introducing a new operator is gonna
> be - any input on that?
>
My understanding is that it is viable for conjunction and disjunction to be
represented by && and || for satisfaction checking; it would be
context-dependent during the evaluation whether the node is within an
atomic constraint (and thus not representative of a conjunction or
disjunction). When checking for subsumption, the ordering ceases to matter
and likewise the contents of atomic constraints: a non-AST representation
would like be what is cached.


> 2. Regarding normalization - my roadmap already incorporates caching a
> 'complete' version of the constraint-expression, we might as well calculate
> a normalized version right there and then.
> 3. Normalization requires we break up ConceptSpecializationExprs into
> their constituents, which would circumvent our proposed caching of concept
> specializations if we were to then calculate the satisfaction of the
> normalized referencing concept. How about using the non-normalized version
> of the constraints to calculate the satisfaction and using the normalized
> version only for subsumption checking? Can you think of any non-conformance
> issues we get from this approach?
>
Normalizing only for subsumption checking sounds good.


> 4. If we're using the normalized version for subsumption checking only, we
> might as well delay the normalization to when we need to calculate
> subsumption.
>
Yes.


> 5. Should we or should we not cache the result of subsumptions? I tend to
> think that we should, what do you thing?
>
I think we should on the basis of candidate pairs. Of course, some
associated constraints may manifestly be such that they cannot be subsumed
except by themselves, and it would make sense to keep that as the first
thing to check.


>
>
>> * Decouple the implementation of requires-expressions from everything
>> else. I would be inclined to implement them first rather than last, but
>> that's up to whoever actually does the implementation work.
>>
> They are decoupled except for their required support of
> partial-concept-ids like so:
> requires (T t) {
>     { t.foo() }-> Same<bool>
> }
> So I'd rather implement them last after we have concept-ids.
>
That's also my inclination; just my 2 cents.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20171118/1a83d8e7/attachment-0001.html>


More information about the cfe-dev mailing list