Skip to content

Commit 6056c45

Browse files
Add LowerIntegralRangesToFastLoops lang feature
1 parent bc3068f commit 6056c45

26 files changed

+108
-19
lines changed

docs/release-notes/.Language/preview.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
### Added
22

3+
* Lower integral ranges to fast loops in more cases and optimize list and array construction from ranges. ([PR #16650](https://github.com/dotnet/fsharp/pull/16650))
34
* Better generic unmanaged structs handling. ([Language suggestion #692](https://github.com/fsharp/fslang-suggestions/issues/692), [PR #12154](https://github.com/dotnet/fsharp/pull/12154))
45
* Bidirectional F#/C# interop for 'unmanaged' constraint. ([PR #12154](https://github.com/dotnet/fsharp/pull/12154))
56
* Make `.Is*` discriminated union properties visible. ([Language suggestion #222](https://github.com/fsharp/fslang-suggestions/issues/222), [PR #16341](https://github.com/dotnet/fsharp/pull/16341))

src/Compiler/FSComp.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1594,6 +1594,7 @@ featureWarningIndexedPropertiesGetSetSameType,"Indexed properties getter and set
15941594
featureChkTailCallAttrOnNonRec,"Raises warnings if the 'TailCall' attribute is used on non-recursive functions."
15951595
featureUnionIsPropertiesVisible,"Union case test properties"
15961596
featureBooleanReturningAndReturnTypeDirectedPartialActivePattern,"Boolean-returning and return-type-directed partial active patterns"
1597+
featureLowerIntegralRangesToFastLoops,"Optimizes certain uses of the integral range (..) and range-step (.. ..) operators to fast while-loops."
15971598
3354,tcNotAFunctionButIndexerNamedIndexingNotYetEnabled,"This value supports indexing, e.g. '%s.[index]'. The syntax '%s[index]' requires /langversion:preview. See https://aka.ms/fsharp-index-notation."
15981599
3354,tcNotAFunctionButIndexerIndexingNotYetEnabled,"This expression supports indexing, e.g. 'expr.[index]'. The syntax 'expr[index]' requires /langversion:preview. See https://aka.ms/fsharp-index-notation."
15991600
3355,tcNotAnIndexerNamedIndexingNotYetEnabled,"The value '%s' is not a function and does not support index notation."

src/Compiler/Facilities/LanguageFeatures.fs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ type LanguageFeature =
8585
| WarningIndexedPropertiesGetSetSameType
8686
| WarningWhenTailCallAttrOnNonRec
8787
| BooleanReturningAndReturnTypeDirectedPartialActivePattern
88+
| LowerIntegralRangesToFastLoops
8889

8990
/// LanguageVersion management
9091
type LanguageVersion(versionText) =
@@ -197,6 +198,7 @@ type LanguageVersion(versionText) =
197198
LanguageFeature.WarningWhenTailCallAttrOnNonRec, previewVersion
198199
LanguageFeature.UnionIsPropertiesVisible, previewVersion
199200
LanguageFeature.BooleanReturningAndReturnTypeDirectedPartialActivePattern, previewVersion
201+
LanguageFeature.LowerIntegralRangesToFastLoops, previewVersion
200202
]
201203

202204
static let defaultLanguageVersion = LanguageVersion("default")
@@ -340,6 +342,7 @@ type LanguageVersion(versionText) =
340342
| LanguageFeature.WarningWhenTailCallAttrOnNonRec -> FSComp.SR.featureChkTailCallAttrOnNonRec ()
341343
| LanguageFeature.BooleanReturningAndReturnTypeDirectedPartialActivePattern ->
342344
FSComp.SR.featureBooleanReturningAndReturnTypeDirectedPartialActivePattern ()
345+
| LanguageFeature.LowerIntegralRangesToFastLoops -> FSComp.SR.featureLowerIntegralRangesToFastLoops ()
343346

344347
/// Get a version string associated with the given feature.
345348
static member GetFeatureVersionString feature =

src/Compiler/Facilities/LanguageFeatures.fsi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ type LanguageFeature =
7676
| WarningIndexedPropertiesGetSetSameType
7777
| WarningWhenTailCallAttrOnNonRec
7878
| BooleanReturningAndReturnTypeDirectedPartialActivePattern
79+
| LowerIntegralRangesToFastLoops
7980

8081
/// LanguageVersion management
8182
type LanguageVersion =

src/Compiler/Optimize/LowerComputedCollections.fs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module internal FSharp.Compiler.LowerComputedCollectionExpressions
55
open FSharp.Compiler.AbstractIL.IL
66
open FSharp.Compiler.AccessibilityLogic
77
open FSharp.Compiler.DiagnosticsLogger
8+
open FSharp.Compiler.Features
89
open FSharp.Compiler.InfoReader
910
open FSharp.Compiler.LowerSequenceExpressions
1011
open FSharp.Compiler.MethodCalls
@@ -389,7 +390,7 @@ let LowerComputedListOrArrayExpr tcVal (g: TcGlobals) amap overallExpr =
389390
match overallSeqExpr with
390391
// [start..finish]
391392
// [start..step..finish]
392-
| IntegralRange g (_, (start, step, finish)) ->
393+
| IntegralRange g (_, (start, step, finish)) when g.langVersion.SupportsFeature LanguageFeature.LowerIntegralRangesToFastLoops ->
393394
Some (List.mkFromIntegralRange tcVal g amap m overallElemTy overallSeqExpr start step finish)
394395

395396
// [(* Anything more complex. *)]
@@ -402,7 +403,7 @@ let LowerComputedListOrArrayExpr tcVal (g: TcGlobals) amap overallExpr =
402403
match overallSeqExpr with
403404
// [|start..finish|]
404405
// [|start..step..finish|]
405-
| IntegralRange g (_, (start, step, finish)) ->
406+
| IntegralRange g (_, (start, step, finish)) when g.langVersion.SupportsFeature LanguageFeature.LowerIntegralRangesToFastLoops ->
406407
Some (Array.mkFromIntegralRange g m overallElemTy overallSeqExpr start step finish)
407408

408409
// [|(* Anything more complex. *)|]

src/Compiler/TypedTree/TypedTreeOps.fs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10694,7 +10694,9 @@ let DetectAndOptimizeForEachExpression g option expr =
1069410694
let spFor = match spFor with DebugPointAtBinding.Yes mFor -> DebugPointAtFor.Yes mFor | _ -> DebugPointAtFor.No
1069510695
mkFastForLoop g (spFor, spIn, mWholeExpr, elemVar, startExpr, (step = 1), finishExpr, bodyExpr)
1069610696

10697-
| OptimizeAllForExpressions, CompiledForEachExpr g (_enumTy, rangeExpr & IntegralRange g (rangeTy, (start, step, finish)), elemVar, bodyExpr, ranges) ->
10697+
| OptimizeAllForExpressions, CompiledForEachExpr g (_enumTy, rangeExpr & IntegralRange g (rangeTy, (start, step, finish)), elemVar, bodyExpr, ranges) when
10698+
g.langVersion.SupportsFeature LanguageFeature.LowerIntegralRangesToFastLoops
10699+
->
1069810700
let mBody, _spFor, _spIn, mFor, mIn, spInWhile, _mWhole = ranges
1069910701

1070010702
mkOptimizedRangeLoop

src/Compiler/xlf/FSComp.txt.cs.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compiler/xlf/FSComp.txt.de.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compiler/xlf/FSComp.txt.es.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compiler/xlf/FSComp.txt.fr.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)