Skip to content

[Scala3] Add Definition/Instance API#5277

Merged
adkian-sifive merged 5 commits into
mainfrom
adkian-sifive/scala3-di
May 5, 2026
Merged

[Scala3] Add Definition/Instance API#5277
adkian-sifive merged 5 commits into
mainfrom
adkian-sifive/scala3-di

Conversation

@adkian-sifive
Copy link
Copy Markdown
Member

@adkian-sifive adkian-sifive commented Apr 20, 2026

Tested locally with (a working subset of) InstanceSpec and DefinitionSpec - will move all tests once other unsupported APIs are ported

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)

Desired Merge Strategy

  • Squash: The PR will be squashed and merged (choose this if you have no preference).

Release Notes

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) and clean up the commit message.
    • Merge: Ensure that contributor has cleaned up their commit history, then merge with Create a merge commit.

@adkian-sifive adkian-sifive added the Scala 3 Changes related to upgrading to Scala 3 label Apr 20, 2026
@adkian-sifive adkian-sifive mentioned this pull request Apr 22, 2026
14 tasks
Comment thread core/src/main/scala-3/chisel3/experimental/hierarchy/IsA.scala
Comment thread core/src/main/scala-3/chisel3/experimental/hierarchy/IsA.scala
/** Determine whether underlying proto is of type provided.
*
* @note IMPORTANT: this function requires summoning a TypeTag[B], which will fail if B is an inner class.
* @note IMPORTANT: this function requires summoning a ClassTag[B], which will fail if B is an inner class.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this statement still true? I asked Opus 4.7 to review and it said ClassTags can be summoned for inner classes, can we add a test for this and delete the note?

There's also a chance that we could capture the ClassTag for A in Scala 3 that might be able to make this whole thing work a lot better and just use <:<. We can save that for a follow on PR though.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Another alternative is to use the new TypeTest, the following works:

case class Box[A](a: A) {
  def isA[B](using tt: TypeTest[A, B]): Boolean = tt.unapply(a).isDefined
}

Box(List(1, 2, 3)).isA[Seq[Int]] // true

That has same limitation about type parameterized types though. Maybe we should consider izumi-reflect?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ok I confirmed that ClassTags work with inner classes, updated comment. In general I agree the isA code can be refactored, we can discuss this for follow up work?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah I think refactoring is a future work thing.

Comment thread core/src/main/scala-3/chisel3/experimental/hierarchy/HierarchyLookup.scala Outdated
Comment on lines +83 to +84
case TypeBounds(lo, hi) if lo =:= hi => lo
case TypeBounds(_, hi) => hi
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Doesn't the 2nd line also implement the first line?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

hah, nice catch

@adkian-sifive adkian-sifive enabled auto-merge (squash) May 5, 2026 01:04
@adkian-sifive adkian-sifive merged commit 0b22734 into main May 5, 2026
28 checks passed
@adkian-sifive adkian-sifive deleted the adkian-sifive/scala3-di branch May 5, 2026 01:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scala 3 Changes related to upgrading to Scala 3

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants