【问题标题】:sbt could not find implicit value for parameter valNamesbt 找不到参数 valName 的隐式值
【发布时间】:2019-12-04 08:01:10
【问题描述】:

我正在使用 sbt 从源代码构建一些 riscv 繁荣,但 sbt 抱怨它“找不到参数 valName::freechips.rocketchip.diplomacy.ValName 的隐含值”。详细的错误信息如下:

[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)

sbt 报错的代码如下:

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)
....
}

LazyModule 对象代码如下:

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
    }
}

我认为 sbt 应该找到一些类型为 freechips.rocketchip.diplomacy.ValName 的 val,但它没有找到这种类型的 val。

【问题讨论】:

    标签: scala implicit chisel rocket-chip


    【解决方案1】:

    您需要在您的LazyModules 实例化的范围内有一个ValName 类型的对象:

    implicit val valName = ValName("MyXbars")
    

    有关 Scala 隐式的更多详细信息,请参阅https://docs.scala-lang.org/tutorials/tour/implicit-parameters.html.html

    【讨论】:

    • 我在另一个文件 ValName.scala 中有一个对象,对象 ValName{implicit def materialize(implicit x: ValNameImpl): ValName = ValName(x.name) } ValName 对象和实例化 LazyModule 的位置位于不同的文件中,但在同一个包中:包 freechips.rocketchip.diplomacy。 sbt 会使用对象作为隐式参数吗?
    • @qqyang10110 其他对象可能不在范围内,除非例如你导入它。最佳实践是尽可能在本地定义implicit 对象。所以我建议你创建一个新实例。
    • 它是ValName的伴生对象,这种类型的隐含在那里查找,但可能没有隐含的ValNameImpl
    【解决方案2】:

    您通常不需要手动创建ValName,Scala 编译器可以根据您分配LazyModule 的值的名称自动实现它们。您的示例中没有包含您的导入,但您可以尝试导入 ValName 吗?

    import freechips.rocketchip.diplomacy.ValName
    

    在大多数火箭芯片代码中,这是通过通配符导入 diplomacy 包中的所有内容

    import freechips.rocketchip.diplomacy._
    

    【讨论】:

      猜你喜欢
      • 2021-02-03
      • 2017-02-02
      • 2016-01-17
      • 2011-10-17
      • 2016-03-31
      • 2015-01-27
      • 1970-01-01
      • 2016-02-27
      • 2016-02-22
      相关资源
      最近更新 更多