Skip to content

Commit df3919d

Browse files
authored
Some diff minimization for RFC FS-1060 (#15155)
* cleanup * more cleanup * fantomas * cleanup * transfer a few more changes * fantomas * fix build
1 parent b131422 commit df3919d

File tree

48 files changed

+382
-336
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+382
-336
lines changed

src/Compiler/AbstractIL/ilread.fs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ type WeakByteFile(fileName: string, chunk: (int * int) option) =
228228
let fileStamp = FileSystem.GetLastWriteTimeShim fileName
229229

230230
/// The weak handle to the bytes for the file
231-
let weakBytes = WeakReference<byte[]>(null)
231+
let weakBytes = WeakReference<byte[] MaybeNull>(null)
232232

233233
member _.FileName = fileName
234234

@@ -254,7 +254,7 @@ type WeakByteFile(fileName: string, chunk: (int * int) option) =
254254

255255
weakBytes.SetTarget bytes
256256

257-
tg
257+
nonNull tg
258258

259259
ByteMemory.FromArray(strongBytes).AsReadOnly()
260260

@@ -941,10 +941,11 @@ let mkCacheInt32 lowMem _inbase _nm _sz =
941941
fun f (idx: int32) ->
942942
let cache =
943943
match cache with
944-
| null -> cache <- ConcurrentDictionary<int32, _>(Environment.ProcessorCount, 11)
945-
| _ -> ()
946-
947-
cache
944+
| Null ->
945+
let v = ConcurrentDictionary<int32, _>(Environment.ProcessorCount, 11)
946+
cache <- v
947+
v
948+
| NonNull v -> v
948949

949950
match cache.TryGetValue idx with
950951
| true, res ->
@@ -969,10 +970,11 @@ let mkCacheGeneric lowMem _inbase _nm _sz =
969970
fun f (idx: 'T) ->
970971
let cache =
971972
match cache with
972-
| null -> cache <- ConcurrentDictionary<_, _>(Environment.ProcessorCount, 11 (* sz: int *) )
973-
| _ -> ()
974-
975-
cache
973+
| Null ->
974+
let v = ConcurrentDictionary<_, _>(Environment.ProcessorCount, 11 (* sz: int *) )
975+
cache <- v
976+
v
977+
| NonNull v -> v
976978

977979
match cache.TryGetValue idx with
978980
| true, v ->

src/Compiler/AbstractIL/ilreflect.fs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ type TypeBuilder with
265265
let t = typB.CreateTypeAndLog()
266266

267267
let m =
268-
if t <> null then
268+
if box t <> null then
269269
t.GetMethod(nm, (args |> Seq.map (fun x -> x.GetType()) |> Seq.toArray))
270270
else
271271
null
@@ -546,10 +546,10 @@ let emEnv0 =
546546
delayedFieldInits = []
547547
}
548548

549-
let envBindTypeRef emEnv (tref: ILTypeRef) (typT, typB, typeDef) =
549+
let envBindTypeRef emEnv (tref: ILTypeRef) (typT: System.Type MaybeNull, typB, typeDef) =
550550
match typT with
551-
| null -> failwithf "binding null type in envBindTypeRef: %s\n" tref.Name
552-
| _ ->
551+
| Null -> failwithf "binding null type in envBindTypeRef: %s\n" tref.Name
552+
| NonNull typT ->
553553
{ emEnv with
554554
emTypMap = Zmap.add tref (typT, typB, typeDef, None) emEnv.emTypMap
555555
}
@@ -1018,7 +1018,7 @@ let queryableTypeGetMethod cenv emEnv parentT (mref: ILMethodRef) : MethodInfo =
10181018
cconv ||| BindingFlags.Public ||| BindingFlags.NonPublic,
10191019
null,
10201020
argTs,
1021-
(null: ParameterModifier[])
1021+
(null: ParameterModifier[] MaybeNull)
10221022
)
10231023
// This can fail if there is an ambiguity w.r.t. return type
10241024
with _ ->
@@ -1102,14 +1102,14 @@ let queryableTypeGetConstructor cenv emEnv (parentT: Type) (mref: ILMethodRef) =
11021102
parentT.GetConstructor(BindingFlags.Public ||| BindingFlags.NonPublic ||| BindingFlags.Instance, null, reqArgTs, null)
11031103

