└── README.md /README.md: -------------------------------------------------------------------------------- 1 | # Concepts ([P0734R0][1]) Implementation in Clang 2 | Roadmap for implementation of Concepts in the Clang compiler. 3 | 4 | ## Roadmap 5 | 6 | 1. There are no longer variable and function concepts, and using VarTemplateDecl to represent concepts is unnecessarily complex and would require many workarounds to prevent said variables from actually being instantiated. 7 | Therefore - remove the support for them (currently there is a flag in TemplateDecl and a 'concept' storage specifier, and a bunch of diagnostics which are no longer relevant). 8 | > Addressed in [D40380][2] 9 | 10 | 2. Add a new "ConceptDecl" AST node which represents a concept declaration. 11 | - inherits from TemplateDecl and not RedeclarableTemplateDecl, because concepts are not redeclarable. 12 | - stores an Expr \* representing the constraint expression in the function's body. 13 | > Addressed in [D40381][3] 14 | 15 | 3. Add code to parse "ConceptDecl"s. 16 | > Addressed in [D40381][3] 17 | 18 | 4. Add a new "ConceptSpecializationExpr" expression which is a concept name with template arguments, which stores a pointer to ConceptDecl and a TemplateArgumentListInfo. 19 | - when a ConceptSpecializationExpr is created without dependent template arguments, it is evaluated for satisfaction, the value stored within the object. 20 | - translate during constant evaluation and code generation to a bool. 21 | > Addressed in [D41217][4] 22 | 23 | 5. Add code to parse "ConceptSpecializationExpr"s. 24 | > Addressed in [D41217][4] 25 | 26 | - There was already a "RequiresClause" field (by means of TrailingObjects) added to TemplateParameterList. 27 | 28 | - There was already a "ConstrainedTemplateDeclInfo" struct which contains a TemplateParameterList and a ConstraintExpression added to TemplateDecl. 29 | Keep that for later caching a combined constraint expression with both the requires clause, constraints arising from constrained template parameters (a.k.a template\), and from trailing requires clauses on functions (a.k.a void foo() requires sizeof(int) == 4). 30 | 31 | 6. Remove ConstrainedTemplateDeclInfo from TemplateDecl constructors and instead create one in the constructor if there are any associated constraints in the TemplateParameterList passed in. 32 | > Addressed in [D41284][5] 33 | 34 | 7. Add ConstrainedTemplateDeclInfo to VarPartialSpecializationTemplateDecl and ClassPartialSpecializationTemplateDecl as well. 35 | > Addressed in [D41284][5] 36 | 37 | 8. Add a function to ClassPartialSpecializationTemplateDecl, VarPartialSpecializationTemplateDecl and TemplateDecl called 38 | "getAssociatedConstraints", which will return the total associated constraints, collected from all sources mentioned above (this method will not do any calculation/creation of "and" expressions - the expression should be created in the ctor of said classes if it requires calculation). 39 | > Addressed in [D41284][5] 40 | 41 | 9. Enforce RequiresClause on template specialization in the following functions: 42 | - CheckTemplateArgumentList which is ran before a primary template is instantiated with arguments. 43 | - ConvertDeducedTemplateArguments which is ran before partial specializations of all kinds are instantiated with arguments. 44 | - Both above functions will use a single template function which checks whether a bunch of arguments satisfy the constraints imposed by a 'templatedecl-like' object - it would basically instantiate the constraint expression returned by the object's getAssociatedConstraints() function. 45 | > Addressed in [D41569][6] 46 | 47 | 10. Create a function which given an Expr \* representing a constraint expression known to have not been satisfied, emits diagnostics as to why it wasn't (it would have special cases for BinaryOperators && and ||, as well as ConceptSpecializationExprs). 48 | Call this function in TemplateSpecCandidateSet::NoteCandidates when appropriate. 49 | > Addressed in [D41569][6] 50 | 51 | 11. Add code to isAtLeastAsSpecializedAs to regard constraint expressions (with partial ordering, subsumption and normalization). 52 | > Addressed in [D41910][7] 53 | 54 | 12. Add code to parse a trailing requires-clause in a function declaration. 55 | > Addressed in [D43357][8] 56 | 57 | 13. Add a ConstraintExpression field to FunctionDecl, add code to TemplateDecl to take the constraint into account (and store it in the constraint stored in ConstrainedTemplateDeclInfo). 58 | - Go over all places where FunctionDecls are created and make sure constraints are passed in if needed. 59 | > Addressed in [D43357][8] 60 | 61 | 14. Add name mangling for the added ConstraintExpression (which is now part of the signature). 62 | > On hold until itanium decides what the mangling's going to be. 63 | 64 | 15. Add ConstraintExpression checking for redeclarations of functions (consider whether or not the ConstraintExpression matches when determining if a function declaration is a redeclaration). 65 | > Addressed in [D43357][8] 66 | 67 | 16. Prohibit virtual functions from being declared with constraints. 68 | > Addressed in [D43357][8] 69 | 70 | 17. Change Sema::IsOverload to regard functions with matching signatures but different constraints as overloads. 71 | > Addressed in [D43357][8] 72 | 73 | 18. Make sure functions whose constraints are not satisfied cannot be referenced. 74 | > Addressed in [D43357][8] 75 | 76 | 19. Change addOverload and addTemplateOverload to disallow adding functions whose constraints are not met. 77 | > Addressed in [D43357][8] 78 | 79 | 20. Change isBetter to regard a candidate whose constraints subsume the other to be better. 80 | > Addressed in [D43357][8] 81 | 82 | 21. Add a ConstraintExpression field to TypeTemplateParmDecl, TemplateTemplateParmDecl and NonTypeTemplateParmDecl, to represent constraints imposed by 'constrained template parameters' (e.g. things such as template). 83 | > Addressed in [D44352][9] 84 | 85 | 22. Add a "calculateAssociatedConstraints" function to TemplateParameterList which returns the requires clause constraint-expression ANDed with all constrained template parameter's cosntraint-expressions, make TemplateDecl, VarPartialSpecializationTemplateDecl and ClassPartialSpecializationTemplateDecl use this function when calculating the associated constraints in TemplateDecl. 86 | > Addressed in [D44352][9] 87 | 88 | 23. Add code to parse constrained template parameters and generate the imposed constraint-expression, storing them in the created 89 | TemplateParameters. 90 | > Addressed in [D44352][9] 91 | 92 | 24. Add a new CXXRequiresExpr expression class (e.g. requires(T t) { t.foo(); }). 93 | > Addressed in [D50360][10] 94 | 95 | 25. Add code to parse CXXRequiresExpr expressions. 96 | > Addressed in [D50360][10] 97 | 98 | 26. Add code to the diagnostics functions we'd previously implemented to introspect into requires expressions which weren't satisfied to further explain why they weren't. 99 | > Addressed in [D50360][10] 100 | 101 | [1]: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0734r0.pdf 102 | [2]: https://reviews.llvm.org/D40380 103 | [3]: https://reviews.llvm.org/D40381 104 | [4]: https://reviews.llvm.org/D41217 105 | [5]: https://reviews.llvm.org/D41284 106 | [6]: https://reviews.llvm.org/D41569 107 | [7]: https://reviews.llvm.org/D41910 108 | [8]: https://reviews.llvm.org/D43357 109 | [9]: https://reviews.llvm.org/D44352 110 | [10]: https://reviews.llvm.org/D50360 111 | --------------------------------------------------------------------------------