chisel icon indicating copy to clipboard operation
chisel copied to clipboard

Rework on SerializableModuleGenerator for abstract type.

Open sequencer opened this issue 2 years ago • 5 comments

The reason this API need to be rewritten is because SerializableModuleGenerator[_, _] cannot live in a collection(e.g. Seq, Map), since the types of SerializableModule and SerializableModuleParameter are unbounded.

Basically I replaced the type bound between SerializableModuleParameter and SerializableModule with concrete inner type: SerializableModule#SerializableModuleParameter. And type bound is not required anymore.

But I'm still struggling with the serialization version of SerializableModuleGenerator[_]:

FIXME: could not find implicit value for parameter e: upickle.default.Reader[Seq[chisel3.experimental.SerializableModuleGenerator[_ <: chisel3.experimental.SerializableModule]]]

This is a type gymnastics that I have been struggled for my evening...

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
  • API deprecation
  • Backend code generation
  • Performance improvement
  • Bugfix
  • Documentation or website-related
  • Dependency update
  • Internal or build-related (includes code refactoring/cleanup)

Desired Merge Strategy

  • Squash: The PR will be squashed and merged (choose this if you have no preference).
  • Rebase: You will rebase the PR onto master and it will be merged with a merge commit.

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.5.x, 3.6.x, or 5.x depending on impact, API modification or big change: 6.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.

sequencer avatar Jul 07 '23 18:07 sequencer

I encountered the deserialization problem in this PR: module and parameter are read from json via ujson at runtime.

which means we cannot use whichbox(macro) to construct it at compile time. So the only solution is runtime reflection.

I spent a whole day to find if there are any solution to instantiate a abstract class with type and implicit val in it. But found nothing...

I comes to doubt that there is no possibility for constructing the SerializableModuleGenerator at Scala runtime.

:melt:

sequencer avatar Jul 08 '23 16:07 sequencer

Maybe use scala plugin to traverse code and find all SerializableModule and create a companion concrete class SerializableGenerator, so that the scala reflection will have concrete class to construct.

sequencer avatar Jul 08 '23 17:07 sequencer

Ok this is still impossible even with the scala compiler plugin.
Since for Seq[SerModule], elements of which are from runtime, and there seems to be no way to pass the implicit parameter during the runtime...

sequencer avatar Jul 10 '23 05:07 sequencer

I wish Chisel could support Scala3 in the future, so that we can have the dependent type to resolve such issues.... We may need to consider switching to runtime json serdes lib like json4s

sequencer avatar Jul 10 '23 05:07 sequencer

@jackkoenig This was the draft PR which I mentioned in the dev meeting.

sequencer avatar Jul 11 '23 05:07 sequencer