Skip to content

RFC: syntax for specifying properties for struct fields #35795

@vtjnash

Description

@vtjnash

We've have some open design questions from the past (#22649, #20415, #9448) of wanting to attach some properties to various fields of an object. Separately, while doing other work (and having need of this now), I ended up stumbling across a syntax that I feel I liked for this. It already parses, but currently has no meaning during lowering. To me, this looks like a parenthetical that describes the field, which is indeed what it is!

So, without further ado, here I show a random example struct (the actual names are nonsense), and apply various keyword attributes to some of the fields (also nonsense, but just to show some possibilities for how this could be used/useful):

mutable struct WrapPointedToThing{T} <: AbstractVector{T}
      # align the start to 64-bytes (a cache line) and then offset
      # by a pointer (to account for type tag)
      # and [only] supports atomic access
    rcounter(atomic, align=(64, Sys.WORD_SIZE / 8))::Int
      # aligned to 32-bytes (just because)
      # and also [only] supports atomic access
    wcounter(atomic, align=32)::Int
      # constant after initialization
    tag(readonly)::Symbol
      # constant also, and always a reference pointer
    something(noinline, readonly)::T
      # just a normal field
    lock::ReentrantLock
end

Thoughts? Reactions?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions