Expose variable names to called function/initializer

In my exploration of a Swift-based hardware description language (HDL) DSL ala. Amaranth, SpinalHDL, and Chisel, one thing that consistently stands out as a usability limitation is the need to name a signal variable, then immediately type a name that is often identical into a string passed to the signal type's initializer so that it can know the name to generate in the final HDL.

In Amaranth this is implemented by using admittedly a "hack" of sorts to parse out the generated Python bytecode and extract the variable name being assigned when the type is created. SpinalHDL integrates a Scala compiler plugin that extracts the names during compilation. Chisel, meanwhile, implements a macro/compiler extension that works very similarly to my proposal for Swift where you can attribute a parameter to signify it should receive the identifier (at least this is my understanding).

It's my opinion that this would be a worthwhile feature to have in Swfit. I'm imagining being able to tag a function parameter as receiving the name of the assigned variable. Obviously DSL implementations like the ones I'm working on can benefit from this, but you could theoretically use this to extract identically named fields out of Dictionaries.


Could you add an example of what you're after using some pseudo-syntax?