Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build.mill files compiled by Scala 3 #3369

Open
wants to merge 23 commits into
base: main
Choose a base branch
from

Conversation

bishabosha
Copy link
Contributor

@bishabosha bishabosha commented Aug 13, 2024

This is work in progress to fix #3152

Numerous fixes were also needed to com-lihaoyi/mainargs, com-lihaoyi/sourcecode, and com-lihaoyi/mill-moduledefs

With the current state, only 1 example/integration tests is still failing:

  • integration.feature[plugin-classpath].local

known TODOs:

  • Discover macro
  • Applicative macro
  • Caller macro
  • Cross.Factory macro
  • EnclosingClass macro
  • Task macros
  • Cacher macro
  • Moduledefs compiler plugin (override inferrence)
  • All core Mill modules compile with Scala 3.5.0
  • Fix Zinc reporter patch linenumbers of build scripts
  • Check that bytecode analyzers work with Scala 3
  • cleanup library dependency conflicts
  • Support new Scala 3 syntax in build.sc files
  • Fix BSP reporter linenumbers for build scripts (Zinc reporter forwards to bsp)
  • Cleanup compiler warnings for outdated syntax

known incompatibilities:

  • can't use ExplicitResultTypes scalafix rule - need to upgrade mill-scalafix
  • Cross.scala uses the new quoted type syntax which scalafmt crashes on, (and version is frozen) so skip the file
  • skipping Mima currently due to 1000s of errors (perhaps we should generate filters?)
  • filtered one flaky test from example.thirdparty[mockito]
  • filtered out integration.feature[plugin-classpath] due to third party plugin dep

@lihaoyi
Copy link
Member

lihaoyi commented Aug 13, 2024

Thanks @bishabosha ! Lets get your mainargs changes landed, that way we can cut a release and you can test your WIP in CI

@lefou
Copy link
Member

lefou commented Aug 13, 2024

+1 for switching over to using directives!

@bishabosha
Copy link
Contributor Author

@bishabosha bishabosha force-pushed the scala3-build-sc branch 3 times, most recently from 9d1a986 to dc71022 Compare August 16, 2024 09:51
@bishabosha
Copy link
Contributor Author

bishabosha commented Aug 16, 2024

[Edit: after switching to depending on mainargs 0.7.2] in https://github.com/com-lihaoyi/mill/actions/runs/10418081276/job/28853542122?pr=3369 you can see integration tests like example/tasks/6-workers/local passing

@bishabosha
Copy link
Contributor Author

Rebased and included the new mill-moduledefs 0.11.0-M1

@bishabosha bishabosha force-pushed the scala3-build-sc branch 4 times, most recently from a06daca to 37ba541 Compare September 11, 2024 11:19
@bishabosha bishabosha force-pushed the scala3-build-sc branch 5 times, most recently from 917a024 to 78beea1 Compare September 17, 2024 18:59
@bishabosha
Copy link
Contributor Author

bishabosha commented Sep 18, 2024

@lihaoyi just recording here that the mockito third party test can be flaky (specifically StubbingLookupListenerCallbackTest.add_listeners_concurrently_sanity_check):

https://github.com/mockito/mockito/blob/1e337ed703ce2b78ce9ea40ff8b8c645f8219cf2/src/test/java/org/mockitousage/debugging/StubbingLookupListenerCallbackTest.java#L199-L202

as seen in the CI run https://github.com/com-lihaoyi/mill/actions/runs/10909315276/job/30277476457?pr=3369#step:9:4941

@bishabosha bishabosha force-pushed the scala3-build-sc branch 9 times, most recently from 022c789 to 368fec9 Compare September 20, 2024 23:18
@lihaoyi
Copy link
Member

lihaoyi commented Oct 13, 2024

@bishabosha got it. Could you open a discussion thread on https://github.com/scala/scala3 with your findings so far? If it turns out to be impossible to implement line-number/position fixing 100% correctly with Scala 3, then we don't have much of a choice, but we should make sure we have a discussion about it so that the upstream folks have a chance to add support for this use case in future

