Skip to content

[Scala 3] restore SharedExtensions debug/reify macros#861

Open
halotukozak wants to merge 10 commits into
AVSystem:scala-3from
halotukozak:02-01-debug-reify
Open

[Scala 3] restore SharedExtensions debug/reify macros#861
halotukozak wants to merge 10 commits into
AVSystem:scala-3from
halotukozak:02-01-debug-reify

Conversation

@halotukozak

Copy link
Copy Markdown
Member

Summary

Restores the 10 SharedExtensions debug/reify macros via Scala 3 inline def + scala.quoted:

  • showAst, showRawAst, showSymbol, showSymbolFullName
  • showType, showRawType, showTypeSymbol, showTypeSymbolFullName
  • sourceCode, withSourceCode

Key changes

  • New file core/src/main/scala/com/avsystem/commons/macros/ShowMacros.scala — 10 quoted impls (def *Impl[A: Type](a: Expr[A])(using Quotes)).
  • SharedExtensions.scala — 10 ??? stubs replaced with inline def wrappers splicing 'a.
  • show* macros now use report.info (Scala 2 used c.error as a print-and-halt hack; Scala 3 has a proper info channel — print + proceed).
  • MIGRATION.md — 10 backlog rows removed; total tags 155 → 144.

Scala 3 semantic deviation

Because UniversalOps[A] is a value-class wrapper (class UniversalOps[A](private val a: A) extends AnyVal), the macro receiver Expr[A] references the synthetic constructor val rather than the original call-site argument. Position.sourceCode therefore returns None on a.asTerm.pos; we fall back to Position.ofMacroExpansion.sourceCode, which captures the full call expression (e.g. (1 + 2).sourceCode instead of 1 + 2). This is a behavioural narrowing vs Scala 2 and is documented inline in the impl + test.

Tests

SharedExtensionsShowTest adds 10 smoke cases covering pass-through semantics for all 8 show* methods plus sourceCode / withSourceCode shape.

Test plan

  • sbt commons-core/compile exit 0
  • sbt commons-core/Test/compile exit 0
  • sbt 'commons-core/testOnly com.avsystem.commons.SharedExtensionsShowTest' 10/10 pass
  • sbt scalafmtCheckAll scalafmtSbtCheck exit 0
  • No new @nowarn / -Wconf introduced

Branched off 01-big-bang (PR #860). Base set to scala-3 upstream.

@halotukozak halotukozak added this to the Scala 3 milestone Jun 1, 2026
@halotukozak halotukozak changed the title [Scala 3] Phase 02-01: restore SharedExtensions debug/reify macros [Scala 3] debug-reify: restore SharedExtensions debug/reify macros Jun 1, 2026
@halotukozak halotukozak changed the title [Scala 3] debug-reify: restore SharedExtensions debug/reify macros [Scala 3] restore SharedExtensions debug/reify macros Jun 1, 2026
@halotukozak halotukozak marked this pull request as ready for review June 1, 2026 14:39
@halotukozak halotukozak marked this pull request as draft June 1, 2026 14:46
@halotukozak halotukozak marked this pull request as ready for review June 1, 2026 14:57
- Add ShowMacros object with 10 quoted impls (showAst, showRawAst,
  showSymbol, showSymbolFullName, showType, showRawType, showTypeSymbol,
  showTypeSymbolFullName, sourceCode, withSourceCode).
- Replace 10 ??? stubs in UniversalOps[A] with inline def wrappers.
- show* macros use report.info (Scala 2 used c.error as a hack;
  Scala 3 has a proper info channel — print + proceed).
- New SharedExtensionsShowTest (10 cases) covering all 8 show* pass-through
  returns + sourceCode + withSourceCode.
- [Rule 1 — Bug] Surfaced by sourceCode test: receiver Expr inside
  UniversalOps wrapper has no source position (it points at the synthetic
  AnyVal constructor val). Added Position.ofMacroExpansion fallback so the
  call site is captured. Documented Scala 3 semantic deviation from Scala 2
  (call-site text instead of receiver-only text).
- Drop 10 backlog rows (SharedExtensions.scala:129-147) covering
  show*/sourceCode/withSourceCode now implemented via Scala 3 quotes.
- Update Total tags counter to 144 (was 155 — actual baseline was 154,
  see footnote; 154 - 10 = 144).
…alOpsMacros

- Drop separate ShowMacros.scala; impls now in UniversalOpsMacros next to
  SharedExtensions (still subpackage to avoid implicit-conversion conflict
  with package object's UniversalOps[A] extension methods)
- Use report.info(msg, expr) overload so position derives from the receiver
- Simplify sourceCode path: use Position.ofMacroExpansion.sourceCode directly
- show* / showRaw* / showType* impls now in `object UniversalOps` (companion of
  the value-class extension), placed in same file next to their `inline def`
- sourceCode / withSourceCode impls remain in a separate file
  (`commons.macros.UniversalOpsSourceMacros`) because the package object's
  auto-imported `universalOps` implicit makes `Position.sourceCode` recursively
  resolve to `UniversalOps.sourceCode` if placed in the same package
…thSourceCode impls in UniversalOps companion and update comments/docs
- showAst now uses treeInfo (Structure + ShortCode) — subsumes showRawAst
- showSymbol now uses symbolInfo (multi-line dump: fullName, flags, fields,
  methods, signature, etc.) — subsumes showSymbolFullName
- showType now uses typeReprInfo (widen, dealias, baseClasses, typeArgs, ...)
- showTypeSymbol now uses symbolInfo on typeSymbol — subsumes showTypeSymbolFullName
- showRawType kept for raw TypeReprStructure dump
- expand SharedExtensionsShowTest from 10 -> 65 tests covering primitives,
  collections, ADTs, generics, single-eval, chaining, source-code capture
… method

- Remove SharedExtensionsShowTest as its purpose is superseded by enhancements in the testing strategy.
- Drop the unused `debugMacro` method in SharedExtensions for simplification.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant