[Scala 3] restore SharedExtensions debug/reify macros#861
Open
halotukozak wants to merge 10 commits into
Open
Conversation
d7270d1 to
9b66d44
Compare
- 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.
2efe8e2 to
7861adf
Compare
… documentation and declarations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Restores the 10 SharedExtensions debug/reify macros via Scala 3
inline def+scala.quoted:showAst,showRawAst,showSymbol,showSymbolFullNameshowType,showRawType,showTypeSymbol,showTypeSymbolFullNamesourceCode,withSourceCodeKey changes
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 withinline defwrappers splicing'a.show*macros now usereport.info(Scala 2 usedc.erroras 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 receiverExpr[A]references the synthetic constructor val rather than the original call-site argument.Position.sourceCodetherefore returnsNoneona.asTerm.pos; we fall back toPosition.ofMacroExpansion.sourceCode, which captures the full call expression (e.g.(1 + 2).sourceCodeinstead of1 + 2). This is a behavioural narrowing vs Scala 2 and is documented inline in the impl + test.Tests
SharedExtensionsShowTestadds 10 smoke cases covering pass-through semantics for all 8show*methods plussourceCode/withSourceCodeshape.Test plan
sbt commons-core/compileexit 0sbt commons-core/Test/compileexit 0sbt 'commons-core/testOnly com.avsystem.commons.SharedExtensionsShowTest'10/10 passsbt scalafmtCheckAll scalafmtSbtCheckexit 0@nowarn/-WconfintroducedBranched off
01-big-bang(PR #860). Base set toscala-3upstream.