From 009921e6b3f0f6d1e881620629a6b4c2a635d72f Mon Sep 17 00:00:00 2001 From: Kevin Ransom Date: Thu, 23 May 2019 17:45:19 -0700 Subject: [PATCH] Remove reshaped_reflection --- FSharp.Profiles.props | 6 - .../FSharp.Compiler.Service.Tests.fsproj | 4 - .../FSharp.Compiler.Service.fsproj | 4 - src/absil/illib.fs | 15 - src/absil/ilreflect.fs | 15 - src/absil/ilwrite.fs | 3 - src/fsharp/FSharp.Build/FSharp.Build.fsproj | 1 - ...Sharp.Compiler.Interactive.Settings.fsproj | 1 - .../FSharp.Compiler.Private.fsproj | 6 - src/fsharp/FSharp.Core/FSharp.Core.fsproj | 3 - src/fsharp/FSharp.Core/Linq.fs | 9 - src/fsharp/FSharp.Core/Query.fs | 5 - src/fsharp/FSharp.Core/QueryExtensions.fs | 9 - src/fsharp/FSharp.Core/array.fs | 11 - src/fsharp/FSharp.Core/async.fs | 8 - src/fsharp/FSharp.Core/async.fsi | 4 +- src/fsharp/FSharp.Core/event.fs | 4 - .../FSharp.Core/fslib-extra-pervasives.fs | 8 - src/fsharp/FSharp.Core/list.fs | 11 - src/fsharp/FSharp.Core/prim-types.fs | 48 +-- src/fsharp/FSharp.Core/prim-types.fsi | 14 - src/fsharp/FSharp.Core/printf.fs | 9 - src/fsharp/FSharp.Core/quotations.fs | 49 +-- src/fsharp/FSharp.Core/reflect.fs | 54 +-- src/fsharp/FSharp.Core/seq.fs | 8 - src/fsharp/IlxGen.fs | 7 +- src/fsharp/fsi/console.fs | 3 - src/fsharp/fsi/fsi.fs | 12 +- src/fsharp/lib.fs | 2 - src/utils/CompilerLocationUtils.fs | 13 - src/utils/reshapedreflection.fs | 401 ------------------ src/utils/sformat.fs | 68 +-- src/utils/sformat.fsi | 8 - .../FSharp.Core/DiscrimantedUnionType.fs | 11 - .../FSharpReflection.fs | 36 +- .../FSharp.Core/RecordTypes.fs | 10 - tests/FSharp.Core.UnitTests/LibraryTestFx.fs | 30 +- tests/fsharp/core/quotes/test.fsx | 20 +- tests/fsharp/core/subtype/test.fsx | 4 - tests/fsharp/single-test.fs | 1 - tests/fsharpqa/Source/Misc/AsyncOperations.fs | 4 +- tests/service/Common.fs | 4 - tests/service/FscTests.fs | 4 - tests/service/ReshapedReflection.fs | 9 - .../Utils/LanguageServiceProfiling/Options.fs | 3 +- 45 files changed, 27 insertions(+), 932 deletions(-) delete mode 100644 src/utils/reshapedreflection.fs delete mode 100644 tests/service/ReshapedReflection.fs diff --git a/FSharp.Profiles.props b/FSharp.Profiles.props index 78b3185ad315..6b473ce7eeac 100644 --- a/FSharp.Profiles.props +++ b/FSharp.Profiles.props @@ -5,7 +5,6 @@ $(DefineConstants);CROSS_PLATFORM_COMPILER $(DefineConstants);ENABLE_MONO_SUPPORT - $(DefineConstants);BE_SECURITY_TRANSPARENT $(DefineConstants);FX_LCIDFROMCODEPAGE @@ -16,17 +15,12 @@ $(DefineConstants);FX_NO_LINKEDRESOURCES $(DefineConstants);FX_NO_PDB_READER $(DefineConstants);FX_NO_PDB_WRITER - $(DefineConstants);FX_NO_RUNTIMEENVIRONMENT - $(DefineConstants);FX_NO_SECURITY_PERMISSIONS - $(DefineConstants);FX_NO_SERVERCODEPAGES $(DefineConstants);FX_NO_SYMBOLSTORE $(DefineConstants);FX_NO_SYSTEM_CONFIGURATION - $(DefineConstants);FX_NO_WEB_CLIENT $(DefineConstants);FX_NO_WIN_REGISTRY $(DefineConstants);FX_NO_WINFORMS $(DefineConstants);FX_NO_INDENTED_TEXT_WRITER $(DefineConstants);FX_RESHAPED_REFEMIT - $(DefineConstants);FX_RESHAPED_REFLECTION $(DefineConstants);FX_RESHAPED_MSBUILD $(OtherFlags) --simpleresolution diff --git a/fcs/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.Tests.fsproj b/fcs/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.Tests.fsproj index 9f16ede65d42..747cbba31cc5 100644 --- a/fcs/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.Tests.fsproj +++ b/fcs/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.Tests.fsproj @@ -12,13 +12,9 @@ true - $(DefineConstants);FX_NO_RUNTIMEENVIRONMENT $(DefineConstants);NO_PROJECTCRACKER - - ReshapedReflection.fs - FsUnit.fs diff --git a/fcs/FSharp.Compiler.Service/FSharp.Compiler.Service.fsproj b/fcs/FSharp.Compiler.Service/FSharp.Compiler.Service.fsproj index 134a3ca745d8..e3fb154d5ff1 100644 --- a/fcs/FSharp.Compiler.Service/FSharp.Compiler.Service.fsproj +++ b/fcs/FSharp.Compiler.Service/FSharp.Compiler.Service.fsproj @@ -34,7 +34,6 @@ $(DefineConstants);FX_NO_SYMBOLSTORE $(DefineConstants);FX_NO_LINKEDRESOURCES $(DefineConstants);FX_NO_APP_DOMAINS - $(DefineConstants);FX_NO_RUNTIMEENVIRONMENT $(DefineConstants);FX_NO_WIN_REGISTRY $(DefineConstants);FX_NO_SYSTEM_CONFIGURATION $(DefineConstants);FX_RESHAPED_REFEMIT @@ -67,9 +66,6 @@ Logger.fs - - Reshaped/reshapedreflection.fs - ErrorText/sformat.fsi diff --git a/src/absil/illib.fs b/src/absil/illib.fs index fea0fd92a972..68b7c8d40a86 100644 --- a/src/absil/illib.fs +++ b/src/absil/illib.fs @@ -12,10 +12,6 @@ open System.Reflection open System.Threading open System.Runtime.CompilerServices -#if FX_RESHAPED_REFLECTION -open Microsoft.FSharp.Core.ReflectionAdapters -#endif - // Logical shift right treating int32 as unsigned integer. // Code that uses this should probably be adjusted to use unsigned integer types. let (>>>&) (x: int32) (n: int32) = int32 (uint32 x >>> n) @@ -258,12 +254,6 @@ module Option = module List = - //let item n xs = List.nth xs n -#if FX_RESHAPED_REFLECTION - open PrimReflectionAdapters - open Microsoft.FSharp.Core.ReflectionAdapters -#endif - let sortWithOrder (c: IComparer<'T>) elements = List.sortWith (Order.toFunction c) elements let splitAfter n l = @@ -1272,11 +1262,6 @@ type LayeredMultiMap<'Key, 'Value when 'Key : equality and 'Key : comparison>(co [] module Shim = -#if FX_RESHAPED_REFLECTION - open PrimReflectionAdapters - open Microsoft.FSharp.Core.ReflectionAdapters -#endif - type IFileSystem = /// A shim over File.ReadAllBytes diff --git a/src/absil/ilreflect.fs b/src/absil/ilreflect.fs index 3acabaff9035..9550c27cb9a2 100644 --- a/src/absil/ilreflect.fs +++ b/src/absil/ilreflect.fs @@ -24,10 +24,6 @@ open FSharp.Compiler.ErrorLogger open FSharp.Compiler.Range open FSharp.Core.Printf -#if FX_RESHAPED_REFLECTION -open Microsoft.FSharp.Core.ReflectionAdapters -#endif - let codeLabelOrder = ComparisonIdentity.Structural // Convert the output of convCustomAttr @@ -661,9 +657,6 @@ let TypeBuilderInstantiationT = ty let typeIsNotQueryable (ty: Type) = -#if FX_RESHAPED_REFLECTION - let ty = ty.GetTypeInfo() -#endif (ty :? TypeBuilder) || ((ty.GetType()).Equals(TypeBuilderInstantiationT)) //---------------------------------------------------------------------------- // convFieldSpec @@ -792,11 +785,7 @@ let queryableTypeGetMethod cenv emEnv parentT (mref: ILMethodRef) = parentT.GetMethod(mref.Name, cconv ||| BindingFlags.Public ||| BindingFlags.NonPublic, null, argTs, -#if FX_RESHAPED_REFLECTION - (null: obj[])) -#else (null: ParameterModifier[])) -#endif // This can fail if there is an ambiguity w.r.t. return type with _ -> null if (isNonNull methInfo && equalTypes resT methInfo.ReturnType) then @@ -1432,11 +1421,7 @@ let buildGenParamsPass1 _emEnv defineGenericParameters (gps: ILGenericParameterD let buildGenParamsPass1b cenv emEnv (genArgs: Type array) (gps: ILGenericParameterDefs) = -#if FX_RESHAPED_REFLECTION - let genpBs = genArgs |> Array.map (fun x -> (x.GetTypeInfo() :?> GenericTypeParameterBuilder)) -#else let genpBs = genArgs |> Array.map (fun x -> (x :?> GenericTypeParameterBuilder)) -#endif gps |> List.iteri (fun i (gp: ILGenericParameterDef) -> let gpB = genpBs.[i] // the Constraints are either the parent (base) type or interfaces. diff --git a/src/absil/ilwrite.fs b/src/absil/ilwrite.fs index 5d6bfd3ee06b..38f9fcfe39fc 100644 --- a/src/absil/ilwrite.fs +++ b/src/absil/ilwrite.fs @@ -3035,9 +3035,6 @@ module FileSystemUtilites = open System open System.Reflection open System.Globalization -#if FX_RESHAPED_REFLECTION - open Microsoft.FSharp.Core.ReflectionAdapters -#endif let progress = try System.Environment.GetEnvironmentVariable("FSharp_DebugSetFilePermissions") <> null with _ -> false let setExecutablePermission (filename: string) = diff --git a/src/fsharp/FSharp.Build/FSharp.Build.fsproj b/src/fsharp/FSharp.Build/FSharp.Build.fsproj index ef4d013dc1fc..72febbd64d3c 100644 --- a/src/fsharp/FSharp.Build/FSharp.Build.fsproj +++ b/src/fsharp/FSharp.Build/FSharp.Build.fsproj @@ -18,7 +18,6 @@ - diff --git a/src/fsharp/FSharp.Compiler.Interactive.Settings/FSharp.Compiler.Interactive.Settings.fsproj b/src/fsharp/FSharp.Compiler.Interactive.Settings/FSharp.Compiler.Interactive.Settings.fsproj index 70c01bec4f03..75af428f4f14 100644 --- a/src/fsharp/FSharp.Compiler.Interactive.Settings/FSharp.Compiler.Interactive.Settings.fsproj +++ b/src/fsharp/FSharp.Compiler.Interactive.Settings/FSharp.Compiler.Interactive.Settings.fsproj @@ -21,7 +21,6 @@ - diff --git a/src/fsharp/FSharp.Compiler.Private/FSharp.Compiler.Private.fsproj b/src/fsharp/FSharp.Compiler.Private/FSharp.Compiler.Private.fsproj index ebef5fb040b8..da4ec9b90daf 100644 --- a/src/fsharp/FSharp.Compiler.Private/FSharp.Compiler.Private.fsproj +++ b/src/fsharp/FSharp.Compiler.Private/FSharp.Compiler.Private.fsproj @@ -73,12 +73,6 @@ Logger.fs - - Reflection\reshapedreflection.fs - - - Reflection\reshapedmsbuild.fs - ErrorText\sformat.fsi diff --git a/src/fsharp/FSharp.Core/FSharp.Core.fsproj b/src/fsharp/FSharp.Core/FSharp.Core.fsproj index 1778e9a240d8..829a118bc819 100644 --- a/src/fsharp/FSharp.Core/FSharp.Core.fsproj +++ b/src/fsharp/FSharp.Core/FSharp.Core.fsproj @@ -113,9 +113,6 @@ Collections/set.fs - - Reflection/reshapedreflection.fs - Reflection/reflect.fsi diff --git a/src/fsharp/FSharp.Core/Linq.fs b/src/fsharp/FSharp.Core/Linq.fs index 4663e6f79a58..cd942cf672ce 100644 --- a/src/fsharp/FSharp.Core/Linq.fs +++ b/src/fsharp/FSharp.Core/Linq.fs @@ -162,11 +162,6 @@ open Microsoft.FSharp.Quotations open Microsoft.FSharp.Quotations.Patterns open Microsoft.FSharp.Quotations.DerivedPatterns -#if FX_RESHAPED_REFLECTION -open PrimReflectionAdapters -open ReflectionAdapters -#endif - module LeafExpressionConverter = // The following is recognized as a LINQ 'member initialization pattern' in a quotation. @@ -219,11 +214,7 @@ module LeafExpressionConverter = SubstHelperRaw(q, x, y) |> Expr.Cast let showAll = -#if FX_RESHAPED_REFLECTION - true -#else BindingFlags.Public ||| BindingFlags.NonPublic -#endif let NullableConstructor = typedefof>.GetConstructors().[0] diff --git a/src/fsharp/FSharp.Core/Query.fs b/src/fsharp/FSharp.Core/Query.fs index 742f04b32d2b..31e78f11dee2 100644 --- a/src/fsharp/FSharp.Core/Query.fs +++ b/src/fsharp/FSharp.Core/Query.fs @@ -302,11 +302,6 @@ open Microsoft.FSharp.Quotations.DerivedPatterns open Microsoft.FSharp.Linq.QueryRunExtensions -#if FX_RESHAPED_REFLECTION -open PrimReflectionAdapters -open ReflectionAdapters -#endif - [] module Query = diff --git a/src/fsharp/FSharp.Core/QueryExtensions.fs b/src/fsharp/FSharp.Core/QueryExtensions.fs index 4885899fe898..bfddf7e57ef7 100644 --- a/src/fsharp/FSharp.Core/QueryExtensions.fs +++ b/src/fsharp/FSharp.Core/QueryExtensions.fs @@ -15,11 +15,6 @@ open System.Collections.Generic open System.Linq open System.Linq.Expressions -#if FX_RESHAPED_REFLECTION -open PrimReflectionAdapters -open ReflectionAdapters -#endif - // ---------------------------------------------------------------------------- /// A type used to reconstruct a grouping after applying a mutable->immutable mapping transformation @@ -171,11 +166,7 @@ module internal Adapters = let (|RecordFieldGetSimplification|_|) (expr:Expr) = match expr with | Patterns.PropertyGet(Some (Patterns.NewRecord(typ,els)),propInfo,[]) -> -#if FX_RESHAPED_REFLECTION - let fields = Microsoft.FSharp.Reflection.FSharpType.GetRecordFields(typ, true) -#else let fields = Microsoft.FSharp.Reflection.FSharpType.GetRecordFields(typ,System.Reflection.BindingFlags.Public|||System.Reflection.BindingFlags.NonPublic) -#endif match fields |> Array.tryFindIndex (fun p -> p = propInfo) with | None -> None | Some i -> if i < els.Length then Some els.[i] else None diff --git a/src/fsharp/FSharp.Core/array.fs b/src/fsharp/FSharp.Core/array.fs index 8d7ce38869d2..0ac47bd39a60 100644 --- a/src/fsharp/FSharp.Core/array.fs +++ b/src/fsharp/FSharp.Core/array.fs @@ -10,9 +10,6 @@ namespace Microsoft.FSharp.Collections open Microsoft.FSharp.Core.Operators open Microsoft.FSharp.Core.CompilerServices open Microsoft.FSharp.Core.LanguagePrimitives.IntrinsicOperators -#if FX_RESHAPED_REFLECTION - open System.Reflection -#endif /// Basic operations on arrays [] @@ -191,11 +188,7 @@ namespace Microsoft.FSharp.Collections [] let countBy (projection: 'T->'Key) (array: 'T[]) = checkNonNull "array" array -#if FX_RESHAPED_REFLECTION - if (typeof<'Key>).GetTypeInfo().IsValueType -#else if typeof<'Key>.IsValueType -#endif then countByValueType projection array else countByRefType projection array @@ -445,11 +438,7 @@ namespace Microsoft.FSharp.Collections [] let groupBy (projection: 'T->'Key) (array: 'T[]) = checkNonNull "array" array -#if FX_RESHAPED_REFLECTION - if (typeof<'Key>).GetTypeInfo().IsValueType -#else if typeof<'Key>.IsValueType -#endif then groupByValueType projection array else groupByRefType projection array diff --git a/src/fsharp/FSharp.Core/async.fs b/src/fsharp/FSharp.Core/async.fs index baa89775622e..86a1b262a4fc 100644 --- a/src/fsharp/FSharp.Core/async.fs +++ b/src/fsharp/FSharp.Core/async.fs @@ -17,10 +17,6 @@ namespace Microsoft.FSharp.Control open Microsoft.FSharp.Control open Microsoft.FSharp.Collections -#if FX_RESHAPED_REFLECTION - open ReflectionAdapters -#endif - type LinkedSubSource(cancellationToken: CancellationToken) = let failureCTS = new CancellationTokenSource() @@ -1701,8 +1697,6 @@ namespace Microsoft.FSharp.Control | _ -> None) -#if !FX_NO_WEB_CLIENT - type System.Net.WebClient with member inline private this.Download(event: IEvent<'T, _>, handler: _ -> 'T, start, result) = let downloadAsync = @@ -1754,5 +1748,3 @@ namespace Microsoft.FSharp.Control start = (fun userToken -> this.DownloadFileAsync(address, fileName, userToken)), result = (fun _ -> ()) ) -#endif - diff --git a/src/fsharp/FSharp.Core/async.fsi b/src/fsharp/FSharp.Core/async.fsi index b3312c6990dc..8e054b39b68e 100644 --- a/src/fsharp/FSharp.Core/async.fsi +++ b/src/fsharp/FSharp.Core/async.fsi @@ -739,8 +739,7 @@ namespace Microsoft.FSharp.Control /// An asynchronous computation that waits for response to the WebRequest. [] // give the extension member a nice, unmangled compiled name, unique within this module member AsyncGetResponse : unit -> Async - -#if !FX_NO_WEB_CLIENT + type System.Net.WebClient with /// Returns an asynchronous computation that, when run, will wait for the download of the given URI. @@ -761,7 +760,6 @@ namespace Microsoft.FSharp.Control /// An asynchronous computation that will wait for the download of the URI to specified file. [] // give the extension member a nice, unmangled compiled name, unique within this module member AsyncDownloadFile : address:System.Uri * fileName: string -> Async -#endif // Internals used by MailboxProcessor module internal AsyncBuilderImpl = diff --git a/src/fsharp/FSharp.Core/event.fs b/src/fsharp/FSharp.Core/event.fs index 4489c325d5ab..8643b669c3e7 100644 --- a/src/fsharp/FSharp.Core/event.fs +++ b/src/fsharp/FSharp.Core/event.fs @@ -11,10 +11,6 @@ namespace Microsoft.FSharp.Control open System.Reflection open System.Diagnostics -#if FX_RESHAPED_REFLECTION - open ReflectionAdapters -#endif - [] type DelegateEvent<'Delegate when 'Delegate :> System.Delegate>() = let mutable multicast : System.Delegate = null diff --git a/src/fsharp/FSharp.Core/fslib-extra-pervasives.fs b/src/fsharp/FSharp.Core/fslib-extra-pervasives.fs index dd8d087345e0..0917f84a50ad 100644 --- a/src/fsharp/FSharp.Core/fslib-extra-pervasives.fs +++ b/src/fsharp/FSharp.Core/fslib-extra-pervasives.fs @@ -166,21 +166,13 @@ module ExtraTopLevelOperators = [] let dict (keyValuePairs:seq<'Key*'T>) : IDictionary<'Key,'T> = -#if FX_RESHAPED_REFLECTION - if (typeof<'Key>).GetTypeInfo().IsValueType -#else if typeof<'Key>.IsValueType -#endif then dictValueType keyValuePairs :> _ else dictRefType keyValuePairs :> _ [] let readOnlyDict (keyValuePairs:seq<'Key*'T>) : IReadOnlyDictionary<'Key,'T> = -#if FX_RESHAPED_REFLECTION - if (typeof<'Key>).GetTypeInfo().IsValueType -#else if typeof<'Key>.IsValueType -#endif then dictValueType keyValuePairs :> _ else dictRefType keyValuePairs :> _ diff --git a/src/fsharp/FSharp.Core/list.fs b/src/fsharp/FSharp.Core/list.fs index 653c557a4555..e7fd17ee52de 100644 --- a/src/fsharp/FSharp.Core/list.fs +++ b/src/fsharp/FSharp.Core/list.fs @@ -9,9 +9,6 @@ namespace Microsoft.FSharp.Collections open Microsoft.FSharp.Collections open Microsoft.FSharp.Core.CompilerServices open System.Collections.Generic -#if FX_RESHAPED_REFLECTION - open System.Reflection -#endif [] [] @@ -71,11 +68,7 @@ namespace Microsoft.FSharp.Collections [] let countBy (projection:'T->'Key) (list:'T list) = -#if FX_RESHAPED_REFLECTION - if (typeof<'Key>).GetTypeInfo().IsValueType -#else if typeof<'Key>.IsValueType -#endif then countByValueType projection list else countByRefType projection list @@ -446,11 +439,7 @@ namespace Microsoft.FSharp.Collections [] let groupBy (projection:'T->'Key) (list:'T list) = -#if FX_RESHAPED_REFLECTION - if (typeof<'Key>).GetTypeInfo().IsValueType -#else if typeof<'Key>.IsValueType -#endif then groupByValueType projection list else groupByRefType projection list diff --git a/src/fsharp/FSharp.Core/prim-types.fs b/src/fsharp/FSharp.Core/prim-types.fs index 4868e2b6e0e6..1fe3d7e841ae 100644 --- a/src/fsharp/FSharp.Core/prim-types.fs +++ b/src/fsharp/FSharp.Core/prim-types.fs @@ -374,29 +374,6 @@ namespace Microsoft.FSharp.Core /// Represents a out-argument managed pointer in F# code. This type should only be used with F# 4.5+. type outref<'T> = byref<'T, ByRefKinds.Out> -#if FX_RESHAPED_REFLECTION - module PrimReflectionAdapters = - - open System.Reflection - open System.Linq - // copied from BasicInlinedOperations - let inline box (x:'T) = (# "box !0" type ('T) x : obj #) - let inline unboxPrim<'T>(x:obj) = (# "unbox.any !0" type ('T) x : 'T #) - type System.Type with - member inline this.IsGenericType = this.GetTypeInfo().IsGenericType - member inline this.IsValueType = this.GetTypeInfo().IsValueType - member inline this.IsSealed = this.GetTypeInfo().IsSealed - member inline this.IsAssignableFrom(otherType: Type) = this.GetTypeInfo().IsAssignableFrom(otherType.GetTypeInfo()) - member inline this.GetGenericArguments() = this.GetTypeInfo().GenericTypeArguments - member inline this.GetProperty(name) = this.GetRuntimeProperty(name) - member inline this.GetMethod(name, parameterTypes) = this.GetRuntimeMethod(name, parameterTypes) - member inline this.GetCustomAttributes(attributeType: Type, inherits: bool) : obj[] = - unboxPrim<_> (box (CustomAttributeExtensions.GetCustomAttributes(this.GetTypeInfo(), attributeType, inherits).ToArray())) - - open PrimReflectionAdapters - -#endif - module internal BasicInlinedOperations = let inline unboxPrim<'T>(x:obj) = (# "unbox.any !0" type ('T) x : 'T #) let inline box (x:'T) = (# "box !0" type ('T) x : obj #) @@ -548,12 +525,8 @@ namespace Microsoft.FSharp.Core ignore obj // pretend the variable is used let e = new System.ArgumentException(ErrorStrings.AddressOpNotFirstClassString) (# "throw" (e :> System.Exception) : nativeptr<'T> #) - - + open IntrinsicOperators -#if FX_RESHAPED_REFLECTION - open PrimReflectionAdapters -#endif [] // nested module OK module IntrinsicFunctions = @@ -4132,22 +4105,12 @@ namespace Microsoft.FSharp.Core module Attributes = open System.Runtime.CompilerServices -#if !FX_NO_COMVISIBLE [] -#endif [] - -#if BE_SECURITY_TRANSPARENT [] // assembly is fully transparent #if CROSS_PLATFORM_COMPILER #else [] // v4 transparency; soon to be the default, but not yet -#endif -#else -#if !FX_NO_SECURITY_PERMISSIONS - // REVIEW: Need to choose a specific permission for the action to be applied to - [] -#endif #endif do () @@ -4514,13 +4477,10 @@ namespace Microsoft.FSharp.Core when ^T : unativeint = (# "conv.ovf.i.un" value : nativeint #) when ^T : byte = (# "conv.ovf.i.un" value : nativeint #) - module OperatorIntrinsics = - + module OperatorIntrinsics = + open System.Collections -#if FX_RESHAPED_REFLECTION - open PrimReflectionAdapters -#endif - + let notStarted() = raise (new System.InvalidOperationException(SR.GetString(SR.enumerationNotStarted))) let alreadyFinished() = raise (new System.InvalidOperationException(SR.GetString(SR.enumerationAlreadyFinished))) diff --git a/src/fsharp/FSharp.Core/prim-types.fsi b/src/fsharp/FSharp.Core/prim-types.fsi index 97aa6df8e435..264cf7ff8725 100644 --- a/src/fsharp/FSharp.Core/prim-types.fsi +++ b/src/fsharp/FSharp.Core/prim-types.fsi @@ -1342,20 +1342,6 @@ namespace Microsoft.FSharp.Core [] val inline FastCompareTuple5 : comparer:System.Collections.IComparer -> tuple1:('T1 * 'T2 * 'T3 * 'T4 * 'T5) -> tuple2:('T1 * 'T2 * 'T3 * 'T4 * 'T5) -> int -#if FX_RESHAPED_REFLECTION - module internal PrimReflectionAdapters = - - open System.Reflection - - type System.Type with - member inline IsGenericType : bool - member inline IsValueType : bool - member inline GetMethod : string * parameterTypes : Type[] -> MethodInfo - member inline GetProperty : string -> PropertyInfo - member inline IsAssignableFrom : otherType : Type -> bool - member inline GetCustomAttributes : attributeType : Type * inherits: bool -> obj[] -#endif - //------------------------------------------------------------------------- // F# Choice Types diff --git a/src/fsharp/FSharp.Core/printf.fs b/src/fsharp/FSharp.Core/printf.fs index 141c9752da91..59a3687698f7 100644 --- a/src/fsharp/FSharp.Core/printf.fs +++ b/src/fsharp/FSharp.Core/printf.fs @@ -47,11 +47,6 @@ module internal PrintfImpl = open Microsoft.FSharp.Collections open LanguagePrimitives.IntrinsicOperators -#if FX_RESHAPED_REFLECTION - open Microsoft.FSharp.Core.PrimReflectionAdapters - open Microsoft.FSharp.Core.ReflectionAdapters -#endif - open System.IO [] @@ -1070,12 +1065,8 @@ module internal PrintfImpl = static member GenericToString<'T>(spec: FormatSpecifier) = let bindingFlags = -#if FX_RESHAPED_REFLECTION - isPlusForPositives spec.Flags // true - show non-public -#else if isPlusForPositives spec.Flags then BindingFlags.Public ||| BindingFlags.NonPublic else BindingFlags.Public -#endif let useZeroWidth = isPadWithZeros spec.Flags let opts = diff --git a/src/fsharp/FSharp.Core/quotations.fs b/src/fsharp/FSharp.Core/quotations.fs index a0df83c05209..974e32c76781 100644 --- a/src/fsharp/FSharp.Core/quotations.fs +++ b/src/fsharp/FSharp.Core/quotations.fs @@ -20,11 +20,6 @@ open Microsoft.FSharp.Text.StructuredPrintfImpl.TaggedTextOps #nowarn "52" // The value has been copied to ensure the original is not mutated by this operation -#if FX_RESHAPED_REFLECTION -open PrimReflectionAdapters -open ReflectionAdapters -#endif - //-------------------------------------------------------------------------- // RAW quotations - basic data types //-------------------------------------------------------------------------- @@ -56,11 +51,7 @@ module Helpers = let staticBindingFlags = BindingFlags.Static ||| BindingFlags.Public ||| BindingFlags.NonPublic ||| BindingFlags.DeclaredOnly let staticOrInstanceBindingFlags = BindingFlags.Instance ||| BindingFlags.Static ||| BindingFlags.Public ||| BindingFlags.NonPublic ||| BindingFlags.DeclaredOnly let instanceBindingFlags = BindingFlags.Instance ||| BindingFlags.Public ||| BindingFlags.NonPublic ||| BindingFlags.DeclaredOnly -#if FX_RESHAPED_REFLECTION - let publicOrPrivateBindingFlags = true -#else let publicOrPrivateBindingFlags = BindingFlags.Public ||| BindingFlags.NonPublic -#endif let isDelegateType (typ:Type) = if typ.IsSubclassOf(typeof) then @@ -989,11 +980,7 @@ module Patterns = let resT = instFormal tyargTs rty let methInfo = try -#if FX_RESHAPED_REFLECTION - match parentT.GetMethod(nm, argTs) with -#else match parentT.GetMethod(nm, staticOrInstanceBindingFlags, null, argTs, null) with -#endif | null -> None | res -> Some res with :? AmbiguousMatchException -> None @@ -1021,11 +1008,7 @@ module Patterns = let tyArgs = List.toArray tyArgs let methInfo = try -#if FX_RESHAPED_REFLECTION - match ty.GetMethod(nm, argTypes) with -#else match ty.GetMethod(nm, staticOrInstanceBindingFlags, null, argTypes, null) with -#endif | null -> None | res -> Some res with :? AmbiguousMatchException -> None @@ -1138,21 +1121,13 @@ module Patterns = | _ -> null | ctor -> ctor - let bindProp (tc, propName, retType, argTypes, tyargs) = // We search in the instantiated type, rather than searching the generic type. let typ = mkNamedType (tc, tyargs) let argtyps : Type list = argTypes |> inst tyargs let retType : Type = retType |> inst tyargs |> removeVoid -#if FX_RESHAPED_REFLECTION - try - typ.GetProperty(propName, staticOrInstanceBindingFlags) - with :? AmbiguousMatchException -> null // more than one property found with the specified name and matching binding constraints - return null to initiate manual search - |> bindPropBySearchIfCandidateIsNull typ propName retType (Array.ofList argtyps) - |> checkNonNullResult ("propName", String.Format(SR.GetString(SR.QfailedToBindProperty), propName)) // fxcop may not see "propName" as an arg -#else typ.GetProperty(propName, staticOrInstanceBindingFlags, null, retType, Array.ofList argtyps, null) |> checkNonNullResult ("propName", String.Format(SR.GetString(SR.QfailedToBindProperty), propName)) // fxcop may not see "propName" as an arg -#endif + let bindField (tc, fldName, tyargs) = let typ = mkNamedType (tc, tyargs) typ.GetField(fldName, staticOrInstanceBindingFlags) |> checkNonNullResult ("fldName", String.Format(SR.GetString(SR.QfailedToBindField), fldName)) // fxcop may not see "fldName" as an arg @@ -1163,26 +1138,12 @@ module Patterns = let bindGenericCtor (tc:Type, argTypes:Instantiable) = let argtyps = instFormal (getGenericArguments tc) argTypes -#if FX_RESHAPED_REFLECTION - let argTypes = Array.ofList argtyps - tc.GetConstructor argTypes - |> bindCtorBySearchIfCandidateIsNull tc argTypes - |> checkNonNullResult ("tc", SR.GetString(SR.QfailedToBindConstructor)) -#else tc.GetConstructor(instanceBindingFlags, null, Array.ofList argtyps, null) |> checkNonNullResult ("tc", SR.GetString(SR.QfailedToBindConstructor)) -#endif let bindCtor (tc, argTypes:Instantiable, tyargs) = let typ = mkNamedType (tc, tyargs) let argtyps = argTypes |> inst tyargs -#if FX_RESHAPED_REFLECTION - let argTypes = Array.ofList argtyps - typ.GetConstructor argTypes - |> bindCtorBySearchIfCandidateIsNull typ argTypes - |> checkNonNullResult ("tc", SR.GetString(SR.QfailedToBindConstructor)) -#else typ.GetConstructor(instanceBindingFlags, null, Array.ofList argtyps, null) |> checkNonNullResult ("tc", SR.GetString(SR.QfailedToBindConstructor)) -#endif let chop n xs = if n < 0 then invalidArg "n" (SR.GetString(SR.inputMustBeNonNegative)) @@ -1358,11 +1319,7 @@ module Patterns = if a = "" then mscorlib elif a = "." then st.localAssembly else -#if FX_RESHAPED_REFLECTION - match System.Reflection.Assembly.Load(AssemblyName a) with -#else match System.Reflection.Assembly.Load a with -#endif | null -> raise <| System.InvalidOperationException(String.Format(SR.GetString(SR.QfailedToBindAssembly), a.ToString())) | assembly -> assembly @@ -1727,11 +1684,7 @@ module Patterns = not (decodedTopResources.ContainsKey((assem, resourceName))) then let cmaAttribForResource = -#if FX_RESHAPED_REFLECTION - CustomAttributeExtensions.GetCustomAttributes(assem, typeof) |> Seq.toArray -#else assem.GetCustomAttributes(typeof, false) -#endif |> (function null -> [| |] | x -> x) |> Array.tryPick (fun ca -> match ca with diff --git a/src/fsharp/FSharp.Core/reflect.fs b/src/fsharp/FSharp.Core/reflect.fs index d028dc8b80f2..f9e0a9daa8ef 100644 --- a/src/fsharp/FSharp.Core/reflect.fs +++ b/src/fsharp/FSharp.Core/reflect.fs @@ -27,11 +27,6 @@ module internal ReflectionUtils = [] module internal Impl = -#if FX_RESHAPED_REFLECTION - open PrimReflectionAdapters - open ReflectionAdapters -#endif - let getBindingFlags allowAccess = ReflectionUtils.toBindingFlags (defaultArg allowAccess false) let inline checkNonNull argName (v: 'T) = @@ -56,31 +51,18 @@ module internal Impl = //----------------------------------------------------------------- // GENERAL UTILITIES -#if FX_RESHAPED_REFLECTION - let instanceFieldFlags = BindingFlags.Instance - let instancePropertyFlags = BindingFlags.Instance - let staticPropertyFlags = BindingFlags.Static - let staticFieldFlags = BindingFlags.Static - let staticMethodFlags = BindingFlags.Static -#else let instanceFieldFlags = BindingFlags.GetField ||| BindingFlags.Instance let instancePropertyFlags = BindingFlags.GetProperty ||| BindingFlags.Instance let staticPropertyFlags = BindingFlags.GetProperty ||| BindingFlags.Static let staticFieldFlags = BindingFlags.GetField ||| BindingFlags.Static let staticMethodFlags = BindingFlags.Static -#endif - let getInstancePropertyInfo (typ: Type, propName, bindingFlags) = typ.GetProperty(propName, instancePropertyFlags ||| bindingFlags) let getInstancePropertyInfos (typ, names, bindingFlags) = names |> Array.map (fun nm -> getInstancePropertyInfo (typ, nm, bindingFlags)) - let getInstancePropertyReader (typ: Type, propName, bindingFlags) = match getInstancePropertyInfo(typ, propName, bindingFlags) with | null -> None -#if FX_RESHAPED_REFLECTION - | prop -> Some(fun (obj: obj) -> prop.GetValue (obj, null)) -#else | prop -> Some(fun (obj: obj) -> prop.GetValue (obj, instancePropertyFlags ||| bindingFlags, null, null, null)) -#endif + //----------------------------------------------------------------- // ATTRIBUTE DECOMPILATION @@ -277,11 +259,8 @@ module internal Impl = let getUnionCaseRecordReader (typ: Type, tag: int, bindingFlags) = let props = fieldsPropsOfUnionCase (typ, tag, bindingFlags) -#if FX_RESHAPED_REFLECTION - (fun (obj: obj) -> props |> Array.map (fun prop -> prop.GetValue (obj, null))) -#else (fun (obj: obj) -> props |> Array.map (fun prop -> prop.GetValue (obj, bindingFlags, null, null, null))) -#endif + let getUnionTagReader (typ: Type, bindingFlags) : (obj -> int) = if isOptionType typ then (fun (obj: obj) -> match obj with null -> 0 | _ -> 1) @@ -294,20 +273,12 @@ module internal Impl = | Some reader -> (fun (obj: obj) -> reader obj :?> int) | None -> (fun (obj: obj) -> -#if FX_RESHAPED_REFLECTION - let m2b = typ.GetMethod("GetTag", [| typ |]) -#else let m2b = typ.GetMethod("GetTag", BindingFlags.Static ||| bindingFlags, null, [| typ |], null) -#endif m2b.Invoke(null, [|obj|]) :?> int) let getUnionTagMemberInfo (typ: Type, bindingFlags) = match getInstancePropertyInfo (typ, "Tag", bindingFlags) with -#if FX_RESHAPED_REFLECTION - | null -> (typ.GetMethod("GetTag") :> MemberInfo) -#else | null -> (typ.GetMethod("GetTag", BindingFlags.Static ||| bindingFlags) :> MemberInfo) -#endif | info -> (info :> MemberInfo) let isUnionCaseNullary (typ: Type, tag: int, bindingFlags) = @@ -327,11 +298,8 @@ module internal Impl = let getUnionCaseConstructor (typ: Type, tag: int, bindingFlags) = let meth = getUnionCaseConstructorMethod (typ, tag, bindingFlags) (fun args -> -#if FX_RESHAPED_REFLECTION - meth.Invoke(null, args)) -#else meth.Invoke(null, BindingFlags.Static ||| BindingFlags.InvokeMethod ||| bindingFlags, null, args, null)) -#endif + let checkUnionType (unionType, bindingFlags) = checkNonNull "unionType" unionType if not (isUnionType (unionType, bindingFlags)) then @@ -505,18 +473,10 @@ module internal Impl = let ctor = if typ.IsValueType then let fields = typ.GetFields (instanceFieldFlags ||| BindingFlags.Public) |> orderTupleFields -#if FX_RESHAPED_REFLECTION - typ.GetConstructor(fields |> Array.map (fun fi -> fi.FieldType)) -#else typ.GetConstructor(BindingFlags.Public ||| BindingFlags.Instance, null, fields |> Array.map (fun fi -> fi.FieldType), null) -#endif else let props = typ.GetProperties() |> orderTupleProperties -#if FX_RESHAPED_REFLECTION - typ.GetConstructor(props |> Array.map (fun p -> p.PropertyType)) -#else typ.GetConstructor(BindingFlags.Public ||| BindingFlags.Instance, null, props |> Array.map (fun p -> p.PropertyType), null) -#endif match ctor with | null -> raise (ArgumentException (String.Format (SR.GetString (SR.invalidTupleTypeConstructorNotDefined), typ.FullName))) | _ -> () @@ -525,11 +485,7 @@ module internal Impl = let getTupleCtor(typ: Type) = let ctor = getTupleConstructorMethod typ (fun (args: obj[]) -> -#if FX_RESHAPED_REFLECTION - ctor.Invoke args) -#else ctor.Invoke(BindingFlags.InvokeMethod ||| BindingFlags.Instance ||| BindingFlags.Public, null, args, null)) -#endif let rec getTupleReader (typ: Type) = let etys = typ.GetGenericArguments() @@ -687,10 +643,6 @@ module internal Impl = if not (isTupleType tupleType) then invalidArg argName (String.Format (SR.GetString (SR.notATupleType), tupleType.FullName)) -#if FX_RESHAPED_REFLECTION -open ReflectionAdapters -#endif - [] type UnionCaseInfo(typ: System.Type, tag: int) = diff --git a/src/fsharp/FSharp.Core/seq.fs b/src/fsharp/FSharp.Core/seq.fs index ab48146b631d..97326e7315aa 100644 --- a/src/fsharp/FSharp.Core/seq.fs +++ b/src/fsharp/FSharp.Core/seq.fs @@ -1071,11 +1071,7 @@ namespace Microsoft.FSharp.Collections [] let groupBy (projection:'T->'Key) (source:seq<'T>) = -#if FX_RESHAPED_REFLECTION - if (typeof<'Key>).GetTypeInfo().IsValueType -#else if typeof<'Key>.IsValueType -#endif then mkDelayedSeq (fun () -> groupByValueType projection source) else mkDelayedSeq (fun () -> groupByRefType projection source) @@ -1164,11 +1160,7 @@ namespace Microsoft.FSharp.Collections let countBy (projection:'T->'Key) (source:seq<'T>) = checkNonNull "source" source -#if FX_RESHAPED_REFLECTION - if (typeof<'Key>).GetTypeInfo().IsValueType -#else if typeof<'Key>.IsValueType -#endif then mkDelayedSeq (fun () -> countByValueType projection source) else mkDelayedSeq (fun () -> countByRefType projection source) diff --git a/src/fsharp/IlxGen.fs b/src/fsharp/IlxGen.fs index c188b5480734..cdd9c84f71c8 100644 --- a/src/fsharp/IlxGen.fs +++ b/src/fsharp/IlxGen.fs @@ -7370,13 +7370,10 @@ and GenExnDef cenv mgbuf eenv m (exnc: Tycon) = mkLdarg 2us mkNormalCall (mkILCtorMethSpecForTy (g.iltyp_Exception, [serializationInfoType; streamingContextType])) ], None)) - -//#if BE_SECURITY_TRANSPARENT + [ilCtorDefForSerialziation] -//#else (* let getObjectDataMethodForSerialization = - let ilMethodDef = mkILNonGenericVirtualMethod ("GetObjectData", ILMemberAccess.Public, @@ -7404,7 +7401,7 @@ and GenExnDef cenv mgbuf eenv m (exnc: Tycon) = | _ -> [] let ilTypeName = tref.Name - + let interfaces = exnc.ImmediateInterfaceTypesOfFSharpTycon |> List.map (GenType cenv.amap m eenv.tyenv) let tdef = mkILGenericClass diff --git a/src/fsharp/fsi/console.fs b/src/fsharp/fsi/console.fs index aa57916df52f..39b2c81e9341 100644 --- a/src/fsharp/fsi/console.fs +++ b/src/fsharp/fsi/console.fs @@ -14,8 +14,6 @@ open Internal.Utilities module internal ConsoleOptions = let readKeyFixup (c:char) = -#if FX_NO_SERVERCODEPAGES -#else // Assumes the c:char is actually a byte in the System.Console.InputEncoding. // Convert it to a Unicode char through the encoding. if 0 <= int c && int c <= 255 then @@ -27,7 +25,6 @@ module internal ConsoleOptions = c // no fix up else assert("readKeyFixHook: given char is outside the 0..255 byte range" = "") -#endif c type internal Style = Prompt | Out | Error diff --git a/src/fsharp/fsi/fsi.fs b/src/fsharp/fsi/fsi.fs index 3ff88bbb9ed1..7032d3a1ac69 100644 --- a/src/fsharp/fsi/fsi.fs +++ b/src/fsharp/fsi/fsi.fs @@ -803,7 +803,6 @@ let internal InstallErrorLoggingOnThisThread errorLogger = SetThreadErrorLoggerNoUnwind(errorLogger) SetThreadBuildPhaseNoUnwind(BuildPhase.Interactive) -#if !FX_NO_SERVERCODEPAGES /// Set the input/output encoding. The use of a thread is due to a known bug on /// on Vista where calls to Console.InputEncoding can block the process. let internal SetServerCodePages(fsiOptions: FsiCommandLineOptions) = @@ -833,7 +832,6 @@ let internal SetServerCodePages(fsiOptions: FsiCommandLineOptions) = if not !successful then System.Windows.Forms.MessageBox.Show(FSIstrings.SR.fsiConsoleProblem()) |> ignore #endif -#endif //---------------------------------------------------------------------------- // Prompt printing @@ -2452,13 +2450,11 @@ type FsiEvaluationSession (fsi: FsiEvaluationSessionHostConfig, argv:string[], i | Some s -> Thread.CurrentThread.CurrentUICulture <- new System.Globalization.CultureInfo(s) | None -> () -#if !FX_NO_SERVERCODEPAGES - do - try - SetServerCodePages fsiOptions - with e -> + do + try + SetServerCodePages fsiOptions + with e -> warning(e) -#endif do updateBannerText() // resetting banner text after parsing options diff --git a/src/fsharp/lib.fs b/src/fsharp/lib.fs index f121639005f7..9a2a80f2b127 100755 --- a/src/fsharp/lib.fs +++ b/src/fsharp/lib.fs @@ -522,9 +522,7 @@ module UnmanagedProcessExecutionOptions = extern UInt32 private GetLastError() // Translation of C# from http://swikb/v1/DisplayOnlineDoc.aspx?entryID=826 and copy in bug://5018 -#if !FX_NO_SECURITY_PERMISSIONS [] -#endif let EnableHeapTerminationOnCorruption() = if (System.Environment.OSVersion.Version.Major >= 6 && // If OS is Vista or higher System.Environment.Version.Major < 3) then // and CLR not 3.0 or higher diff --git a/src/utils/CompilerLocationUtils.fs b/src/utils/CompilerLocationUtils.fs index 41de8bb911c9..a2861bf6d5f3 100644 --- a/src/utils/CompilerLocationUtils.fs +++ b/src/utils/CompilerLocationUtils.fs @@ -23,20 +23,7 @@ module internal FSharpEnvironment = #endif let versionOf<'t> = -#if FX_RESHAPED_REFLECTION - let aq = (typeof<'t>).AssemblyQualifiedName - let version = - if aq <> null then - let x = aq.Split(',', ' ') |> Seq.filter(fun x -> x.StartsWith("Version=", StringComparison.OrdinalIgnoreCase)) |> Seq.tryHead - match x with - | Some(x) -> x.Substring(8) - | _ -> null - else - null - version -#else typeof<'t>.Assembly.GetName().Version.ToString() -#endif let FSharpCoreLibRunningVersion = try match versionOf with diff --git a/src/utils/reshapedreflection.fs b/src/utils/reshapedreflection.fs deleted file mode 100644 index 0b143951ddac..000000000000 --- a/src/utils/reshapedreflection.fs +++ /dev/null @@ -1,401 +0,0 @@ -// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. - -namespace Microsoft.FSharp.Core -open System.Reflection - -//Replacement for: System.Security.SecurityElement.Escape(line) All platforms -module internal XmlAdapters = - open System.Text - open Microsoft.FSharp.Collections - - let s_escapeChars = [| '<'; '>'; '\"'; '\''; '&' |] - - let getEscapeSequence c = - match c with - | '<' -> "<" - | '>' -> ">" - | '\"' -> """ - | '\'' -> "'" - | '&' -> "&" - | _ as ch -> ch.ToString() - - let escape str = String.collect getEscapeSequence str - -#if FX_RESHAPED_REFLECTION -module internal ReflectionAdapters = - open System - open Microsoft.FSharp.Core.LanguagePrimitives.IntrinsicOperators - open Microsoft.FSharp.Collections - open PrimReflectionAdapters - - let inline hasFlag (flag : BindingFlags) f = (f &&& flag) = flag - let isDeclaredFlag f = hasFlag BindingFlags.DeclaredOnly f - let isPublicFlag f = hasFlag BindingFlags.Public f - let isStaticFlag f = hasFlag BindingFlags.Static f - let isInstanceFlag f = hasFlag BindingFlags.Instance f - let isNonPublicFlag f = hasFlag BindingFlags.NonPublic f - - let isAcceptable bindingFlags isStatic isPublic = - // 1. check if member kind (static\instance) was specified in flags - ((isStaticFlag bindingFlags && isStatic) || (isInstanceFlag bindingFlags && not isStatic)) && - // 2. check if member accessibility was specified in flags - ((isPublicFlag bindingFlags && isPublic) || (isNonPublicFlag bindingFlags && not isPublic)) - - let publicFlags = BindingFlags.Public ||| BindingFlags.Instance ||| BindingFlags.Static - - let commit (results : _[]) = - match results with - | [||] -> null - | [| m |] -> m - | _ -> raise (AmbiguousMatchException()) - - let canUseAccessor (accessor : MethodInfo) nonPublic = - (not (isNull (box accessor))) && (accessor.IsPublic || nonPublic) - - type System.Type with - member this.GetTypeInfo() = IntrospectionExtensions.GetTypeInfo(this) - member this.GetRuntimeProperties() = RuntimeReflectionExtensions.GetRuntimeProperties(this) - member this.GetRuntimeEvents() = RuntimeReflectionExtensions.GetRuntimeEvents(this) - member this.Attributes = this.GetTypeInfo().Attributes - member this.GetCustomAttributes(attrTy, inherits) : obj[] = downcast box(CustomAttributeExtensions.GetCustomAttributes(this.GetTypeInfo(), attrTy, inherits) |> Seq.toArray) - member this.GetNestedType (name, bindingFlags) = - // MSDN: http://msdn.microsoft.com/en-us/library/0dcb3ad5.aspx - // The following BindingFlags filter flags can be used to define which nested types to include in the search: - // You must specify either BindingFlags.Public or BindingFlags.NonPublic to get a return. - // Specify BindingFlags.Public to include public nested types in the search. - // Specify BindingFlags.NonPublic to include non-public nested types (that is, private, internal, and protected nested types) in the search. - // This method returns only the nested types of the current type. It does not search the base classes of the current type. - // To find types that are nested in base classes, you must walk the inheritance hierarchy, calling GetNestedType at each level. - let nestedTyOpt = - this.GetTypeInfo().DeclaredNestedTypes - |> Seq.tryFind (fun nestedTy -> - nestedTy.Name = name && ( - (isPublicFlag bindingFlags && nestedTy.IsNestedPublic) || - (isNonPublicFlag bindingFlags && (nestedTy.IsNestedPrivate || nestedTy.IsNestedFamily || nestedTy.IsNestedAssembly || nestedTy.IsNestedFamORAssem || nestedTy.IsNestedFamANDAssem)) - ) - ) - |> Option.map (fun ti -> ti.AsType()) - defaultArg nestedTyOpt null - // use different sources based on Declared flag - member this.GetMethods(bindingFlags) = - (if isDeclaredFlag bindingFlags then this.GetTypeInfo().DeclaredMethods else this.GetRuntimeMethods()) - |> Seq.filter (fun m -> isAcceptable bindingFlags m.IsStatic m.IsPublic) - |> Seq.toArray - - // use different sources based on Declared flag - member this.GetFields(bindingFlags) = - (if isDeclaredFlag bindingFlags then this.GetTypeInfo().DeclaredFields else this.GetRuntimeFields()) - |> Seq.filter (fun f -> isAcceptable bindingFlags f.IsStatic f.IsPublic) - |> Seq.toArray - - // use different sources based on Declared flag - member this.GetProperties(?bindingFlags) = - let bindingFlags = defaultArg bindingFlags publicFlags - (if isDeclaredFlag bindingFlags then this.GetTypeInfo().DeclaredProperties else this.GetRuntimeProperties()) - |> Seq.filter (fun pi-> - let mi = match pi.GetMethod with | null -> pi.SetMethod | _ -> pi.GetMethod - if mi = null then false - else isAcceptable bindingFlags mi.IsStatic mi.IsPublic - ) - |> Seq.toArray - - member this.GetEvents(?bindingFlags) = - let bindingFlags = defaultArg bindingFlags publicFlags - (if isDeclaredFlag bindingFlags then this.GetTypeInfo().DeclaredEvents else this.GetRuntimeEvents()) - |> Seq.filter (fun ei-> - let m = ei.GetAddMethod(true) - if m = null then false - else isAcceptable bindingFlags m.IsStatic m.IsPublic - ) - |> Seq.toArray - - member this.GetEvent(name, ?bindingFlags) = - let bindingFlags = defaultArg bindingFlags publicFlags - this.GetEvents(bindingFlags) - |> Array.filter (fun ei -> ei.Name = name) - |> commit - - member this.GetConstructor(bindingFlags, _binder, argsT:Type[], _parameterModifiers) = - this.GetConstructor(bindingFlags,argsT) - - member this.GetMethod(name, ?bindingFlags) = - let bindingFlags = defaultArg bindingFlags publicFlags - this.GetMethods(bindingFlags) - |> Array.filter(fun m -> m.Name = name) - |> commit - - member this.GetMethod(name, _bindingFlags, _binder, argsT:Type[], _parameterModifiers) = - this.GetMethod(name, argsT) - - // use different sources based on Declared flag - member this.GetProperty(name, bindingFlags) = - this.GetProperties(bindingFlags) - |> Array.filter (fun pi -> pi.Name = name) - |> commit - - member this.GetMethod(methodName, args:Type[], ?bindingFlags) = - let bindingFlags = defaultArg bindingFlags publicFlags - let compareSequences parms args = - Seq.compareWith (fun parm arg -> if parm <> arg then 1 else 0) parms args - this.GetMethods(bindingFlags) - |> Array.filter(fun m -> m.Name = methodName && (compareSequences (m.GetParameters() |> Seq.map(fun x -> x.ParameterType)) args) = 0) - |> commit - - member this.GetNestedTypes(?bindingFlags) = - let bindingFlags = defaultArg bindingFlags publicFlags - this.GetTypeInfo().DeclaredNestedTypes - |> Seq.filter (fun nestedTy-> - (isPublicFlag bindingFlags && nestedTy.IsNestedPublic) || - (isNonPublicFlag bindingFlags && (nestedTy.IsNestedPrivate || nestedTy.IsNestedFamily || nestedTy.IsNestedAssembly || nestedTy.IsNestedFamORAssem || nestedTy.IsNestedFamANDAssem))) - |> Seq.map (fun ti -> ti.AsType()) - |> Seq.toArray - - member this.GetEnumUnderlyingType() = - Enum.GetUnderlyingType(this) - - 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) - match m with - | null -> raise <| System.MissingMethodException(String.Format("Method '{0}.{1}' not found.", this.FullName, memberName)) - | _ -> m.Invoke(target, arguments) - - member this.IsGenericType = this.GetTypeInfo().IsGenericType - - member this.IsGenericTypeDefinition = this.GetTypeInfo().IsGenericTypeDefinition - - member this.GetGenericArguments() = - if this.IsGenericTypeDefinition then this.GetTypeInfo().GenericTypeParameters - elif this.IsGenericType then this.GenericTypeArguments - else [||] - - member this.IsInterface = this.GetTypeInfo().IsInterface - - member this.IsPublic = this.GetTypeInfo().IsPublic - - member this.IsNestedPublic = this.GetTypeInfo().IsNestedPublic - - member this.IsClass = this.GetTypeInfo().IsClass - - member this.IsValueType = this.GetTypeInfo().IsValueType - - member this.IsSealed = this.GetTypeInfo().IsSealed - - member this.BaseType = this.GetTypeInfo().BaseType - - member this.GetConstructor(bindingFlags, parameterTypes : Type[]) = - this.GetTypeInfo().DeclaredConstructors - |> Seq.filter (fun ci -> isAcceptable bindingFlags ci.IsStatic ci.IsPublic) - |> Seq.filter (fun ci -> - ( - let parameters = ci.GetParameters() - (parameters.Length = parameterTypes.Length) && - (parameterTypes, parameters) ||> Array.forall2 (fun ty pi -> pi.ParameterType.Equals ty) - ) - ) - |> Seq.toArray - |> commit - - member this.GetConstructor(parameterTypes : Type[]) = - this.GetConstructor(BindingFlags.Public ||| BindingFlags.NonPublic ||| BindingFlags.Instance, parameterTypes) - - member this.GetConstructors(?bindingFlags) = - let bindingFlags = defaultArg bindingFlags (BindingFlags.Public ||| BindingFlags.Instance) - // type initializer will also be included in resultset - this.GetTypeInfo().DeclaredConstructors - |> Seq.filter (fun ci -> isAcceptable bindingFlags ci.IsStatic ci.IsPublic) - |> Seq.toArray - - // MSDN: returns an array of Type objects representing all the interfaces implemented or inherited by the current Type. - member this.GetInterfaces() = this.GetTypeInfo().ImplementedInterfaces |> Seq.toArray - - member this.GetMethods() = this.GetMethods(publicFlags) - - member this.Assembly = this.GetTypeInfo().Assembly - - member this.IsSubclassOf(otherTy : Type) = this.GetTypeInfo().IsSubclassOf(otherTy) - - member this.IsEnum = this.GetTypeInfo().IsEnum; - - member this.GetField(name, bindingFlags) = - this.GetFields(bindingFlags) - |> Array.filter (fun fi -> fi.Name = name) - |> commit - - member this.GetField(name) = RuntimeReflectionExtensions.GetRuntimeField(this, name) - - member this.GetProperty(name, propertyType, parameterTypes : Type[]) = - this.GetProperties() - |> Array.filter (fun pi -> - pi.Name = name && - pi.PropertyType = propertyType && - ( - let parameters = pi.GetIndexParameters() - (parameters.Length = parameterTypes.Length) && - (parameterTypes, parameters) ||> Array.forall2 (fun ty pi -> pi.ParameterType.Equals ty) - ) - ) - |> commit - - static member GetTypeCode(ty : Type) = - if typeof.Equals ty then TypeCode.Int32 - elif typeof.Equals ty then TypeCode.Int64 - elif typeof.Equals ty then TypeCode.Byte - elif ty = typeof then TypeCode.SByte - elif ty = typeof then TypeCode.Int16 - elif ty = typeof then TypeCode.UInt16 - elif ty = typeof then TypeCode.UInt32 - elif ty = typeof then TypeCode.UInt64 - elif ty = typeof then TypeCode.Single - elif ty = typeof then TypeCode.Double - elif ty = typeof then TypeCode.Decimal - else TypeCode.Object - - member this.Module = - this.GetTypeInfo().Module - - member this.MetadataToken = - // TODO: is this an adequate replacement for MetadataToken - let s = String.Format("{0}", this.ToString()) - s.GetHashCode() - - type System.Reflection.EventInfo with - - member this.GetAddMethod() = - this.AddMethod - - member this.GetRemoveMethod() = - this.RemoveMethod - - member this.MetadataToken = - // TODO: is this an adequate replacement for MetadataToken - let s = String.Format("{0},{0}", this.DeclaringType.ToString(), this.ToString()) - s.GetHashCode() - - type System.Reflection.FieldInfo with - member this.GetRawConstantValue() = - this.GetValue(null) - - member this.MetadataToken = - // TODO: is this an adequate replacement for MetadataToken - let s = String.Format("{0},{0}", this.DeclaringType.ToString(), this.ToString()) - s.GetHashCode() - - type System.Reflection.MemberInfo with - member this.GetCustomAttributes(attrTy, inherits) : obj[] = downcast box(CustomAttributeExtensions.GetCustomAttributes(this, attrTy, inherits) |> Seq.toArray) - - // TODO: is this an adequate replacement for MetadataToken - member this.MetadataToken = - // TODO: is this an adequate replacement for MetadataToken - let s = String.Format("{0},{0}", this.DeclaringType.ToString(), this.ToString()) - s.GetHashCode() - - type System.Reflection.MethodInfo with - - member this.GetCustomAttributes(inherits : bool) : obj[] = downcast box(CustomAttributeExtensions.GetCustomAttributes(this, inherits) |> Seq.toArray) - - member this.Invoke(obj, _bindingFlags, _binder, args, _ci) = - this.Invoke(obj, args) - - member this.MetadataToken = - // TODO: is this an adequate replacement for MetadataToken - let s = String.Format("{0},{0}", this.DeclaringType.ToString(), this.ToString()) - s.GetHashCode() - - type System.Reflection.ParameterInfo with - - member this.RawDefaultValue = this.DefaultValue - - member this.MetadataToken = - // TODO: is this an adequate replacement for MetadataToken - // I really do not understand why: sprintf "%s,%s" (this.ReflectedType.ToString()) (this.ToString()) did not work - let s = String.Format("{0},{0},{0}", this.Member.DeclaringType.ToString(),this.Member.ToString(), this.ToString()) - s.GetHashCode() - - type System.Reflection.PropertyInfo with - - member this.GetGetMethod(nonPublic) = - let mi = this.GetMethod - if canUseAccessor mi nonPublic then mi - else null - - member this.GetSetMethod(nonPublic) = - let mi = this.SetMethod - if canUseAccessor mi nonPublic then mi - else null - - member this.GetGetMethod() = this.GetMethod - - member this.GetSetMethod() = this.SetMethod - - type System.Reflection.Assembly with - - member this.GetTypes() = - this.DefinedTypes - |> Seq.map (fun ti -> ti.AsType()) - |> Seq.toArray - - member this.GetExportedTypes() = - this.DefinedTypes - |> Seq.filter(fun ti -> ti.IsPublic) - |> Seq.map (fun ti -> ti.AsType()) - |> Seq.toArray - - member this.Location = - this.ManifestModule.FullyQualifiedName - - type System.Delegate with - - static member CreateDelegate(delegateType, methodInfo : MethodInfo) = methodInfo.CreateDelegate(delegateType) - - static member CreateDelegate(delegateType, obj : obj, methodInfo : MethodInfo) = methodInfo.CreateDelegate(delegateType, obj) - - type System.Object with - member this.GetPropertyValue(propName) = - this.GetType().GetProperty(propName, BindingFlags.Public).GetValue(this, null) - - member this.SetPropertyValue(propName, propValue) = - this.GetType().GetProperty(propName, BindingFlags.Public).SetValue(this, propValue, null) - - member this.GetMethod(methodName, argTypes) = - this.GetType().GetMethod(methodName, argTypes, BindingFlags.Public) - - type System.Char with - static member GetUnicodeCategory(c: char) = System.Globalization.CharUnicodeInfo.GetUnicodeCategory(c) - - type System.Reflection.Module with - member this.MetadataToken = - // TODO: is this an adequate replacement for MetadataToken - let s = this.FullyQualifiedName - s.GetHashCode() - -#if COMPILER // This part includes global state in globalLoadContext. Only include this support "once", i.e. when compiling FSharp.Compiler.Private.dll, FSharp.Compiler.Service.dll, fsc-proto.exe - - type CustomAssemblyResolver() = - inherit System.Runtime.Loader.AssemblyLoadContext() - override this.Load (assemblyName:AssemblyName):Assembly = - this.LoadFromAssemblyName(assemblyName) - - let globalLoadContext = - // This is an unfortunate temporary fix!!!! - // ======================================== - // We need to run fsi tests on a very old version of the corclr because of an unfortunate test framework - // This hack detects that, and uses the old code. - // On slightly newer code AssemblyLoadContext.Default is the way to go. - match Seq.tryHead (typeof.GetTypeInfo().Assembly.GetCustomAttributes()) with - | Some a when a.Version = "4.6.24410.01" -> new CustomAssemblyResolver() :> System.Runtime.Loader.AssemblyLoadContext - | _ -> System.Runtime.Loader.AssemblyLoadContext.Default - - type System.Reflection.Assembly with - static member LoadFrom(filename:string) = - globalLoadContext.LoadFromAssemblyPath(filename) - - static member UnsafeLoadFrom(filename:string) = - globalLoadContext.LoadFromAssemblyPath(filename) - - type System.Reflection.AssemblyName with - static member GetAssemblyName(path) = - System.Runtime.Loader.AssemblyLoadContext.GetAssemblyName(path) - -#endif - -#endif diff --git a/src/utils/sformat.fs b/src/utils/sformat.fs index b490283f6746..9d4508f4a94a 100644 --- a/src/utils/sformat.fs +++ b/src/utils/sformat.fs @@ -38,11 +38,6 @@ namespace Microsoft.FSharp.Text.StructuredPrintfImpl open Microsoft.FSharp.Collections open Microsoft.FSharp.Primitives.Basics -#if FX_RESHAPED_REFLECTION - open PrimReflectionAdapters - open ReflectionAdapters -#endif - [] type LayoutTag = | ActivePatternCase @@ -321,11 +316,7 @@ namespace Microsoft.FSharp.Text.StructuredPrintfImpl StringLimit : int; #endif FormatProvider: System.IFormatProvider; -#if FX_RESHAPED_REFLECTION - ShowNonPublic : bool -#else BindingFlags: System.Reflection.BindingFlags -#endif PrintWidth : int; PrintDepth : int; PrintLength : int; @@ -339,11 +330,7 @@ namespace Microsoft.FSharp.Text.StructuredPrintfImpl StringLimit = System.Int32.MaxValue; #endif AttributeProcessor= (fun _ _ _ -> ()); -#if FX_RESHAPED_REFLECTION - ShowNonPublic = false -#else BindingFlags = System.Reflection.BindingFlags.Public; -#endif FloatingPointFormat = "g10"; PrintWidth = 80 ; PrintDepth = 100 ; @@ -358,11 +345,6 @@ namespace Microsoft.FSharp.Text.StructuredPrintfImpl open System open System.Reflection -#if FX_RESHAPED_REFLECTION - open PrimReflectionAdapters - open Microsoft.FSharp.Core.ReflectionAdapters -#endif - [] type TypeInfo = | TupleType of Type list @@ -404,10 +386,7 @@ namespace Microsoft.FSharp.Text.StructuredPrintfImpl // Analyze an object to see if it the representation // of an F# value. - let GetValueInfoOfObject (bindingFlags:BindingFlags) (obj : obj) = -#if FX_RESHAPED_REFLECTION - let showNonPublic = isNonPublicFlag bindingFlags -#endif + let GetValueInfoOfObject (bindingFlags:BindingFlags) (obj : obj) = match obj with | null -> ObjectValue(obj) | _ -> @@ -429,34 +408,18 @@ namespace Microsoft.FSharp.Text.StructuredPrintfImpl // the type are the actual fields of the type. Again, // we should be reading attributes here that indicate the // true structure of the type, e.g. the order of the fields. -#if FX_RESHAPED_REFLECTION - elif FSharpType.IsUnion(reprty, showNonPublic) then - let tag,vals = FSharpValue.GetUnionFields (obj,reprty, showNonPublic) -#else elif FSharpType.IsUnion(reprty,bindingFlags) then let tag,vals = FSharpValue.GetUnionFields (obj,reprty,bindingFlags) -#endif let props = tag.GetFields() let pvals = (props,vals) ||> Array.map2 (fun prop v -> prop.Name,(v, prop.PropertyType)) ConstructorValue(tag.Name, Array.toList pvals) -#if FX_RESHAPED_REFLECTION - elif FSharpType.IsExceptionRepresentation(reprty, showNonPublic) then - let props = FSharpType.GetExceptionFields(reprty, showNonPublic) - let vals = FSharpValue.GetExceptionFields(obj, showNonPublic) -#else elif FSharpType.IsExceptionRepresentation(reprty,bindingFlags) then let props = FSharpType.GetExceptionFields(reprty,bindingFlags) let vals = FSharpValue.GetExceptionFields(obj,bindingFlags) -#endif let pvals = (props,vals) ||> Array.map2 (fun prop v -> prop.Name,(v, prop.PropertyType)) ExceptionValue(reprty, pvals |> Array.toList) -#if FX_RESHAPED_REFLECTION - elif FSharpType.IsRecord(reprty, showNonPublic) then - let props = FSharpType.GetRecordFields(reprty, showNonPublic) -#else elif FSharpType.IsRecord(reprty,bindingFlags) then let props = FSharpType.GetRecordFields(reprty,bindingFlags) -#endif RecordValue(props |> Array.map (fun prop -> prop.Name, prop.GetValue(obj,null), prop.PropertyType) |> Array.toList) else ObjectValue(obj) @@ -491,12 +454,8 @@ namespace Microsoft.FSharp.Text.StructuredPrintfImpl let string_of_int (i:int) = i.ToString() let typeUsesSystemObjectToString (ty:System.Type) = - try -#if FX_RESHAPED_REFLECTION - let methInfo = ty.GetRuntimeMethod("ToString",[| |]) -#else + try let methInfo = ty.GetMethod("ToString",BindingFlags.Public ||| BindingFlags.Instance,null,[| |],null) -#endif methInfo.DeclaringType = typeof with e -> false /// If "str" ends with "ending" then remove it from "str", otherwise no change. @@ -800,16 +759,8 @@ namespace Microsoft.FSharp.Text.StructuredPrintfImpl // -------------------------------------------------------------------- let getProperty (ty: Type) (obj: obj) name = -#if FX_RESHAPED_REFLECTION - let prop = ty.GetProperty(name, (BindingFlags.Instance ||| BindingFlags.Public ||| BindingFlags.NonPublic)) - if not (isNull prop) then prop.GetValue(obj,[||]) - // Others raise MissingMethodException - else - let msg = System.String.Concat([| "Method '"; ty.FullName; "."; name; "' not found." |]) - raise (System.MissingMethodException(msg)) -#else ty.InvokeMember(name, (BindingFlags.GetProperty ||| BindingFlags.Instance ||| BindingFlags.Public ||| BindingFlags.NonPublic), null, obj, [| |],CultureInfo.InvariantCulture) -#endif + let getField obj (fieldInfo: FieldInfo) = fieldInfo.GetValue(obj) @@ -1177,11 +1128,7 @@ namespace Microsoft.FSharp.Text.StructuredPrintfImpl // If the leafFormatter was directly here, then layout leaves could store strings. match obj with | _ when opts.ShowProperties -> -#if FX_RESHAPED_REFLECTION - let props = ty.GetProperties(BindingFlags.Instance ||| BindingFlags.Public) -#else let props = ty.GetProperties(BindingFlags.GetField ||| BindingFlags.Instance ||| BindingFlags.Public) -#endif let fields = ty.GetFields(BindingFlags.Instance ||| BindingFlags.Public) |> Array.map (fun i -> i :> MemberInfo) let propsAndFields = props |> Array.map (fun i -> i :> MemberInfo) @@ -1198,9 +1145,9 @@ namespace Microsoft.FSharp.Text.StructuredPrintfImpl let nDepth = depthLim/10 #if NETSTANDARD Array.Sort((propsAndFields),{ new IComparer with member this.Compare(p1,p2) = compare (p1.Name) (p2.Name) } ); -#else +#else Array.Sort((propsAndFields :> Array),{ new System.Collections.IComparer with member this.Compare(p1,p2) = compare ((p1 :?> MemberInfo).Name) ((p2 :?> MemberInfo).Name) } ); -#endif +#endif if propsAndFields.Length = 0 || (nDepth <= 0) then basicL else basicL --- @@ -1311,12 +1258,7 @@ namespace Microsoft.FSharp.Text.StructuredPrintfImpl let fsi_any_to_layout opts x = anyL ShowTopLevelBinding BindingFlags.Public opts x #else // FSharp.Core -#if FX_RESHAPED_REFLECTION - let internal anyToStringForPrintf options (showNonPublicMembers : bool) x = - let bindingFlags = ReflectionUtils.toBindingFlags showNonPublicMembers -#else let internal anyToStringForPrintf options (bindingFlags:BindingFlags) x = -#endif x |> anyL ShowAll bindingFlags options |> layout_to_string options #endif diff --git a/src/utils/sformat.fsi b/src/utils/sformat.fsi index f7c053e51fc6..e6ff9762bb54 100644 --- a/src/utils/sformat.fsi +++ b/src/utils/sformat.fsi @@ -302,11 +302,7 @@ namespace Microsoft.FSharp.Text.StructuredPrintfImpl StringLimit: int; #endif FormatProvider: System.IFormatProvider -#if FX_RESHAPED_REFLECTION - ShowNonPublic : bool -#else BindingFlags: System.Reflection.BindingFlags -#endif PrintWidth : int PrintDepth : int PrintLength : int @@ -341,11 +337,7 @@ namespace Microsoft.FSharp.Text.StructuredPrintfImpl #if FSHARP_CORE // FSharp.Core.dll: Most functions aren't needed in FSharp.Core.dll, but we add one entry for printf -#if FX_RESHAPED_REFLECTION - val anyToStringForPrintf: options:FormatOptions -> showNonPublicMembers : bool -> value:'T * Type -> string -#else val anyToStringForPrintf: options:FormatOptions -> bindingFlags:System.Reflection.BindingFlags -> value:'T * Type -> string -#endif #else val asTaggedTextWriter: writer: TextWriter -> TaggedTextWriter val any_to_layout : options:FormatOptions -> value:'T * Type -> Layout diff --git a/tests/FSharp.Core.UnitTests/FSharp.Core/DiscrimantedUnionType.fs b/tests/FSharp.Core.UnitTests/FSharp.Core/DiscrimantedUnionType.fs index 90d30f40a6c1..e5a48ad30078 100644 --- a/tests/FSharp.Core.UnitTests/FSharp.Core/DiscrimantedUnionType.fs +++ b/tests/FSharp.Core.UnitTests/FSharp.Core/DiscrimantedUnionType.fs @@ -10,17 +10,6 @@ open NUnit.Framework open FsCheck open FsCheck.PropOperators -#if FX_RESHAPED_REFLECTION -open FSharp.Reflection.FSharpReflectionExtensions - -[] -module PrimReflectionAdapters = - - type System.Type with - member this.IsValueType = this.GetTypeInfo().IsValueType -#endif - - type EnumUnion = | A | B diff --git a/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Reflection/FSharpReflection.fs b/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Reflection/FSharpReflection.fs index 7e1dec5a2ff9..21df908745db 100644 --- a/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Reflection/FSharpReflection.fs +++ b/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Reflection/FSharpReflection.fs @@ -26,30 +26,6 @@ Make sure each method works on: * Struct versions of the above *) -#if FX_RESHAPED_REFLECTION -module PrimReflectionAdapters = - open System.Linq - - type System.Type with - member this.Assembly = this.GetTypeInfo().Assembly - member this.IsGenericType = this.GetTypeInfo().IsGenericType - member this.IsValueType = this.GetTypeInfo().IsValueType - member this.IsAssignableFrom(otherTy : Type) = this.GetTypeInfo().IsAssignableFrom(otherTy.GetTypeInfo()) - member this.GetProperty(name) = this.GetRuntimeProperty(name) - member this.GetProperties() = this.GetRuntimeProperties() |> Array.ofSeq - member this.GetMethod(name, parameterTypes) = this.GetRuntimeMethod(name, parameterTypes) - member this.GetCustomAttributes(attrTy : Type, inherits : bool) : obj[] = - unbox (box (CustomAttributeExtensions.GetCustomAttributes(this.GetTypeInfo(), attrTy, inherits).ToArray())) - - type System.Reflection.MemberInfo with - member this.ReflectedType = this.DeclaringType - - type System.Reflection.Assembly with - member this.GetTypes() = this.DefinedTypes |> Seq.map (fun ti -> ti.AsType()) |> Array.ofSeq - -open PrimReflectionAdapters -#endif - module IsModule = type IsModuleType () = member __.M = 1 @@ -1056,22 +1032,14 @@ type FSharpTypeTests() = // Regression for 5588, Reflection: unit is still treated as a record type, but only if you pass BindingFlags.NonPublic [] - member __.``IsRecord.Regression5588``() = - + member __.``IsRecord.Regression5588``() = // negative Assert.IsFalse(FSharpType.IsRecord(typeof)) - -#if FX_RESHAPED_REFLECTION - Assert.IsFalse( FSharpType.IsRecord(typeof, true) ) -#else Assert.IsFalse( FSharpType.IsRecord(typeof, System.Reflection.BindingFlags.NonPublic) ) -#endif () - [] - member __.IsTuple() = - + member __.IsTuple() = // positive Assert.IsTrue(FSharpType.IsTuple(typeof>)) Assert.IsTrue(FSharpType.IsTuple(typeof>)) diff --git a/tests/FSharp.Core.UnitTests/FSharp.Core/RecordTypes.fs b/tests/FSharp.Core.UnitTests/FSharp.Core/RecordTypes.fs index 112c3509b1bb..e131a9274dd6 100644 --- a/tests/FSharp.Core.UnitTests/FSharp.Core/RecordTypes.fs +++ b/tests/FSharp.Core.UnitTests/FSharp.Core/RecordTypes.fs @@ -11,16 +11,6 @@ open NUnit.Framework open FsCheck open FsCheck.PropOperators -#if FX_RESHAPED_REFLECTION -open FSharp.Reflection.FSharpReflectionExtensions - -[] -module PrimReflectionAdapters = - - type System.Type with - member this.IsValueType = this.GetTypeInfo().IsValueType -#endif - type Record = { A: int B: int diff --git a/tests/FSharp.Core.UnitTests/LibraryTestFx.fs b/tests/FSharp.Core.UnitTests/LibraryTestFx.fs index db2b759069b6..77a9b2a3e607 100644 --- a/tests/FSharp.Core.UnitTests/LibraryTestFx.fs +++ b/tests/FSharp.Core.UnitTests/LibraryTestFx.fs @@ -61,48 +61,22 @@ module SurfaceArea = open System.Reflection open System open System.Text.RegularExpressions - + // gets string form of public surface area for the currently-loaded FSharp.Core let private getActual () = - // get current FSharp.Core let asm = -#if FX_RESHAPED_REFLECTION - typeof.GetTypeInfo().Assembly -#else typeof.Assembly -#endif - + // public types only let types = -#if FX_RESHAPED_REFLECTION - asm.ExportedTypes |> Seq.filter (fun ty -> let ti = ty.GetTypeInfo() in ti.IsPublic || ti.IsNestedPublic) |> Array.ofSeq -#else asm.GetExportedTypes() -#endif // extract canonical string form for every public member of every type let getTypeMemberStrings (t : Type) = // for System.Runtime-based profiles, need to do lots of manual work -#if FX_RESHAPED_REFLECTION - let getMembers (t : Type) = - let ti = t.GetTypeInfo() - let cast (info : #MemberInfo) = (t, info :> MemberInfo) - seq { - yield! t.GetRuntimeEvents() |> Seq.filter (fun m -> m.AddMethod.IsPublic) |> Seq.map cast - yield! t.GetRuntimeProperties() |> Seq.filter (fun m -> m.GetMethod.IsPublic) |> Seq.map cast - yield! t.GetRuntimeMethods() |> Seq.filter (fun m -> m.IsPublic) |> Seq.map cast - yield! t.GetRuntimeFields() |> Seq.filter (fun m -> m.IsPublic) |> Seq.map cast - yield! ti.DeclaredConstructors |> Seq.filter (fun m -> m.IsPublic) |> Seq.map cast - yield! ti.DeclaredNestedTypes |> Seq.filter (fun ty -> ty.IsNestedPublic) |> Seq.map cast - } |> Array.ofSeq - - getMembers t - |> Array.map (fun (ty, m) -> sprintf "%s: %s" (ty.ToString()) (m.ToString())) -#else t.GetMembers() |> Array.map (fun v -> sprintf "%s: %s" (v.ReflectedType.ToString()) (v.ToString())) -#endif let actual = types |> Array.collect getTypeMemberStrings diff --git a/tests/fsharp/core/quotes/test.fsx b/tests/fsharp/core/quotes/test.fsx index 289988569de5..8be5e210971b 100644 --- a/tests/fsharp/core/quotes/test.fsx +++ b/tests/fsharp/core/quotes/test.fsx @@ -2007,7 +2007,6 @@ module TestQuotationOfCOnstructors = | _ -> false) -#if !FX_RESHAPED_REFLECTION // Also test getting the reflected definition for private members implied by "let f() = ..." bindings let fMethod = (typeof.GetMethod("f", Reflection.BindingFlags.Instance ||| Reflection.BindingFlags.Public ||| Reflection.BindingFlags.NonPublic)) @@ -2020,9 +2019,7 @@ module TestQuotationOfCOnstructors = -> unitVar.Type = typeof | _ -> false) - Expr.TryGetReflectedDefinition fMethod |> printfn "%A" -#endif test "vkjnkvrw0" (match Expr.TryGetReflectedDefinition (typeof.GetConstructors().[0]) with @@ -2312,29 +2309,17 @@ module ReflectedDefinitionOnTypesWithImplicitCodeGen = // This type has an implicit IComparable implementation, it is not accessible as a reflected definition type U = A of int | B of string | C of System.DateTime -#if FX_RESHAPED_REFLECTION - for m in typeof.GetMethods() do -#else for m in typeof.GetMethods(System.Reflection.BindingFlags.DeclaredOnly) do -#endif check "celnwer33" (Quotations.Expr.TryGetReflectedDefinition(m).IsNone) true // This type has some implicit codegen exception X of string * int -#if FX_RESHAPED_REFLECTION - for m in typeof.GetMethods() do -#else for m in typeof.GetMethods(System.Reflection.BindingFlags.DeclaredOnly) do -#endif check "celnwer34" (Quotations.Expr.TryGetReflectedDefinition(m).IsNone) true // This type has an implicit IComparable implementation, it is not accessible as a reflected definition [] type SR = { x:int; y:string; z:System.DateTime } -#if FX_RESHAPED_REFLECTION - for m in typeof.GetMethods() do -#else for m in typeof.GetMethods(System.Reflection.BindingFlags.DeclaredOnly) do -#endif check "celnwer35" (Quotations.Expr.TryGetReflectedDefinition(m).IsNone) true #if !NETCOREAPP @@ -3175,13 +3160,10 @@ module TestMatchBang = | expr -> Error "Delay is incorrect") (Ok ()) - testSimpleMatchBang() - + testSimpleMatchBang() -#if !FX_RESHAPED_REFLECTION module TestAssemblyAttributes = let attributes = System.Reflection.Assembly.GetExecutingAssembly().GetCustomAttributes(false) -#endif #if TESTS_AS_APP let RUN() = !failures diff --git a/tests/fsharp/core/subtype/test.fsx b/tests/fsharp/core/subtype/test.fsx index 381e5b9a658c..9751d03e6e33 100644 --- a/tests/fsharp/core/subtype/test.fsx +++ b/tests/fsharp/core/subtype/test.fsx @@ -1386,12 +1386,10 @@ module CoercivePipingTest = check "clwcweki" (f8 3) (box 3) check "clwcweki" (f9 3) (box 3) -#if !FX_RESHAPED_REFLECTION // this was the actual repro let f (info: System.Reflection.MethodInfo) = System.Attribute.GetCustomAttribute(info, typeof) :?> ReflectedDefinitionAttribute -#endif module Test_Dev10_Bug_917383 = @@ -1728,7 +1726,6 @@ module InliningOnSubTypes1 = do check "clkewlijwlkw" (f()) (13, 17) -#if !FX_RESHAPED_REFLECTION module StructUnionSingleCase = [] type S = S @@ -1756,7 +1753,6 @@ module StructUnionSingleCase = do check "wekew0ewek5" (typeof.IsValueType) true do check "wekew0ewek5b" (typeof.BaseType) typeof -#endif // See https://github.com/Microsoft/visualfsharp/issues/238 module GenericPropertyConstraintSolvedByRecord = diff --git a/tests/fsharp/single-test.fs b/tests/fsharp/single-test.fs index 9584d1329337..d3dc0f0c83e9 100644 --- a/tests/fsharp/single-test.fs +++ b/tests/fsharp/single-test.fs @@ -150,7 +150,6 @@ let generateProjectArtifacts (pc:ProjectConfiguration) outputType (targetFramewo portable $(OPTIMIZE) false - FX_RESHAPED_REFLECTION NETCOREAPP false $(RestoreFromArtifactsPath) diff --git a/tests/fsharpqa/Source/Misc/AsyncOperations.fs b/tests/fsharpqa/Source/Misc/AsyncOperations.fs index 4b53b0ccff7e..2bc7738de70b 100644 --- a/tests/fsharpqa/Source/Misc/AsyncOperations.fs +++ b/tests/fsharpqa/Source/Misc/AsyncOperations.fs @@ -127,8 +127,7 @@ namespace Microsoft.FSharp.Control type System.Net.WebRequest with member req.AsyncGetResponse() = callFSharpCoreAsyncGetResponse req // this calls the FSharp.Core method member req.GetResponseAsync() = callFSharpCoreAsyncGetResponse req // this calls the FSharp.Core method - -#if !FX_NO_WEB_CLIENT + [] module WebClientExtensions = open System.Net @@ -138,5 +137,4 @@ namespace Microsoft.FSharp.Control type WebClient with member this.AsyncDownloadString address = callFSharpCoreAsyncDownloadString this address -#endif diff --git a/tests/service/Common.fs b/tests/service/Common.fs index 4c3b5c6a037f..6920e682afe5 100644 --- a/tests/service/Common.fs +++ b/tests/service/Common.fs @@ -6,10 +6,6 @@ open System.Collections.Generic open FSharp.Compiler open FSharp.Compiler.SourceCodeServices -#if FX_RESHAPED_REFLECTION -open ReflectionAdapters -#endif - #if NETCOREAPP2_0 let readRefs (folder : string) (projectFile: string) = let runProcess (workingDir: string) (exePath: string) (args: string) = diff --git a/tests/service/FscTests.fs b/tests/service/FscTests.fs index 9bedfd38b1b2..b7ff870675e0 100644 --- a/tests/service/FscTests.fs +++ b/tests/service/FscTests.fs @@ -20,10 +20,6 @@ open FSharp.Compiler.Service.Tests.Common open NUnit.Framework -#if FX_RESHAPED_REFLECTION -open ReflectionAdapters -#endif - exception VerificationException of (*assembly:*)string * (*errorCode:*)int * (*output:*)string with override e.Message = sprintf "Verification of '%s' failed with code %d, message <<<%s>>>" e.Data0 e.Data1 e.Data2 diff --git a/tests/service/ReshapedReflection.fs b/tests/service/ReshapedReflection.fs deleted file mode 100644 index 3b1ba07ce810..000000000000 --- a/tests/service/ReshapedReflection.fs +++ /dev/null @@ -1,9 +0,0 @@ -namespace FSharp.Compiler.Service.Tests - -#if FX_RESHAPED_REFLECTION -module internal ReflectionAdapters = - open System.Reflection - - type System.Type with - member this.Assembly = this.GetTypeInfo().Assembly -#endif diff --git a/vsintegration/Utils/LanguageServiceProfiling/Options.fs b/vsintegration/Utils/LanguageServiceProfiling/Options.fs index 07d3b5804ee4..1357e0da45a9 100644 --- a/vsintegration/Utils/LanguageServiceProfiling/Options.fs +++ b/vsintegration/Utils/LanguageServiceProfiling/Options.fs @@ -29,7 +29,6 @@ let FCS (repositoryDir: string) : Options = @"src\fsharp\FSharp.Compiler.Service\obj\Release\FSIstrings.fs" @"src\assemblyinfo\assemblyinfo.FSharp.Compiler.Private.dll.fs" @"src\assemblyinfo\assemblyinfo.shared.fs" - @"src\utils\reshapedreflection.fs" @"src\utils\sformat.fsi" @"src\utils\sformat.fs" @"src\fsharp\sr.fsi" @@ -205,7 +204,7 @@ let FCS (repositoryDir: string) : Options = [|@"-o:obj\Release\FSharp.Compiler.Private.dll"; "-g"; "--noframework"; @"--baseaddress:0x06800000"; "--define:DEBUG"; @"--define:CROSS_PLATFORM_COMPILER"; - @"--define:FX_ATLEAST_40"; "--define:BE_SECURITY_TRANSPARENT"; + @"--define:FX_ATLEAST_40"; @"--define:COMPILER"; @"--define:ENABLE_MONO_SUPPORT"; "--define:FX_MSBUILDRESOLVER_RUNTIMELIKE"; @"--define:FX_LCIDFROMCODEPAGE"; "--define:FX_RESX_RESOURCE_READER";