-
Notifications
You must be signed in to change notification settings - Fork 260
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
[SUGGESTION] can we add a way to use attributes? #1252
Comments
Thanks for the suggestion! I haven't implemented attributes yet, but intend to. |
There might be some overlap with meta-functions and attributes. Maybe C++ attributes could be implemented as meta functions if they are allowed on if statements, expressions etc.
the meta-function would simply lower to if(condition) [[likely]] {
// ...
} else {
// ...
} |
What do you envision the meta function looking like in the case of @likely?
On 21 August 2024 19:30:42 Ezekiel Warren ***@***.***> wrote:
There might be some overlap with meta-functions and attributes. Maybe C++ attributes could be implemented as meta functions if they are allowed on if statements, expressions etc.
if condition @likely {
// ...
} else {
// ...
}
// or maybe it should be before the if
@likely if condition {
// ...
} else {
// ...
}
—
Reply to this email directly, view it on GitHub<#1252 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AALUZQNZX5S5ITIAOIQO5Z3ZSTME5AVCNFSM6AAAAABM34W6S6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMBSG4YTEMRZG4>.
You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
|
perhaps
|
uhm yes you can, you can add |
we actually should have both |
this suggestion was meant to be more generic though... I want to be able to add attributes to functions as well... and a way to add them so that it just works no matter the compiler or attribute I want to be able to use
and others as well |
Using metafunctions to add attributes makes a lot of sense IMO:
|
When all you have is a hammer, everything looks like a nail. I personally don't believe metafunctions / metaprograms are the right approach for attributes, as they are supposed to be hints for the implementation, rather than having big impact on the program you are writing (at least that's my perception). |
I agree that it makes sense to distinguish things that are just optimization hints which can be ignored from metafunctions which offer guarantees.
|
As always, the right answer is probably somewhere in the middle. If you are relying on a certain optimization (e.g. loop unrolling), it might be a better idea to write a little reflection tool that does that for you automatically so you get a stronger guarantee, and attributes remain for hinting the implementation. In this case I would say we need both and that they are orthogonal. I am curious what Herb thinks about completely subsuming attributes as part of the metafunction syntax, its an interesting take for sure. |
The line between what is just an optimization hint and what should have first class support can be blurry. For example, one can argue that loop unrolling is just an optimization and that this should be left to the compiler (maybe with the ability to add an attribute as a hint). static_for< 0, N >( [&]( auto i ){
some_regular_function_call( i.value );
some_template_function_call< i.value >();
} ); EDIT: it seems like you have mind-reading abilities @DyXel 😅 |
I don't see how a library can implement some of these features, at some point there must be some indication to the compiler, an [[attribute]] so to speak, is burying that in a meta function better than declaring it upfront?
On 22 August 2024 13:25:07 Alex Dutka ***@***.***> wrote:
Using metafunctions to add attributes makes a lot of sense IMO:
* it fits nicely in the "reducing the concept count" and "simplification through generalization" principles
* attributes can become a library feature rather than a core language thing, which enables the use of non-standard (user-defined or compiler-dependant) ones for special purposes
—
Reply to this email directly, view it on GitHub<#1252 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AALUZQJAYRPWG2BTYIYSV4TZSXKB7AVCNFSM6AAAAABM34W6S6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMBUGU2DANZQG4>.
You are receiving this because you commented.Message ID: ***@***.***>
|
I don't see why we must have an attribute syntax in cpp2 to emit cpp1 code with attributes. Am I missing something there? |
Conceptually, at some point, there must be something that the transpiler, reads and understands as an attribute, rather than code. I don't believe that reserving various meta function names to replace attributes is a good course of action.
On 22 August 2024 15:46:15 Alex Dutka ***@***.***> wrote:
I don't see how a library can implement some of these features
I don't see why we must have attributes in cpp2 to emit cpp1 code with attributes. Am I missing something there?
—
Reply to this email directly, view it on GitHub<#1252 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AALUZQKXW3FOJAHGLATM3ATZSX2THAVCNFSM6AAAAABM34W6S6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMBUHA2TQNBWG4>.
You are receiving this because you commented.Message ID: ***@***.***>
|
not to detract from C++ attributes too much here, but to expand the idea of "emitting cpp1" in a metafunction (which would cover C++ attributes) - the unreal engine has a sort of "attribute" that they decorate their classes and functions with that I think having an "emitting cpp1" feature could cover. for instance you could write an unreal engine class in cpp2 like this:
that would lower to this UCLASS()
class AMyActor : public AActor {
GENERATED_BODY()
}; |
Ideally, the metaclass would expand to whatever the macro expands to, not to the macro itself. Same idea with |
Totally agree, but it would be a really nice stepping stone. Especially for the unreal example above since if it could emit what I described it could be used today since it could use existing tools (unreal header tool, unreal build tool, etc.) |
I've been waiting on
|
I agree that we shouldn't abuse metafunctions. The likes of There are other features we don't have in Cpp2 yet.
|
I am not aware of any way to hint the branch predictor in the new syntax
I'd like to be able to use attributes, example cpp1 code:
The text was updated successfully, but these errors were encountered: