Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate auto-application of empty argument lists to parameterless functions #2124

Merged

Conversation

jared-barocsi
Copy link
Contributor

Scala 3 now enforces a distinction between nullary parameter-less functions and nullary functions with empty argument lists. Previously, Scala 2 would auto-apply an empty parameter list onto any invocation of a nullary parameter-less function.

As such, in order to migrate to Scala 3, any nullary function that doesn't induce a side effect, e.g. asUInt, must not include a parameter list in its invocation. To deprecate the use of empty parameter lists for these functions, dummy versions of these functions are included which explicitly allow use of an empty parameter list (for example, a default dummy argument or a vararg).

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 state the API impact?
  • Did you specify the code generation impact?
  • Did you request a desired merge strategy?
  • Did you add text to be included in the Release Notes for this change?

Type of Improvement

code refactoring

API Impact

No effect

Backend Code Generation Impact

No impact

Desired Merge Strategy

Squash and merge

Release Notes

Reviewer Checklist (only modified by reviewer)

  • Did you add the appropriate labels?
  • Did you mark the proper milestone (Bug fix: 3.3.x, [small] API extension: 3.4.x, API modification or big change: 3.5.0)?
  • Did you review?
  • Did you check whether all relevant Contributor checkboxes have been checked?
  • Did you mark as Please Merge?

@jared-barocsi jared-barocsi marked this pull request as ready for review September 16, 2021 20:02
@davidbiancolin
Copy link
Contributor

Inb4 "asUInt does have a side effect".

@aswaterman
Copy link
Member

Inb4 "asUInt does have a side effect".

trigger warning

@jackkoenig
Copy link
Contributor

Inb4 "asUInt does have a side effect".

Go away.

In all seriousness though for anyone wondering though--while basically any Chisel API does have side effects, we go to great lengths to hide those side effects from the user such that Chisel APIs appear to be side effect free and therefore will follow the Scala style of not having parentheses.

Copy link
Contributor

@jackkoenig jackkoenig left a comment

Choose a reason for hiding this comment

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

Please follow Megan's suggestion on the deprecation messages (ie. they need to tell the user what to do). As I said in the comment, I don't think they need to mention the name of the method, but do need to say something like "use form without parentheses" or "use form of method without parentheses" or something.

Please also make the dummy argument style consistent. Since varargs are the only style that work for macros, I'd apply that throughout.

Also, please leave a blank line between a method definition and the start of the following definition (including when it's a deprecation annotation).

Copy link
Contributor

@jackkoenig jackkoenig left a comment

Choose a reason for hiding this comment

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

Every deprecation warning needs the version to be "Chisel 3.5", not just "3.5" because the Scala compiler either doesn't know or at least doesn't report the name of the project that deprecation warnings come from.

Comment on lines 331 to 332
final def asSInt: SInt = macro SourceInfoTransform.noArg
@deprecated("Calling this function with an empty argument list is invalid in Scala 3. Use the form without parentheses instead", "3.5")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
final def asSInt: SInt = macro SourceInfoTransform.noArg
@deprecated("Calling this function with an empty argument list is invalid in Scala 3. Use the form without parentheses instead", "3.5")
final def asSInt: SInt = macro SourceInfoTransform.noArg
@deprecated("Calling this function with an empty argument list is invalid in Scala 3. Use the form without parentheses instead", "3.5")

Comment on lines 318 to 319
final def asBools: Seq[Bool] = macro SourceInfoTransform.noArg
@deprecated("Calling this function with an empty argument list is invalid in Scala 3. Use the form without parentheses instead", "3.5")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
final def asBools: Seq[Bool] = macro SourceInfoTransform.noArg
@deprecated("Calling this function with an empty argument list is invalid in Scala 3. Use the form without parentheses instead", "3.5")
final def asBools: Seq[Bool] = macro SourceInfoTransform.noArg
@deprecated("Calling this function with an empty argument list is invalid in Scala 3. Use the form without parentheses instead", "3.5")

core/src/main/scala/chisel3/Bits.scala Outdated Show resolved Hide resolved
src/main/scala/chisel3/util/Decoupled.scala Show resolved Hide resolved
@jackkoenig jackkoenig added this to the 3.5.0 milestone Oct 5, 2021
@jackkoenig jackkoenig enabled auto-merge (squash) October 5, 2021 18:52
@jackkoenig jackkoenig added the Please Merge Accepted PRs that are ready to be merged. Useful when waiting on CI. label Oct 5, 2021
@jackkoenig jackkoenig merged commit 110705e into chipsalliance:master Oct 5, 2021
@sequencer
Copy link
Member

this breaks dsptools.

[#4] [error] /Users/sequencer/projects/playground/wtf/dependencies/dsptools/src/main/scala/dsptools/numbers/chisel_types/FixedPointTypeClass.scala:40:43: ambiguous reference to overloaded definition,
[#4] [error] both method unary_- in class FixedPoint of type (implicit sourceInfo: chisel3.internal.sourceinfo.SourceInfo, implicit compileOptions: chisel3.CompileOptions)chisel3.experimental.FixedPoint
[#4] [error] and  macro method unary_- in class FixedPoint of type => chisel3.experimental.FixedPoint
[#4] [error] match expected type chisel3.experimental.FixedPoint
[#4] [error]   def negate(f: FixedPoint): FixedPoint = -f
[#4] [error]                                           ^
[#4] [error] /Users/sequencer/projects/playground/wtf/dependencies/dsptools/src/main/scala/dsptools/numbers/chisel_types/IntervalTypeClass.scala:44:39: ambiguous reference to overloaded definition,
[#4] [error] both method unary_- in class Interval of type (implicit sourceInfo: chisel3.internal.sourceinfo.SourceInfo, implicit compileOptions: chisel3.CompileOptions)chisel3.experimental.Interval
[#4] [error] and  macro method unary_- in class Interval of type => chisel3.experimental.Interval
[#4] [error] match expected type chisel3.experimental.Interval
[#4] [error]   def negate(f: Interval): Interval = -(f)
[#4] [error]                                       ^
[#4] [error] two errors found

@sequencer
Copy link
Member

@chick
Copy link
Contributor

chick commented Oct 7, 2021

@jackkoenig @sequencer I think I might have figured this out. Looks like the macro expansions of do_unary_- are not defined for FixedPoint and Interval, not sure how everything worked before here but I'm testing a fix now

chick added a commit that referenced this pull request Oct 7, 2021
In `Bits.scala`, `FixedPoint` and `Interval` did not defeine the `do_unary_-` methods (the `do_`) was missing
The recent PR #2124 combined with the above fact made DspTools break. This fix is necessary to get
that repo to build.
jackkoenig pushed a commit that referenced this pull request Oct 7, 2021
In `Bits.scala`, `FixedPoint` and `Interval` did not defeine the `do_unary_-` methods (the `do_`) was missing
The recent PR #2124 combined with the above fact made DspTools break. This fix is necessary to get
that repo to build.
@sequencer
Copy link
Member

super fast!

carlosedp added a commit to carlosedp/chiselv that referenced this pull request Oct 20, 2021
jackkoenig added a commit that referenced this pull request Feb 28, 2023
Due to inlining of Boolean expressions, the following circuit is handled
directly by the VerilogEmitter:

input a: UInt<4>
input b: SInt<1>
output o: UInt<5>
o <= dshl(a, asUInt(cvt(b)))

Priot to this change, this could crash due to mishandling of cvt in the
logic to inject parentheses based on Verilog precedence rules.

This is a corner case, but similar bugs would drop up if we open up the
VerilogEmitter to more expression inlining.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Please Merge Accepted PRs that are ready to be merged. Useful when waiting on CI.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants