Skip to content

Commit f40f00d

Browse files
authored
Chore :: Remove #IF NULLABLE, MaybeNull and other leftovers from bootstrap times of Nullable feature (#19235)
* Create TASKLIST.md * Remove BUILDING_WITH_LKG conditionals from FSharp.Core Remove all #if BUILDING_WITH_LKG || BUILD_FROM_SOURCE conditionals from prim-types.fsi (7 blocks), prim-types.fs (2 blocks), event.fsi (2 blocks), and event.fs (2 blocks). For each block, kept the #else branch which includes: - IsError=true in CompilerMessage attributes (prim-types.fsi) - 'not null' type constraints on delegate types (all files) These conditionals were only needed during F# 9 development when the shipped .NET SDK didn't yet understand NRT. Now that NRT is stable, this code can be unconditionally included. * Replace MaybeNull usages with 'T | null in Compiler/Utilities - Update NullnessShims.fs: nullSafeEquality and NonEmptyString now use 'T | null - Update lib.fs/fsi: dispose and DisposablesTracker.Register use 'T | null - Update illib.fs: reportTime and DelayInitArrayMap use nullable types - Update FileSystem.fs: isInvalidPath/Filename/Directory use pattern matching - Update Activity.fs: escapeStringForCsv and appendWithLeadingComma use nullable - Update Cancellable.fs: Using member uses _ | null - Update LruCache.fs: removeCollected uses nullable LinkedListNode - Minor formatting fix in event.fs (fantomas) Note: Cancellable.fsi retains MaybeNull in signature for backwards compatibility with consuming code (changing it causes FS3261 nullness errors downstream). The MaybeNull type alias is kept in NullnessShims.fs for this purpose. * Replace MaybeNull usages with 'T | null in FSharp.Build Replace all MaybeNull<'T> usages with the canonical 'T | null syntax in FSharp.Build implementation files: - Fsc.fs: 33 replacements - Fsi.fs: 11 replacements - FSharpCommandLineBuilder.fs: 2 method signature replacements - WriteCodeFragment.fs: 2 replacements The MaybeNull type definition is retained for backward compatibility. Type annotations added to match expressions returning null to ensure proper type inference with nullable types. * Remove unused (^) operator and cleanup MaybeNull type alias - Remove unused MaybeNull type alias definition from FSharpCommandLineBuilder.fs - Remove unused (^) null-propagation operator from NullnessShims.fs - Inline (^) usage in fsi.fs with direct null check pattern - All FSharp.Build files now use 'T | null syntax directly * Cleanup NULLABLE guarded leftovers * Delete TASKLIST.md
1 parent 7172d27 commit f40f00d

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

+262
-320
lines changed

src/Compiler/AbstractIL/ilnativeres.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ type WORD = uint16
2727

2828
let inline WORD s = uint16 s
2929

30-
type ResourceException(name: string, ?inner: Exception MaybeNull) =
30+
type ResourceException(name: string, ?inner: (Exception | null)) =
3131
inherit Exception(name, Option.toObj inner)
3232

3333
type RESOURCE_STRING() =

src/Compiler/AbstractIL/ilread.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ type WeakByteFile(fileName: string, chunk: (int * int) option) =
226226
let fileStamp = FileSystem.GetLastWriteTimeShim fileName
227227

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

231231
member _.FileName = fileName
232232

src/Compiler/AbstractIL/ilreflect.fs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ let emEnv0 =
550550
delayedFieldInits = []
551551
}
552552

553-
let envBindTypeRef emEnv (tref: ILTypeRef) (typT: Type MaybeNull, typB, typeDef) =
553+
let envBindTypeRef emEnv (tref: ILTypeRef) (typT: Type | null, typB, typeDef) =
554554
match typT with
555555
| Null -> failwithf "binding null type in envBindTypeRef: %s\n" tref.Name
556556
| NonNull typT ->
@@ -697,7 +697,7 @@ let rec convTypeSpec cenv emEnv preferCreated (tspec: ILTypeSpec) =
697697
let typT = convTypeRef cenv emEnv preferCreated tspec.TypeRef
698698
let tyargs = List.map (convTypeAux cenv emEnv preferCreated) tspec.GenericArgs
699699

700-
let res: Type MaybeNull =
700+
let res: Type | null =
701701
match isNil tyargs, typT.IsGenericType with
702702
| _, true -> typT.MakeGenericType(List.toArray tyargs)
703703
| true, false -> typT
@@ -1013,7 +1013,7 @@ let queryableTypeGetMethod cenv emEnv parentT (mref: ILMethodRef) : MethodInfo =
10131013
else
10141014
queryableTypeGetMethodBySearch cenv emEnv parentT mref
10151015

1016-
let nonQueryableTypeGetMethod (parentTI: Type) (methInfo: MethodInfo) : MethodInfo MaybeNull =
1016+
let nonQueryableTypeGetMethod (parentTI: Type) (methInfo: MethodInfo) : MethodInfo | null =
10171017
if
10181018
(parentTI.IsGenericType
10191019
&& not (equalTypes parentTI (getTypeConstructor parentTI)))
@@ -1102,7 +1102,7 @@ let queryableTypeGetConstructor cenv emEnv (parentT: Type) (mref: ILMethodRef) =
11021102
)
11031103
| NonNull res -> res
11041104

1105-
let nonQueryableTypeGetConstructor (parentTI: Type) (consInfo: ConstructorInfo) : ConstructorInfo MaybeNull =
1105+
let nonQueryableTypeGetConstructor (parentTI: Type) (consInfo: ConstructorInfo) : ConstructorInfo | null =
11061106
if parentTI.IsGenericType then
11071107
TypeBuilder.GetConstructor(parentTI, consInfo)
11081108
else

src/Compiler/AbstractIL/ilsign.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ let RSAParametersFromBlob blob keyType =
171171
key.D <- reader.ReadBigInteger byteLen
172172
key
173173

174-
let validateRSAField (field: byte array MaybeNull) expected (name: string) =
174+
let validateRSAField (field: byte array | null) expected (name: string) =
175175
match field with
176176
| Null -> ()
177177
| NonNull field ->
@@ -237,7 +237,7 @@ let toCLRKeyBlob (rsaParameters: RSAParameters) (algId: int) : byte array =
237237

238238
buffer
239239

240-
let safeArrayRev (buffer: _ MaybeNull) =
240+
let safeArrayRev (buffer: _ | null) =
241241
match buffer with
242242
| Null -> Array.empty<byte>
243243
| NonNull buffer -> buffer |> Array.rev

src/Compiler/Checking/AccessibilityLogic.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ let IsPropInfoAccessible g amap m ad = function
374374
| ProvidedProp (amap, tppi, m) as pp->
375375
let access =
376376
let a = tppi.PUntaint((fun ppi ->
377-
let tryGetILAccessForProvidedMethodBase (mi : ProvidedMethodInfo MaybeNull) =
377+
let tryGetILAccessForProvidedMethodBase (mi : (ProvidedMethodInfo | null)) =
378378
match mi with
379379
| Null -> None
380380
| NonNull mi ->

src/Compiler/Checking/MethodCalls.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1871,7 +1871,7 @@ module ProvidedMethodCalls =
18711871
allArgs: Exprs,
18721872
paramVars: Tainted<ProvidedVar>[],
18731873
g, amap, mut, isProp, isSuperInit, m,
1874-
expr: Tainted<ProvidedExpr MaybeNull>) =
1874+
expr: Tainted<(ProvidedExpr | null)>) =
18751875

18761876
let varConv =
18771877
// note: Assuming the size based on paramVars
@@ -1881,8 +1881,8 @@ module ProvidedMethodCalls =
18811881
dict.Add(v, (None, e))
18821882
dict
18831883

1884-
let rec exprToExprAndWitness top (ea: Tainted<ProvidedExpr MaybeNull>) =
1885-
let fail() = error(Error(FSComp.SR.etUnsupportedProvidedExpression(ea.PUntaint((fun etree -> etree.UnderlyingExpressionString), m)), m))
1884+
let rec exprToExprAndWitness top (ea: Tainted<(ProvidedExpr | null)>) =
1885+
let fail() = error(Error(FSComp.SR.etUnsupportedProvidedExpression(ea.PUntaint((fun etree -> match etree with null -> "<null>" | e -> e.UnderlyingExpressionString), m)), m))
18861886
match ea with
18871887
| Tainted.Null -> error(Error(FSComp.SR.etNullProvidedExpression(ea.TypeProviderDesignation), m))
18881888
| Tainted.NonNull ea ->

src/Compiler/Checking/import.fs

Lines changed: 1 addition & 1 deletion
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 MaybeNull> -> bool * ProvidedAssemblyStaticLinkingMap option
41+
abstract GetProvidedAssemblyInfo : CompilationThreadToken * range * Tainted<(ProvidedAssembly | null)> -> bool * ProvidedAssemblyStaticLinkingMap option
4242

4343
/// Record a root for a [<Generate>] type to help guide static linking & type relocation
4444
abstract RecordGeneratedTypeRoot : ProviderGeneratedType -> unit

src/Compiler/Checking/import.fsi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ type AssemblyLoader =
2828
/// table of information recording remappings from type names in the provided assembly to type
2929
/// names in the statically linked, embedded assembly.
3030
abstract GetProvidedAssemblyInfo:
31-
CompilationThreadToken * range * Tainted<ProvidedAssembly MaybeNull> ->
31+
CompilationThreadToken * range * Tainted<(ProvidedAssembly | null)> ->
3232
bool * ProvidedAssemblyStaticLinkingMap option
3333

3434
/// Record a root for a [<Generate>] type to help guide static linking & type relocation

src/Compiler/Checking/infos.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ let CrackParamAttribsInfo g (ty: TType, argInfo: ArgReprInfo) =
341341
type ILFieldInit with
342342

343343
/// Compute the ILFieldInit for the given provided constant value for a provided enum type.
344-
static member FromProvidedObj m (v: obj MaybeNull) =
344+
static member FromProvidedObj m (v: obj | null) =
345345
match v with
346346
| Null -> ILFieldInit.Null
347347
| NonNull v ->
@@ -393,8 +393,8 @@ let OptionalArgInfoOfProvidedParameter (amap: ImportMap) m (provParam : Tainted<
393393
NotOptional
394394

395395
/// Compute the ILFieldInit for the given provided constant value for a provided enum type.
396-
let GetAndSanityCheckProviderMethod m (mi: Tainted<'T :> ProvidedMemberInfo>) (get : 'T -> ProvidedMethodInfo MaybeNull) err =
397-
match mi.PApply((fun mi -> (get mi :> ProvidedMethodBase MaybeNull)),m) with
396+
let GetAndSanityCheckProviderMethod m (mi: Tainted<'T :> ProvidedMemberInfo>) (get : 'T -> (ProvidedMethodInfo | null)) err =
397+
match mi.PApply((fun mi -> (get mi :> (ProvidedMethodBase | null))),m) with
398398
| Tainted.Null -> error(Error(err(mi.PUntaint((fun mi -> mi.Name),m),mi.PUntaint((fun mi -> (nonNull mi.DeclaringType).Name), m)), m))
399399
| Tainted.NonNull meth -> meth
400400

src/Compiler/CodeGen/IlxGen.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12194,7 +12194,7 @@ let LookupGeneratedValue (cenv: cenv) (ctxt: ExecutionContext) eenv (v: Val) =
1219412194
if hasLiteralAttr then
1219512195
let staticTy = ctxt.LookupTypeRef fspec.DeclaringTypeRef
1219612196
// Checked: This FieldInfo (FieldBuilder) supports GetValue().
12197-
(!!staticTy.GetField(fspec.Name)).GetValue(null: obj MaybeNull)
12197+
(!!staticTy.GetField(fspec.Name)).GetValue(null: obj | null)
1219812198
else
1219912199
let staticTy = ctxt.LookupTypeRef ilContainerTy.TypeRef
1220012200
// We can't call .Invoke on the ILMethodRef's MethodInfo,

0 commit comments

Comments
 (0)