Skip to content

Commit

Permalink
Cleanup isNotNull
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed Aug 22, 2016
1 parent 123eea8 commit 374bbc8
Show file tree
Hide file tree
Showing 14 changed files with 39 additions and 13 deletions.
10 changes: 8 additions & 2 deletions src/fsharp/ErrorLogger.fs
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,17 @@ type internal CompileThreadStatic =

static member BuildPhaseUnchecked with get() = CompileThreadStatic.buildPhase (* This can be a null value *)
static member BuildPhase
with get() = if box CompileThreadStatic.buildPhase <> null then CompileThreadStatic.buildPhase else (assert false; BuildPhase.DefaultPhase)
with get() =
match box CompileThreadStatic.buildPhase with
| null -> assert false; BuildPhase.DefaultPhase
| _ -> CompileThreadStatic.buildPhase
and set v = CompileThreadStatic.buildPhase <- v

static member ErrorLogger
with get() = if box CompileThreadStatic.errorLogger <> null then CompileThreadStatic.errorLogger else !uninitializedErrorLoggerFallback
with get() =
match box CompileThreadStatic.errorLogger with
| null -> !uninitializedErrorLoggerFallback
| _ -> CompileThreadStatic.errorLogger
and set v = CompileThreadStatic.errorLogger <- v


