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
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.
The text was updated successfully, but these errors were encountered:
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 barefor
-loops as well as in computed collections.When
start
andfinish
(for(..)
) andstart
,step
, andfinish
(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
, orfinish
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.That is, these pairs are compiled identically (as expected):
But these pairs are compiled differently:
This divergence is happening in the compiler somewhere before
for
-loops or computed collections are optimized, which means that neither the longstanding optimization for integerfor
-loops over ranges with a step of1
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.
The text was updated successfully, but these errors were encountered: