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

Add partial cross-compilation for Scala 3 #4549

Merged
merged 31 commits into from
Dec 19, 2024
Merged

Conversation

adkian-sifive
Copy link
Contributor

@adkian-sifive adkian-sifive commented Dec 4, 2024

Adds initial support for Scala 3 with sources and reference to 3.3.3 LTS in the Mill build config.

This PR depends on #4467 which is (roughly) commit 0ba3c5, which are all the scala-2/ and scala/ changes visible in this PR. @jackkoenig and I need to determine whether those changes are necessary and either merge that PR first and rebase this on main, OR figure out an alternative.

I've added a CI test unit for Scala 3 compilation with Mill, @jackkoenig it probably needs your attention

Contributor Checklist

  • Did you add Scaladoc to every public function/method?
  • Did you add at least one test demonstrating the PR?
  • Did you delete any extraneous printlns/debugging code?
  • Did you specify the type of improvement?
  • Did you add appropriate documentation in docs/src?
  • Did you request a desired merge strategy?
  • Did you add text to be included in the Release Notes for this change?

Type of Improvement

  • Feature (or new API)
  • API modification
  • Internal or build-related (includes code refactoring/cleanup)

Desired Merge Strategy

  • Rebase: You will rebase the PR onto master and it will be merged with a merge commit.

Release Notes

Adds initial support for Scala 3 LTS version 3.3.3

Reviewer Checklist (only modified by reviewer)

  • Did you add the appropriate labels? (Select the most appropriate one based on the "Type of Improvement")
  • Did you mark the proper milestone (Bug fix: 3.6.x, 5.x, or 6.x depending on impact, API modification or big change: 7.0)?
  • Did you review?
  • Did you check whether all relevant Contributor checkboxes have been checked?
  • Did you do one of the following when ready to merge:
    • Squash: You/ the contributor Enable auto-merge (squash), clean up the commit message, and label with Please Merge.
    • Merge: Ensure that contributor has cleaned up their commit history, then merge with Create a merge commit.

@adkian-sifive adkian-sifive added Feature New feature, will be included in release notes API Modification Scala 3 Changes related to upgrading to Scala 3 and removed API Modification labels Dec 4, 2024
@adkian-sifive adkian-sifive force-pushed the adkian-sifive/scala3-v0.1 branch from fb521df to 725a184 Compare December 4, 2024 17:50
.github/workflows/test.yml Outdated Show resolved Hide resolved
build.sc Outdated Show resolved Hide resolved
build.sc Show resolved Hide resolved
core/src/main/scala-3/chisel3/Aggregate.scala Outdated Show resolved Hide resolved
core/src/main/scala-3/chisel3/Bits.scala Show resolved Hide resolved
core/src/main/scala-3/chisel3/Disable.scala Outdated Show resolved Hide resolved
Comment on lines +16 to +17
// TODO(adkian-sifive) the callsite here explicitly passes
// sourceInfo so it cannot be a contextual parameter
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment looks to be no longer true? But even if it were, you can always summon[_].

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so the comment here is referring to this callsite:

Module.do_apply(new ViewParentAPI)(UnlocatableSourceInfo)

i think we need the do_apply here? (same comment for below)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That callsight should call _applyImpl, that's the replacement for do_apply. This is the same thing as the other places where we got rid of do_ versions of things because we no longer need the macro on apply, we can just take a contextual parameter.

Comment on lines 18 to 19
def apply[T <: BaseModule](bc: => T): T = _applyImpl(bc)
def do_apply[T <: BaseModule](bc: => T)(implicit sourceInfo: SourceInfo): T = apply(bc)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def apply[T <: BaseModule](bc: => T): T = _applyImpl(bc)
def do_apply[T <: BaseModule](bc: => T)(implicit sourceInfo: SourceInfo): T = apply(bc)
def apply[T <: BaseModule](bc: => T)(using SourceInfo): T = _applyImpl(bc)

No do_apply and apply needs the context parameter.

core/src/main/scala-3/chisel3/Printf.scala Outdated Show resolved Hide resolved
@adkian-sifive adkian-sifive force-pushed the adkian-sifive/scala3-v0.1 branch 3 times, most recently from b07dc4a to 30d797f Compare December 12, 2024 01:47
Format code
Use compileAll in CI Mill compilation
Share def format
Refactor cross-compilation logic
@adkian-sifive adkian-sifive force-pushed the adkian-sifive/scala3-v0.1 branch from 3f5ca9d to 88cb4d3 Compare December 18, 2024 10:09
@adkian-sifive adkian-sifive force-pushed the adkian-sifive/scala3-v0.1 branch from a6046d8 to 0f72720 Compare December 18, 2024 20:07
@adkian-sifive adkian-sifive force-pushed the adkian-sifive/scala3-v0.1 branch from 0f72720 to 9a8b282 Compare December 18, 2024 20:11
Comment on lines 18 to 19
def apply[T <: BaseModule](bc: => T): T = _applyImpl(bc)
def do_apply[T <: BaseModule](bc: => T)(implicit sourceInfo: SourceInfo): T = apply(bc)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def apply[T <: BaseModule](bc: => T): T = _applyImpl(bc)
def do_apply[T <: BaseModule](bc: => T)(implicit sourceInfo: SourceInfo): T = apply(bc)
def apply[T <: BaseModule](bc: => T)(using sourceInfo: SourceInfo): T = _applyImpl(bc)

As mentioned above, change that Module.do_apply call in chisel/core/src/main/scala/chisel3/internal/package.scala to use _applyImpl.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so making this change + changing the Module.do_apply to Module._applyImpl in internal/package.scala throws this error

core/src/main/scala/chisel3/internal/package.scala:133:12: method _applyImpl in trait ObjectModuleImpl cannot be accessed as a member of object chisel3.Module from package object internal in package internal
[error]  Access to protected method _applyImpl not permitted because
[error]  enclosing package object internal in package internal is not a subclass of
[error]  trait ObjectModuleImpl in package chisel3 where target is defined
[error]     Module._applyImpl(new ViewParentAPI)(UnlocatableSourceInfo)
[error]            ^

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not really sure what subclassing requirement is not being satisfied here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm guessing it's cause _applyImpl is protected in ObjectModuleImpl?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, try making it protected[chisel3] instead

Comment on lines +9 to +35
object PrintfMacrosCompat {
private[chisel3] def printfWithReset(
pable: Printable
)(
using sourceInfo: SourceInfo
): chisel3.printf.Printf = {
var printfId: chisel3.printf.Printf = null
when(!Module.reset.asBool) {
printfId = printfWithoutReset(pable)
}
printfId
}

private[chisel3] def printfWithoutReset(
pable: Printable
)(
using sourceInfo: SourceInfo
): chisel3.printf.Printf = {
val clock = Builder.forcedClock
val printfId = new chisel3.printf.Printf(pable)

Printable.checkScope(pable)

pushCommand(chisel3.internal.firrtl.ir.Printf(printfId, sourceInfo, clock.ref, pable))
printfId
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wy is all of this code here instead of in src/main/scala? This is definitely code that we don't wan't duplicated as it's likely to need to change and that will cause bugs. There's an open PR touching similar code: #4504.

Comment on lines +20 to +34
def formatFailureMessage(
kind: String,
lineInfo: SourceLineInfo,
cond: Bool,
message: Option[Printable]
)(
using sourceInfo: SourceInfo
): Printable = {
val (filename, line) = lineInfo
val lineMsg = s"$filename:$line".replaceAll("%", "%%")
message match {
case Some(msg) =>
p"$kind failed: $msg\n"
case None => p"$kind failed at $lineMsg\n"
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this duplicated?

Comment on lines +14 to +25
// This code handles a special-case where, within an mdoc context, the type returned from
// scala reflection (typetag) looks different than when returned from java reflection.
// This function detects this case and reshapes the string to match.
private def modifyReplString(clz: String): String = {
if (clz != null) {
clz.split('.').toList match {
case "repl" :: "MdocSession" :: app :: rest => s"$app.this." + rest.mkString(".")
case other => clz
}
} else clz
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method should be in src/main/scala

@jackkoenig jackkoenig changed the title Add initial support for Scala 3 Add partial cross-compilation for Scala 3 Dec 19, 2024
@jackkoenig jackkoenig added this to the 7.0 milestone Dec 19, 2024
@jackkoenig jackkoenig enabled auto-merge (squash) December 19, 2024 22:27
Copy link
Contributor

@jackkoenig jackkoenig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's much more to do and I'm sure there will be issues we need to solve, but this is a huge step! Great work @adkian-sifive

FYI @sequencer

@jackkoenig jackkoenig merged commit 2d9c719 into main Dec 19, 2024
15 checks passed
@jackkoenig jackkoenig deleted the adkian-sifive/scala3-v0.1 branch December 19, 2024 22:27
@sequencer
Copy link
Member

Extraordinary work!
BTW, I’m trying to figure out a new types system and Scala 3 only design pattern and ask for public review before next Q1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New feature, will be included in release notes Scala 3 Changes related to upgrading to Scala 3
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants