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

DontCare Influences Type Inference #728

Closed
jackkoenig opened this issue Dec 8, 2017 · 2 comments
Closed

DontCare Influences Type Inference #728

jackkoenig opened this issue Dec 8, 2017 · 2 comments
Labels

Comments

@jackkoenig
Copy link
Contributor

Consider the following:

class DontCareTest extends Module {
  class Bun extends Bundle {
    val foo = UInt(8.W)
  }
  val io = IO(new Bundle {
    val uint = Output(UInt())
    val bun = Output(Valid(new Bun))
  })
  val uint = WireInit(UInt(8.W), DontCare)
  io.uint := uint

  val bun = WireInit(Valid(new Bun), DontCare)
  bun.valid := false.B
  io.bun := bun
}

This gives the following error:

[info] Compiling 1 Scala source to /Users/jack.koenig3/ucb-bar/chisel3-raw/target/scala-2.12/classes...
[error] /Users/jack.koenig3/ucb-bar/chisel3-raw/src/main/scala/DontCare.scala:16: value valid is not a member of chisel3.core.Data
[error]   bun.valid := false.B
[error]       ^
[error] one error found

The definition of WireInit.apply being:

def apply[T <: Data](t: T, init: T)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): T

Now changing the type of init to Data should fix this particular instance but this problem will pop up all over the place, including in libraries. Is there a way to tell the type system to ignore DontCare for type inference? @ducky64 @sdtwigg

@jackkoenig jackkoenig added the bug label Dec 8, 2017
@ducky64
Copy link
Contributor

ducky64 commented Dec 8, 2017

What other instances of this problem are there? := is already untyped, and changing init to type Data makes the WireInit equivalent to a Wire declaration followed by an untyped := connect.

I'd imagine it doesn't make any sense to initialize a register with DontCare, since Chisel doesn't complain about uninitialized Regs?

jackkoenig added a commit that referenced this issue Dec 8, 2017
Prevents DontCare from affecting type inference
Fixes #728
@jackkoenig
Copy link
Contributor Author

In library code if you accept both a t and an init it will do the same type inference and you'll get the same issue. That being said I don't think there's a fundamental fix other than "don't write bad library code".

jackkoenig added a commit that referenced this issue Dec 20, 2017
Prevents DontCare from affecting type inference
Fixes #728
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants