From 6ee8691d861578adba93a5f8ea571e6fb2e46f2c Mon Sep 17 00:00:00 2001 From: Daveed Vandevoorde Date: Mon, 9 Oct 2023 18:25:51 -0400 Subject: [PATCH 1/5] Initial structure for the paper I wrote some initial introductory material, and outlined a bit of the overall paper structure. --- 2996_reflection/reflection.md | 88 +++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/2996_reflection/reflection.md b/2996_reflection/reflection.md index 895d806e..907f40ab 100644 --- a/2996_reflection/reflection.md +++ b/2996_reflection/reflection.md @@ -11,3 +11,91 @@ toc: true --- # Introduction + +This is a proposal for a reduced initial set of features to support static reflection in C++. +Specifically, we are mostly proposing a subset of features suggested in P1240R2: + + - the representation of program elements via constant-expressions producing + _reflection values_ — _reflections_ for short — of an opaque type `std::meta::info`, + - a _reflection operator_ (prefix `^`) that produces a reflection value for its operand construct, + - a number of `consteval` _metafunctions_ to work with reflections (including deriving other reflections), and + - constructs called _splicers_ to produce grammatical elements from reflections (e.g., `[:` _refl_ `:]`). + +This proposal is not intended to be the end-game as far as reflection and compile-time +metaprogramming are concerned. Instead, we expect it will be a useful core around which more +powerful features can be added incrementally over time. In particular, we believe that most +or all the remaining features explored in P1240R2 and that code injection +(along the lines described in P2237R0) are desirable directions to pursue. + +Our choice to start with something smaller is primarily motivated by the belief that that +improves the chances of these facilities making it into the language sooner rather than +later. + + +## Why a single opaque reflection type? + +Perhaps the most common suggestion made regarding the framework outlined in P1240 is to +switch from the single `std::meta::info` type to a family of types covering various +language elements (e.g., `std::meta::variable`, `std::meta::type`, etc.). + +We believe that doing so would be mistake with very serious consequences for the future of C++. + +Specifically, it would codify the language design into the type system. We know from +experience that it has been quasi-impossible to change the semantics of standard types once they +were standardized, and there is no reason to think that such evolution would become easier in +the future. Suppose for example that we had standardized a reflection type `std::meta::variable` +in C++03 to represent what the standard called "variables" at the time. In C++11, the term +"variable" was extended to include "references". Such an change would have been difficult to +do given that C++ by then likely would have had plenty of code that depended on a type arrangement +around the more restricted definition of "variable". That scenario is clearly backward-looking, +but there is no reason to believe that similar changes might not be wanted in the future and we +strongly believe that it behooves us to avoid adding undue constraints on the evolution of the +language. + +Other advantages of a single opaque type include: + + - it makes no assumptions about the representation used within the implementation + (e.g., it doesn't advantage one compiler over another), + - it is trivially extensible (no types need to be added to represent additional + language elements and meta-elements as the language evolves), and + - it allows convenient collections of heterogeneous constructs without having + to surface reference semantics (e.g., a `std::vector` + can easily represent a mixed template argument list — containing types and + nontypes — without fear of slicing values). + +# Examples + +# Proposed Features + +## `std::meta::info` + +The type `std::meta::info` can be defined as follows: + +```c++ +namespace std { + namespace meta { + using info = decltype(^int); + } +} +``` + +In our initial proposal a value of type `std::meta::info` can represent: + + - an error + - any (C++) type and type-alias + - any function or member function + - any namespace-scope variable or any C++ static data member + - any nonstatic data member + - any constant value + - any template + +[ (DV) I'm currently excluding local variable representation. We can change that if we have a use for them that we feel must be in the initial core functionality. ] + +## The Reflection Operator (`^`) + + +## Splicers (`[:`...`:]`) + +## Metafunctions + + From 6bd2f798e822b519a6c6912b1c8146383cb0f9ef Mon Sep 17 00:00:00 2001 From: Daveed Vandevoorde Date: Tue, 10 Oct 2023 10:35:21 -0400 Subject: [PATCH 2/5] Update 2996_reflection/reflection.md Co-authored-by: Barry Revzin --- 2996_reflection/reflection.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/2996_reflection/reflection.md b/2996_reflection/reflection.md index 907f40ab..a86a1b34 100644 --- a/2996_reflection/reflection.md +++ b/2996_reflection/reflection.md @@ -13,7 +13,7 @@ toc: true # Introduction This is a proposal for a reduced initial set of features to support static reflection in C++. -Specifically, we are mostly proposing a subset of features suggested in P1240R2: +Specifically, we are mostly proposing a subset of features suggested in [@P1240R2]: - the representation of program elements via constant-expressions producing _reflection values_ — _reflections_ for short — of an opaque type `std::meta::info`, From 333938383edf4eb6341bba748d2cdf9b9bd297af Mon Sep 17 00:00:00 2001 From: Daveed Vandevoorde Date: Tue, 10 Oct 2023 10:35:32 -0400 Subject: [PATCH 3/5] Update 2996_reflection/reflection.md Co-authored-by: Barry Revzin --- 2996_reflection/reflection.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/2996_reflection/reflection.md b/2996_reflection/reflection.md index a86a1b34..881dc05b 100644 --- a/2996_reflection/reflection.md +++ b/2996_reflection/reflection.md @@ -19,7 +19,7 @@ Specifically, we are mostly proposing a subset of features suggested in [@P1240R _reflection values_ — _reflections_ for short — of an opaque type `std::meta::info`, - a _reflection operator_ (prefix `^`) that produces a reflection value for its operand construct, - a number of `consteval` _metafunctions_ to work with reflections (including deriving other reflections), and - - constructs called _splicers_ to produce grammatical elements from reflections (e.g., `[:` _refl_ `:]`). + - constructs called _splicers_ to produce grammatical elements from reflections (e.g., `[: $refl$ :]`). This proposal is not intended to be the end-game as far as reflection and compile-time metaprogramming are concerned. Instead, we expect it will be a useful core around which more From db5328d5aad474834d4dbdb7f6e8d612f27cd4dd Mon Sep 17 00:00:00 2001 From: Daveed Vandevoorde Date: Tue, 10 Oct 2023 10:35:41 -0400 Subject: [PATCH 4/5] Update 2996_reflection/reflection.md Co-authored-by: Barry Revzin --- 2996_reflection/reflection.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/2996_reflection/reflection.md b/2996_reflection/reflection.md index 881dc05b..b4a029b3 100644 --- a/2996_reflection/reflection.md +++ b/2996_reflection/reflection.md @@ -25,7 +25,7 @@ This proposal is not intended to be the end-game as far as reflection and compil metaprogramming are concerned. Instead, we expect it will be a useful core around which more powerful features can be added incrementally over time. In particular, we believe that most or all the remaining features explored in P1240R2 and that code injection -(along the lines described in P2237R0) are desirable directions to pursue. +(along the lines described in [@P2237R0]) are desirable directions to pursue. Our choice to start with something smaller is primarily motivated by the belief that that improves the chances of these facilities making it into the language sooner rather than From dcf7aa637c28806566f51ece417d0e8d0bae0bc1 Mon Sep 17 00:00:00 2001 From: Daveed Vandevoorde Date: Tue, 10 Oct 2023 10:37:04 -0400 Subject: [PATCH 5/5] Update 2996_reflection/reflection.md Co-authored-by: Barry Revzin --- 2996_reflection/reflection.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/2996_reflection/reflection.md b/2996_reflection/reflection.md index b4a029b3..0c65d59d 100644 --- a/2996_reflection/reflection.md +++ b/2996_reflection/reflection.md @@ -85,7 +85,7 @@ In our initial proposal a value of type `std::meta::info` can represent: - any (C++) type and type-alias - any function or member function - any namespace-scope variable or any C++ static data member - - any nonstatic data member + - any non-static data member - any constant value - any template