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

experiment with removing transparent inline from op definitions #264

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions core/src/main/scala/coulomb/ops/standard/pow.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,19 @@ import coulomb.ops.{Pow, SimplifiedUnit}
import coulomb.rational.typeexpr
import coulomb.ops.algebra.FractionalPower

transparent inline given ctx_pow_FractionalPower[V, U, E](using
given ctx_pow_FractionalPower[V, U, E](using
alg: FractionalPower[V],
dbv: typeexpr.DoubleValue[E],
su: SimplifiedUnit[U ^ E]
): Pow[V, U, E] =
val e = typeexpr.double[E]
val e = dbv.value
new Pow[V, U, E]:
Comment on lines -29 to 35
Copy link
Contributor

@armanbilge armanbilge Mar 31, 2022

Choose a reason for hiding this comment

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

Question: instead of making this an anonymous class within the inline function, can we make it a named class outside that is then instantiated within the inline function? The problem with anonymous classes in inline functions is that means everywhere the function is inlined, you will get a completely new (anonymous) class. This causes code bloat, esp. on JS.

Copy link
Owner Author

Choose a reason for hiding this comment

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

I'll play around with it 👍

Copy link
Owner Author

Choose a reason for hiding this comment

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

See #265. If I'm understanding what you are thinking, it looks promising

type VO = V
type UO = su.UO
def apply(q: Quantity[V, U]): Quantity[VO, UO] =
alg.pow(q.value, e).withUnit[UO]

transparent inline given ctx_pow_MultiplicativeGroup[V, U, E](using
given ctx_pow_MultiplicativeGroup[V, U, E](using
nfp: NotGiven[FractionalPower[V]],
alg: MultiplicativeGroup[V],
aie: typeexpr.AllInt[E],
Expand All @@ -50,7 +51,7 @@ transparent inline given ctx_pow_MultiplicativeGroup[V, U, E](using
def apply(q: Quantity[V, U]): Quantity[VO, UO] =
alg.pow(q.value, e).withUnit[UO]

transparent inline given ctx_pow_MultiplicativeSemigroup[V, U, E](using
given ctx_pow_MultiplicativeSemigroup[V, U, E](using
nfp: NotGiven[FractionalPower[V]],
nmg: NotGiven[MultiplicativeGroup[V]],
alg: MultiplicativeSemigroup[V],
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/coulomb/quantity.scala
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ object quantity:
transparent inline def tquot[VR, UR](qr: Quantity[VR, UR])(using tq: TQuot[VL, UL, VR, UR]): Quantity[tq.VO, tq.UO] =
tq(ql, qr)

transparent inline def pow[P](using pow: Pow[VL, UL, P]): Quantity[pow.VO, pow.UO] =
def pow[P](using pow: Pow[VL, UL, P]): Quantity[pow.VO, pow.UO] =
pow(ql)

transparent inline def tpow[P](using tp: TPow[VL, UL, P]): Quantity[tp.VO, tp.UO] =
Expand Down
10 changes: 10 additions & 0 deletions core/src/main/scala/coulomb/rational/rational.scala
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,16 @@ object typeexpr:
inline def bigInt[E]: BigInt = ${ meta.teToBigInt[E] }
inline def double[E]: Double = ${ meta.teToDouble[E] }


@implicitNotFound("type expr ${E} is not a Double")
abstract class DoubleValue[E]:
val value: Double

object DoubleValue:
transparent inline given ctx_DoubleValue[E]: DoubleValue[E] =
new DoubleValue[E]:
val value: Double = double[E]

@implicitNotFound("type expr ${E} is not a non-negative Int")
abstract class NonNegInt[E]:
val value: Int
Expand Down