-
Notifications
You must be signed in to change notification settings - Fork 769
First attempt at __unique_stable_name #250
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This implementation uses the keyword __unique_stable_name as an operator that can take a type or expression, and will result in a constexpr constant character array that (hopefully) uniquely represents the type or type-of-expression being passed to it. The unique representation is the normal mangled name of the type, except in the cases of a lambda, where the ordinal "number" is just replaced with LINE->COL. Macro expansions are also appended with '~' followed by the LINE->COL that it appears in. For example, a lambda declared in 'main' would look like _ZTSZ4mainEUlvE25->12 (line 25, column 12). A Lambda that comes from a macro looks like: _ZTSZ4mainEUlvE45->3~18->32 (macro invoked on 45/3, lambda defined inside the macro on line 18, column 32). Template instantiations based on the lambda would result in a name that contains the lambda mangling, for example: _ZTSZ3bazIZ4mainEUlvE25->12EvvEUlvE14->12 A function template named 'baz' that is instantiated with a lambda declared in 'main' on line 25/col 12 has another macro in it, declared on line 14, column 12. Signed-off-by: Erich Keane <[email protected]>
+@hfinkel. |
Thanks, @bader (and @erichkeane )! Making the kernel names optional will really help our adoption of SYCL. Are you also working on Microsoft mangling support? As a quick note, your clang/test/CodeGenSYCL/unique-stable-name.cpp doesn't seem to test multiple nested macros. |
We don't require microsoft mangling, this is simply a "unique" and "stable" name that just so happens to be implemented in terms of the Itanium mangling structure. I'll add that test when I ge ta shot. |
Signed-off-by: Erich Keane <[email protected]>
4c30e4a
to
ddd09b0
Compare
@hfinkel Test Case Added. |
return E; | ||
|
||
return getSema().BuildUniqueStableName(E->getLocation(), SubExpr.get()); | ||
} else if (E->getIdentKind() == PredefinedExpr::UniqueStableNameType) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No else
after return
.
Signed-off-by: Erich Keane <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Super useful!
I would love more comments.
Add some documentation so it can land to https://clang.llvm.org/docs/LanguageExtensions.html
It would be nice to work with ISO C++ SG7 to have this feature in the standard.
@@ -436,6 +436,9 @@ KEYWORD(L__FUNCSIG__ , KEYMS) | |||
TYPE_TRAIT_1(__is_interface_class, IsInterfaceClass, KEYMS) | |||
TYPE_TRAIT_1(__is_sealed, IsSealed, KEYMS) | |||
|
|||
// Extensions for SYCL. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Elaborate the comment to say what it does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a category heading, it isn't directly associated with the keyword itself. If you see the rest of the file, that is the format of comments in this file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably, we can move this built-in to some "generic" clang built-ins category.
@@ -3205,6 +3205,65 @@ ExprResult Sema::BuildPredefinedExpr(SourceLocation Loc, | |||
|
|||
return PredefinedExpr::Create(Context, Loc, ResTy, IK, SL); | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 to Ronan's comment to add a new line here.
Signed-off-by: Erich Keane <[email protected]>
Patch incoming. A feature like this fits very well in with the Reflection work, though I haven't been participating in SG7 very much lately. This is implemented more like a builtin that would be used as a building block for such a proposal. As far as putting this in LangExtensions, Clang typically doesn't document builtins in lang-extensions. This is a building block for omitting the kernel name in SYCL functions, so I suspect this is best documented as a part of that. The intent of this patch is to unblock that kernel naming effort, so I suspect this is a first-of-many patch for this builtin. |
@erichkeane , we do, see https://clang.llvm.org/docs/LanguageExtensions.html#builtin-functions - and we should document this as well. Regarding a proposal for WG21, I'm happy to work with you and anyone else interested on a proposal. For those of you attending the next WG21 meeting, I'm also happy to chat about this in person. That seems useful. |
Huh, I've never documented one there before! I'll work on it then. As for the proposal, perhaps the 3 of us should discuss it in Cologne. I'd presume that we'd need to find a way to fit this into the Reflection TS/Reflection Constexpr proposals in a way that didn't look terrible. Additionally, we'd likely wish to propose an actual standardized naming convention here. This patch chooses a modified Itanium ABI, but any string would work. |
I will skip the Köln meeting unfortunately... :-( Belfast? |
Cya there. |
Signed-off-by: Erich Keane <[email protected]>
Interestingly, I got the reverse comment on the initial patch (that it was only necessary in SYCL mode).
On Sunday, June 30, 2019 rolandschulz <[email protected]> wrote:
@rolandschulz commented on this pull request.
In clang/include/clang/Basic/TokenKinds.def:
@@ -436,6 +436,9 @@ KEYWORD(L__FUNCSIG__ , KEYMS)
TYPE_TRAIT_1(__is_interface_class, IsInterfaceClass, KEYMS)
TYPE_TRAIT_1(__is_sealed, IsSealed, KEYMS)
+// Extensions for SYCL.
+KEYWORD(__unique_stable_name , KEYSYCL)
It is also needed in standard C++ mode for the host compilation.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Signed-off-by: Erich Keane <[email protected]>
@@ -436,6 +436,9 @@ KEYWORD(L__FUNCSIG__ , KEYMS) | |||
TYPE_TRAIT_1(__is_interface_class, IsInterfaceClass, KEYMS) | |||
TYPE_TRAIT_1(__is_sealed, IsSealed, KEYMS) | |||
|
|||
// Extensions for SYCL. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably, we can move this built-in to some "generic" clang built-ins category.
@@ -3205,6 +3205,65 @@ ExprResult Sema::BuildPredefinedExpr(SourceLocation Loc, | |||
|
|||
return PredefinedExpr::Create(Context, Loc, ResTy, IK, SL); | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 to Ronan's comment to add a new line here.
Signed-off-by: Erich Keane <[email protected]>
I'm not authorized to merge this pull request, so I don't know should be doing it. |
I'd like to wait a bit to see if other reviewers have additional comments to the latest version of the patch and if there are no objections, I'll merge this patch tomorrow. |
CONFLICT (content): Merge conflict in clang/lib/CodeGen/CGExpr.cpp
This implementation uses the keyword __unique_stable_name as an operator
that can take a type or expression, and will result in a constexpr
constant character array that (hopefully) uniquely represents the type
or type-of-expression being passed to it.
The unique representation is the normal mangled name of the type, except
in the cases of a lambda, where the ordinal "number" is just replaced
with LINE->COL. Macro expansions are also appended with '~' followed by
the LINE->COL that it appears in.
For example, a lambda declared in
'main' would look like _ZTSZ4mainEUlvE25->12 (line 25, column 12).
A Lambda that comes from a macro looks like:
_ZTSZ4mainEUlvE45->3~18->32 (macro invoked on 45/3, lambda defined
inside the macro on line 18, column 32).
Template instantiations based on the lambda would result in a name that
contains the lambda mangling, for example:
_ZTSZ3bazIZ4mainEUlvE25->12EvvEUlvE14->12
A function template named 'baz' that is instantiated with a lambda
declared in 'main' on line 25/col 12 has another macro in it, declared
on line 14, column 12.
Signed-off-by: Erich Keane [email protected]