experiment with removing transparent inline from op definitions#264
experiment with removing transparent inline from op definitions#264erikerlandson wants to merge 1 commit into
transparent inline from op definitions#264Conversation
|
The results are interesting. The operator itself, in isolation, works, but it does lose important type information. Welcome to Scala 3.1.1 (11.0.14, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.
scala> import coulomb.*, algebra.instances.all.given, coulomb.ops.standard.given, coulomb.policy.standard.given
scala> import coulomb.units.us.{*,given}, coulomb.units.mks.{*,given}, coulomb.units.accepted.{*,given}
scala> 2d.withUnit[Meter].pow[3]
val res0: Any = 8.0
scala> res0.asInstanceOf[Quantity[Double, Meter ^ 3]]
val res1: coulomb.Quantity[Double, coulomb.units.us.Meter ^ 3] = 8.0
scala> def f(q: Quantity[Double, Meter ^ 3]): Double = q.value
def f(q: coulomb.Quantity[Double, coulomb.units.us.Meter ^ 3]): Double
scala> f(res0)
-- [E007] Type Mismatch Error: -------------------------------------------------
1 |f(res0)
| ^^^^
| Found: (res0 : Any)
| Required: coulomb.Quantity[Double, coulomb.units.us.Meter ^ (3 : Int)]
longer explanation available when compiling with `-explain`
1 error found
scala> From the above we can see that applying the This is also reflected in the failures of the unit tests. |
|
Overall this does not seem viable. It might be possible to recover using the old |
|
|
||
| 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]: |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
I'll play around with it 👍
There was a problem hiding this comment.
See #265. If I'm understanding what you are thinking, it looks promising
An experiment in removing
transparent inlineon operators.This branch removes
transparent inlinefrom thepowmethod.