Skip to content

Commit 8f4f286

Browse files
committed
Merge pull request #404 from dsyme/vf-align-4
more code alignment with Microsoft/visualfsharp
2 parents 7f8761a + 0b837b7 commit 8f4f286

11 files changed

+58
-61
lines changed

src/assemblyinfo/assemblyinfo.FSharp.Compiler.Silverlight.dll.fs

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/fsharp/CheckFormatStrings.fs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ let lowestDefaultPriority = 0 (* See comment on TyparConstraint.DefaultsTo *)
2424

2525
let mkFlexibleFormatTypar m tys dflt =
2626
let tp = NewTypar (TyparKind.Type,TyparRigidity.Rigid,Typar(mkSynId m "fmt",HeadTypeStaticReq,true),false,TyparDynamicReq.Yes,[],false,false)
27-
tp.FixupConstraints [ TyparConstraint.SimpleChoice (tys,m); TyparConstraint.DefaultsTo (lowestDefaultPriority,dflt,m)];
27+
tp.FixupConstraints [ TyparConstraint.SimpleChoice (tys,m); TyparConstraint.DefaultsTo (lowestDefaultPriority,dflt,m)]
2828
copyAndFixupFormatTypar m tp
2929

3030
let mkFlexibleIntFormatTypar g m =
@@ -48,7 +48,7 @@ let newInfo ()=
4848
addZeros = false
4949
precision = false}
5050

51-
let ParseFormatString (m: Range.range) g (source: string option) report fmt bty cty dty =
51+
let ParseFormatString (m: Range.range) g (source: string option) fmt bty cty dty =
5252
// Offset is used to adjust ranges depending on whether input string is regular, verbatim or triple-quote.
5353
// We construct a new 'fmt' string since the current 'fmt' string doesn't distinguish between "\n" and escaped "\\n".
5454
let (offset, fmt) =
@@ -291,7 +291,4 @@ let ParseFormatString (m: Range.range) g (source: string option) report fmt bty
291291
| _ -> parseLoop acc (i+1, relLine, relCol+1)
292292

293293
let results = parseLoop [] (0, 0, m.StartColumn)
294-
// Only report specifier locations if entire format strings are well-formed.
295-
for specifierLocation in specifierLocations do
296-
report specifierLocation
297-
results
294+
results, Seq.toList specifierLocations

src/fsharp/CheckFormatStrings.fsi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ open Microsoft.FSharp.Compiler.Tast
1313
open Microsoft.FSharp.Compiler.TcGlobals
1414
open Microsoft.FSharp.Compiler.AbstractIL.Internal
1515

16-
val ParseFormatString : Range.range -> TcGlobals -> string option -> (Range.range -> unit) -> string -> TType -> TType -> TType -> TType * TType
16+
val ParseFormatString : Range.range -> TcGlobals -> source: string option -> fmt: string -> bty: TType -> cty: TType -> dty: TType -> (TType * TType) * Range.range list

src/fsharp/IlxGen.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6010,7 +6010,7 @@ and GenTypeDef cenv mgbuf lazyInitInfo eenv m (tycon:Tycon) =
60106010
// sort by order of declaration
60116011
// REVIEW: this should be based off tcaug_adhoc_list, which is in declaration order
60126012
tycon.MembersOfFSharpTyconSorted
6013-
|> List.sortWith (fun v1 v2 -> rangeOrder.Compare(v1.ImplRange,v2.ImplRange))
6013+
|> List.sortWith (fun v1 v2 -> rangeOrder.Compare(v1.DefinitionRange,v2.DefinitionRange))
60146014
|> List.map (GenAbstractBinding cenv eenv tref)
60156015
|> List.unzip3
60166016
|> mapTriple (List.concat, List.concat, List.concat)

src/fsharp/NameResolution.fs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,20 +1183,20 @@ let (|ValUse|_|) (item:Item) =
11831183

11841184
let (|ActivePatternCaseUse|_|) (item:Item) =
11851185
match item with
1186-
| Item.ActivePatternCase(APElemRef(_, vref, idx)) -> Some (vref.SigRange, vref.ImplRange, idx)
1186+
| Item.ActivePatternCase(APElemRef(_, vref, idx)) -> Some (vref.SigRange, vref.DefinitionRange, idx)
11871187
| Item.ActivePatternResult(ap, _, idx,_) -> Some (ap.Range, ap.Range, idx)
11881188
| _ -> None
11891189

11901190
let tyconRefDefnEq g (eref1:EntityRef) (eref2: EntityRef) =
11911191
tyconRefEq g eref1 eref2
11921192
// Signature items considered equal to implementation items
1193-
|| ((eref1.ImplRange = eref2.ImplRange || eref1.SigRange = eref2.SigRange) &&
1193+
|| ((eref1.DefinitionRange = eref2.DefinitionRange || eref1.SigRange = eref2.SigRange) &&
11941194
(eref1.LogicalName = eref2.LogicalName))
11951195

11961196
let valRefDefnEq g (vref1:ValRef) (vref2: ValRef) =
11971197
valRefEq g vref1 vref2
11981198
// Signature items considered equal to implementation items
1199-
|| ((vref1.ImplRange = vref2.ImplRange || vref1.SigRange = vref2.SigRange)) &&
1199+
|| ((vref1.DefinitionRange = vref2.DefinitionRange || vref1.SigRange = vref2.SigRange)) &&
12001200
(vref1.LogicalName = vref2.LogicalName)
12011201

12021202
let unionCaseRefDefnEq g (uc1:UnionCaseRef) (uc2: UnionCaseRef) =
@@ -1245,7 +1245,7 @@ let ItemsAreEffectivelyEqual g orig other =
12451245

12461246
| (Item.ArgName (id,_, _), ValUse vref) | (ValUse vref, Item.ArgName (id, _, _)) ->
12471247
(id.idText = vref.DisplayName &&
1248-
(id.idRange = vref.ImplRange || id.idRange = vref.SigRange))
1248+
(id.idRange = vref.DefinitionRange || id.idRange = vref.SigRange))
12491249

12501250
| ILFieldUse f1, ILFieldUse f2 ->
12511251
ILFieldInfo.ILFieldInfosUseIdenticalDefinitions f1 f2

src/fsharp/PostInferenceChecks.fs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,7 +1260,7 @@ let CheckEntityDefn cenv env (tycon:Entity) =
12601260
let hashOfImmediateProps = new Dictionary<string,_>()
12611261
for minfo in immediateMeths do
12621262
let nm = minfo.LogicalName
1263-
let m = (match minfo.ArbitraryValRef with None -> m | Some vref -> vref.ImplRange)
1263+
let m = (match minfo.ArbitraryValRef with None -> m | Some vref -> vref.DefinitionRange)
12641264
let others = getOtherMethods minfo
12651265
// abstract/default pairs of duplicate methods are OK
12661266
let IsAbstractDefaultPair (x:MethInfo) (y:MethInfo) =
@@ -1289,7 +1289,7 @@ let CheckEntityDefn cenv env (tycon:Entity) =
12891289

12901290
for pinfo in immediateProps do
12911291
let nm = pinfo.PropertyName
1292-
let m = (match pinfo.ArbitraryValRef with None -> m | Some vref -> vref.ImplRange)
1292+
let m = (match pinfo.ArbitraryValRef with None -> m | Some vref -> vref.DefinitionRange)
12931293
if hashOfImmediateMeths.ContainsKey(nm) then
12941294
errorR(Error(FSComp.SR.chkPropertySameNameMethod(nm),m))
12951295
let others = getHash hashOfImmediateProps nm
@@ -1344,7 +1344,7 @@ let CheckEntityDefn cenv env (tycon:Entity) =
13441344
for minfo in immediateMeths do
13451345
if not minfo.IsDispatchSlot && not minfo.IsVirtual && minfo.IsInstance then
13461346
let nm = minfo.LogicalName
1347-
let m = (match minfo.ArbitraryValRef with None -> m | Some vref -> vref.ImplRange)
1347+
let m = (match minfo.ArbitraryValRef with None -> m | Some vref -> vref.DefinitionRange)
13481348
let parentMethsOfSameName = getHash hashOfAllVirtualMethsInParent nm
13491349
let checkForDup erasureFlag (minfo2:MethInfo) = minfo2.IsDispatchSlot && MethInfosEquivByNameAndSig erasureFlag true cenv.g cenv.amap m minfo minfo2
13501350
match parentMethsOfSameName |> List.tryFind (checkForDup EraseAll) with
@@ -1359,11 +1359,11 @@ let CheckEntityDefn cenv env (tycon:Entity) =
13591359

13601360
if minfo.IsDispatchSlot then
13611361
let nm = minfo.LogicalName
1362-
let m = (match minfo.ArbitraryValRef with None -> m | Some vref -> vref.ImplRange)
1362+
let m = (match minfo.ArbitraryValRef with None -> m | Some vref -> vref.DefinitionRange)
13631363
let parentMethsOfSameName = getHash hashOfAllVirtualMethsInParent nm
13641364
let checkForDup erasureFlag minfo2 = MethInfosEquivByNameAndSig erasureFlag true cenv.g cenv.amap m minfo minfo2
13651365
//if minfo.NumArgs.Length > 1 then
1366-
// warning(Error(sprintf "Abstract methods taking curried arguments Duplicate method. The method '%s' has curried arguments but has the same name as another method in this type. Methods with curried arguments may not be overloaded" nm,(match minfo.ArbitraryValRef with None -> m | Some vref -> vref.ImplRange)))
1366+
// warning(Error(sprintf "Abstract methods taking curried arguments Duplicate method. The method '%s' has curried arguments but has the same name as another method in this type. Methods with curried arguments may not be overloaded" nm,(match minfo.ArbitraryValRef with None -> m | Some vref -> vref.DefinitionRange)))
13671367
if parentMethsOfSameName |> List.exists (checkForDup EraseAll) then
13681368
if parentMethsOfSameName |> List.exists (checkForDup EraseNone) then
13691369
errorR(Error(FSComp.SR.chkDuplicateMethodInheritedType(nm),m))

src/fsharp/TastPickle.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1840,7 +1840,7 @@ and p_ValData x st =
18401840
( x.val_logical_name,
18411841
x.val_compiled_name,
18421842
// only keep range information on published values, not on optimization data
1843-
(if x.val_repr_info.IsSome then Some(x.val_range, x.ImplRange) else None),
1843+
(if x.val_repr_info.IsSome then Some(x.val_range, x.DefinitionRange) else None),
18441844
x.val_type,
18451845
x.val_flags.PickledBits,
18461846
x.val_member_info,

src/fsharp/TcGlobals.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ let global_g = ref (None : TcGlobals option)
549549
#endif
550550

551551
let mkTcGlobals (compilingFslib,sysCcu,ilg,fslibCcu,directoryToResolveRelativePaths,mlCompatibility,
552-
using40environment,isInteractive,getTypeCcu, emitDebugInfoInQuotations) =
552+
using40environment,isInteractive,getTypeCcu, emitDebugInfoInQuotations) =
553553

554554
let vara = NewRigidTypar "a" envRange
555555
let varb = NewRigidTypar "b" envRange

src/fsharp/TypeChecker.fs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4115,7 +4115,7 @@ and TcTyparOrMeasurePar optKind cenv (env:TcEnv) newOk tpenv (Typar(id,_,_) as t
41154115
| _, _ ->
41164116
let item = Item.TypeVar(id.idText, res)
41174117
CallNameResolutionSink cenv.tcSink (id.idRange,env.NameEnv,item,item,ItemOccurence.UseInType,env.DisplayEnv,env.eAccessRights)
4118-
// // record the ' as well for tokenization
4118+
// record the ' as well for tokenization
41194119
// CallNameResolutionSink cenv.tcSink (tp.Range.StartRange,env.NameEnv,item,item,ItemOccurence.UseInType,env.DisplayEnv,env.eAccessRights)
41204120
res, tpenv
41214121
let key = id.idText
@@ -6299,10 +6299,16 @@ and TcConstStringExpr cenv overallTy env m tpenv s =
62996299
let ty' = mkPrintfFormatTy cenv.g aty bty cty dty ety
63006300
if (not (isObjTy cenv.g overallTy) && AddCxTypeMustSubsumeTypeUndoIfFailed env.DisplayEnv cenv.css m overallTy ty') then
63016301
// Parse the format string to work out the phantom types
6302-
let report m = match cenv.tcSink.CurrentSink with None -> () | Some sink -> sink.NotifyFormatSpecifierLocation m
63036302
let source = match cenv.tcSink.CurrentSink with None -> None | Some sink -> sink.CurrentSource
63046303

6305-
let aty',ety' = (try CheckFormatStrings.ParseFormatString m cenv.g source report (s.Replace("\r\n", "\n").Replace("\r", "\n")) bty cty dty with Failure s -> error (Error(FSComp.SR.tcUnableToParseFormatString(s),m)))
6304+
let (aty',ety'), specifierLocations = (try CheckFormatStrings.ParseFormatString m cenv.g source (s.Replace("\r\n", "\n").Replace("\r", "\n")) bty cty dty with Failure s -> error (Error(FSComp.SR.tcUnableToParseFormatString(s),m)))
6305+
6306+
match cenv.tcSink.CurrentSink with
6307+
| None -> ()
6308+
| Some sink ->
6309+
for specifierLocation in specifierLocations do
6310+
sink.NotifyFormatSpecifierLocation specifierLocation
6311+
63066312
UnifyTypes cenv env m aty aty'
63076313
UnifyTypes cenv env m ety ety'
63086314
mkCallNewFormat cenv.g m aty bty cty dty ety (mkString cenv.g m s),tpenv

src/fsharp/tast.fs

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ type Entity =
518518
x.Data.entity_range
519519

520520
/// The range in the implementation, adjusted for an item in a signature
521-
member x.ImplRange =
521+
member x.DefinitionRange =
522522
match x.Data.entity_other_range with
523523
| Some (r, true) -> r
524524
| _ -> x.Range
@@ -977,7 +977,7 @@ and
977977
entity_range: range
978978

979979
// MUTABILITY: the signature is adjusted when it is checked
980-
/// If the flag is true, this is the implementation range for an item in a signature, otherwise it is
980+
/// If this field is populated, this is the implementation range for an item in a signature, otherwise it is
981981
/// the signature range for an item in an implementation
982982
mutable entity_other_range: (range * bool) option
983983

@@ -1303,7 +1303,7 @@ and
13031303
/// Name/range of the case
13041304
Id: Ident
13051305

1306-
/// If the flag is true, this is the implementation range for an item in a signature, otherwise it is
1306+
/// If this field is populated, this is the implementation range for an item in a signature, otherwise it is
13071307
/// the signature range for an item in an implementation
13081308
// MUTABILITY: used when propagating signature attributes into the implementation.
13091309
mutable OtherRangeOpt : (range * bool) option
@@ -1316,14 +1316,17 @@ and
13161316
mutable Attribs: Attribs }
13171317

13181318
member uc.Range = uc.Id.idRange
1319-
member uc.ImplRange =
1319+
1320+
member uc.DefinitionRange =
13201321
match uc.OtherRangeOpt with
13211322
| Some (m,true) -> m
13221323
| _ -> uc.Range
1324+
13231325
member uc.SigRange =
13241326
match uc.OtherRangeOpt with
13251327
| Some (m,false) -> m
13261328
| _ -> uc.Range
1329+
13271330
member uc.DisplayName = uc.Id.idText
13281331
member uc.RecdFieldsArray = uc.FieldTable.FieldsByIndex
13291332
member uc.RecdFields = uc.FieldTable.FieldsByIndex |> Array.toList
@@ -1373,7 +1376,7 @@ and
13731376
/// Name/declaration-location of the field
13741377
rfield_id: Ident
13751378

1376-
/// If the flag is true, this is the implementation range for an item in a signature, otherwise it is
1379+
/// If this field is populated, this is the implementation range for an item in a signature, otherwise it is
13771380
/// the signature range for an item in an implementation
13781381
// MUTABILITY: used when propagating signature attributes into the implementation.
13791382
mutable rfield_other_range: (range * bool) option }
@@ -1389,10 +1392,12 @@ and
13891392

13901393
/// Declaration-location of the field
13911394
member v.Range = v.rfield_id.idRange
1392-
member v.ImplRange =
1395+
1396+
member v.DefinitionRange =
13931397
match v.rfield_other_range with
13941398
| Some (m, true) -> m
13951399
| _ -> v.Range
1400+
13961401
member v.SigRange =
13971402
match v.rfield_other_range with
13981403
| Some (m, false) -> m
@@ -2050,11 +2055,9 @@ and
20502055
member x.Accessibility = x.Data.val_access
20512056

20522057
/// Range of the definition (implementation) of the value, used by Visual Studio
2053-
/// Updated by mutation when the implementation is matched against the signature.
2054-
member x.ImplRange = x.Data.ImplRange
2058+
member x.DefinitionRange = x.Data.DefinitionRange
20552059

20562060
/// Range of the definition (signature) of the value, used by Visual Studio
2057-
/// Updated by mutation when the implementation is matched against the signature.
20582061
member x.SigRange = x.Data.SigRange
20592062

20602063
/// The value of a value or member marked with [<LiteralAttribute>]
@@ -2392,7 +2395,7 @@ and
23922395
{ val_logical_name: string
23932396
val_compiled_name: string option
23942397
val_range: range
2395-
/// If the flag is true, this is the implementation range for an item in a signature, otherwise it is
2398+
/// If this field is populated, this is the implementation range for an item in a signature, otherwise it is
23962399
/// the signature range for an item in an implementation
23972400
mutable val_other_range: (range * bool) option
23982401
mutable val_type: TType
@@ -2438,7 +2441,7 @@ and
24382441
/// XML documentation signature for the value
24392442
mutable val_xmldocsig : string }
24402443

