2

I'm using sbt to build some of the riscv boom from the source code, but the sbt complains that it "could not find implicit value for parameter valName: : freechips.rocketchip.diplomacy.ValName". The detailed error message are as below:

[error] F:\hiMCU\my_proj\src\main\scala\freechips\rocketchip\tile\BaseTile.scala:170:42: could not find implicit value for parameter valName: freechips.rocketchip.diplomacy.ValName
[error] Error occurred in an application involving default arguments.
[error]   protected val tlMasterXbar = LazyModule(new TLXbar)

The code where sbt complains is as below:

abstract class BaseTile private (val crossing: ClockCrossingType, q: Parameters)
    extends LazyModule()(q)
    with CrossesToOnlyOneClockDomain
    with HasNonDiplomaticTileParameters
{
    // Public constructor alters Parameters to supply some legacy compatibility keys
    def this(tileParams: TileParams, crossing: ClockCrossingType, lookup: LookupByHartIdImpl, p: Parameters) = {
        this(crossing, p.alterMap(Map(
            TileKey -> tileParams,
            TileVisibilityNodeKey -> TLEphemeralNode()(ValName("tile_master")),
            LookupByHartId -> lookup
    )))
}

def module: BaseTileModuleImp[BaseTile]
def masterNode: TLOutwardNode
def slaveNode: TLInwardNode
def intInwardNode: IntInwardNode    // Interrupts to the core from external devices
def intOutwardNode: IntOutwardNode  // Interrupts from tile-internal devices (e.g. BEU)
def haltNode: IntOutwardNode        // Unrecoverable error has occurred; suggest reset
def ceaseNode: IntOutwardNode       // Tile has ceased to retire instructions
def wfiNode: IntOutwardNode         // Tile is waiting for an interrupt

protected val tlOtherMastersNode = TLIdentityNode()
protected val tlSlaveXbar = LazyModule(new TLXbar)
protected val tlMasterXbar = LazyModule(new TLXbar)
protected val intXbar = LazyModule(new IntXbar)
....
}

The LazyModule object code is as below:

object LazyModule
{
    protected[diplomacy] var scope: Option[LazyModule] = None
    private var index = 0

    def apply[T <: LazyModule](bc: T)(implicit valName: ValName, sourceInfo: SourceInfo): T = {
        // Make sure the user put LazyModule around modules in the correct order
        // If this require fails, probably some grandchild was missing a LazyModule
        // ... or you applied LazyModule twice
        require (scope.isDefined, s"LazyModule() applied to ${bc.name} twice ${sourceLine(sourceInfo)}")
        require (scope.get eq bc, s"LazyModule() applied to ${bc.name} before ${scope.get.name} ${sourceLine(sourceInfo)}")
        scope = bc.parent
        bc.info = sourceInfo
        if (!bc.suggestedNameVar.isDefined) bc.suggestName(valName.name)
        bc
    }
}

I think the sbt should find some val of type freechips.rocketchip.diplomacy.ValName, but it didn't find such kind of val.

jwvh
  • 50,871
  • 7
  • 38
  • 64

2 Answers2

0

You need to have an object of type ValName in the scope where your LazyModules are instantiated:

implicit val valName = ValName("MyXbars")

For more details on Scala's implicit please see https://docs.scala-lang.org/tutorials/tour/implicit-parameters.html.html

ɹɐʎɯɐʞ
  • 542
  • 5
  • 15
  • I have an object in another file ValName.scala, object ValName{ implicit def materialize(implicit x: ValNameImpl): ValName = ValName(x.name) } The ValName object and where the LazyModule are instantiated are in different files, but in the same package: package freechips.rocketchip.diplomacy. Will sbt use the object for the implicit parameter? – qqyang10110 Jul 26 '19 at 02:28
  • @qqyang10110 That other object would probably not be in scope, unless e.g. you import it. Best practice is to define the `implicit` objects as locally as possible. So I'd recommend you create a new instance. – ɹɐʎɯɐʞ Jul 26 '19 at 02:32
  • 1
    It it's the companion object of `ValName`, implicits of this type _will_ be looked up there, but there may be no implicit `ValNameImpl`. – Alexey Romanov Jul 26 '19 at 07:48
0

You generally shouldn't need to manually create a ValName, the Scala compiler can materialize them automatically based on the name of the val you're assigning the LazyModule to. You didn't include your imports in your example, but can you try importing ValName?

import freechips.rocketchip.diplomacy.ValName

In most of rocket-chip code, this is imported via wildcard importing everything in the diplomacy package

import freechips.rocketchip.diplomacy._
Jack Koenig
  • 5,840
  • 15
  • 21