Expand Down
1 change: 1 addition & 0 deletions src/fsharp/FSharp.Core.Unittests/SurfaceArea.coreclr.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2546,6 +2546,7 @@ Microsoft.FSharp.Core.Operators+Unchecked: System.Type GetType()
Microsoft.FSharp.Core.Operators+Unchecked: T DefaultOf[T]()
Microsoft.FSharp.Core.Operators+Unchecked: T Unbox[T](System.Object)
Microsoft.FSharp.Core.Operators: Boolean Equals(System.Object)
Microsoft.FSharp.Core.Operators: Boolean IsNotNull[T](T)
Microsoft.FSharp.Core.Operators: Boolean IsNull[T](T)
Microsoft.FSharp.Core.Operators: Boolean Not(Boolean)
Microsoft.FSharp.Core.Operators: Boolean op_Equality[T](T, T)
Expand Down
1 change: 1 addition & 0 deletions src/fsharp/FSharp.Core.Unittests/SurfaceArea.net20.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2412,6 +2412,7 @@ Microsoft.FSharp.Core.Operators+Unchecked: System.Type GetType()
Microsoft.FSharp.Core.Operators+Unchecked: T DefaultOf[T]()
Microsoft.FSharp.Core.Operators+Unchecked: T Unbox[T](System.Object)
Microsoft.FSharp.Core.Operators: Boolean Equals(System.Object)
Microsoft.FSharp.Core.Operators: Boolean IsNotNull[T](T)
Microsoft.FSharp.Core.Operators: Boolean IsNull[T](T)
Microsoft.FSharp.Core.Operators: Boolean Not(Boolean)
Microsoft.FSharp.Core.Operators: Boolean op_Equality[T](T, T)
Expand Down
1 change: 1 addition & 0 deletions src/fsharp/FSharp.Core.Unittests/SurfaceArea.net40.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2576,6 +2576,7 @@ Microsoft.FSharp.Core.Operators+Unchecked: System.Type GetType()
Microsoft.FSharp.Core.Operators+Unchecked: T DefaultOf[T]()
Microsoft.FSharp.Core.Operators+Unchecked: T Unbox[T](System.Object)
Microsoft.FSharp.Core.Operators: Boolean Equals(System.Object)
Microsoft.FSharp.Core.Operators: Boolean IsNotNull[T](T)
Microsoft.FSharp.Core.Operators: Boolean IsNull[T](T)
Microsoft.FSharp.Core.Operators: Boolean Not(Boolean)
Microsoft.FSharp.Core.Operators: Boolean op_Equality[T](T, T)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2551,6 +2551,7 @@ Microsoft.FSharp.Core.Operators+Unchecked: System.Type GetType()
Microsoft.FSharp.Core.Operators+Unchecked: T DefaultOf[T]()
Microsoft.FSharp.Core.Operators+Unchecked: T Unbox[T](System.Object)
Microsoft.FSharp.Core.Operators: Boolean Equals(System.Object)
Microsoft.FSharp.Core.Operators: Boolean IsNotNull[T](T)
Microsoft.FSharp.Core.Operators: Boolean IsNull[T](T)
Microsoft.FSharp.Core.Operators: Boolean Not(Boolean)
Microsoft.FSharp.Core.Operators: Boolean op_Equality[T](T, T)
Expand Down
1 change: 1 addition & 0 deletions src/fsharp/FSharp.Core.Unittests/SurfaceArea.portable47.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2553,6 +2553,7 @@ Microsoft.FSharp.Core.Operators+Unchecked: System.Type GetType()
Microsoft.FSharp.Core.Operators+Unchecked: T DefaultOf[T]()
Microsoft.FSharp.Core.Operators+Unchecked: T Unbox[T](System.Object)
Microsoft.FSharp.Core.Operators: Boolean Equals(System.Object)
Microsoft.FSharp.Core.Operators: Boolean IsNotNull[T](T)
Microsoft.FSharp.Core.Operators: Boolean IsNull[T](T)
Microsoft.FSharp.Core.Operators: Boolean Not(Boolean)
Microsoft.FSharp.Core.Operators: Boolean op_Equality[T](T, T)
Expand Down
1 change: 1 addition & 0 deletions src/fsharp/FSharp.Core.Unittests/SurfaceArea.portable7.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2564,6 +2564,7 @@ Microsoft.FSharp.Core.Operators+Unchecked: System.Type GetType()
Microsoft.FSharp.Core.Operators+Unchecked: T DefaultOf[T]()
Microsoft.FSharp.Core.Operators+Unchecked: T Unbox[T](System.Object)
Microsoft.FSharp.Core.Operators: Boolean Equals(System.Object)
Microsoft.FSharp.Core.Operators: Boolean IsNotNull[T](T)
Microsoft.FSharp.Core.Operators: Boolean IsNull[T](T)
Microsoft.FSharp.Core.Operators: Boolean Not(Boolean)
Microsoft.FSharp.Core.Operators: Boolean op_Equality[T](T, T)
Expand Down
1 change: 1 addition & 0 deletions src/fsharp/FSharp.Core.Unittests/SurfaceArea.portable78.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2551,6 +2551,7 @@ Microsoft.FSharp.Core.Operators+Unchecked: System.Type GetType()
Microsoft.FSharp.Core.Operators+Unchecked: T DefaultOf[T]()
Microsoft.FSharp.Core.Operators+Unchecked: T Unbox[T](System.Object)
Microsoft.FSharp.Core.Operators: Boolean Equals(System.Object)
Microsoft.FSharp.Core.Operators: Boolean IsNotNull[T](T)
Microsoft.FSharp.Core.Operators: Boolean IsNull[T](T)
Microsoft.FSharp.Core.Operators: Boolean Not(Boolean)
Microsoft.FSharp.Core.Operators: Boolean op_Equality[T](T, T)
Expand Down
6 changes: 3 additions & 3 deletions src/fsharp/FSharp.Core/control.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2228,7 +2228,7 @@ namespace Microsoft.FSharp.Control
event.RemoveHandler handle
if args.Cancelled then
ccont (new OperationCanceledException())
elif args.Error <> null then
elif isNotNull args.Error then
econt args.Error
else
cont (result args)
Expand Down Expand Up @@ -2515,8 +2515,8 @@ namespace Microsoft.FSharp.Control
| Some res -> return res }

interface System.IDisposable with
member x.Dispose() =
if pulse <> null then (pulse :> IDisposable).Dispose()
member __.Dispose() =
if isNotNull pulse then (pulse :> IDisposable).Dispose()

#if DEBUG
member x.UnsafeContents =
Expand Down
6 changes: 6 additions & 0 deletions src/fsharp/FSharp.Core/prim-types.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3804,6 +3804,12 @@ namespace Microsoft.FSharp.Core
| null -> true
| _ -> false

[<CompiledName("IsNotNull")>]
let inline isNotNull (value : 'T) =
match value with
| null -> false
| _ -> true

[<CompiledName("Raise")>]
let raise (e: exn) = (# "throw" e : 'T #)

Expand Down
6 changes: 6 additions & 0 deletions src/fsharp/FSharp.Core/prim-types.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -2150,6 +2150,12 @@ namespace Microsoft.FSharp.Core
/// <returns>True when value is null, false otherwise.</returns>
[<CompiledName("IsNull")>]
val inline isNull : value:'T -> bool when 'T : null

/// <summary>Determines whether the given value is not null.</summary>
/// <param name="value">The value to check.</param>
/// <returns>True when value is not null, false otherwise.</returns>
[<CompiledName("IsNotNull")>]
val inline isNotNull : value:'T -> bool when 'T : null

/// <summary>Throw a <c>System.Exception</c> exception.</summary>
/// <param name="message">The exception message.</param>
Expand Down
6 changes: 3 additions & 3 deletions src/fsharp/FSharp.Core/reflect.fs
Original file line number Diff line number Diff line change
Expand Up @@ -149,21 +149,21 @@ module internal Impl =

let tryFindCompilationMappingAttributeFromType (typ:Type) =
let assem = typ.Assembly
if assem <> null && assem.ReflectionOnly then
if isNotNull assem && assem.ReflectionOnly then
tryFindCompilationMappingAttributeFromData ( typ.GetCustomAttributesData())
else
tryFindCompilationMappingAttribute ( typ.GetCustomAttributes (typeof<CompilationMappingAttribute>,false))

let tryFindCompilationMappingAttributeFromMemberInfo (info:MemberInfo) =
let assem = info.DeclaringType.Assembly
if assem <> null && assem.ReflectionOnly then
if isNotNull assem && assem.ReflectionOnly then
tryFindCompilationMappingAttributeFromData (info.GetCustomAttributesData())
else
tryFindCompilationMappingAttribute (info.GetCustomAttributes (typeof<CompilationMappingAttribute>,false))

let findCompilationMappingAttributeFromMemberInfo (info:MemberInfo) =
let assem = info.DeclaringType.Assembly
if assem <> null && assem.ReflectionOnly then
if isNotNull assem && assem.ReflectionOnly then
findCompilationMappingAttributeFromData (info.GetCustomAttributesData())
else
findCompilationMappingAttribute (info.GetCustomAttributes (typeof<CompilationMappingAttribute>,false))
Expand Down
9 changes: 5 additions & 4 deletions src/utils/reshapedreflection.fs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ module internal ReflectionAdapters =
| _ -> raise (AmbiguousMatchException())

let canUseAccessor (accessor : MethodInfo) nonPublic =
box accessor <> null && (accessor.IsPublic || nonPublic)
isNotNull(box accessor) && (accessor.IsPublic || nonPublic)

type System.Type with
member this.GetTypeInfo() = IntrospectionExtensions.GetTypeInfo(this)
Expand Down Expand Up @@ -124,7 +124,7 @@ module internal ReflectionAdapters =
let bindingFlags = defaultArg bindingFlags publicFlags
(if isDeclaredFlag bindingFlags then this.GetTypeInfo().DeclaredProperties else this.GetRuntimeProperties())
|> Seq.filter (fun pi->
let mi = if pi.GetMethod <> null then pi.GetMethod else pi.SetMethod
let mi = match pi.GetMethod with | null -> pi.SetMethod | _ -> pi.GetMethod
if mi = null then false
else isAcceptable bindingFlags mi.IsStatic mi.IsPublic
)
Expand Down Expand Up @@ -179,8 +179,9 @@ module internal ReflectionAdapters =
#if FX_RESHAPED_REFLECTION_CORECLR
member this.InvokeMember(memberName, bindingFlags, _binder, target:obj, arguments:obj[], _cultureInfo) =
let m = this.GetMethod(memberName, (arguments |> Seq.map(fun x -> x.GetType()) |> Seq.toArray), bindingFlags)
if m <> null then m.Invoke(target, arguments)
else raise <| System.MissingMethodException(String.Format("Method '{0}.{1}' not found.", this.FullName, memberName))
match m with
| null -> raise <| System.MissingMethodException(String.Format("Method '{0}.{1}' not found.", this.FullName, memberName))
| _ -> m.Invoke(target, arguments)
#endif
member this.IsGenericType = this.GetTypeInfo().IsGenericType
member this.IsGenericTypeDefinition = this.GetTypeInfo().IsGenericTypeDefinition
Expand Down
2 changes: 1 addition & 1 deletion src/utils/sformat.fs
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ namespace Microsoft.FSharp.Text.StructuredFormat
let ty = obj.GetType()
#if FX_ATLEAST_PORTABLE
let prop = ty.GetProperty(name, (BindingFlags.Instance ||| BindingFlags.Public ||| BindingFlags.NonPublic))
if prop <> null then prop.GetValue(obj,[||])
if isNotNull prop then prop.GetValue(obj,[||])
#if FX_NO_MISSINGMETHODEXCEPTION
// Profile 7, 47, 78 and 259 raise MissingMemberException
else
Expand Down

0 comments on commit 374bbc8

Please sign in to comment.