Skip to content

Commit

Permalink
Inline parameters to shorten generated code
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheeandres committed Mar 14, 2023
1 parent 28bf386 commit c825198
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions InlineNumeric.scala
Original file line number Diff line number Diff line change
Expand Up @@ -214,23 +214,23 @@ given BigDecimalAsIfInlineIntegral: BigDecimalIsConflicted with InlineIntegral[B

object tests:
import InlineNumeric.*
import InlineIntegral.{/ => quot, %}
import InlineFractional.{/}

// A generic inline operation that inlines/specializes primitive operations
inline def foo[T: InlineNumeric](a: T, b: T) =
inline def foo[T: InlineNumeric](inline a: T, inline b: T) =
a + b * b

inline def div[T: InlineIntegral](a: T, b: T) =
import InlineIntegral.{/, %}
a / b % b
inline def div[T: InlineIntegral](inline a: T, inline b: T) =
a quot b % b

inline def div[T: InlineFractional](a: T, b: T) =
import InlineFractional.{/}
inline def div[T: InlineFractional](inline a: T, inline b: T) =
a / b + a

inline def bar[T: InlineNumeric](a: T) =
inline def bar[T: InlineNumeric](inline a: T) =
a.toInt

inline def sign[T: InlineNumeric](a: T) =
inline def sign[T: InlineNumeric](inline a: T) =
a.sign

def test(a: Int, b: Int) =
Expand Down

0 comments on commit c825198

Please sign in to comment.