11041104
match res with
1105-
| null ->
1105+
| Null ->
11061106
error (
11071107
Error(
11081108
FSComp.SR.itemNotFoundInTypeDuringDynamicCodeGen ("constructor", mref.Name, parentT.FullName, parentT.Assembly.FullName),
11091109
range0
11101110
)
11111111
)
1112-
| _ -> res
1112+
| NonNull res -> res
11131113

11141114
let nonQueryableTypeGetConstructor (parentTI: Type) (consInfo: ConstructorInfo) : ConstructorInfo MaybeNull =
11151115
if parentTI.IsGenericType then

src/Compiler/Checking/CheckExpressions.fs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4332,7 +4332,7 @@ and TcTypeOrMeasure kindOpt (cenv: cenv) newOk checkConstraints occ (iwsam: Warn
43324332
TcLongIdentType kindOpt cenv newOk checkConstraints occ iwsam env tpenv synLongId
43334333

43344334
| MultiDimensionArrayType (rank, elemTy, m) ->
4335-
TcElementType cenv newOk checkConstraints occ env tpenv rank elemTy m
4335+
TcArrayType cenv newOk checkConstraints occ env tpenv rank elemTy m
43364336

43374337
| SynType.App (StripParenTypes (SynType.LongIdent longId), _, args, _, _, postfix, m) ->
43384338
TcLongIdentAppType kindOpt cenv newOk checkConstraints occ iwsam env tpenv longId postfix args m
@@ -4353,7 +4353,7 @@ and TcTypeOrMeasure kindOpt (cenv: cenv) newOk checkConstraints occ (iwsam: Warn
43534353
TcFunctionType cenv newOk checkConstraints occ env tpenv domainTy resultTy
43544354

43554355
| SynType.Array (rank , elemTy, m) ->
4356-
TcElementType cenv newOk checkConstraints occ env tpenv rank elemTy m
4356+
TcArrayType cenv newOk checkConstraints occ env tpenv rank elemTy m
43574357

43584358
| SynType.Var (tp, _) ->
43594359
TcTypeParameter kindOpt cenv env newOk tpenv tp
@@ -4521,7 +4521,7 @@ and TcFunctionType (cenv: cenv) newOk checkConstraints occ env tpenv domainTy re
45214521
let tyR = mkFunTy g domainTyR resultTyR
45224522
tyR, tpenv
45234523

4524-
and TcElementType (cenv: cenv) newOk checkConstraints occ env tpenv rank elemTy m =
4524+
and TcArrayType (cenv: cenv) newOk checkConstraints occ env tpenv rank elemTy m =
45254525
let g = cenv.g
45264526
let elemTy, tpenv = TcTypeAndRecover cenv newOk checkConstraints occ WarnOnIWSAM.Yes env tpenv elemTy
45274527
let tyR = mkArrayTy g rank elemTy m
@@ -5339,8 +5339,8 @@ and TcExprUndelayedNoType (cenv: cenv) env tpenv synExpr =
53395339
let expr, tpenv = TcExprUndelayed cenv (MustEqual overallTy) env tpenv synExpr
53405340
expr, overallTy, tpenv
53415341

5342-
/// Process a leaf construct where the actual type (or an approximation of it such as 'list<_>'
5343-
/// or 'array<_>') is already sufficiently pre-known, and the information in the overall type
5342+
/// Process a leaf construct where the actual type (or an approximation of it such as '_ list'
5343+
/// or '_ array') is already sufficiently pre-known, and the information in the overall type
53445344
/// can be eagerly propagated into the actual type (UnifyOverallType), including pre-calculating
53455345
/// any type-directed conversion. This must mean that types extracted when processing the expression are not
53465346
/// considered in determining any type-directed conversion.

src/Compiler/Checking/ConstraintSolver.fs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1203,7 +1203,9 @@ and SolveTypeEqualsType (csenv: ConstraintSolverEnv) ndeep m2 (trace: OptionalTr
12031203
if not (typarsAEquiv g aenv tps1 tps2) then localAbortD else
12041204
SolveTypeEqualsTypeKeepAbbrevs csenv ndeep m2 trace bodyTy1 bodyTy2
12051205

1206-
| TType_ucase (uc1, l1), TType_ucase (uc2, l2) when g.unionCaseRefEq uc1 uc2 -> SolveTypeEqualsTypeEqns csenv ndeep m2 trace None l1 l2
1206+
| TType_ucase (uc1, l1), TType_ucase (uc2, l2) when g.unionCaseRefEq uc1 uc2 ->
1207+
SolveTypeEqualsTypeEqns csenv ndeep m2 trace None l1 l2
1208+
12071209
| _ -> localAbortD
12081210

12091211
and SolveTypeEqualsTypeKeepAbbrevs csenv ndeep m2 trace ty1 ty2 =

src/Compiler/Checking/MethodCalls.fs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,7 +1067,7 @@ let MakeMethInfoCall (amap: ImportMap) m (minfo: MethInfo) minst args staticTyOp
10671067
let isProp = false // not necessarily correct, but this is only used post-creflect where this flag is irrelevant
10681068
let ilMethodRef = Import.ImportProvidedMethodBaseAsILMethodRef amap m mi
10691069
let isConstructor = mi.PUntaint((fun c -> c.IsConstructor), m)
1070-
let isStruct = mi.PUntaint((fun c -> c.DeclaringType.IsValueType), m)
1070+
let isStruct = mi.PUntaint((fun c -> (nonNull<ProvidedType> c.DeclaringType).IsValueType), m)
10711071
let actualTypeInst = [] // GENERIC TYPE PROVIDERS: for generics, we would have something here
10721072
let actualMethInst = [] // GENERIC TYPE PROVIDERS: for generics, we would have something here
10731073
let ilReturnTys = Option.toList (minfo.GetCompiledReturnType(amap, m, [])) // GENERIC TYPE PROVIDERS: for generics, we would have more here
@@ -1080,7 +1080,7 @@ let MakeMethInfoCall (amap: ImportMap) m (minfo: MethInfo) minst args staticTyOp
10801080
// This imports a provided method, and checks if it is a known compiler intrinsic like "1 + 2"
10811081
let TryImportProvidedMethodBaseAsLibraryIntrinsic (amap: Import.ImportMap, m: range, mbase: Tainted<ProvidedMethodBase>) =
10821082
let methodName = mbase.PUntaint((fun x -> x.Name), m)
1083-
let declaringType = Import.ImportProvidedType amap m (mbase.PApply((fun x -> x.DeclaringType), m))
1083+
let declaringType = Import.ImportProvidedType amap m (mbase.PApply((fun x -> nonNull<ProvidedType> x.DeclaringType), m))
10841084
match tryTcrefOfAppTy amap.g declaringType with
10851085
| ValueSome declaringEntity ->
10861086
if not declaringEntity.IsLocalRef && ccuEq declaringEntity.nlr.Ccu amap.g.fslibCcu then
@@ -2042,7 +2042,7 @@ module ProvidedMethodCalls =
20422042
let thisArg, paramVars =
20432043
match objArgs with
20442044
| [objArg] ->
2045-
let erasedThisTy = eraseSystemType (amap, m, mi.PApply((fun mi -> mi.DeclaringType), m))
2045+
let erasedThisTy = eraseSystemType (amap, m, mi.PApply((fun mi -> nonNull<ProvidedType> mi.DeclaringType), m))
20462046
let thisVar = erasedThisTy.PApply((fun ty -> ty.AsProvidedVar("this")), m)
20472047
Some objArg, Array.append [| thisVar |] paramVars
20482048
| [] -> None, paramVars
@@ -2062,7 +2062,7 @@ module ProvidedMethodCalls =
20622062
methInfoOpt, expr, exprTy
20632063
with
20642064
| :? TypeProviderError as tpe ->
2065-
let typeName = mi.PUntaint((fun mb -> mb.DeclaringType.FullName), m)
2065+
let typeName = mi.PUntaint((fun mb -> (nonNull<ProvidedType> mb.DeclaringType).FullName), m)
20662066
let methName = mi.PUntaint((fun mb -> mb.Name), m)
20672067
raise( tpe.WithContext(typeName, methName) ) // loses original stack trace
20682068
#endif

src/Compiler/Checking/MethodOverrides.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ module DispatchSlotChecking =
621621
// dispatch slots are ordered from the derived classes to base
622622
// so we can check the topmost dispatch slot if it is final
623623
match dispatchSlots with
624-
| meth :: _ when meth.IsFinal -> errorR(Error(FSComp.SR.tcCannotOverrideSealedMethod (sprintf "%s::%s" (meth.ApparentEnclosingType.ToString()) meth.LogicalName), m))
624+
| meth :: _ when meth.IsFinal -> errorR(Error(FSComp.SR.tcCannotOverrideSealedMethod((sprintf "%s::%s" (NicePrint.stringOfTy denv meth.ApparentEnclosingType) meth.LogicalName)), m))
625625
| _ -> ()
626626

627627
/// Get the slots of a type that can or must be implemented. This depends

src/Compiler/Checking/TypeHierarchy.fs

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -41,44 +41,47 @@ let GetSuperTypeOfType g amap m ty =
4141
let ty = stripTyEqnsAndMeasureEqns g ty
4242
#endif
4343

44-
match metadataOfTy g ty with
44+
let resBeforeNull =
45+
match metadataOfTy g ty with
4546
#if !NO_TYPEPROVIDERS
46-
| ProvidedTypeMetadata info ->
47-
let st = info.ProvidedType
48-
let superOpt = st.PApplyOption((fun st -> match st.BaseType with null -> None | t -> Some t), m)
49-
match superOpt with
50-
| None -> None
51-
| Some super -> Some(ImportProvidedType amap m super)
47+
| ProvidedTypeMetadata info ->
48+
let st = info.ProvidedType
49+
let superOpt = st.PApplyOption((fun st -> match st.BaseType with null -> None | t -> Some t), m)
50+
match superOpt with
51+
| None -> None
52+
| Some super -> Some(ImportProvidedType amap m super)
5253
#endif
53-
| ILTypeMetadata (TILObjectReprData(scoref, _, tdef)) ->
54-
let tinst = argsOfAppTy g ty
55-
match tdef.Extends with
56-
| None -> None
57-
| Some ilTy -> Some (RescopeAndImportILType scoref amap m tinst ilTy)
58-
59-
| FSharpOrArrayOrByrefOrTupleOrExnTypeMetadata ->
60-
if isFSharpObjModelTy g ty || isFSharpExceptionTy g ty then
61-
let tcref = tcrefOfAppTy g ty
62-
Some (instType (mkInstForAppTy g ty) (superOfTycon g tcref.Deref))
63-
elif isArrayTy g ty then
64-
Some g.system_Array_ty
65-
elif isRefTy g ty && not (isObjTy g ty) then
66-
Some g.obj_ty
67-
elif isStructTupleTy g ty then
68-
Some g.system_Value_ty
69-
elif isFSharpStructOrEnumTy g ty then
70-
if isFSharpEnumTy g ty then
71-
Some g.system_Enum_ty
72-
else
54+
| ILTypeMetadata (TILObjectReprData(scoref, _, tdef)) ->
55+
let tinst = argsOfAppTy g ty
56+
match tdef.Extends with
57+
| None -> None
58+
| Some ilTy -> Some (RescopeAndImportILType scoref amap m tinst ilTy)
59+
60+
| FSharpOrArrayOrByrefOrTupleOrExnTypeMetadata ->
61+
if isFSharpObjModelTy g ty || isFSharpExceptionTy g ty then
62+
let tcref = tcrefOfAppTy g ty
63+
Some (instType (mkInstForAppTy g ty) (superOfTycon g tcref.Deref))
64+
elif isArrayTy g ty then
65+
Some g.system_Array_ty
66+
elif isRefTy g ty && not (isObjTy g ty) then
67+
Some g.obj_ty
68+
elif isStructTupleTy g ty then
69+
Some g.system_Value_ty
70+
elif isFSharpStructOrEnumTy g ty then
71+
if isFSharpEnumTy g ty then
72+
Some g.system_Enum_ty
73+
else
74+
Some g.system_Value_ty
75+
elif isStructAnonRecdTy g ty then
7376
Some g.system_Value_ty
74-
elif isStructAnonRecdTy g ty then
75-
Some g.system_Value_ty
76-
elif isAnonRecdTy g ty then
77-
Some g.obj_ty
78-
elif isRecdTy g ty || isUnionTy g ty then
79-
Some g.obj_ty
80-
else
81-
None
77+
elif isAnonRecdTy g ty then
78+
Some g.obj_ty
79+
elif isRecdTy g ty || isUnionTy g ty then
80+
Some g.obj_ty
81+
else
82+
None
83+
84+
resBeforeNull
8285

8386
/// Make a type for System.Collections.Generic.IList<ty>
8487
let mkSystemCollectionsGenericIListTy (g: TcGlobals) ty =

src/Compiler/Checking/import.fs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type AssemblyLoader =
3838
/// Get a flag indicating if an assembly is a provided assembly, plus the
3939
/// table of information recording remappings from type names in the provided assembly to type
4040
/// names in the statically linked, embedded assembly.
41-
abstract GetProvidedAssemblyInfo : CompilationThreadToken * range * Tainted<ProvidedAssembly> -> bool * ProvidedAssemblyStaticLinkingMap option
41+
abstract GetProvidedAssemblyInfo : CompilationThreadToken * range * Tainted<ProvidedAssembly MaybeNull> -> bool * ProvidedAssemblyStaticLinkingMap option
4242

4343
/// Record a root for a [<Generate>] type to help guide static linking & type relocation
4444
abstract RecordGeneratedTypeRoot : ProviderGeneratedType -> unit
@@ -183,16 +183,24 @@ let rec ImportILType (env: ImportMap) m tinst ty =
183183
ImportTyconRefApp env tcref inst
184184

185185
| ILType.Byref ty -> mkByrefTy env.g (ImportILType env m tinst ty)
186+
186187
| ILType.Ptr ILType.Void when env.g.voidptr_tcr.CanDeref -> mkVoidPtrTy env.g
188+
187189
| ILType.Ptr ty -> mkNativePtrTy env.g (ImportILType env m tinst ty)
190+
188191
| ILType.FunctionPointer _ -> env.g.nativeint_ty (* failwith "cannot import this kind of type (ptr, fptr)" *)
192+
189193
| ILType.Modified(_, _, ty) ->
190194
// All custom modifiers are ignored
191195
ImportILType env m tinst ty
196+
192197
| ILType.TypeVar u16 ->
193-
try List.item (int u16) tinst
194-
with _ ->
195-
error(Error(FSComp.SR.impNotEnoughTypeParamsInScopeWhileImporting(), m))
198+
let ty =
199+
try
200+
List.item (int u16) tinst
201+
with _ ->
202+
error(Error(FSComp.SR.impNotEnoughTypeParamsInScopeWhileImporting(), m))
203+
ty
196204

197205
/// Determines if an IL type can be imported as an F# type
198206
let rec CanImportILType (env: ImportMap) m ty =
@@ -354,15 +362,15 @@ let rec ImportProvidedType (env: ImportMap) (m: range) (* (tinst: TypeInst) *) (
354362

355363
/// Import a provided method reference as an Abstract IL method reference
356364
let ImportProvidedMethodBaseAsILMethodRef (env: ImportMap) (m: range) (mbase: Tainted<ProvidedMethodBase>) =
357-
let tref = GetILTypeRefOfProvidedType (mbase.PApply((fun mbase -> mbase.DeclaringType), m), m)
365+
let tref = GetILTypeRefOfProvidedType (mbase.PApply((fun mbase -> nonNull<ProvidedType> mbase.DeclaringType), m), m)
358366

359367
let mbase =
360368
// Find the formal member corresponding to the called member
361369
match mbase.OfType<ProvidedMethodInfo>() with
362370
| Some minfo when
363-
minfo.PUntaint((fun minfo -> minfo.IsGenericMethod|| minfo.DeclaringType.IsGenericType), m) ->
371+
minfo.PUntaint((fun minfo -> minfo.IsGenericMethod|| (nonNull<ProvidedType> minfo.DeclaringType).IsGenericType), m) ->
364372

365-
let declaringType = minfo.PApply((fun minfo -> minfo.DeclaringType), m)
373+
let declaringType = minfo.PApply((fun minfo -> nonNull<ProvidedType> minfo.DeclaringType), m)
366374

367375
let declaringGenericTypeDefn =
368376
if declaringType.PUntaint((fun t -> t.IsGenericType), m) then
@@ -381,8 +389,8 @@ let ImportProvidedMethodBaseAsILMethodRef (env: ImportMap) (m: range) (mbase: Ta
381389
error(Error(FSComp.SR.etIncorrectProvidedMethod(DisplayNameOfTypeProvider(minfo.TypeProvider, m), methodName, metadataToken, typeName), m))
382390
| _ ->
383391
match mbase.OfType<ProvidedConstructorInfo>() with
384-
| Some cinfo when cinfo.PUntaint((fun x -> x.DeclaringType.IsGenericType), m) ->
385-
let declaringType = cinfo.PApply((fun x -> x.DeclaringType), m)
392+
| Some cinfo when cinfo.PUntaint((fun x -> (nonNull<ProvidedType> x.DeclaringType).IsGenericType), m) ->
393+
let declaringType = cinfo.PApply((fun x -> nonNull<ProvidedType> x.DeclaringType), m)
386394
let declaringGenericTypeDefn = declaringType.PApply((fun x -> x.GetGenericTypeDefinition()), m)
387395

388396
// We have to find the uninstantiated formal signature corresponding to this instantiated constructor.

0 commit comments

Comments
 (0)