B-Lang-org / bsc

Bluespec Compiler (BSC)
Other
954 stars 146 forks source link

Implement type-level string append function #726

Open krame505 opened 3 months ago

krame505 commented 3 months ago

This adds a TApp type pseudo-constructor like TAdd and friends, for appending type-level strings.

quark17 commented 1 month ago

Looks good! I'm a tad concerned that TApp can be misread as type application (like BSC's TAp), but I'm not sure that I have a better suggestion.

mieszko commented 1 month ago

Looks good! I'm a tad concerned that TApp can be misread as type application (like BSC's TAp), but I'm not sure that I have a better suggestion.

Yeah TApp looks to me like application of some kind. Why not just TAppend? Unambiguous, and not too long.

krame505 commented 1 month ago

I went with TApp mostly for consistency, the other type-level functions are all abbreviated to 3 letters: TAdd, TSub, TMul, TDiv, TLog, TExp, TMax, TMin.

TAppend is a little more verbose. No strong objection, though.

quark17 commented 2 weeks ago

If we can decide on the name, then this can be merged. As far as consistency, note that the other type constructors are for numeric types. Another option for this one could be, say, TStrApp (which doesn't save any characters over TAppend). I have no strong objection to TAppend, but would feel better getting more opinions -- maybe we can discuss offline next week?

Can you confirm my understanding: This feature came up because it can be used with the other PR for splitting structs, but that PR doesn't include these commits? I get that this feature is generally useful, but I just wanted to understand any relationship/dependency between the PRs.

krame505 commented 2 weeks ago

I was originally planning to do the computation of names for split fields completely at the type level. I forget the exact blocking problem that I ran into with this approach, but I ultimately ended up doing the field name computation in the evaluator with ordinary type class methods instead. So this feature is not currently used by anything, but it seems like a good thing to have, for completeness.

Note that to make type-level string construction useful, we would probably also want to add a type-level primitive NumToStr :: # -> $.

krame505 commented 1 week ago

Meeting consensus: we'll call the primitives TStrCat and TNumToStr. We should also add a StrAlias type class, corresponding to Alias and NumAlias. We could have equivalent type classes StrCat and NumToStr, I'm not sure how useful these are however, with StrAlias.

I'll add these when I get around to it, hopefully before our next sync meeting.