chipsalliance / chipsalliance/rocket-chip

Does this line of code make any sense?

Open
#2,803 1 comment 0 reactions 0 assignees View on GitHub
question
Dominant language
Scala
Stars
3.9k
Forks
1.3k
Avg merge
5d 13m
Merged PRs (30d)
1

Description

https://github.com/chipsalliance/rocket-chip/blob/c095dbc8fd7b4097a0540266bac3336fdef4b0d4/src/main/scala/tilelink/BusWrapper.scala#L80

Inside the TLBusWrapper there are methods like `to` and `from`. IMO, using these APIS we can attach other TLMaster or Slaves to this bus. But I think the implmentation is very confusing:
```
def to[T](name: String)(body: => T): T = {
this { LazyScope(s"coupler_to_${name}", "TLInterconnectCoupler") { body } }
}
```
Inside the `to` method, the `this{}` is actually a call to the `LazyScope.apply({LazyScope(s"coupler_to_${name}", "TLInterconnectCoupler") { body } })`
and the `LazyScope(s"coupler_to_${name}", "TLInterconnectCoupler") { body })` will also call the `trait LazyScope.apply()`. **So, IMHO the trait LazyScope's apply method will be called exactly twice which doen not make any sense for me.** I wonder why you construct the code this way? Is there something I miss ?

@hcook @terpstra @sequencer @richardxia

Contributor guide

Open the contributing guide

Research direction

Read src/main/scala/tilelink/BusWrapper.scala around line 80, focusing on TLBusWrapper.to/from and the LazyScope.apply calls. Trace the two apply invocations and their surrounding scope behavior to determine whether this is intentional; done means the behavior is explained and any needed simplification or clarification is agreed.

Written by the indexing model from the issue text.

Assessment

Tech stack
scala
Domain
embedded-iot, tooling
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.