@lihaoyi
Copy link
Member

lihaoyi commented Oct 13, 2024

Seems like Ammonite does the bytecode postprocessing approach and scalacli does as well https://github.com/com-lihaoyi/Ammonite/blob/main/amm/compiler/src/main/scala-3/ammonite/compiler/AsmPositionUpdater.scala

@lefou
Copy link
Member

lefou commented Oct 14, 2024

If we can't access the full path from ASM, we could make the generated filename more special, e.g. by always appending a MillGenerated, then we can detect and handle it also from ASM.

@bishabosha
Copy link
Contributor Author

bishabosha commented Oct 14, 2024

So an ASM rewrite could be done the same-time/after methodCodeHashSignatures?

this would still mean semanticdb, tasty will be wrong.

plugin could still handle rewriting sourcecode.{Line, FileName}.

Edit: Right, I guess you can propose a compiler plugin that does the correct position rewrite, so that all those things are correct, and then an Additional ASM post processor that has to correct the corrected-but-still-wrong class line numbers.
At which point perhaps line-numbers plugin with two phases would work

@bishabosha
Copy link
Contributor Author

bishabosha commented Oct 14, 2024

My other solution: patch ASAP in compiler in backend the ability to trust positions in the code - I looked in the Scala 2 implementation and it accounts for "underlying" sourcefiles

Edit: I quickly prototyped this fix to dotty in scala/scala3#21763, and used it in my linenumbers mill branch and it works - meaning that the linenumber plugin can be very simple - and no double remapping in the zinc reporter (still need one remapping for typing errors)

Edit 2: added a test with a similar plugin design

- use Scala 3.5.0
- add Scala 3 dialect to scalafmt.conf
- synthesize Mirrors from macro
- remove some warnings
- run scalafmt on previous code
- use scala 3 version of scalatags in test
  Note: scalatags brings in scala 2 version of sourcecode transitively,
  which then fails to summon sourcecode.Enclosing.
- re-enable jmh, bsp and testkit modules in integration tests
- fix giter8 module resolution with scala 3
- fix compilation of scalalib tests - derive ReadWriter for PomSettings
- fix compilation of scalajslib tests
- fix compilation of scalanativelib tests
- move things-outside-top-level-module to integration.feature
- resolve scala-library when mill scala version is 3.x
- add given imports
- add import mill.given
- fix summon of Discover in CodeGen
- fix scanning of Cross modules in Discover macro
- improvement: check factory value matches crossValueN
enhancement to zinc reporter and avoid mangling ansi escapes
- update com-lihaoyi/sourcecode to use new macro implementation
- fix callgraph 4-actors test: account for private[this] inferrence
- fix - callgraph 8-linked-list-scala test: account for new override semantics
- fix 5-parser codesig test to account for new expansion
- use custom SAM type in lambda tests for scala (specialisation dropped in scala 3)
- tweak CodeSig ignoreCall logic to account for Scala 3 lambdas
- update some dependencies so invalidation tests actually run
- fix indentation in codesig tests
- In Scala 3 an implicitly inserted else branch will not be implicitly converted
  to the type of the then branch, so use explicit else branch with NodeSeq.Empty
- create and load scala compiler worker from MillMain
- splitScript (mill scripts are a compilation unit where top stats are a template stat sequence)
- cached initCtx
- tested concurrent parsing
- bin-pack comma separated import clauses into one
- extract ImportTree from import code snippets
- extract ObjectData from object code snippets
- patch end marker of wrapper object
- splice millDiscover into wrapper object after last statement
- add passing scala-3-syntax test
- account for code splice offset in ZincWorkerImpl reporter
new bootstrap patch

remake patch

regenerate patch

correct bootstrap patch

new rebootstrap patch

regen bootstrap

regenerate bootstrap patch again

regenerate patch
@bishabosha
Copy link
Contributor Author

so the compiler backend fix was merged

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.

Migrate build.sc to Scala 3
5 participants