Repository navigation
Description
In 11.0.0 (maintainer, 2026-11-28). It was moved out for a few hours that day, to tag v11.0.0 sooner, and the maintainer put it back: every consumer of a range set gains from it, and it fits only in a major. It ships in 11.0.0-preview.2 (moved there from preview.3 on 2026-11-28; PR #551) and holds the v11.0.0 tag (#147).
Problem
RangeSet<TRange, T> makes every consumer spell both type arguments — RangeSet<DateRange, DateOnly> — although T is fully determined by TRange. C# does not infer type arguments from constraints, so the element type has to be named at every declaration: entity properties, DTOs, method signatures. The From remarks and docs/ranges.md already tell consumers to prefer the collection expression because of it.
The quirk is not local to one declaration. Everything around the set exists because an open generic cannot name a closed type:
RangeSetnamesRangeJsonConverterFactoryand registers closed converters throughGenericConverters.Register, because an attribute cannot name a converter closed over the set's own type (AGENTS.md, "AOT").- The EF translators match members by
typeof(RangeSet<,>)andnameof(RangeSet<,>.Union)inValueRangesMethodCallTranslator,ValueRangesQueryExpressionInterceptorandValueRangesAggregateMethodCallTranslator, instead of a registry lookup by CLR type as the ranges do. RangeAgg/RangeIntersectAggover ranges are thirteen per-type overloads for the same reason (docs/architecture.md, "Aggregates").YearMonthRangeSetTypeMappingis a hand-written special case beside the genericValueRangeSetTypeMapping<TRange, T>.
Change
One sealed set type per domain, built as the value-set family is (StringSet, GuidSet, …):
- Core:
Int32RangeSet,Int64RangeSet,DecimalRangeSet,DateRangeSet,DateTimeRangeSet,DateTimeOffsetRangeSet,TimeRangeSet,Float64RangeSet,Float32RangeSet. NodaTime satellite:LocalDateRangeSet,LocalDateTimeRangeSet,InstantRangeSet,YearMonthRangeSet. TheRangeSetsuffix keeps the vocabulary the docs, the claim catalogue andarea/range-setuse;Int32Set(values) againstInt32RangeSet(ranges) reads correctly. - An
IRangeSet<TRange, T>interface and a static-abstractIRangeSetFactory<TSet, TRange, T>, mirroringIValueSet<T>/IValueSetFactory<TSet, T>. The current body ofRangeSet.csmoves into an internal engine (Internals/) the thirteen types delegate to, so the algebra stays in one place and a fix to set semantics is one change. - Generic producers (
Union,Except,Gaps,ToRangeSet, the set aggregates,RangeTypeDefinition<TRange, T>) learn the set type from the range side: a third type parameter onIRangeFactory<TRange, T>or a companion interface withstatic abstract TSet CreateSet(ReadOnlySpan<TRange>). The infrastructure generics then carry three parameters a consumer never writes. Per-type overloads (theRangeAggprecedent) are the fallback, not the plan. - Each set type names its own closed
[JsonConverter]and[TypeConverter]; theGenericConvertersregistration for sets and the factory indirection go. The EF side looks sets up throughRangeTypeRegistryby CLR type (RangeSetClrTypealready exists) and drops thetypeof(RangeSet<,>)matches.YearMonthRangeSetstops being the odd one out. RangeSet<TRange, T>and the non-genericRangeSetbuilder are removed.Int32RangeSet set = [a, b];keeps working through[CollectionBuilder]on each type.- New clone-sweep family (
core range sets,nodatime range sets) inclone-waivers.json; claims inclaims.jsonre-pointed;RangeProbes,RangeSetLiftParityTestsand the EF discovery pick the types up by reflection. docs/migration.mdv10.x section gives the rename as a regex (RangeSet<(\w+)Range, \w+>→$1RangeSet), and the changelog's "what can break you" list carries it.
Why 11.0.0 and not 10.0.0
10.0.0 tags on the commit the gate (#179) passed on 2026-10-19; its changelog opens with "Nothing was removed or renamed", and additions were frozen on 2026-10-18. Epic #147 reserves surface changes for the 11 line, and since #149 (closed unions) turned out non-breaking, this is the one breaking surface change 11.0.0 carries. The cost is that the two lines differ in the set family for the LTS lifetime, so a set-semantics fix on main is a manual port into release/10.x; keeping the algebra in a shared engine keeps that port small. 10.x consumers can alias (using DateRangeSet = CodoMetis.ValueRanges.RangeSet<CodoMetis.ValueRanges.DateRange, System.DateOnly>;) in the meantime; docs/ranges.md should say so.
Footprint (measured 2026-10-19 on main)
| Area | Mentions of RangeSet< |
|---|---|
Shipping source outside RangeSet.cs |
about 90 across core, EF and both satellites |
| Test files | 87 files, 397 mentions |
claims.json |
180 lines mention RangeSet |
Verification
- Discovered tests and the clone sweep list what is missing for each new sibling (
docs/architecture.md#adding-a-range-or-set-type);dotnet run tools/oracles.cs clonesclean or waived. JsonDefaultContractTests,TypeConverterContractTests,OracleSurfaceCoverageTestsandOracleCatalogueTestspass with the thirteen types and noRangeSet<,>.- Every EF translation test asserts the same SQL as before;
ShapeMatrixParityTests,RangeSetLiftParityTests,TemporalStoreParityTestsand the aggregate integration tests pass on PostgreSQL 16 and 18. - The Native AOT consumer in
test/consumer-smoke-test.shdeclares and serializes at least one set type per package. - ApiCompat suppression file lists every removed member; each is in the changelog's "what can break you" list.
Sequence on the 11 line
After 11.0.0-preview.1 (#103, pure retarget) and preview.2 (#149, closed unions): this is the third step before 11.0.0.
Found-By: maintainer, API review of the 10.0.0 surface
Activity
1 remaining item
CaffeinatedCoder commentedon Nov 28, 2026
Design decision: how the generic producers learn the set type
Decision: a companion interface on the range side,
IRangeSetProducer<TRange, T, TSet>, without members.IRangeFactory<TRange, T>keeps its two parameters. The aggregates over sets need one more thing, a one-parameter interface, because the range side can't help them (below).Both options from the issue were prototyped on
Int32Range(core),LocalDateRangeandYearMonthRange(NodaTime) in a scratch copy ofmainat 9c6b5b1, with the three set types wrapping the currentRangeSet<TRange, T>.What was measured
IRangeFactorya.Union(b)on a union and on a sealed variant, no type argumentsInt32RangeSetLocalDateRangeandYearMonthRangePublishAot, osx-arm64, run as a native binary)r.Range.Union(b)MemberAccesstypedInt32Range; C# writes noConvertto the interfaceint4multirange(b."Seats") + int4multirange(@other), anddatemultirange(r."BillingPeriod") + datemultirange(@months)forYearMonthRange, either operand orderwhere TRange : IRangeFactory<TRange, T>gains a parameter: 85 mentions insrc/, 179 with the tests, and the public genericsRangeJsonConverter<TRange, T>,RangeVariantJsonConverter<,,>,RangeTypeConverter<,>,RangeVariantTypeConverter<,,>andRangeLowerBoundComparer<,>change aritySo the two are equal at the call site, under AOT and in EF. They differ in how far the break reaches. A third parameter on the factory would break every consumer who names
RangeJsonConverter<Int32Range, int>(the AOT section ofdocs/serialization.mdtells them to) or writes a method generic over a range, although neither has anything to do with sets. The companion breaks only what the issue sets out to break.In both options the receiver of
UnionandExcepthas to be the interface that namesTSet, notTRange: C# does not infer from constraints, soextension<TRange, T, TSet>(TRange range)fails with CS0411.Why the companion has no
CreateSetThe issue words the companion with
static abstract TSet CreateSet(ReadOnlySpan<TRange>). I tried that shape and one without members, where the interface only constrainsTSet : IRangeSetFactory<TSet, TRange, T>and a producer callsTSet.From(…). Both work. I'm taking the one without members, for three reasons:IEnumerable<IRangeSetProducer<TRange, T, TSet>>is legal and infers all three from anIEnumerable<Int32Range>, aFinite[]or anImmutableArray<Int32Range>(checked). That is the one shape that could later replace the thirteen per-typeRangeAgg/RangeIntersectAggoverloads over ranges with two generic methods. This PR leaves those overloads as they are (only their return type changes); it just doesn't close that door.TSet.From), and the thirteen range types implement nothing.whereline in code that is generic over a range and its set. Only the library's own generics and tests have such code today.The aggregates over sets
RangeAgg(IEnumerable<RangeSet<TRange, T>>)andRangeIntersectAggof the same source can't learn anything from the range side: their source is the set. WithTSet : IRangeSetFactory<TSet, TRange, T>as the only link,sets.RangeAgg()fails with CS0411, andIEnumerable<IRangeSetFactory<TSet, TRange, T>>is CS8920. Neither option in the issue covers this, so here is what I'm doing instead of falling back to 26 per-type overloads:IRangeSetOperations<TSet>, a base ofIRangeSetFactory<TSet, TRange, T>holding the members that name the set type alone (Empty,Infinite,Union(TSet),Intersect(TSet),Except(TSet),Complement()). The aggregates becomeRangeAgg<TSet>(this IEnumerable<TSet?>) where TSet : class, IRangeSetOperations<TSet>. A consumer writessets.RangeAgg(); the method in the expression tree is closed overInt32RangeSetwith a source ofIEnumerable<Int32RangeSet>, which is what the aggregate translator already compares againstRangeSetClrType. Checked under the JIT and Native AOT, also forYearMonthRangeSetand a source with nulls.If you'd rather have the 26 overloads than a third interface, say so and I'll switch; nothing else depends on it.
The shape that follows
IReadOnlyList<TRange>, soset.Union(other)andset.Contains(range)as extensions would lose to, or tie with,Enumerable.UnionandEnumerable.Contains. Each method is one line into the engine.Internals/RangeSetEngine.cswith its body unchanged, so a set fix onmainstill cherry-picks intorelease/10.x'sRangeSet.csas a rename. It also keeps the null rules (A null range answers some extensions in memory and throws on others, and the answers it gives disagree with PostgreSQL on a NULL column #350) in one place.ToStringtraps (SIGTRAP) in the defaultIFormattable.ToStringofIValueSetFactory<TSet, T>#291.IRangeSetFactoryhas an internal static abstract member, which closes the family asFromTrustedcloses the value sets.range.IsContainedBy(set)) takesIRangeSet<TRange, T>and needs no set type parameter.RangeTypeDefinition<TRange, T, TSet>, registered as before; the translators look the declaring type up inRangeTypeRegistryinstead of matchingtypeof(RangeSet<,>).One PR, in commits that can be reviewed one at a time (engine move, interfaces and types, EF, tests, oracles, docs). If it turns out too large for that I'll propose the split here first.
CaffeinatedCoder commentedon Nov 28, 2026
Implemented in #551, open against
main(not merged). What the design comment above did not know yet:IRangeSet<TRange, T>.Contains,IRangeSetOperations<TSet>.Unionor, forCount, the BCL'sIReadOnlyCollection<TRange>.Count. With the genericRangeSet<TRange, T>both forms of a query were the same member. The translators resolve all three now;Countwas found untranslated byRangeSetCountParityTests.|,&and-are static abstract on the interfaces, and C# refuses them in an expression tree written in generic code (CS8927). The methods run as the same SQL. Code that names a set type is unaffected.YearMonthRangeSetTypeMappingstays hand-written. It goes throughNpgsqlRange<LocalDate>becauseYearMonthhas no wire form, asYearMonthRangeTypeMappingdoes. That was never a consequence of the open generic, so this change does not remove it. No translator has a special case for it any more.Except(TRange)shapes its pieces throughExceptEngine(the range-levelExceptnow returns a set type),NormalizeSinglenames the three bounded shapes and throws for anything else, and the operators stay on the set types. The algebra is the same code.PackageValidationBaselineFrameworkToIgnore net10.0, pack compares nothing on this line. The PR carries a handdotnet apicompatrun against 10.4.0 instead: 59 differences over the four packages, every one namingRangeSet<…>.Open questions are in the PR: which changelog section the
### Breakinglines belong to (Versionis still11.0.0-preview.1, and #546 dates that section), and whether the set aggregates should stay generic overIRangeSetOperations<TSet>.Follow-ups: #548 (the alias in the 10.x docs, as this issue asks), #549 (the per-type
RangeAggoverloads over ranges could now be generic), #550 (drop the sample's alias when it pins an 11 release).feat: one range set type per range type replaces RangeSet<TRange, T> (#…
feat: the EF Core packages map and translate the per-range set types (#…
test: the suites follow the per-range set types (#275)
test: clone families, claims and seeds for the range set types (#275)
docs: range sets are one type per range type, with the v10.x migratio…
feat: the set aggregates union in one pass and take a nullable source (…
docs: the sample and the walkthrough show the range set code of both …
Merge branch 'main' into feat/275-per-domain-range-sets
test: the seed range-mapping-drops-store-type-name follows the merged…
Merge pull request #551 from CaffeinatedCoder/feat/275-per-domain-ran…