Skip to content

Conversation

@jackkoenig
Copy link
Contributor

@jackkoenig jackkoenig commented Dec 9, 2025

I tried really hard to write a test for this, but I could not get it to work, even in our lit tests due to Mill sandboxing. I would like to revisit this at some point but I have spent too long on this at the moment.

Proof this works, try:

//> using scala 2.13.18
//> using dep org.chipsalliance::chisel:7.4.0
//> using plugin org.chipsalliance:::chisel-plugin:7.4.0

import chisel3._
import circt.stage.ChiselStage

class Foo extends Module {
  val foo, bar = IO(Input(UInt(8.W)))
  val out = IO(Output(UInt(8.W)))

  out := foo + bar(10, 0)
}

object Main extends App {
  println(ChiselStage.emitCHIRRTL(new Foo))
}

Output is:

[error] Users/koenig/work/chisel/tt/chisel-example.scala 12:19: High index 10 is out of range [0, 7]
[error] There were 1 error(s) during hardware elaboration.

Note the missing leading /, because we were stripping it in SourceInfoFileResolver.scala.

With publish local of this branch (7.4.0+18-4e05e9fc-SNAPSHOT):

[error] /Users/koenig/work/chisel/tt/chisel-example.scala 12:19: High index 10 is out of range [0, 7]
[error]   out := foo + bar(10, 0)
[error]                   ^
[error] There were 1 error(s) during hardware elaboration.

It might be worth simplifying /Users/koenig/work/chisel/tt/chisel-example.scala at error report time as well since scala-cli may compile in /, but it actually runs in the users current working directory.

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

The default behavior of Scala-cli is to use a Bloop server running in the root directory for compilation. This results in absolute paths in for source locators at compile time, but our logic had assumed we always had relative paths and was manually stripping the leading forward slash in source locator paths. Instead, we strip the leading forward slash for relative paths by including it in the path prefix we remove, and then in error reporting we add support for paths that are already absolute.

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) and clean up the commit message.
    • Merge: Ensure that contributor has cleaned up their commit history, then merge with Create a merge commit.

@jackkoenig jackkoenig added the Bugfix Fixes a bug, will be included in release notes label Dec 9, 2025
@jackkoenig jackkoenig force-pushed the jackkoenig/source-locator-scala-cli branch from 1042d3d to 4e05e9f Compare December 9, 2025 00:11
The default behavior of Scala-cli is to use a Bloop server running in
the root directory for compilation. This results in absolute paths in
for source locators at compile time, but our logic had assumed we always
had relative paths and was manually stripping the leading forward slash
in source locator paths. Instead, we strip the leading forward slash for
relative paths by including it in the path prefix we remove, and then in
error reporting we add support for paths that are already absolute.
@jackkoenig jackkoenig force-pushed the jackkoenig/source-locator-scala-cli branch from 4e05e9f to 6a43307 Compare December 9, 2025 00:45
@jackkoenig jackkoenig enabled auto-merge (squash) December 9, 2025 00:45
Copy link
Member

Choose a reason for hiding this comment

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

Nice.

@jackkoenig jackkoenig merged commit 25d2f7b into main Dec 9, 2025
28 of 30 checks passed
@jackkoenig jackkoenig deleted the jackkoenig/source-locator-scala-cli branch December 9, 2025 03:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bugfix Fixes a bug, will be included in release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants