Skip to content

Commit ee71c6a

Browse files
authored
Mark Range.Zero as obsolete in favor of Range.range0 (#18664)
1 parent bac7602 commit ee71c6a

25 files changed

+49
-46
lines changed

docs/release-notes/.FSharp.Compiler.Service/10.0.100.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@
2121
* Scoped Nowarn: Add the #warnon compiler directive ([Language suggestion #278](https://github.com/fsharp/fslang-suggestions/issues/278), [RFC FS-1146 PR](https://github.com/fsharp/fslang-design/pull/782), [PR #18049](https://github.com/dotnet/fsharp/pull/18049) and [PR #18637](https://github.com/dotnet/fsharp/pull/18637))
2222
* Simplify creation of `FSharpDiagnostics`. In a few cases, errors without ranges were assigned to the currently checked file, while in other cases they carried an empty range. The latter is now true in all cases. In a few cases, ranges at eof were corrected, while in others they were not. They are now always left uncorrected. This is a prerequisit for [#18553](https://github.com/dotnet/fsharp/issues/18553). ([PR #18610](https://github.com/dotnet/fsharp/pull/18610)).
2323
* `SynExprRecordField` now includes a `range` field ([PR #18617](https://github.com/dotnet/fsharp/pull/18617))
24+
* Mark `Range.Zero` as obsolete in favor of `Range.range0` ([PR #18664](https://github.com/dotnet/fsharp/pull/18664))

src/Compiler/Checking/CheckIncrementalClasses.fs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ open FSharp.Compiler.NameResolution
1818
open FSharp.Compiler.Syntax
1919
open FSharp.Compiler.SyntaxTreeOps
2020
open FSharp.Compiler.Text
21+
open FSharp.Compiler.Text.Range
2122
open FSharp.Compiler.Xml
2223
open FSharp.Compiler.TcGlobals
2324
open FSharp.Compiler.TypedTree
@@ -111,7 +112,7 @@ let TcStaticImplicitCtorInfo_Phase2A(cenv: cenv, env, tcref: TyconRef, m, copyOf
111112
let prelimValReprInfo = TranslateSynValInfo cenv m (TcAttributes cenv env) valSynData
112113
let prelimTyschemeG = GeneralizedType(copyOfTyconTypars, cctorTy)
113114
let valReprInfo = InferGenericArityFromTyScheme prelimTyschemeG prelimValReprInfo
114-
let cctorValScheme = ValScheme(id, prelimTyschemeG, Some valReprInfo, None, Some memberInfo, false, ValInline.Never, NormalVal, Some (SynAccess.Private Range.Zero), false, true, false, false)
115+
let cctorValScheme = ValScheme(id, prelimTyschemeG, Some valReprInfo, None, Some memberInfo, false, ValInline.Never, NormalVal, Some (SynAccess.Private range0), false, true, false, false)
115116

116117
let cctorVal = MakeAndPublishVal cenv env (Parent tcref, false, ModuleOrMemberBinding, ValNotInRecScope, cctorValScheme, [(* no attributes*)], XmlDoc.Empty, None, false)
117118
cctorArgs, cctorVal, cctorValScheme

src/Compiler/Checking/Expressions/CheckExpressions.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -811,10 +811,10 @@ let TcConst (cenv: cenv) (overallTy: TType) m env synConst =
811811
Measure.Prod(tcMeasure ms1, tcMeasure ms2, m)
812812
| SynMeasure.Divide(ms1, _, (SynMeasure.Seq (_ :: _ :: _, _) as ms2), m) ->
813813
warning(Error(FSComp.SR.tcImplicitMeasureFollowingSlash(), m))
814-
let factor1 = ms1 |> Option.defaultValue (SynMeasure.One Range.Zero)
814+
let factor1 = ms1 |> Option.defaultValue (SynMeasure.One range0)
815815
Measure.Prod(tcMeasure factor1, Measure.Inv (tcMeasure ms2), ms.Range)
816816
| SynMeasure.Divide(measure1 = ms1; measure2 = ms2) ->
817-
let factor1 = ms1 |> Option.defaultValue (SynMeasure.One Range.Zero)
817+
let factor1 = ms1 |> Option.defaultValue (SynMeasure.One range0)
818818
Measure.Prod(tcMeasure factor1, Measure.Inv (tcMeasure ms2), ms.Range)
819819
| SynMeasure.Seq(mss, _) -> ProdMeasures (List.map tcMeasure mss)
820820
| SynMeasure.Anon _ -> error(Error(FSComp.SR.tcUnexpectedMeasureAnon(), m))
@@ -2307,7 +2307,7 @@ module GeneralizationHelpers =
23072307
declaredTypars
23082308
|> List.map(fun typar -> typar.Range)
23092309

2310-
let m = declaredTyparsRange |> List.fold (fun r a -> unionRanges r a) range.Zero
2310+
let m = declaredTyparsRange |> List.fold (fun r a -> unionRanges r a) range0
23112311

23122312
errorR(Error(FSComp.SR.tcPropertyRequiresExplicitTypeParameters(), m))
23132313
| SynMemberKind.Constructor ->

src/Compiler/Checking/import.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -565,10 +565,10 @@ let rec ImportProvidedType (env: ImportMap) (m: range) (* (tinst: TypeInst) *) (
565565
| TType_app (tcref, [], _) when tcref.TypeOrMeasureKind = TyparKind.Measure -> Measure.Const(tcref, tcref.Range)
566566
| TType_app (tcref, _, _) ->
567567
errorR(Error(FSComp.SR.impInvalidMeasureArgument1(tcref.CompiledName, tp.Name), m))
568-
Measure.One(tcref.Range)
568+
Measure.One tcref.Range
569569
| _ ->
570570
errorR(Error(FSComp.SR.impInvalidMeasureArgument2(tp.Name), m))
571-
Measure.One(Range.Zero)
571+
Measure.One range0
572572

573573
TType_measure (conv genericArg)
574574
else

src/Compiler/CodeGen/IlxGenSupport.fs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ open System.Reflection
77
open Internal.Utilities.Library
88
open FSharp.Compiler.AbstractIL.IL
99
open FSharp.Compiler.TcGlobals
10+
open FSharp.Compiler.Text.Range
1011
open FSharp.Compiler.TypedTreeOps
1112
open FSharp.Compiler.TypedTree
1213

@@ -404,10 +405,7 @@ let rec GetNullnessFromTType (g: TcGlobals) ty =
404405
else if isValueType then
405406
// Generic value type: 0, followed by the representation of the type arguments in order including containing types
406407
yield NullnessInfo.AmbivalentToNull
407-
else if
408-
IsUnionTypeWithNullAsTrueValue g tcref.Deref
409-
|| TypeHasAllowNull tcref g FSharp.Compiler.Text.Range.Zero
410-
then
408+
else if IsUnionTypeWithNullAsTrueValue g tcref.Deref || TypeHasAllowNull tcref g range0 then
411409
yield NullnessInfo.WithNull
412410
else
413411
// Reference type: the nullability (0, 1, or 2), followed by the representation of the type arguments in order including containing types

src/Compiler/Driver/CompilerDiagnostics.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,7 @@ type Exception with
889889
|> List.map (fun (name, tTy) ->
890890
tTy,
891891
{
892-
ArgReprInfo.Name = name |> Option.map (fun name -> Ident(name, range.Zero))
892+
ArgReprInfo.Name = name |> Option.map (fun name -> Ident(name, range0))
893893
ArgReprInfo.Attribs = []
894894
ArgReprInfo.OtherRange = None
895895
})

src/Compiler/Service/FSharpCheckerResults.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3388,7 +3388,7 @@ type FSharpCheckFileResults
33883388
| None -> ()
33893389
| Some kwDescription ->
33903390
let kwText = kw |> TaggedText.tagKeyword |> wordL |> LayoutRender.toArray
3391-
yield ToolTipElement.Single(kwText, FSharpXmlDoc.FromXmlText(Xml.XmlDoc([| kwDescription |], range.Zero)))
3391+
yield ToolTipElement.Single(kwText, FSharpXmlDoc.FromXmlText(Xml.XmlDoc([| kwDescription |], range0)))
33923392
]
33933393

33943394
/// Resolve the names at the given location to give a data tip

src/Compiler/Service/ServiceDeclarationLists.fs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ open FSharp.Compiler.Symbols.SymbolHelpers
2424
open FSharp.Compiler.Syntax.PrettyNaming
2525
open FSharp.Compiler.TcGlobals
2626
open FSharp.Compiler.Text
27+
open FSharp.Compiler.Text.Range
2728
open FSharp.Compiler.Text.Layout
2829
open FSharp.Compiler.Text.LayoutRender
2930
open FSharp.Compiler.Text.TaggedText
@@ -100,7 +101,7 @@ module DeclarationListHelpers =
100101
/// Generate the structured tooltip for a method info
101102
let FormatOverloadsToList (infoReader: InfoReader) m denv (item: ItemWithInst) minfos symbol (width: int option) : ToolTipElement =
102103
ToolTipFault |> Option.iter (fun msg ->
103-
let exn = Error((0, msg), range.Zero)
104+
let exn = Error((0, msg), range0)
104105
let ph = PhasedDiagnostic.Create(exn, BuildPhase.TypeCheck)
105106
simulateError ph)
106107

src/Compiler/Service/ServiceNavigation.fs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,14 @@ type NavigationItems(declarations: NavigationTopLevelDeclaration[]) =
100100

101101
module NavigationImpl =
102102
let unionRangesChecked r1 r2 =
103-
if equals r1 range.Zero then r2
104-
elif equals r2 range.Zero then r1
103+
if equals r1 range0 then r2
104+
elif equals r2 range0 then r1
105105
else unionRanges r1 r2
106106

107107
let rangeOfDecls2 f decls =
108108
match decls |> List.map (f >> (fun (d: NavigationItem) -> d.bodyRange)) with
109109
| hd :: tl -> tl |> List.fold unionRangesChecked hd
110-
| [] -> range.Zero
110+
| [] -> range0
111111

112112
let rangeOfDecls = rangeOfDecls2 fst
113113

@@ -118,7 +118,7 @@ module NavigationImpl =
118118
match fldspec with
119119
| SynUnionCaseKind.Fields(flds) ->
120120
flds
121-
|> List.fold (fun st (SynField(range = m)) -> unionRangesChecked m st) range.Zero
121+
|> List.fold (fun st (SynField(range = m)) -> unionRangesChecked m st) range0
122122
| SynUnionCaseKind.FullType(ty, _) -> ty.Range
123123

124124
let bodyRange mBody decls =
@@ -357,7 +357,7 @@ module NavigationImpl =
357357
]
358358
| _ -> []))
359359

360-
let m2 = members |> Seq.map fst |> Seq.fold unionRangesChecked range.Zero
360+
let m2 = members |> Seq.map fst |> Seq.fold unionRangesChecked range0
361361
let items = members |> List.collect snd
362362
m2, items
363363

src/Compiler/Symbols/FSharpDiagnostic.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ type FSharpDiagnostic(m: range, severity: FSharpDiagnosticSeverity, message: str
235235
| _ -> diagnostic.FormatCore(flatErrors, suggestNames)
236236

237237
let errorNum = diagnostic.Number
238-
let m = match diagnostic.Range with Some m -> m | None -> range.Zero
238+
let m = match diagnostic.Range with Some m -> m | None -> range0
239239
FSharpDiagnostic(m, severity, msg, diagnostic.Subcategory(), errorNum, "FS", extendedData)
240240

241241
static member NewlineifyErrorString(message) = NewlineifyErrorString(message)

0 commit comments

Comments
 (0)