Skip to content
This repository has been archived by the owner on Aug 20, 2024. It is now read-only.

Fix serialization of whens with empty blocks #2560

Merged
merged 1 commit into from
Sep 22, 2022

Conversation

jackkoenig
Copy link
Contributor

@jackkoenig jackkoenig commented Sep 22, 2022

Also get rid of whitespace-only lines that were emitted after every when block.

This fixes 2 bugs (1 functional, 1 just a little ugly):

  1. Whens with empty Blocks (ie. Block(Seq())) were emitting with just an empty line, this fixes it to have a skip
  2. The line after a when was blank (except it had the same number of spaces as the indenting in the when block)

This is best illustrated with some simple Chisel

class Example extends RawModule {
  val a, b = IO(Input(UInt(8.W)))
  val c, d = IO(Output(UInt(8.W)))

  d := b
  when (a === b) {
  }
  c := a
}

Emitted with spaces replaced by _ to visualize whitespace

Current master/1.5.x (Chisel 3.5-SNAPSHOT Scastie):

__module_Example_:
____input_a_:_UInt<8>
____input_b_:_UInt<8>
____output_c_:_UInt<8>
____output_d_:_UInt<8>

____d_<=_b
____node__T_=_eq(a,_b)
____
____when__T_:
______
____c_<=_a

This PR:

__module_Example_:
____input_a_:_UInt<8>
____input_b_:_UInt<8>
____output_c_:_UInt<8>
____output_d_:_UInt<8>

____d_<=_b
____node__T_=_eq(a,_b)
____when__T_:
______skip
____c_<=_a

Which matches the behavior of 3.5.4 (3.5.4 Scastie).

Contributor Checklist

  • [NA] Did you add Scaladoc to every public function/method?
  • [NA] Did you update the FIRRTL spec to include every new feature/behavior?
  • 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 state the API impact?
  • Did you specify the code generation impact?
  • Did you request a desired merge strategy?
  • [NA] Did you add text to be included in the Release Notes for this change?

Fix for unreleased bug so no need for release notes.

Type of Improvement

  • bug fix

API Impact

No impact

Backend Code Generation Impact

This fixes emission of .fir

Desired Merge Strategy

  • Squash

Release Notes

Reviewer Checklist (only modified by reviewer)

  • Did you add the appropriate labels?
  • Did you mark the proper milestone (1.2.x, 1.3.0, 1.4.0) ?
  • Did you review?
  • Did you check whether all relevant Contributor checkboxes have been checked?
  • Did you mark as Please Merge?

@jackkoenig jackkoenig added this to the 1.5.x milestone Sep 22, 2022
Copy link
Member

@seldridge seldridge left a comment

Choose a reason for hiding this comment

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

This looks fine.

Would it be even better to just not emit the when at all in this case as opposed to an empty when?

Also get rid of whitespace-only lines that were emitted after every when
block.
@jackkoenig jackkoenig force-pushed the fix-when-serialization branch from 03cd8c5 to f252b38 Compare September 22, 2022 22:42
@jackkoenig
Copy link
Contributor Author

Would it be even better to just not emit the when at all in this case as opposed to an empty when?

Perhaps, but this PR is just fixing a bug, restoring the old behavior.

It's also arguably good to have the empty when for debugging your Chisel by looking at the .fir, but anyway, beyond the scope of this PR.

@jackkoenig jackkoenig enabled auto-merge (squash) September 22, 2022 22:45
@jackkoenig jackkoenig disabled auto-merge September 22, 2022 22:51
@jackkoenig jackkoenig merged commit 79c17c8 into master Sep 22, 2022
@jackkoenig jackkoenig deleted the fix-when-serialization branch September 22, 2022 23:00
mergify bot pushed a commit that referenced this pull request Sep 22, 2022
Also get rid of whitespace-only lines that were emitted after every when
block.

(cherry picked from commit 79c17c8)
@mergify mergify bot added the Backported This PR has been backported to marked stable branch label Sep 22, 2022
mergify bot added a commit that referenced this pull request Sep 22, 2022
Also get rid of whitespace-only lines that were emitted after every when
block.

(cherry picked from commit 79c17c8)

Co-authored-by: Jack Koenig <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Backported This PR has been backported to marked stable branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants