I'd like to share my macro-related problems [Blog]

Just published my first technical blog post about solving the “method too large” error in Scala macros. If you’ve ever wondered how local methods are compiled or need to generate massive amounts of code at compile-time, this one’s for you!

The blog, unlike this topic, created without AI.

2 Likes

Hey, if you did use AI, you had me fooled. If you are actually an LLM yourself, congratulations on passing your first round Turing test. :grin:

1 Like

I initially thought I’d stop after just one blog post, but what wouldn’t a person do to avoid studying for their thesis defence? Part two is now live.
The post showcases a Scala 3 macro that extracts default parameter values from methods and provides type-safe field access via Selectable and Computed Field Names.
Read the full post here: Type-Safe Access to Method Parameter Defaults in Scala - halotukozak

2 Likes

Scala Type Class Derivation with (almost) no macros

Just published a deep dive on how Scala 3’s native Mirror API and compile-time utilities eliminate the need for heavy reflection or macro-heavy libraries.
I’ve taken GenCodecs from the AVSystem’s scala-commons library and implemented them in Scala 3.

Full post in my blog. Feedback welcome!

me: I should get some sleep before my thesis defense
also me: writes 1,500 words about compile-time metaprogramming

4 Likes

Mapping over Scala 3 tuples usually ends in a mess of asInstanceOf because Tuple.map is just too generic.
I’ve been playing with clause interleaving and match types to fix this. The result is a mapAs[T] extension that proves a tuple is homogeneous at compile-time with zero runtime overhead.
No more unsafe casts, just type-level proofs that actually work.

2 Likes

@halotukozak Very cool stuff!

It’s amazing to see Scala 3 features (extension, intersection, match type, interleaving etc.) helping to solve each step of the problem :smiley:

Do you think mapAs would be appropriate for standard library ?

2 Likes

Thanks!

Do you think mapAs would be appropriate for standard library ?

I don’t know, it’s a bit hacky. Maybe it would be better to integrate homogenous tuples into the language itself. But I wouldn’t mind to see mapAs equivalent in the stdlib :sweat_smile:

1 Like

Nice read! One comment about handling cycles: You don’t really need the Deferred wrapper as givens themselves are lazy, so you could just do:

inline def derived[T]: GenCodec[T] =
  given instance: GenCodec[T] = unsafeDerived[T]
  instance

(At least, this works fine for all my derivation code.)

2 Likes