llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

Extend `counted_by` support beyond struct fields

Open rapidsna opened this issue 1 year ago • 8 comments

Currently, counted_by and related attributes are only supported in struct fields. This issue tracks extending support to:

  • Function parameters
  • Return types
  • Global variables
  • Local variables

For typedef, support would only make sense if the attribute argument is a constexpr or constant literal.

rapidsna avatar Nov 10 '25 18:11 rapidsna

Hello! I plan to work on this issue. I have been reading the RFC and the Bounds Safety documentation to understand the intended semantics for the past couple of days.

To keep the work reviewable, I am planning on starting with function parameter support only and send an initial PR as Part of #167365. After, I plan follow-up with PRs for locals, globals, typedef, and then return types.

If there is any preferred order or there are any constraints I should be following for parameter semantics then please let me know

imvinlin avatar Feb 21 '26 10:02 imvinlin

Hello, I have been looking through the codebase over the past couple of days to add support for global and local variables, and I'm planning on opening a PR soon for global variables.

Holo-xy avatar Feb 22 '26 03:02 Holo-xy

@Vincent-Lin-UF @Holo-xy Hi thanks for your interest.

This issue depends on a large patch for proper late parsing of type attributes: github.com/llvm/llvm-project/pull/179612. Many features are blocked on this one.

As a follow-up, I'll need to backport it to the swiftlang repo. This will require refactoring to match the upstream PR and verify it works in the full bounds-safety context, since swiftlang took a different approach.

I'd prefer we start preparing other patches after this one; otherwise, we'll have to redo much of the work.

Once that's complete, I expect we can parallelize some of the upstream work.

Also, please let me know if you are interested in trying to back port github.com/llvm/llvm-project/pull/179612 to the swiftlang repo. We can discuss it separately.

rapidsna avatar Feb 23 '26 12:02 rapidsna

Also, please let me know if you are interested in trying to back port github.com//pull/179612 to the swiftlang repo. We can discuss it separately.

Yes, I’m interested in backporting it.

Holo-xy avatar Feb 23 '26 18:02 Holo-xy

Also, please let me know if you are interested in trying to back port github.com//pull/179612 to the swiftlang repo. We can discuss it separately.

Thanks for the context @rapidsna ! I’ll pause work on the counted_by extensions until #179612 is merged and backported.

I’m also interested in helping with the swiftlang backport. If you share the target branch, I can start preparing the backport and tests.

imvinlin avatar Feb 23 '26 21:02 imvinlin

Hey, I'd also like to help with the backporting to swiftlang repo.

abhijeetsharma200 avatar Feb 24 '26 07:02 abhijeetsharma200

Thanks everyone for your interest! After further consideration, back-porting #179612 would be too complex for a starter task, as it requires familiarity with -fbounds-safety functionality that hasn't yet been upstreamed.

If you're still looking to contribute, there are other back-porting/refactoring tasks that would make great starter issues:

github.com/swiftlang/llvm-project/issues/12435 github.com/swiftlang/llvm-project/issues/12436

Please let me know if you have any trouble assigning yourself to the issues or opening a PR!

rapidsna avatar Feb 25 '26 00:02 rapidsna

Thanks for the guidance @rapidsna ! That makes sense. I will take a look at both issues and pick one to work on. I will comment on the issue I choose so it is clear who is taking what

imvinlin avatar Feb 25 '26 00:02 imvinlin