Post-merge fixes.

This commit is contained in:
Dan Katz
2024-09-17 20:09:54 -04:00
parent f4138861d9
commit e130488ee5
11 changed files with 39 additions and 16 deletions

View File

@@ -4,7 +4,7 @@ Clang/P2996 is a fork of the [llvm/llvm-project](https://github.com/llvm/llvm-pr
The Clang/P2996 fork is highly experimental; sharp edges abound and occasional crashes should be expected. Memory usage has not been optimized and is, in many cases, wasteful. **DO NOT use this project to build any artifacts destined for production.**
That said, this project represents one of the most complete known implementations of P2996 to date. It is possible to use Clang/P2996 to build nontrivial reflection-heavy programs. We encourage all interested parties to try it out, and we welcome any pull requests or feedback.
That said, this project represents the most complete implementation of P2996 to date. It is possible to use Clang/P2996 to build nontrivial reflection-heavy programs. We encourage all interested parties to try it out, and we welcome any pull requests or feedback.
The intent of this project is to continue tracking changes to P2996 as it makes its way through WG21's stages of development. That said, this is an aspiration and not a promise. The project is provided "as is." Subsequent development will be on a "best effort" basis, and we offer no guarantees as to its continued maintenance.
@@ -43,20 +43,24 @@ The initial implementation of Clang/P2996 was led by Dan Katz, with significant
The upstream LLVM project provides an excellent [Getting Started](https://llvm.org/docs/GettingStarted.html) guide with instructions for building `clang` and `libc++`. After building both of these targets, support for reflection can be enabled in Clang/P2996 by compiling with both the `-std=c++26` and `-freflection` flags.
The following additional experimental features can be enabled on top of `-freflection`:
- Metafunction extensions proposed for [P3096](https://wg21.link/p3096) (`-fparameter-reflection`).
- Parameter reflection as proposed by [P3096](https://wg21.link/p3096) (`-fparameter-reflection`).
- Partial support for expansion statements as proposed by [P1306](https://wg21.link/p1306) (`-fexpansion-statements`). Note that expansions over constexpr ranges are not supported.
- Consteval blocks as proposed by [P3289](https://wg21.link/p3289) (`-fconsteval-blocks`).
- Newly proposed reflection syntax from [P3381](https://wg21.link/p3381) (`-freflection-new-syntax`).
For convenience, a unified `-freflection-latest` flag enables all of these features. Note that this fork does not implement any features proposed by P3294 ("Code Injection with Token Sequences").
## Implementation status
At present, Clang/P2996 supports:
* Reflection over all entities supported by P2996 (i.e., types, functions, variables, class members, templates, namespaces, constant values)
* Splicing types, expressions, and namespaces
* All metafunctions propopsed by P2996 (except where noted in the [issue tracker](https://github.com/bloomberg/clang-p2996/issues))
* Reflection and splicing of all entities supported by P2996 (i.e., types, functions, variables, class members, templates, namespaces, constant values)
* All metafunctions propopsed by P2996
* P3096 metafunction extensions for function parameters (enabled with `-fparameter-reflection`)
* P1306 expansion statements over _expansion-init-lists_ and _destructurable expressions_
* P3289 `consteval` blocks
Any implemented language or library extensions that are _not_ candidates for inclusion in P2996 will be enabled by separate feature flags. Proposed features like expansion statements (i.e., `template for`) and non-transient `constexpr` allocation are not supported at this time. Any behaviors divergent from what is described by P2996, unless implemented experimentally for possible adoption by P2996, should be considered bugs.
One sharp edge worth mentioning is that our current implementation of P2996 metafunctions is regrettably resistant to proper AST serialization. As such, this compiler cannot, in its current state, be safely used to build precompiled headers or C++20 modules that contain reflection features. This is a difficult problem that is discussed in greater detail below. We are very interested in identifying a design that can elegantly address this issue.
Any implemented language or library extensions that are _not_ candidates for inclusion in P2996 are enabled by separate feature flags (as documented above). Any behaviors divergent from what is described by P2996, unless implemented experimentally for possible adoption by P2996, should be considered bugs.
### Incomplete features
Nearly all of P2996 is supported. We make an effort to keep the [issue tracker](https://github.com/bloomberg/clang-p2996/issues) updated with all known bugs, noncomformant behaviors, and missing features.
@@ -66,7 +70,7 @@ It has been our goal to provide a working compiler capable of building executabl
### P2996 test cases
A significant number of tests have been written for this project, covering both the reflection and splicing operators proposed for the core language and the various metafunctions proposed for the Standard Library (found [here](/clang/test/Reflection/) and [here](/libcxx/test/std/experimental/reflection/) respectively). Among these tests are many of the examples from the P2996 paper (e.g., "_Parsing Command-Line Options II_", "_Compile-Time Ticket Counter_", and "_Emulating Typeful Reflection_"). We expect for this body of tests to continue to grow, and hope that it may furthermore assist validation of future implementations of P2996.
At this time, our test cases only verify correct uses of P2996 facilities; that is, we have not yet written tests to validate expected diagnostics for ill-formed programs. As such, this is probably an area having a nontrivial number of bugs and crashes waiting to be discovered.
At this time, our test cases primarily verify correct uses of P2996 facilities; that is, we have not yet written tests to validate expected diagnostics for ill-formed programs. As such, this is probably an area having a nontrivial number of bugs and crashes waiting to be discovered.
## License

View File

@@ -2295,7 +2295,7 @@ APValue SourceLocExpr::EvaluateInContext(const ASTContext &Ctx,
// for it. Because we do not have access to Sema/function scopes here, we
// detect this case by relying on the fact such method doesn't yet have a
// type.
if (const auto *D = dyn_cast<CXXMethodDecl>(Context);
if (const auto *D = dyn_cast_if_present<CXXMethodDecl>(Context);
D && D->getFunctionTypeLoc().isNull() && isLambdaCallOperator(D))
Context = D->getParent()->getParent();

View File

@@ -313,7 +313,8 @@ TemplateNameDependence TemplateName::getDependence() const {
case NameKind::DependentTemplate: {
DependentTemplateName *S = getAsDependentTemplateName();
auto D = TemplateNameDependence::DependentInstantiation;
D |= toTemplateNameDependence(S->getQualifier()->getDependence());
if (!getAsDependentTemplateName()->isSpliceSpecifier())
D |= toTemplateNameDependence(S->getQualifier()->getDependence());
return D;
}
case NameKind::SubstTemplateTemplateParm: {

View File

@@ -54,6 +54,11 @@ prec::Level getBinOpPrecedence(tok::TokenKind Kind, bool GreaterThanIsOperator,
case tok::pipepipe: return prec::LogicalOr;
case tok::ampamp: return prec::LogicalAnd;
case tok::pipe: return prec::InclusiveOr;
// Accidental parsing of a bitwise-or followed by a block.
// Will be replaced with two carets during parsing.
case tok::caretcaret:
case tok::caret: return prec::ExclusiveOr;
case tok::amp: return prec::And;
case tok::exclaimequal:

View File

@@ -870,7 +870,7 @@ static bool findBaseSpecLoc(APValue &Result, ASTContext &C, EvalFn Evaluator,
SourceLocExpr *SLE =
new (C) SourceLocExpr(C, SourceLocIdentKind::SourceLocStruct,
ResultTy, B->getBeginLoc(), SourceLocation(),
nullptr);
B->getDerived());
return !Evaluator(Result, SLE, true);
}

View File

@@ -581,8 +581,11 @@ typedef __char32_t char32_t;
#define _LIBCPP_BEGIN_NAMESPACE_LFTS_V2 _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL inline namespace fundamentals_v2 {
#define _LIBCPP_END_NAMESPACE_LFTS_V2 } _LIBCPP_END_NAMESPACE_EXPERIMENTAL
#define _LIBCPP_BEGIN_NAMESPACE_META _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL inline namespace meta {
#define _LIBCPP_END_NAMEPSPACE_META } _LIBCPP_END_NAMESPACE_EXPERIMENTAL
#define _LIBCPP_BEGIN_NAMESPACE_META _LIBCPP_BEGIN_NAMESPACE_STD namespace meta {
#define _LIBCPP_END_NAMESPACE_META } _LIBCPP_END_NAMESPACE_STD
#define _LIBCPP_BEGIN_NAMESPACE_REFLECTION_V2 _LIBCPP_BEGIN_NAMESPACE_META inline namespace reflection_v2 {
#define _LIBCPP_END_NAMESPACE_REFLECTION_V2 } _LIBCPP_END_NAMESPACE_META
#ifdef _LIBCPP_ABI_NO_FILESYSTEM_INLINE_NAMESPACE
# define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM _LIBCPP_BEGIN_NAMESPACE_STD namespace filesystem {

View File

@@ -408,7 +408,7 @@ consteval auto annotate(info) -> info;
#define LIFT(x) ^x
#endif
_LIBCPP_BEGIN_NAMESPACE_META_V2
_LIBCPP_BEGIN_NAMESPACE_REFLECTION_V2
// An opaque handle to a reflected entity.
using info = decltype(LIFT(int));
@@ -2858,7 +2858,7 @@ consteval auto u8display_string_of(info R) -> u8string_view {
return detail::pretty_printer<char8_t>::print(R);
}
_LIBCPP_END_NAMESPACE_META_V2
_LIBCPP_END_NAMESPACE_REFLECTION_V2
#endif // __has_feature(reflection)

View File

@@ -21,6 +21,13 @@
// RUN: %{build}
// RUN: %{exec} %t.exe > %t.stdout
// The 'alisdair_universal_swap' test-case was broken by a change to libcxx's
// include/__memory/compressed_pair.h
// which gives 'vector<int>' a member having type 'char[0]'. Alisdair's
// existing cases are not sufficient to handle this, since 'char[0]' is "not
// an array" (in the strict sense implemented by 'std::is_array').
#define _LIBCPP_ABI_NO_COMPRESSED_PAIR_PADDING
#include <experimental/meta>
#include <algorithm>

View File

@@ -1,5 +1,6 @@
// FILE_DEPENDENCIES: example-module.cppm
//
// RUN: mkdir %t
// RUN: %{cxx} %{compile_flags} -std=c++26 \
// RUN: -freflection -freflection-new-syntax -fparameter-reflection \
// RUN: --precompile example-module.cppm -o %t/example-module.pcm

View File

@@ -17,6 +17,7 @@
//
// [reflection]
//
// RUN: ls /Users/dkatz85/src/bloomberg/clang-p2996/build-llvm/runtimes/runtimes-bins/libcxx/
// RUN: %{build}
// RUN: %{exec} %t.exe -n WG21 --count 5 > %t.stdout

View File

@@ -40,6 +40,7 @@ lit_header_restrictions = {
"cwchar": "// UNSUPPORTED: no-wide-characters",
"cwctype": "// UNSUPPORTED: no-wide-characters",
"experimental/iterator": "// UNSUPPORTED: c++03",
"experimental/meta": "// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23",
"experimental/propagate_const": "// UNSUPPORTED: c++03",
"experimental/simd": "// UNSUPPORTED: c++03",
"experimental/type_traits": "// UNSUPPORTED: c++03",