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

Require target is hardware for Vec.apply(a: UInt) #1148

Merged
merged 1 commit into from
Aug 8, 2019

Conversation

seldridge
Copy link
Member

Adds a check that a Vec being indexed by a UInt is, in fact, a
hardware type. This includes a test for this.

h/t @schoeberl
cc: @aswaterman

Consider the following where a Chisel type Vec is indexed by a hardware type:

  property("Indexing a Chisel type Vec(Vec) should give a sane error message") {
    assertThrows[ExpectedHardwareException] {
      elaborate{
        new Module {
          val io = IO(new Bundle{})
          val foo = Vec(2, Bool())
          foo(0.U) := false.B
        }}
    }
  }

On master, this will generate:

[info] - Indexing a Chisel type Vec(Vec) should give a sane error message *** FAILED ***
[info]   java.util.NoSuchElementException: None.get
[info]   at scala.None$.get(Option.scala:349)
[info]   at scala.None$.get(Option.scala:347)
[info]   at chisel3.Data.direction(Data.scala:343)
[info]   at chisel3.Vec.do_apply(Aggregate.scala:224)
[info]   at chiselTests.VecSpec$$anon$15.<init>(Vec.scala:281)
[info]   at chiselTests.VecSpec.$anonfun$new$64(Vec.scala:278)
[info]   at chisel3.Module$.do_apply(Module.scala:53)
[info]   at chisel3.Driver$.$anonfun$elaborate$1(Driver.scala:94)
[info]   at chisel3.internal.Builder$.$anonfun$build$2(Builder.scala:352)
[info]   at scala.util.DynamicVariable.withValue(DynamicVariable.scala:58)
[info]   ...

This adds a check that the underlying Vec is a hardware type to prodcue:

[info] - Indexing a Chisel type Vec(Vec) should give a sane error message *** FAILED ***
[info]   chisel3.package$ExpectedHardwareException: vec 'Bool[2]' must be hardware, not a bare Chisel type. Perhaps you forgot to wrap it in Wire(_) or IO(_)?
[info]   at chisel3.internal.requireIsHardware$.apply(Binding.scala:20)
[info]   at chisel3.Vec.do_apply(Aggregate.scala:219)
[info]   at chiselTests.VecSpec$$anon$16.<init>(Vec.scala:281)
[info]   at chiselTests.VecSpec.$anonfun$new$64(Vec.scala:278)
[info]   at chisel3.Module$.do_apply(Module.scala:53)
[info]   at chisel3.Driver$.$anonfun$elaborate$1(Driver.scala:94)
[info]   at chisel3.internal.Builder$.$anonfun$build$2(Builder.scala:352)
[info]   at scala.util.DynamicVariable.withValue(DynamicVariable.scala:58)
[info]   at chisel3.internal.Builder$.$anonfun$build$1(Builder.scala:350)
[info]   at scala.util.DynamicVariable.withValue(DynamicVariable.scala:58)
[info]   ...

Related issue:

Type of change: other enhancement

Impact: no functional change

Development Phase: implementation

Release Notes

  • Improved error message if doing UInt indexing on a Chisel Vec

@seldridge seldridge requested a review from a team as a code owner August 7, 2019 22:07
Copy link
Member

@aswaterman aswaterman left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @seldridge

Adds a check that a Vec being indexed by a UInt is, in fact, a
hardware type. This includes a test for this.

Signed-off-by: Schuyler Eldridge <[email protected]>
@seldridge seldridge force-pushed the vec-vec-chisel-type-message branch from cdc09fa to 9e99adb Compare August 8, 2019 19:19
@seldridge seldridge merged commit 87a5755 into master Aug 8, 2019
@seldridge seldridge deleted the vec-vec-chisel-type-message branch August 13, 2019 01:04
jackkoenig pushed a commit that referenced this pull request Feb 28, 2023
* Avoid redundancy between CheckChirrtl and CheckHighForm, add more checks

* Add test case for illegal Chirrtl memory in HighForm
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.

2 participants