Open
Conversation
12 tasks
Collaborator
|
I think this might be useful but am hesitant to add this unless we actually use it. Or did you plan to annotate the coming c api? |
Collaborator
|
also, in case swift would use the C++ api, would this be the right macros? looking at #893 (comment) it seems like they would need to do different things depending on compilation mode (switft/C++). |
Member
Author
|
@pauldreik I don't know. I just wanted us to consider that we can add these things if we want. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add lifetimebound and noescape attribute macros
Although simdutf currently has no use cases for the lifetimebound attribute, define a cross-compiler macro for it to enable potential future usage. This follows the evolving C++ lifetime profile proposals and provides compatibility with MSVC and Clang attributes where available.
Additionally, introduce a macro for Clang's noescape attribute. This attribute indicates that a pointer parameter does not escape the function scope, allowing optimizers to make stronger assumptions. Include detailed explanatory comments describing its purpose, valid and invalid usage examples, current limitations (Clang-only support, declarative only with no static enforcement), and restriction to pointer parameters.
These macros fall back to empty definitions on unsupported compilers to ensure portability.
Add lifetimebound and noescape attribute macros
Although simdutf currently has no use cases for the lifetimebound attribute, define a cross-compiler macro for it to enable potential future usage. This follows the evolving C++ lifetime profile proposals and provides compatibility with MSVC and Clang attributes where available.
The lifetimebound attribute indicates that a pointer (or reference) parameter or return value does not outlive the object it refers to. It helps compilers detect potential lifetime issues, such as dangling pointers or references, by enforcing that the lifetime of the pointed-to object extends at least as long as the function's result or any derived pointers. For example, it could be applied to a function returning a pointer into an input buffer:
An invalid use might return a pointer to a local variable, which the compiler could warn about if the attribute is present.
The noescape attribute signals that the function does not store the pointer (or anything derived from it) in a location accessible after the function returns, such as globals or heap allocations. This enables better optimizations, like assuming the pointer remains valid only within the call. A valid example is local access only:
An invalid example stores it globally:
These macros fall back to empty definitions on unsupported compilers to ensure portability.