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

Support for Scala 3 #10

Open
ryanstull opened this issue Jun 30, 2024 · 3 comments
Open

Support for Scala 3 #10

ryanstull opened this issue Jun 30, 2024 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@ryanstull
Copy link
Owner

No description provided.

@ryanstull ryanstull added the enhancement New feature or request label Jun 30, 2024
@ryanstull ryanstull self-assigned this Jun 30, 2024
@RileyDByrd
Copy link

Hi, Ryan. I wrote a flat implementation of Option using opaque types over type unions with Null for Scala 3. I think this could help you in writing support for Scala 3 for ScalaNullSafe.

Here's the implementation, https://github.com/RileyDByrd/option-replacement/blob/master/src/main/scala/FlatOptionModule.scala.

Here's the benchmark code, https://github.com/RileyDByrd/option-replacement-benchmark/tree/master/src/test/scala.

And here are the benchmarks. It performs as well as if-statements.

[info] # Run complete. Total time: 00:12:33
[info] REMEMBER: The numbers below are just data. To gain reusable insights, you need to follow up on
[info] why the numbers are the way they are. Use profilers (see -prof, -lprof), design factorial
[info] experiments, perform baseline and negative tests that provide experimental control, make sure
[info] the benchmarking environment is safe on JVM/OS/HW level, ask for reviews from the domain experts.
[info] Do not assume the numbers tell you what you want them to tell.
[info] NOTE: Current JVM experimentally supports Compiler Blackholes, and they are in use. Please exercise
[info] extra caution when trusting the results, look into the generated code to check the benchmark still
[info] works, and factor in a small probability of new VM bugs. Additionally, while comparisons between
[info] different JVMs are already problematic, the performance difference caused by different Blackhole
[info] modes can be very significant. Please make sure you use the consistent Blackhole mode for comparisons.
[info] Benchmark                            (size)  Mode  Cnt     Score    Error  Units
[info] FlatOptionBenchmarks.measureFlatMap       1  avgt   15     7.758 ┬▒  1.696  ns/op
[info] FlatOptionBenchmarks.measureFlatMap      10  avgt   15    13.654 ┬▒  0.182  ns/op
[info] FlatOptionBenchmarks.measureFlatMap     100  avgt   15    97.570 ┬▒ 16.698  ns/op
[info] FlatOptionBenchmarks.measureFlatMap    1000  avgt   15  1863.216 ┬▒  7.887  ns/op
[info] FlatOptionBenchmarks.measureMap           1  avgt   15     6.118 ┬▒  0.091  ns/op
[info] FlatOptionBenchmarks.measureMap          10  avgt   15    13.461 ┬▒  0.155  ns/op
[info] FlatOptionBenchmarks.measureMap         100  avgt   15    89.379 ┬▒  0.927  ns/op
[info] FlatOptionBenchmarks.measureMap        1000  avgt   15  1864.249 ┬▒ 16.321  ns/op
[info] IfThenElseBenchmarks.measureFlatMap       1  avgt   15     6.003 ┬▒  0.072  ns/op
[info] IfThenElseBenchmarks.measureFlatMap      10  avgt   15    13.251 ┬▒  0.084  ns/op
[info] IfThenElseBenchmarks.measureFlatMap     100  avgt   15    90.911 ┬▒  2.780  ns/op
[info] IfThenElseBenchmarks.measureFlatMap    1000  avgt   15  1849.186 ┬▒ 15.827  ns/op
[info] IfThenElseBenchmarks.measureMap           1  avgt   15     6.274 ┬▒  0.055  ns/op
[info] IfThenElseBenchmarks.measureMap          10  avgt   15    14.322 ┬▒  0.110  ns/op
[info] IfThenElseBenchmarks.measureMap         100  avgt   15    91.964 ┬▒  0.586  ns/op
[info] IfThenElseBenchmarks.measureMap        1000  avgt   15  2963.798 ┬▒ 26.699  ns/op
[info] OptionBenchmarks.measureFlatMap           1  avgt   15     7.216 ┬▒  0.249  ns/op
[info] OptionBenchmarks.measureFlatMap          10  avgt   15    27.343 ┬▒  0.192  ns/op
[info] OptionBenchmarks.measureFlatMap         100  avgt   15   218.185 ┬▒  1.505  ns/op
[info] OptionBenchmarks.measureFlatMap        1000  avgt   15  3714.361 ┬▒ 51.253  ns/op
[info] OptionBenchmarks.measureMap               1  avgt   15     7.883 ┬▒  0.062  ns/op
[info] OptionBenchmarks.measureMap              10  avgt   15    44.384 ┬▒  0.527  ns/op
[info] OptionBenchmarks.measureMap             100  avgt   15   406.676 ┬▒  2.955  ns/op
[info] OptionBenchmarks.measureMap            1000  avgt   15  4797.272 ┬▒ 41.573  ns/op

@ryanstull
Copy link
Owner Author

Hey @RileyDByrd , thanks for your interest in the project! I'm not sure if I'll be able to use these opaque type aliases for my Scala 3 implementation since I need to rewrite the ASTs in order to do what the macro does, but it is an interesting approach.

@RileyDByrd
Copy link

@ryanstull, no worries. I'll keep using this FlatOption implementation at least for now, but I eagerly await your Scala 3 implementation!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants