Skip to content

[DRAFT] Forward-port zinc bridge fixes to scala2-sbt-bridge (sbt/zinc#1316, #1324, #1507, #1782, #1803) - #134

Draft
retronym wants to merge 10 commits into
2.13.xfrom
bridge/2.13.x-s1-forward-ports
Draft

retronym wants to merge 10 commits into
2.13.xfrom
bridge/2.13.x-s1-forward-ports

Conversation

@retronym

@retronym retronym commented Oct 2, 2026 •

Copy link
Copy Markdown
Owner

Requested by Jason · project thread

Staging PR in retronym/scala. Work in progress. Its base is this fork's 2.13.x, synced to scala/scala 2.13.x at 8b318bf. It goes to scala/scala once reviewed here. This is S1 in the backport plan. S2, which ports the bridge side of sbt/zinc#1807 (AnalysisCallback4), waits on a zinc 1.12.x release.

Before: on Scala 2.13.12 and later, sbt and other build tools use scala2-sbt-bridge from this repo instead of zinc's own bridge. Several fixes made to zinc's bridge never reached it. That leaves both over-compilation (spurious invalidations from constructor default arguments, compound types recorded as inheritance, unstable type-lambda parameter names) and under-compilation (macro call sites not invalidated when a type argument changes).

After: scala2-sbt-bridge has those fixes, with unit tests where upstream had them.

Commit zinc PR Test
Invalidate macro client when type parameter changes sbt/zinc#1316 new DependencyTest case (upstream test is scripted only)
Avoid spurious recompilations when unrelated constructor with default argument changes sbt/zinc#1324 new ExtractAPITest case (upstream test is scripted only)
Precompile a regex in hot code zinc 9e0c6635 (follow-up to scala#1324) n/a
Exclude anon classes from dependency registration sbt/zinc#1507 (+ scala#1517 test) new DependencyTest case
Stabilize names of refinement-owned type parameters sbt/zinc#1782 ExtractAPITest, plus the sibling-refinement test from sbt/zinc@1e54146d8
Don't record parents in compound types as parents sbt/zinc#1803 DependencyTest

Deviations from upstream:

Test coverage beyond upstream:

To do: run zinc's scripted tests against a publishLocal'd bridge from this branch, using the sbt/zinc#1829 harness, so the pending-2.13 tests for these PRs should pass.

Friendseeker and others added 6 commits October 2, 2026 22:49
Forward-port of sbt/zinc#1316 (zinc develop merge cfd5081860).

Record dependencies on the type arguments passed to a macro as a
DependencyByMacroExpansion, so that changes to those types invalidate
call sites whose macro expansion depends on them.

Differences from upstream:
- Boolean literals passed to addTypeDependencies use named arguments
  (forMacro = ...) to avoid 2.13 lint warnings.
- No unit test: upstream only added scripted tests (macro-type-change-*).
… argument changes (sbt/zinc#1324)

Forward-port of sbt/zinc#1324 (zinc develop fc22a8e322).

Give constructor default-argument getters (`<init>$default$N`) a name that
includes the enclosing class and the argument index, so that default
getters of different classes' constructors do not collide in the API.

Differences from upstream:
- simpleName / simpleNameForMethod call `.decode.toString` because in 2.13's
  Global `Name#decode` is a String; the rest is identical.
- No unit test: upstream only added scripted tests.
Forward-port of zinc develop 9e0c663561, a follow-up to sbt/zinc#1324.

Follow-up to the sbt/zinc#1324 forward-port: compile the <init>$default$N
pattern once instead of on every method name.
Forward-port of sbt/zinc#1507 (zinc develop af2004f4f2).

Do not register a class dependency on an anonymous class. Before
scala#10940 an anonymous class could be the enclosing class of an
existential type symbol inferred from a refinement, producing a dependency
on a class name that does not exist. Also documents why a symbol may have
no associated file.

Includes the unit-test counterpart of the scripted test added in
sbt/zinc#1517 (source-dependencies/anon-class-dep).

Differences from upstream:
- The test from sbt/zinc#1517 is a scripted test (checkNumberOfLibraries),
  which has no equivalent here. It is adapted to a DependencyTest case
  asserting no anonymous-class dependency is recorded; with this repo's
  compiler (which already has scala#10940) it passes with or without
  the guard, so it is only a smoke test.
Forward-port of sbt/zinc#1782 (zinc develop 0f120a9f89).

Name a type parameter declared inside a refinement relative to the outermost
refinement class, because the pickler rewrites that class's owner and the
full name otherwise differs between compiling from source and unpickling,
flipping the API hash (sbt/sbt#1079).

Differences from upstream:
- The ported test only asserts SameAPI between the from-source and unpickled
  Impl; upstream also asserts on ShowAPI output (`<refinement>.a`), but
  ShowAPI is not available to scala/scala's junit tests.
  Verified the test fails without the ExtractAPI change.
sbt/zinc#1803)

Forward-port of sbt/zinc#1803 (zinc develop 738fc6e89b).

Traverse the parents of a CompoundTypeTree (`B with C`) as ordinary member
references instead of through the Template case, which treated them as
inheritance parents of the enclosing class.
@retronym
retronym changed the base branch from upstream-2.13.x to 2.13.x October 2, 2026 22:50
@retronym retronym self-assigned this Oct 2, 2026
@retronym
retronym force-pushed the bridge/2.13.x-s1-forward-ports branch from 2bb65b2 to bbbb372 Compare October 2, 2026 23:39
@retronym
retronym force-pushed the bridge/2.13.x-s1-forward-ports branch from bbbb372 to 27f5d88 Compare October 3, 2026 12:04
@retronym retronym changed the title Forward-port zinc bridge fixes to scala2-sbt-bridge (#1316, #1324, #1507, #1782, #1803) Forward-port zinc bridge fixes to scala2-sbt-bridge (sbt/zinc#1316, #1324, #1507, #1782, #1803) Oct 3, 2026
@retronym retronym changed the title Forward-port zinc bridge fixes to scala2-sbt-bridge (sbt/zinc#1316, #1324, #1507, #1782, #1803) [DRAFT] Forward-port zinc bridge fixes to scala2-sbt-bridge (sbt/zinc#1316, #1324, #1507, #1782, #1803) Oct 4, 2026
Upstream only has scripted tests for this. Compile a macro in one run
and call it with a type argument in a second run, then check that the
type argument is recorded as a DependencyByMacroExpansion dependency.
Upstream only has a scripted test for this. Check that each class's
constructor default getter is named after that class, instead of the
shared name `<init>$default$N`.
Since sbt/zinc#1782, a type parameter declared inside a refinement is
named relative to the outermost refinement, so the parameters of two
sibling type lambdas get the same name. A parameter is only referenced
inside its own refinement, so the API structure still tells them apart.
DependencyContext.DependencyByMacroExpansion only exists since Zinc
1.10. sbt 1.9.x also loads scala2-sbt-bridge for Scala 2.13.12+, so
reading it eagerly when the Dependency phase starts would fail every
compilation there with NoSuchFieldError. Like the AnalysisCallback3
guard in CallbackGlobal, catch the linkage error and record those
dependencies as DependencyByMemberRef instead.
@retronym
retronym force-pushed the bridge/2.13.x-s1-forward-ports branch from 21ff5e8 to b4ad445 Compare October 5, 2026 01:41

This branch has not been deployed

No deployments
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.

4 participants