2441-
member x.ImplRange =
2444+
member x.DefinitionRange =
24422445
match x.val_other_range with
24432446
| Some (m,true) -> m
24442447
| _ -> x.val_range
@@ -2711,7 +2714,7 @@ and
27112714
member x.CompiledRepresentationForNamedType = x.Deref.CompiledRepresentationForNamedType
27122715

27132716
/// The implementation definition location of the namespace, module or type
2714-
member x.ImplRange = x.Deref.ImplRange
2717+
member x.DefinitionRange = x.Deref.DefinitionRange
27152718

27162719
/// The signature definition location of the namespace, module or type
27172720
member x.SigRange = x.Deref.SigRange
@@ -3051,7 +3054,7 @@ and
30513054
/// For other values it is just the actual parent.
30523055
member x.ApparentParent = x.Deref.ApparentParent
30533056

3054-
member x.ImplRange = x.Deref.ImplRange
3057+
member x.DefinitionRange = x.Deref.DefinitionRange
30553058

30563059
member x.SigRange = x.Deref.SigRange
30573060

@@ -3186,11 +3189,16 @@ and UnionCaseRef =
31863189
match x.TyconRef.GetUnionCaseByName x.CaseName with
31873190
| Some res -> res
31883191
| None -> error(InternalError(sprintf "union case %s not found in type %s" x.CaseName x.TyconRef.LogicalName, x.TyconRef.Range))
3192+
31893193
member x.TryUnionCase = x.TyconRef.TryDeref |> Option.bind (fun tcref -> tcref.GetUnionCaseByName x.CaseName)
3194+
31903195
member x.Attribs = x.UnionCase.Attribs
31913196
member x.Range = x.UnionCase.Range
3192-
member x.ImplRange = x.UnionCase.ImplRange
3193-
member x.SigRange = x.UnionCase.ImplRange
3197+
3198+
member x.DefinitionRange = x.UnionCase.DefinitionRange
3199+
3200+
member x.SigRange = x.UnionCase.DefinitionRange
3201+
31943202
member x.Index =
31953203
try
31963204
// REVIEW: this could be faster, e.g. by storing the index in the NameMap
@@ -3211,11 +3219,15 @@ and RecdFieldRef =
32113219
match tcref.GetFieldByName id with
32123220
| Some res -> res
32133221
| None -> error(InternalError(sprintf "field %s not found in type %s" id tcref.LogicalName, tcref.Range))
3222+
32143223
member x.TryRecdField = x.TyconRef.TryDeref |> Option.bind (fun tcref -> tcref.GetFieldByName x.FieldName)
3224+
32153225
member x.PropertyAttribs = x.RecdField.PropertyAttribs
32163226
member x.Range = x.RecdField.Range
3217-
member x.ImplRange = x.RecdField.ImplRange
3218-
member x.SigRange = x.RecdField.ImplRange
3227+
3228+
member x.DefinitionRange = x.RecdField.DefinitionRange
3229+
3230+
member x.SigRange = x.RecdField.DefinitionRange
32193231

32203232
member x.Index =
32213233
let (RFRef(tcref,id)) = x

src/fsharp/vs/ServiceDeclarations.fs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,13 @@ module internal ItemDescriptionsImpl =
135135
let rangeOfValRef preferFlag (vref:ValRef) =
136136
match preferFlag with
137137
| None -> vref.Range
138-
| Some false -> vref.ImplRange
138+
| Some false -> vref.DefinitionRange
139139
| Some true -> vref.SigRange
140140

141141
let rangeOfEntityRef preferFlag (eref:EntityRef) =
142142
match preferFlag with
143143
| None -> eref.Range
144-
| Some false -> eref.ImplRange
144+
| Some false -> eref.DefinitionRange
145145
| Some true -> eref.SigRange
146146

147147

@@ -170,13 +170,13 @@ module internal ItemDescriptionsImpl =
170170
let rangeOfUnionCaseInfo preferFlag (ucinfo:UnionCaseInfo) =
171171
match preferFlag with
172172
| None -> ucinfo.UnionCase.Range
173-
| Some false -> ucinfo.UnionCase.ImplRange
173+
| Some false -> ucinfo.UnionCase.DefinitionRange
174174
| Some true -> ucinfo.UnionCase.SigRange
175175

176176
let rangeOfRecdFieldInfo preferFlag (rfinfo:RecdFieldInfo) =
177177
match preferFlag with
178178
| None -> rfinfo.RecdField.Range
179-
| Some false -> rfinfo.RecdField.ImplRange
179+
| Some false -> rfinfo.RecdField.DefinitionRange
180180
| Some true -> rfinfo.RecdField.SigRange
181181

182182
let rec rangeOfItem (g:TcGlobals) preferFlag d =

0 commit comments

Comments
 (0)