Skip to content

Commit

Permalink
Computed collections: simple count check (dotnet#16947)
Browse files Browse the repository at this point in the history
* Use count = 0 instead of count < 1

* The count < 1 check was a vestige of an older approach for computing
  the count that could result in a negative count.

* Update baselines

* Update release notes
  • Loading branch information
brianrourkeboll authored Apr 4, 2024
1 parent 06c85f0 commit 71442c8
Show file tree
Hide file tree
Showing 5 changed files with 2,205 additions and 2,320 deletions.
2 changes: 1 addition & 1 deletion docs/release-notes/.FSharp.Compiler.Service/8.0.300.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@
* Reverted [#16348](https://github.com/dotnet/fsharp/pull/16348) `ThreadStatic` `CancellationToken` changes to improve test stability and prevent potential unwanted cancellations. ([PR #16536](https://github.com/dotnet/fsharp/pull/16536))
* Refactored parenthesization API. ([PR #16461])(https://github.com/dotnet/fsharp/pull/16461))
* Optimize some interpolated strings by lowering to string concatenation. ([PR #16556](https://github.com/dotnet/fsharp/pull/16556))
* Integral range optimizations. ([PR #16650](https://github.com/dotnet/fsharp/pull/16650), [PR #16832](https://github.com/dotnet/fsharp/pull/16832))
* Integral range optimizations. ([PR #16650](https://github.com/dotnet/fsharp/pull/16650), [PR #16832](https://github.com/dotnet/fsharp/pull/16832), [PR #16947](https://github.com/dotnet/fsharp/pull/16947))
11 changes: 2 additions & 9 deletions src/Compiler/Optimize/LowerComputedCollections.fs
Original file line number Diff line number Diff line change
Expand Up @@ -393,14 +393,7 @@ module Array =
mkCompGenLetIn m (nameof count) (tyOfExpr g count) count (fun (_, count) ->
let countTy = tyOfExpr g count

// count < 1
let countLtOne =
if isSignedIntegerTy g countTy then
mkILAsmClt g m count (mkTypedOne g m countTy)
else
mkAsmExpr ([AI_clt_un], [], [count; mkTypedOne g m countTy], [g.bool_ty], m)

// if count < 1 then
// if count = 0 then
// [||]
// else
// let array = (# "newarr !0" type ('T) count : 'T array #) in
Expand All @@ -410,7 +403,7 @@ module Array =
DebugPointAtBinding.NoneAtInvisible
m
arrayTy
countLtOne
(mkILAsmCeq g m count (mkTypedZero g m countTy))
(mkArray (overallElemTy, [], m))
(mkArrayInit count mkLoop)
)
Expand Down
Loading

0 comments on commit 71442c8

Please sign in to comment.