Skip to content

Commit cea594e

Browse files
committed
Merge pull request #399 from dsyme/align-visualfsharp-1
misc. changes to align with Microsoft/visualfsharp
2 parents 74287eb + f1caaf4 commit cea594e

25 files changed

+127
-174
lines changed

src/absil/il.fs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -908,7 +908,7 @@ type ILAttribElem =
908908
type ILAttributeNamedArg = (string * ILType * bool * ILAttribElem)
909909
type ILAttribute =
910910
{ Method: ILMethodSpec;
911-
#if SILVERLIGHT
911+
#if FX_REFLECTION_EMITS_CUSTOM_ATTRIBUTES_USING_BUILDER
912912
Arguments: ILAttribElem list * ILAttributeNamedArg list
913913
#endif
914914
Data: byte[] }
@@ -4410,7 +4410,7 @@ let mkILCustomAttribMethRef (ilg: ILGlobals) (mspec:ILMethodSpec, fixedArgs: lis
44104410
yield! encodeCustomAttrNamedArg ilg namedArg |]
44114411

44124412
{ Method = mspec;
4413-
#if SILVERLIGHT
4413+
#if FX_REFLECTION_EMITS_CUSTOM_ATTRIBUTES_USING_BUILDER
44144414
Arguments = fixedArgs, namedArgs
44154415
#endif
44164416
Data = args }
@@ -5068,11 +5068,7 @@ let parseILVersion (vstr : string) =
50685068
let version = System.Version(vstr)
50695069
let zero32 n = if n < 0 then 0us else uint16(n)
50705070
// since the minor revision will be -1 if none is specified, we need to truncate to 0 to not break existing code
5071-
#if SILVERLIGHT
5072-
let minorRevision = if version.Revision = -1 then 0us else uint16(version.Revision)
5073-
#else
5074-
let minorRevision = if version.Revision = -1 then 0us else uint16(version.MinorRevision)
5075-
#endif
5071+
let minorRevision = if version.Revision = -1 then 0us else uint16(version.MinorRevision)
50765072
(zero32 version.Major, zero32 version.Minor, zero32 version.Build, minorRevision);;
50775073

50785074

src/absil/il.fsi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ type PublicKey =
118118
member IsKeyToken: bool
119119
member Key: byte[]
120120
member KeyToken: byte[]
121-
static member KeyAsToken: byte[] -> PublicKey
121+
static member KeyAsToken: byte[] -> PublicKey
122122

123123
type ILVersionInfo = uint16 * uint16 * uint16 * uint16
124124

@@ -1028,7 +1028,7 @@ type ILAttributeNamedArg = string * ILType * bool * ILAttribElem
10281028
/// to ILAttribElem's as best as possible.
10291029
type ILAttribute =
10301030
{ Method: ILMethodSpec;
1031-
#if SILVERLIGHT
1031+
#if FX_REFLECTION_EMITS_CUSTOM_ATTRIBUTES_USING_BUILDER
10321032
Arguments: ILAttribElem list * ILAttributeNamedArg list
10331033
#endif
10341034
Data: byte[] }

src/absil/illib.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ module Eventually =
628628
let force e = Option.get (forceWhile (fun () -> true) e)
629629

630630
/// Keep running the computation bit by bit until a time limit is reached.
631-
#if SILVERLIGHT
631+
#if FX_NO_SYSTEM_DIAGNOSTICS_STOPWATCH
632632
// There is no Stopwatch on Silverlight, so use DateTime.Now. I'm not sure of the pros and cons of this.
633633
// An alternative is just to always force the computation all the way to the end.
634634
//let repeatedlyProgressUntilDoneOrTimeShareOver _timeShareInMilliseconds runner e =
@@ -990,7 +990,7 @@ module Shim =
990990
abstract AssemblyLoadFrom: fileName:string -> System.Reflection.Assembly
991991
abstract AssemblyLoad: assemblyName:System.Reflection.AssemblyName -> System.Reflection.Assembly
992992

993-
#if SILVERLIGHT
993+
#if FX_FILE_SYSTEM_USES_ISOLATED_STORAGE
994994
open System.IO.IsolatedStorage
995995
open System.Windows
996996
open System
@@ -1105,7 +1105,7 @@ module Shim =
11051105

11061106
type System.Text.Encoding with
11071107
static member GetEncodingShim(n:int) =
1108-
#if SILVERLIGHT
1108+
#if FX_NO_GET_ENCODING_BY_INTEGER
11091109
System.Text.Encoding.GetEncoding(n.ToString())
11101110
#else
11111111
System.Text.Encoding.GetEncoding(n)

src/absil/ilread.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ type BinaryFile() =
105105
abstract CountUtf8String : addr:int -> int
106106
abstract ReadUTF8String : addr: int -> string
107107

108-
#if SILVERLIGHT
108+
#if FX_NO_NATIVE_MEMORY_MAPPED_FILES
109109

110110
#else
111111

@@ -2530,7 +2530,7 @@ and seekReadCustomAttr ctxt (TaggedIndex(cat,idx),b) =
25302530
and seekReadCustomAttrUncached ctxtH (CustomAttrIdx (cat,idx,valIdx)) =
25312531
let ctxt = getHole ctxtH
25322532
{ Method=seekReadCustomAttrType ctxt (TaggedIndex(cat,idx));
2533-
#if SILVERLIGHT
2533+
#if FX_REFLECTION_EMITS_CUSTOM_ATTRIBUTES_USING_BUILDER
25342534
Arguments = [], []
25352535
#endif
25362536
Data=
@@ -3973,7 +3973,7 @@ let ClosePdbReader pdb =
39733973

39743974
let OpenILModuleReader infile opts =
39753975

3976-
#if SILVERLIGHT
3976+
#if FX_NO_NATIVE_MEMORY_MAPPED_FILES
39773977
#else
39783978
try
39793979
let mmap = MemoryMappedFile.Create infile

src/absil/ilreflect.fs

Lines changed: 20 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ open System.Collections.Generic
2828
let codeLabelOrder = ComparisonIdentity.Structural<ILCodeLabel>
2929

3030
// Convert the output of convCustomAttr
31-
#if SILVERLIGHT
31+
#if FX_REFLECTION_EMITS_CUSTOM_ATTRIBUTES_USING_BUILDER
3232
let wrapCustomAttr setCustomAttr (cinfo, cinfoBuilder) =
3333
setCustomAttr(cinfoBuilder cinfo)
3434
#else
@@ -46,12 +46,7 @@ let logRefEmitCalls = false
4646

4747
type System.AppDomain with
4848
member x.DefineDynamicAssemblyAndLog(asmName,flags,asmDir:string) =
49-
#if SILVERLIGHT
50-
ignore asmDir
51-
let asmB = x.DefineDynamicAssembly(asmName,flags)
52-
#else
5349
let asmB = x.DefineDynamicAssembly(asmName,flags,asmDir)
54-
#endif
5550
if logRefEmitCalls then
5651
printfn "open System"
5752
printfn "open System.Reflection"
@@ -62,20 +57,15 @@ type System.AppDomain with
6257

6358
type System.Reflection.Emit.AssemblyBuilder with
6459
member asmB.DefineDynamicModuleAndLog(a,b,c) =
65-
#if SILVERLIGHT
66-
ignore c
67-
let modB = asmB.DefineDynamicModule(a,b)
68-
#else
6960
let modB = asmB.DefineDynamicModule(a,b,c)
70-
#endif
7161
if logRefEmitCalls then printfn "let moduleBuilder%d = assemblyBuilder%d.DefineDynamicModule(%A,%A,%A)" (abs <| hash modB) (abs <| hash asmB) a b c
7262
modB
7363

7464
member asmB.SetCustomAttributeAndLog(cinfo,bytes) =
7565
if logRefEmitCalls then printfn "assemblyBuilder%d.SetCustomAttribute(%A, %A)" (abs <| hash asmB) cinfo bytes
7666
wrapCustomAttr asmB.SetCustomAttribute (cinfo, bytes)
7767

78-
#if SILVERLIGHT
68+
#if FX_NO_REFLECTION_EMIT_RESOURCE_FILE
7969
#else
8070
member asmB.AddResourceFileAndLog(nm1, nm2, attrs) =
8171
if logRefEmitCalls then printfn "assemblyBuilder%d.AddResourceFile(%A, %A, enum %d)" (abs <| hash asmB) nm1 nm2 (LanguagePrimitives.EnumToValue attrs)
@@ -108,11 +98,7 @@ type System.Reflection.Emit.ModuleBuilder with
10898

10999
member modB.DefineManifestResourceAndLog(name,stream,attrs) =
110100
if logRefEmitCalls then printfn "moduleBuilder%d.DefineManifestResource(%A,%A,enum %d)" (abs <| hash modB) name stream (LanguagePrimitives.EnumToValue attrs)
111-
#if SILVERLIGHT
112-
// Annoyingly, DefineManifestResource is security critical on Silverlight
113-
#else
114101
modB.DefineManifestResource(name,stream,attrs)
115-
#endif
116102

117103
member modB.SetCustomAttributeAndLog(cinfo,bytes) =
118104
if logRefEmitCalls then printfn "moduleBuilder%d.SetCustomAttribute(%A, %A)" (abs <| hash modB) cinfo bytes
@@ -210,13 +196,12 @@ type System.Reflection.Emit.TypeBuilder with
210196
if logRefEmitCalls then printfn "typeBuilder%d.AddInterfaceImplementation(%A)" (abs <| hash typB) ty
211197
typB.AddInterfaceImplementation(ty)
212198

199+
#if FX_NO_INVOKE_MEMBER
200+
#else
213201
member typB.InvokeMemberAndLog(nm,flags,args) =
214202
if logRefEmitCalls then printfn "typeBuilder%d.InvokeMember(\"%s\",enum %d,null,null,%A,Globalization.CultureInfo.InvariantCulture)" (abs <| hash typB) nm (LanguagePrimitives.EnumToValue flags) args
215-
#if SILVERLIGHT
216-
typB.InvokeMember(nm,flags,null,null,args)
217-
#else
218203
typB.InvokeMember(nm,flags,null,null,args,Globalization.CultureInfo.InvariantCulture)
219-
#endif
204+
#endif
220205

221206
member typB.SetCustomAttributeAndLog(cinfo,bytes) =
222207
if logRefEmitCalls then printfn "typeBuilder%d.SetCustomAttribute(%A, %A)" (abs <| hash typB) cinfo bytes
@@ -355,11 +340,8 @@ let convTypeRefAux (cenv:cenv) (tref:ILTypeRef) =
355340
| ILScopeRef.Assembly asmref ->
356341
let assembly =
357342
match cenv.resolvePath asmref with
358-
#if SILVERLIGHT
359-
#else
360343
| Some (Choice1Of2 path) ->
361344
FileSystem.AssemblyLoadFrom(path)
362-
#endif
363345
| Some (Choice2Of2 assembly) ->
364346
assembly
365347
| None ->
@@ -418,8 +400,6 @@ let envUpdateCreatedTypeRef emEnv (tref:ILTypeRef) =
418400
let typT,typB,typeDef,_createdTypOpt = Zmap.force tref emEnv.emTypMap "envGetTypeDef: failed"
419401
if typB.IsCreated() then
420402
let typ = typB.CreateTypeAndLog()
421-
#if SILVERLIGHT
422-
#else
423403
// Bug DevDev2 40395: Mono 2.6 and 2.8 has a bug where executing code that includes an array type
424404
// match "match x with :? C[] -> ..." before the full loading of an object of type
425405
// causes a failure when C is later loaded. One workaround for this is to attempt to do a fake allocation
@@ -430,7 +410,6 @@ let envUpdateCreatedTypeRef emEnv (tref:ILTypeRef) =
430410
try
431411
System.Runtime.Serialization.FormatterServices.GetUninitializedObject(typ) |> ignore
432412
with e -> ()
433-
#endif
434413

435414
{emEnv with emTypMap = Zmap.add tref (typT,typB,typeDef,Some typ) emEnv.emTypMap}
436415
else
@@ -616,7 +595,7 @@ let convFieldInit x =
616595
| ILFieldInit.Double ieee64 -> box ieee64
617596
| ILFieldInit.Null -> (null :> Object)
618597

619-
#if SILVERLIGHT
598+
#if FX_REFLECTION_EMITS_CUSTOM_ATTRIBUTES_USING_BUILDER
620599
//----------------------------------------------------------------------------
621600
// convAttribElem
622601
//----------------------------------------------------------------------------
@@ -891,7 +870,7 @@ let emitInstrNewobj cenv emEnv (ilG:ILGenerator) mspec varargs =
891870
| Some _vartyps -> failwith "emit: pending new varargs" // XXX - gap
892871

893872
let emitSilverlightCheck (ilG:ILGenerator) =
894-
#if SILVERLIGHT
873+
#if DYNAMIC_CODE_EMITS_INTERRUPT_CHECKS
895874
if Microsoft.FSharp.Silverlight.EmitInterruptChecks then
896875
let methWL = typeof<Microsoft.FSharp.Silverlight>.GetMethod("CheckInterrupt", BindingFlags.Static ||| BindingFlags.Public ||| BindingFlags.NonPublic, null, [||], null)
897876
ilG.EmitCall(OpCodes.Call, methWL, [||])
@@ -909,7 +888,7 @@ let emitInstrCall cenv emEnv (ilG:ILGenerator) opCall tail (mspec:ILMethodSpec)
909888
| Some _vartyps -> failwith "emitInstrCall: .ctor and varargs"
910889
else
911890
let minfo = convMethodSpec cenv emEnv mspec
912-
#if SILVERLIGHT
891+
#if DYNAMIC_CODE_REWRITES_CONSOLE_WRITE
913892
// When generating code for silverlight, we intercept direct
914893
// calls to System.Console.WriteLine.
915894
let fullName = minfo.DeclaringType.FullName + "." + minfo.Name
@@ -1090,7 +1069,7 @@ let rec emitInstr cenv (modB : ModuleBuilder) emEnv (ilG:ILGenerator) instr =
10901069
emitInstrCall cenv emEnv ilG OpCodes.Callvirt tail mspec varargs
10911070
| I_callconstraint (tail,typ,mspec,varargs) -> ilG.Emit(OpCodes.Constrained,convType cenv emEnv typ);
10921071
emitInstrCall cenv emEnv ilG OpCodes.Callvirt tail mspec varargs
1093-
#if SILVERLIGHT
1072+
#if FX_NO_REFLECTION_EMIT_CALLI
10941073
| I_calli (tail,_callsig,None) -> emitInstrTail ilG tail (fun () -> ())
10951074
| I_calli (tail,_callsig,Some _vartyps) -> emitInstrTail ilG tail (fun () -> ())
10961075
#else
@@ -1356,7 +1335,7 @@ let convCustomAttr cenv emEnv cattr =
13561335
| res -> res
13571336
// In Silverlight, we cannot use the byte[] data to generate attributes (security restriction).
13581337
// Instead, we return a function which creates a CustomAttributeBuilder to be used for SetCustomAttributes.
1359-
#if SILVERLIGHT
1338+
#if FX_REFLECTION_EMITS_CUSTOM_ATTRIBUTES_USING_BUILDER
13601339
let ty : System.Type = convType cenv emEnv cattr.Method.EnclosingType
13611340
let convAttrArray arr = [|for i in arr -> convAttribElem cenv emEnv i|]
13621341

@@ -1531,7 +1510,7 @@ let rec buildMethodPass2 cenv tref (typB:TypeBuilder) emEnv (mdef : ILMethodDef)
15311510
(* p.CharBestFit *)
15321511
(* p.NoMangle *)
15331512

1534-
#if SILVERLIGHT
1513+
#if FX_NO_REFLECTION_EMIT_PINVOKE
15351514
failwith "PInvoke methods may not be defined when targeting Silverlight via System.Reflection.Emit"
15361515
#else
15371516
let methB = typB.DefinePInvokeMethod(mdef.Name,
@@ -1641,7 +1620,7 @@ let buildFieldPass2 cenv tref (typB:TypeBuilder) emEnv (fdef : ILFieldDef) =
16411620
let attrs = attrsAccess ||| attrsOther
16421621
let fieldT = convType cenv emEnv fdef.Type
16431622
let fieldB =
1644-
#if SILVERLIGHT
1623+
#if FX_NO_REFLECTION_EMIT_STATIC_DATA
16451624
#else
16461625
match fdef.Data with
16471626
| Some d -> typB.DefineInitializedData(fdef.Name, d, attrs)
@@ -1667,7 +1646,7 @@ let buildFieldPass2 cenv tref (typB:TypeBuilder) emEnv (fdef : ILFieldDef) =
16671646
// => here we cannot detect if underlying type is already set so as a conservative solution we delay initialization of fields
16681647
// to the end of pass2 (types and members are already created but method bodies are yet not emitted)
16691648
{ emEnv with delayedFieldInits = (fun() -> fieldB.SetConstant(convFieldInit initial))::emEnv.delayedFieldInits }
1670-
#if SILVERLIGHT
1649+
#if FX_NO_REFLECTION_EMIT_STATIC_DATA
16711650
#else
16721651
fdef.Offset |> Option.iter (fun offset -> fieldB.SetOffset(offset));
16731652
#endif
@@ -1976,7 +1955,7 @@ let createTypeRef (visited : Dictionary<_,_>, created : Dictionary<_,_>) emEnv t
19761955
visited.[tref] <- priority;
19771956
let tdef = envGetTypeDef emEnv tref
19781957
if verbose2 then dprintf "- traversing type %s\n" typB.FullName;
1979-
#if SILVERLIGHT
1958+
#if FX_NO_TYPE_RESOLVE_EVENT
19801959
traverseTypeDef priority tref tdef;
19811960
#else
19821961
let typeCreationHandler =
@@ -2055,7 +2034,7 @@ let buildModuleFragment cenv emEnv (asmB : AssemblyBuilder) (modB : ModuleBuilde
20552034
| ILResourceLocation.Local bf ->
20562035
modB.DefineManifestResourceAndLog(r.Name, new System.IO.MemoryStream(bf()), attribs)
20572036
| ILResourceLocation.File (mr,_n) ->
2058-
#if SILVERLIGHT
2037+
#if FX_NO_REFLECTION_EMIT_RESOURCE_FILE
20592038
()
20602039
#else
20612040
asmB.AddResourceFileAndLog(r.Name, mr.Name, attribs)
@@ -2071,16 +2050,14 @@ let buildModuleFragment cenv emEnv (asmB : AssemblyBuilder) (modB : ModuleBuilde
20712050
let mkDynamicAssemblyAndModule (assemblyName, optimize, debugInfo, collectible) =
20722051
let filename = assemblyName ^ ".dll"
20732052
let currentDom = System.AppDomain.CurrentDomain
2074-
#if SILVERLIGHT
2075-
ignore optimize
20762053
let asmName = new AssemblyName()
2077-
asmName.Name <- assemblyName;
2054+
asmName.Name <- assemblyName
2055+
#if FX_NO_REFLECTION_EMIT_SAVE_ASSEMBLY
2056+
ignore optimize
20782057
let asmB = currentDom.DefineDynamicAssembly(asmName,AssemblyBuilderAccess.Run)
20792058
let modB = asmB.DefineDynamicModule(filename,debugInfo)
20802059
#else
20812060
let asmDir = "."
2082-
let asmName = new AssemblyName()
2083-
asmName.Name <- assemblyName;
20842061
let asmAccess = if collectible then AssemblyBuilderAccess.RunAndCollect else AssemblyBuilderAccess.RunAndSave
20852062
let asmB = currentDom.DefineDynamicAssemblyAndLog(asmName,asmAccess,asmDir)
20862063
if not optimize then
@@ -2093,7 +2070,7 @@ let mkDynamicAssemblyAndModule (assemblyName, optimize, debugInfo, collectible)
20932070
#endif
20942071
asmB,modB
20952072

2096-
#if SILVERLIGHT
2073+
#if FX_NO_INVOKE_MEMBER
20972074
type EntryDelegate = delegate of unit -> unit
20982075
#endif
20992076

@@ -2109,7 +2086,7 @@ let emitModuleFragment (ilg, emEnv, asmB : AssemblyBuilder, modB : ModuleBuilder
21092086
// invoke entry point methods
21102087
let execEntryPtFun ((typB : TypeBuilder),methodName) () =
21112088
try
2112-
#if SILVERLIGHT
2089+
#if FX_NO_INVOKE_MEMBER
21132090
let mi = typB.GetMethod(methodName, BindingFlags.InvokeMethod ||| BindingFlags.Public ||| BindingFlags.Static)
21142091
System.Diagnostics.Debug.WriteLine("mi: {0}", string(mi.ToString()))
21152092
let dm = DynamicMethod((methodName+"dm"),null,null)

src/absil/ilsupp.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ let DateTime1970Jan01 = new System.DateTime(1970,1,1,0,0,0,System.DateTimeKind.U
77
let absilWriteGetTimeStamp () = (System.DateTime.UtcNow - DateTime1970Jan01).TotalSeconds |> int
88

99

10-
#if SILVERLIGHT
10+
#if NO_PDB_READER
1111
type PdbReader = | NeverImplemented
1212
let pdbReadClose (_pdb:PdbReader) = ()
1313
type PdbWriter = | NeverImplemented

src/absil/ilsupp.fsi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ val pdbInitialize : string -> string -> PdbWriter
1515
val absilWriteGetTimeStamp: unit -> int32
1616

1717

18-
#if SILVERLIGHT
18+
#if NO_PDB_READER
1919
#else
2020
open System
2121
open System.Runtime.InteropServices

0 commit comments

Comments
 (0)