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

Fix Nested Instantiate #4018

Merged
merged 3 commits into from
Apr 24, 2024
Merged

Fix Nested Instantiate #4018

merged 3 commits into from
Apr 24, 2024

Conversation

sequencer
Copy link
Member

@sequencer sequencer commented Apr 19, 2024

When Instantiate a instantiable module, if it has other instantiable modules inside it, inner module will miss cache.

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

  • Bugfix

Desired Merge Strategy

  • Squash

Release Notes

Fix Nested Instantiate

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.

@sequencer sequencer changed the title Fix Instantiate Class Fix Nested Instantiate Apr 19, 2024
@sequencer sequencer force-pushed the instantiate-class branch 2 times, most recently from 1a5f6f9 to 30ee35d Compare April 19, 2024 22:42
Copy link
Member Author

@sequencer sequencer left a comment

Choose a reason for hiding this comment

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

This bug is because in each definition elaboration, previous elaborated definition and cache doesn't exist, so Definition/Instantiate inside other Definition never worked before.
This doesn't affect Module since it can be resolved by firtool dedup, but for Class, multiple Instantiate lead to different type: e.g. FooOM, FooOM_1, FooOM_2.

@@ -475,4 +491,12 @@ class InstantiateSpec extends ChiselFunSpec with Utils {
)
)
}

it("Nested Instantiate should work") {
Copy link
Member Author

Choose a reason for hiding this comment

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

Reproduce via:

mill chiselut[2.13.12].testOnly chiselTests.experimental.hierarchy.InstantiateSpec

Here is log:

List("Bar", "Bar_1", "Bar_2", "Bar_3", "Baz", "Baz_1", "Baz_2", "Baz_3", "Foo", "Foo_1", "Top") did not equal List("Bar", "Bar_1", "Baz", "Foo", "Foo_1", "Top")
ScalaTestFailureLocation: chiselTests.experimental.hierarchy.InstantiateSpec at (InstantiateSpec.scala:500)
Expected :List("Bar", "Bar_1", "Baz", "Foo", "Foo_1", "Top")
Actual   :List("Bar", "Bar_1", "Bar_2", "Bar_3", "Baz", "Baz_1", "Baz_2", "Baz_3", "Foo", "Foo_1", "Top")

@sequencer sequencer added Bugfix Fixes a bug, will be included in release notes Backport Automated backport, please consider for minor release Performance Improves performance, will be included in release notes labels Apr 19, 2024
@sequencer sequencer marked this pull request as ready for review April 19, 2024 22:49
@sequencer sequencer removed the Performance Improves performance, will be included in release notes label Apr 19, 2024
@mikeurbach
Copy link
Contributor

Thanks for the PR. I had been playing around with Instantiate and noticed this behavior, but I never got around to sending a PR or filing an issue. I took a quick look and I think this makes sense, I had something similar when I was trying to fix this on my end once.

@jackkoenig jackkoenig added this to the 3.6.x milestone Apr 20, 2024
@jackkoenig jackkoenig removed the Backport Automated backport, please consider for minor release label Apr 20, 2024
@sequencer sequencer added the Please Merge Accepted PRs that are ready to be merged. Useful when waiting on CI. label Apr 24, 2024
@chiselbot chiselbot merged commit 02b01e8 into main Apr 24, 2024
18 checks passed
@chiselbot chiselbot deleted the instantiate-class branch April 24, 2024 06:16
@mergify mergify bot added the Backported This PR has been backported label Apr 24, 2024
mergify bot pushed a commit that referenced this pull request Apr 24, 2024
* minimal reproduce Nested Instantiate bug

* expose cache and elaborated defination to inner defination

* fix up

(cherry picked from commit 02b01e8)

# Conflicts:
#	core/src/main/scala/chisel3/experimental/hierarchy/core/Definition.scala
#	core/src/main/scala/chisel3/experimental/hierarchy/core/Instance.scala
#	core/src/main/scala/chisel3/internal/Builder.scala
#	src/main/scala/chisel3/aop/injecting/InjectingAspect.scala
#	src/main/scala/chisel3/stage/phases/Elaborate.scala
#	src/test/scala/chiselTests/experimental/hierarchy/InstantiateSpec.scala
mergify bot pushed a commit that referenced this pull request Apr 24, 2024
* minimal reproduce Nested Instantiate bug

* expose cache and elaborated defination to inner defination

* fix up

(cherry picked from commit 02b01e8)

# Conflicts:
#	core/src/main/scala/chisel3/experimental/hierarchy/core/Definition.scala
#	core/src/main/scala/chisel3/experimental/hierarchy/core/Instance.scala
#	core/src/main/scala/chisel3/internal/Builder.scala
#	src/main/scala/chisel3/aop/injecting/InjectingAspect.scala
#	src/main/scala/chisel3/stage/phases/Elaborate.scala
mergify bot pushed a commit that referenced this pull request Apr 24, 2024
* minimal reproduce Nested Instantiate bug

* expose cache and elaborated defination to inner defination

* fix up

(cherry picked from commit 02b01e8)
@mergify mergify bot mentioned this pull request Apr 24, 2024
14 tasks
chiselbot pushed a commit that referenced this pull request Apr 24, 2024
* minimal reproduce Nested Instantiate bug

* expose cache and elaborated defination to inner defination

* fix up

(cherry picked from commit 02b01e8)

Co-authored-by: Jiuyang Liu <liu@jiuyang.me>
chiselbot pushed a commit that referenced this pull request May 2, 2024
* Fix Nested Instantiate (#4018)

* minimal reproduce Nested Instantiate bug

* expose cache and elaborated defination to inner defination

* fix up

(cherry picked from commit 02b01e8)

# Conflicts:
#	core/src/main/scala/chisel3/experimental/hierarchy/core/Definition.scala
#	core/src/main/scala/chisel3/experimental/hierarchy/core/Instance.scala
#	core/src/main/scala/chisel3/internal/Builder.scala
#	src/main/scala/chisel3/aop/injecting/InjectingAspect.scala
#	src/main/scala/chisel3/stage/phases/Elaborate.scala

* Resolve backport conflicts

---------

Co-authored-by: Jiuyang Liu <liu@jiuyang.me>
Co-authored-by: Jack Koenig <koenig@sifive.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backported This PR has been backported Bugfix Fixes a bug, will be included in release notes Please Merge Accepted PRs that are ready to be merged. Useful when waiting on CI.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants