Skip to content

Commit c90668b

Browse files
xperiandriclaude
andcommitted
docs: accept ADR 0002 and record the answers to its questions
The maintainers accepted every recommendation of section 11 on 2026-10-18, and pull request #28 implements step 1. - Status Accepted; section 11 records the decisions. - Section 1: the library compiles against the signature, `Slice` included. - Sections 5 and 6: step 1 also has `unsafeOfArray`, which throws for `null` like `ofArray`. - Section 7: the categories as implemented, the exact allocation counts, and the C# test project that the maintainers chose. - Section 9: the four differences the first consumer notices when it moves to the library type. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 86043a1 commit c90668b

1 file changed

Lines changed: 45 additions & 33 deletions

File tree

‎docsSrc/Explanations/ADR_0002_EquatableArray.md‎

Lines changed: 45 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ index: 3
99

1010
| | |
1111
|---|---|
12-
| Status | Proposed |
12+
| Status | Accepted (2026-10-18) |
1313
| Date | 2026-10-11 |
1414
| Deciders | maintainers |
1515

@@ -18,10 +18,12 @@ Facts marked *(verified)* were run for this document with F# 10 on .NET SDK 10.0
1818
repository – compiled in Release for `net8.0` and run on `net10.0`. Allocated bytes are exact; times are stopwatch
1919
readings and show the order of magnitude only.
2020

21-
This is a design document: nothing of it is in the library yet. The questions of §11 wait for the maintainers.
22-
ADR 0001 – Per-collection modules (`ADR_0001_Collection_Modules.md`) proposes to rewrite the collection modules and is
23-
itself only proposed, in [pull request #23](https://github.com/fsprojects/FSharp.Collections.Immutable/pull/23); §5 to §7
24-
say where the two meet.
21+
The maintainers accepted this design and the recommendations of §11 on 2026-10-18. Step 1 of §6 is
22+
[pull request #28](https://github.com/fsprojects/FSharp.Collections.Immutable/pull/28), and its tests (§7) pin the
23+
verified facts. ADR 0001 – Per-collection modules (`ADR_0001_Collection_Modules.md`) proposes to rewrite the
24+
collection modules and is still proposed, in
25+
[pull request #23](https://github.com/fsprojects/FSharp.Collections.Immutable/pull/23); §5 to §7 say where the two
26+
meet.
2527

2628
## Context
2729

@@ -98,8 +100,8 @@ create a no-cost wrapper around ImmutableArray that has sequence-equality semant
98100

99101
## 1. The type
100102

101-
The prototype compiles against the signature below for `net8.0`, with nullness checking on and without warnings
102-
*(verified)*.
103+
The library compiles against the signature below for `net8.0`, with nullness checking on and without warnings (step 1,
104+
pull request #28). The prototype did too, except for `Slice`, which a separate probe verified.
103105

104106
```fsharp
105107
namespace FSharp.Collections.Immutable
@@ -338,7 +340,8 @@ body is written twice. What differs:
338340
* `ofImmutableArray` and `toImmutableArray` are added.
339341
* `unsafeOfArray` is added, as in the first consumer: it wraps an array without copying it, through
340342
`ImmutableCollectionsMarshal.AsImmutableArray`, for a caller that gives the array away and never writes to it again.
341-
`ofArray` copies.
343+
`ofArray` copies. Both throw `ArgumentNullException` for `null`, as FSharp.Core does; the first consumer's functions
344+
return an empty array.
342345
* Results that nest arrays (`groupBy`, `chunkBySize`, `windowed`, `splitInto`, `transpose`) hold `EquatableArray`s
343346
inside, otherwise the inner arrays would compare by reference (§2).
344347
* Functions that compare elements (`contains`, `distinct`, `indexOf`, …) keep the F# equality they have in `FlatList`.
@@ -410,9 +413,9 @@ tests/FSharp.Collections.Immutable.Tests/
410413
the full function set, the builder module and the computation expressions exist only on unmerged local branches, and
411414
ADR 0001 proposes to rewrite them in a chain of pull requests with no release before its end.
412415

413-
1. *On `main` now*: the type, the factory class, the converter, the patterns and a module with `empty`, `singleton`,
414-
`ofSeq`, `ofArray`, `ofList`, `ofImmutableArray`, `toImmutableArray`, `length`, `isEmpty` and `map`, with the tests
415-
of §7. This is what the first consumer uses, and a release can follow.
416+
1. *On `main` now* (pull request #28): the type, the factory class, the converter, the patterns and a module with
417+
`empty`, `singleton`, `ofSeq`, `ofArray`, `ofList`, `ofImmutableArray`, `unsafeOfArray`, `toImmutableArray`,
418+
`length`, `isEmpty` and `map`, with the tests of §7. This is what the first consumer uses, and a release can follow.
416419
2. *With the `FlatList` rewrite*: the mirror of the module, the builder functions and the computation expression, as one
417420
more pull request of that chain and under its rules for layout, function order and tests.
418421

@@ -422,10 +425,10 @@ Under the repository's rules: MSTest 4, a failure message on every assert, categ
422425
attributes sorted by type name.
423426

424427
* **Categories.** `EquatableArrayTestCategory` on every test class. `TestCategory (nameof EquatableArray.ofSeq)` and the
425-
like on tests of module functions. For the behaviour of the type itself, new attributes `ComparisonTestCategory`,
426-
`EqualityTestCategory`, `InteropTestCategory` and `JsonTestCategory`, next to `BuilderTestCategory`,
427-
`ComputationExpressionTestCategory` and `PatternMatchingTestCategory`. Those three and `TestCategories.fs` itself are
428-
not on `main` yet.
428+
like on tests of module functions. For the behaviour of the type itself: `AllocationTestCategory`,
429+
`ComparisonTestCategory`, `DefaultValueTestCategory`, `EqualityTestCategory`, `FormattingTestCategory`,
430+
`InteropTestCategory`, `JsonTestCategory` and `PatternMatchingTestCategory`, in the `TestCategories.fs` that step 1
431+
adds. `BuilderTestCategory` and `ComputationExpressionTestCategory` come with step 2.
429432
* **Equality under every caller**: `=`, `.Equals`, `EqualityComparer<_>.Default`, `HashIdentity.Structural`, a default
430433
`Dictionary` and `HashSet`, `ValueTuple.Equals`, a record field, a recursive union.
431434
* **The defects of `ImmutableArray` as regression tests**: arrays of different length compare, sort and build a `Set`;
@@ -443,7 +446,9 @@ attributes sorted by type name.
443446
* **Constraints**: the type parameter carries `EqualityConditionalOn` and `ComparisonConditionalOn`, read by reflection,
444447
since a test cannot assert a compile error.
445448
* **Allocation**: 0 B, by `GC.GetAllocatedBytesForCurrentThread`, for `=` on arrays of `int`, `string`, a union and
446-
struct tuples, on the value and as a record field; for `for`; for a pattern match. These tests run in Release only.
449+
struct tuples, on the value and as a record field; for `for`; for a pattern match. These tests run in Release only,
450+
with tiered compilation off so that every method is fully optimized from its first call. A control test shows that
451+
the counter sees an allocation.
447452
* **Interop**: both conversions keep the underlying array; `CollectionBuilderAttribute` names the factory class and
448453
`Create`, and the class has exactly one `Create`; `GetSlice` follows F# arrays; `Slice` follows `ImmutableArray.Slice`,
449454
including `ArgumentOutOfRangeException`; `op_Equality` and `op_Inequality` agree with `Equals`; the mutating members of
@@ -456,8 +461,9 @@ attributes sorted by type name.
456461
the failure readable; sizes with `Assert.HasCount` and `Assert.IsEmpty`. `CollectionAssert` does not apply: it needs
457462
the non-generic `ICollection`.
458463

459-
C# collection expressions were checked in the design probe. A C# test project is added only if the maintainer wants C#
460-
covered in CI.
464+
The maintainers chose to cover C# in CI. The C# MSTest project `tests/FSharp.Collections.Immutable.CSharp.Tests` checks
465+
what only the C# compiler binds: collection expressions, indices and ranges, `==` and `!=`, the default collections,
466+
record structs, the implicit conversions and the compiled names of the module.
461467

462468
## 8. Benchmarks before release
463469

@@ -475,11 +481,15 @@ type; JSON within 10 % of `ImmutableArray<'T>`.
475481

476482
## 9. Consumers and migration
477483

478-
* **The first consumer** removes its own `EquatableArray` after the release that contains the type and opens
479-
`FSharp.Collections.Immutable` instead. The constructor, `Items`, `Length`, `IsEmpty`, the indexer, `for` and the
480-
module functions it uses keep their names. It will notice three things: the patterns take `EquatableArray<'T>` where
481-
its own take `ImmutableArray<'T>` (question 4); the type has comparison where its own is `NoComparison`; `ToString ()`
482-
prints `[|1; 2|]` where its own prints `[| 1; 2 |]`.
484+
* **The first consumer** removes its own `EquatableArray` after the release that contains the type and adds
485+
`open FSharp.Collections.Immutable` to the files that use it. The constructor, `Items`, `Length`, `IsEmpty`, the
486+
indexer, `for` and the module functions it uses keep their names. It will notice four things:
487+
* `ofArray null` and `unsafeOfArray null` throw `ArgumentNullException` where its own return an empty array.
488+
* The type has comparison where its own is `NoComparison`, so its records and unions gain comparison.
489+
* The patterns take `EquatableArray<'T>` where its own take `ImmutableArray<'T>` (question 4). Its own patterns are
490+
not used in its production code.
491+
* `ToString ()` of an array wider than one line, or longer than 100 elements, wraps and ends in `...`, as `%A` of an
492+
F# array does. Short arrays print the same `[|1; 2|]`.
483493
* **`FlatList` users** change nothing. They switch a field to `EquatableArray<'T>` where the value is a key, is compared
484494
or is persisted; stored JSON stays valid (§4).
485495
* **Query translators** that map collection functions by compiled declaring type add
@@ -513,36 +523,38 @@ Deliberately different from the FS-1094 draft:
513523
| `%A` | the notation of an F# array | `immarray [1; 2; 3]` |
514524
| Library additions | `Items`, the constructor, `AsMemory`, `Slice`, read-only `IList<'T>`, `==` and `!=`, the JSON converter, the patterns, `equatableArray { }` | no `==`, no converter on the type, patterns left to users |
515525

516-
## 11. Open questions
526+
## 11. Questions and decisions
527+
528+
The maintainers accepted every recommendation on 2026-10-18. The questions stay here with the reasons for each answer.
517529

518530
1. **Element equality.** `EqualityComparer<'T>.Default`, or the rules of F# lists through `IStructuralEquatable`?
519-
*Recommendation: `EqualityComparer<'T>.Default`.* It is the only strategy that does not allocate for struct elements,
531+
*Decided: `EqualityComparer<'T>.Default`.* It is the only strategy that does not allocate for struct elements,
520532
and allocation-free equality is the first use case. The price is the two differences of §2 and, for elements that
521533
are arrays, the keys of question 8.
522-
2. **Comparison.** Length first as for F# arrays, or lexicographic as for F# lists? *Recommendation: length first.* It
534+
2. **Comparison.** Length first as for F# arrays, or lexicographic as for F# lists? *Decided: length first.* It
523535
is the rule of F# arrays and of the FS-1094 draft, and arrays of different length are compared without reading an
524536
element. Independently of that, elements are compared in the order of F# generic comparison and not with
525-
`Comparer<'T>.Default` as in the first draft of this design (§3); this needs confirming.
526-
3. **`op_Implicit` in both directions**, or only the named conversions? *Recommendation: both.* The conversions are O(1)
537+
`Comparer<'T>.Default` as in the first draft of this design (§3); the maintainers confirmed this too.
538+
3. **`op_Implicit` in both directions**, or only the named conversions? *Decided: both.* The conversions are O(1)
527539
and lose nothing, a default array becomes empty, and F# warns wherever the conversion is not at a method argument.
528540
4. **The input of the patterns.** `EquatableArray<'T>`, or `ImmutableArray<'T>` as in the first consumer?
529-
*Recommendation: `EquatableArray<'T>`*: nested in a union case a pattern cannot convert, at the head of a `match` the
541+
*Decided: `EquatableArray<'T>`*: nested in a union case a pattern cannot convert, at the head of a `match` the
530542
wrap is one word. Inline patterns constrained on `Length` and the indexer accept both types and F# arrays without
531543
allocation *(verified)*, but they throw `NullReferenceException` on a default `ImmutableArray` and need the input
532544
type known at the pattern.
533-
5. **Read-only `IList<'T>` and `ICollection<'T>`.** *Recommendation: yes.* FSharp.Core and LINQ take their fast paths
545+
5. **Read-only `IList<'T>` and `ICollection<'T>`.** *Decided: yes.* FSharp.Core and LINQ take their fast paths
534546
for these two interfaces, not for `IReadOnlyList<'T>`. On 1000 `int` *(verified)*: `Seq.length` 4630 ns → 30 ns,
535547
`Seq.toArray` 5490 ns and 12.5 kB → 1020 ns and 4 kB, `Enumerable.Count` 940 ns → 40 ns, `Enumerable.ToList` 4600 ns
536548
→ 750 ns, `ResizeArray (xs)` 3080 ns → 580 ns. The members are explicit, report `IsReadOnly`, and the mutating ones
537549
throw `NotSupportedException`, as on `ImmutableArray`.
538-
6. **A JSON `null`.** The empty array, or an error? *Recommendation: the empty array*, the JSON counterpart of the
550+
6. **A JSON `null`.** The empty array, or an error? *Decided: the empty array*, the JSON counterpart of the
539551
default value. It takes effect under plain System.Text.Json only (§4).
540552
7. **Two steps** (§6): release the type, the patterns and the converter from `main` before the chain of ADR 0001 starts,
541-
or make the type one link of that chain? *Recommendation: release first.* The first consumer is waiting for a
553+
or make the type one link of that chain? *Decided: release first.* The first consumer is waiting for a
542554
release, and the chain cuts none before its end.
543555
8. **Keys with array elements** (decision 5). Accept that equality and comparison disagree on F# arrays, `FlatList`s
544556
and tuples that hold them, or compare such elements by contents, as `.Equals` on an F# list does?
545-
*Recommendation: accept.* The element keeps the equality that .NET and C# give it. The type needs no list of element
557+
*Decided: accept.* The element keeps the equality that .NET and C# give it. The type needs no list of element
546558
types that it treats differently. The other choice is cheap *(verified)*. It compares through
547559
`LanguagePrimitives.GenericEqualityERComparer`. On 32 elements that are arrays of `int` or `string`, it allocates
548560
nothing. On 32 `FlatList`s of four `int`, it allocates 7680 B per `Equals` and 3840 B per hash. That is not more than

0 commit comments

Comments
 (0)