You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Units of measure can affect compiled form of integral ranges #17046
When looking into #17025, I found that the presence of units of measure can affect the compiled form of the range (..) and range-step (.. ..) operators. This applies to their use in bare for-loops as well as in computed collections.
When start and finish (for (..)) and start, step, and finish (for (.. ..)) are all literal values, local variables, or parameter values, the compiled form with units of measure is the same as it is without units of measure.
But when any of start, step, or finish is a function call, method call, property access, etc., the compiled form with units of measure diverges from the compiled form without units of measure.
letf1 g =for n in g ()..1..10do ignore (float n ** float n)letf2 g =for n in g ()..1<m>..10<m>do ignore (float n ** float n)
letf3 g =[g ()..1..10]letf4 g =[g ()..1<m>..10<m>]
letf5 g =[|g ()..1..10|]letf6 g =[|g ()..1<m>..10<m>|]
This divergence is happening in the compiler somewhere before for-loops or computed collections are optimized, which means that neither the longstanding optimization for integer for-loops over ranges with a step of 1 or -1 nor the new optimizations introduced in #16650 are applied in certain scenarios when units of measure are involved.
I don't believe that this should be the case. Ideally, the presence of units of measure should not affect the compiled form of these constructs.
Activity
T-Gro commentedon Apr 29, 2024
This was fixed by #17048 right?
brianrourkeboll commentedon Apr 29, 2024
No. This is actually a longstanding difference that also affects the older optimizations (see the second SharpLab link from above).