Skip to content

Commit c494a9c

Browse files
authored
Merge pull request #641 from dsyme/integrate-776
Integrate from fsharp\fsharp master
2 parents e798ab3 + f7a868a commit c494a9c

Some content is hidden

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

77 files changed

+2493
-1909
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,3 +198,7 @@ src/fsharp/FSharp.Compiler.Service/FSIstrings.fs
198198
src/fsharp/FSharp.Compiler.Service/FSIstrings.resx
199199
Tools/
200200
Backup/
201+
tests/fsharp/core/array/dont.run.peverify
202+
tests/fsharp/core/innerpoly/dont.run.peverify
203+
tests/fsharp/typecheck/sigs/neg94-pre.dll
204+
times

src/absil/il.fs

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ let runningOnMono =
3838

3939
let _ = if logging then dprintn "* warning: Il.logging is on"
4040

41-
let isNil x = match x with [] -> true | _ -> false
42-
let nonNil x = match x with [] -> false | _ -> true
4341
let int_order = LanguagePrimitives.FastGenericComparer<int>
4442

4543
let notlazy v = Lazy.CreateFromValue v
@@ -86,11 +84,7 @@ let memoizeNamespaceRightTable = new ConcurrentDictionary<string,string option *
8684

8785

8886
let splitNamespace nm =
89-
let mutable res = Unchecked.defaultof<_>
90-
let ok = memoizeNamespaceTable.TryGetValue(nm,&res)
91-
if ok then res else
92-
let x = splitNamespaceAux nm
93-
(memoizeNamespaceTable.[nm] <- x; x)
87+
memoizeNamespaceTable.GetOrAdd(nm, splitNamespaceAux)
9488

9589
let splitNamespaceMemoized nm = splitNamespace nm
9690

@@ -99,12 +93,9 @@ let memoizeNamespaceArrayTable =
9993
Concurrent.ConcurrentDictionary<string,string[]>()
10094

10195
let splitNamespaceToArray nm =
102-
let mutable res = Unchecked.defaultof<_>
103-
let ok = memoizeNamespaceArrayTable.TryGetValue(nm,&res)
104-
if ok then res else
105-
let x = Array.ofList (splitNamespace nm)
106-
(memoizeNamespaceArrayTable.[nm] <- x; x)
107-
96+
memoizeNamespaceArrayTable.GetOrAdd(nm, fun nm ->
97+
let x = Array.ofList (splitNamespace nm)
98+
x)
10899

109100
let splitILTypeName (nm:string) =
110101
match nm.LastIndexOf '.' with
@@ -157,11 +148,7 @@ let splitTypeNameRightAux nm =
157148
else None, nm
158149

159150
let splitTypeNameRight nm =
160-
let mutable res = Unchecked.defaultof<_>
161-
let ok = memoizeNamespaceRightTable.TryGetValue(nm,&res)
162-
if ok then res else
163-
let x = splitTypeNameRightAux nm
164-
(memoizeNamespaceRightTable.[nm] <- x; x)
151+
memoizeNamespaceRightTable.GetOrAdd(nm, splitTypeNameRightAux)
165152

166153
// --------------------------------------------------------------------
167154
// Ordered lists with a lookup table
@@ -1987,7 +1974,7 @@ let mkILFieldRef(tref,nm,ty) = { EnclosingTypeRef=tref; Name=nm; Type=ty}
19871974
let mkILFieldSpec (tref,ty) = { FieldRef= tref; EnclosingType=ty }
19881975

19891976
let mkILFieldSpecInTy (typ:ILType,nm,fty) =
1990-
mkILFieldSpec (mkILFieldRef (typ.TypeRef,nm,fty), typ)
1977+
mkILFieldSpec (mkILFieldRef (typ.TypeRef,nm,fty), typ)
19911978

19921979
let emptyILCustomAttrs = ILAttributes (fun () -> [| |])
19931980

@@ -2650,7 +2637,7 @@ let rec rescopeILTypeSpecQuick scoref (tspec:ILTypeSpec) =
26502637
let tref = tspec.TypeRef
26512638
let tinst = tspec.GenericArgs
26522639
let qtref = qrescope_tref scoref tref
2653-
if ILList.isEmpty tinst && isNone qtref then
2640+
if ILList.isEmpty tinst && Option.isNone qtref then
26542641
None (* avoid reallocation in the common case *)
26552642
else
26562643
match qtref with
@@ -3692,12 +3679,13 @@ type ILGlobals with
36923679
mkILCustomAttribute this (mkSystemDiagnosticsDebuggableTypeRef this, [this.typ_Bool; this.typ_Bool], [ILAttribElem.Bool false; ILAttribElem.Bool jitOptimizerDisabled], [])
36933680

36943681

3695-
member this.mkDebuggableAttributeV2(ignoreSymbolStoreSequencePoints, jitOptimizerDisabled, enableEnC) =
3682+
member this.mkDebuggableAttributeV2(jitTracking, ignoreSymbolStoreSequencePoints, jitOptimizerDisabled, enableEnC) =
36963683
let tref = mkSystemDiagnosticsDebuggableTypeRef this
36973684
mkILCustomAttribute this
36983685
(tref,[mkILNonGenericValueTy (tref_DebuggableAttribute_DebuggingModes this)],
36993686
(* See System.Diagnostics.DebuggableAttribute.DebuggingModes *)
3700-
[ILAttribElem.Int32( (if jitOptimizerDisabled then 256 else 0) |||
3687+
[ILAttribElem.Int32( (if jitTracking then 1 else 0) |||
3688+
(if jitOptimizerDisabled then 256 else 0) |||
37013689
(if ignoreSymbolStoreSequencePoints then 2 else 0) |||
37023690
(if enableEnC then 4 else 0))],[])
37033691

@@ -4288,7 +4276,7 @@ let rec unscopeILTypeSpecQuick (tspec:ILTypeSpec) =
42884276
let tref = tspec.TypeRef
42894277
let tinst = tspec.GenericArgs
42904278
let qtref = qunscope_tref tref
4291-
if ILList.isEmpty tinst && isNone qtref then
4279+
if ILList.isEmpty tinst && Option.isNone qtref then
42924280
None (* avoid reallocation in the common case *)
42934281
else
42944282
match qtref with
@@ -4329,7 +4317,7 @@ let resolveILMethodRefWithRescope r td (mref:ILMethodRef) =
43294317
let nargs = args.Length
43304318
let nm = mref.Name
43314319
let possibles = td.Methods.FindByNameAndArity (nm,nargs)
4332-
if isNil possibles then failwith ("no method named "+nm+" found in type "+td.Name);
4320+
if List.isEmpty possibles then failwith ("no method named "+nm+" found in type "+td.Name);
43334321
let argTypes = mref.ArgTypes |> List.map r
43344322
let retType : ILType = r mref.ReturnType
43354323
match

src/absil/il.fsi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1624,7 +1624,7 @@ type ILGlobals =
16241624
with
16251625
member mkDebuggableAttribute: bool (* disable JIT optimizations *) -> ILAttribute
16261626
/// Some commonly used custom attibutes
1627-
member mkDebuggableAttributeV2 : bool (* ignoreSymbolStoreSequencePoints *) * bool (* disable JIT optimizations *) * bool (* enable EnC *) -> ILAttribute
1627+
member mkDebuggableAttributeV2 : bool (* jitTracking *) * bool (* ignoreSymbolStoreSequencePoints *) * bool (* disable JIT optimizations *) * bool (* enable EnC *) -> ILAttribute
16281628
member mkCompilerGeneratedAttribute : unit -> ILAttribute
16291629
member mkDebuggerNonUserCodeAttribute : unit -> ILAttribute
16301630
member mkDebuggerStepThroughAttribute : unit -> ILAttribute

src/absil/illib.fs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,8 @@ let (>>>&) (x:int32) (n:int32) = int32 (uint32 x >>> n)
2020

2121
let notlazy v = Lazy<_>.CreateFromValue v
2222

23-
let isSome x = match x with None -> false | _ -> true
24-
let isNone x = match x with None -> true | _ -> false
25-
let isNil x = match x with [] -> true | _ -> false
26-
let nonNil x = match x with [] -> false | _ -> true
27-
let isNull (x : 'T) = match (x :> obj) with null -> true | _ -> false
28-
let isNonNull (x : 'T) = match (x :> obj) with null -> false | _ -> true
29-
let nonNull msg x = if isNonNull x then x else failwith ("null: " ^ msg)
23+
let inline isNonNull x = not (isNull x)
24+
let inline nonNull msg x = if isNull x then failwith ("null: " ^ msg) else x
3025
let (===) x y = LanguagePrimitives.PhysicalEquality x y
3126

3227
//---------------------------------------------------------------------
@@ -438,7 +433,7 @@ module String =
438433
else
439434
None
440435

441-
let hasPrefix s t = isSome (tryDropPrefix s t)
436+
let hasPrefix s t = Option.isSome (tryDropPrefix s t)
442437
let dropPrefix s t = match (tryDropPrefix s t) with Some(res) -> res | None -> failwith "dropPrefix"
443438

444439
let dropSuffix s t = match (tryDropSuffix s t) with Some(res) -> res | None -> failwith "dropSuffix"
@@ -716,8 +711,8 @@ type LazyWithContext<'T,'ctxt> =
716711
funcOrException = box f;
717712
findOriginalException = findOriginalException }
718713
static member NotLazy(x:'T) : LazyWithContext<'T,'ctxt> =
719-
{ value = x;
720-
funcOrException = null;
714+
{ value = x
715+
funcOrException = null
721716
findOriginalException = id }
722717
member x.IsDelayed = (match x.funcOrException with null -> false | :? LazyWithContextFailure -> false | _ -> true)
723718
member x.IsForced = (match x.funcOrException with null -> true | _ -> false)
@@ -785,6 +780,7 @@ module NameMap =
785780
let exists f m = Map.foldBack (fun x y sofar -> sofar || f x y) m false
786781
let ofKeyedList f l = List.foldBack (fun x acc -> Map.add (f x) x acc) l Map.empty
787782
let ofList l : NameMap<'T> = Map.ofList l
783+
let ofSeq l : NameMap<'T> = Map.ofSeq l
788784
let ofFlatList (l:FlatList<_>) : NameMap<'T> = FlatList.toMap l
789785
let toList (l: NameMap<'T>) = Map.toList l
790786
let layer (m1 : NameMap<'T>) m2 = Map.foldBack Map.add m1 m2

src/absil/ilprint.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ and goutput_gparam env os (gf: ILGenericParameterDef) =
285285
output_parens (output_seq "," (goutput_typ env)) os gf.Constraints
286286

287287
and goutput_gparams env os b =
288-
if nonNil b then
288+
if not (List.isEmpty b) then
289289
output_string os "<"; output_seq "," (goutput_gparam env) os b; output_string os ">"; ()
290290

291291
and output_bcc os bcc =

src/absil/ilread.fs

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,6 @@ module MemoryMapping =
153153
let OPEN_EXISTING = 0x0003
154154
let OPEN_ALWAYS = 0x0004
155155

156-
let derefByte (p:nativeint) =
157-
NativePtr.read (NativePtr.ofNativeInt<byte> p)
158-
159156
type MemoryMappedFile(hMap: MemoryMapping.HANDLE, start:nativeint) =
160157
inherit BinaryFile()
161158

@@ -182,37 +179,38 @@ type MemoryMappedFile(hMap: MemoryMapping.HANDLE, start:nativeint) =
182179
start + nativeint i
183180

184181
override m.ReadByte i =
185-
derefByte (m.Addr i)
182+
Marshal.ReadByte(m.Addr i)
186183

187184
override m.ReadBytes i len =
188185
let res = Bytes.zeroCreate len
189186
Marshal.Copy(m.Addr i, res, 0,len)
190187
res
191188

192189
override m.ReadInt32 i =
193-
NativePtr.read (NativePtr.ofNativeInt<int32> (m.Addr i))
190+
Marshal.ReadInt32(m.Addr i)
194191

195192
override m.ReadUInt16 i =
196-
NativePtr.read (NativePtr.ofNativeInt<uint16> (m.Addr i))
193+
uint16(Marshal.ReadInt16(m.Addr i))
197194

198195
member m.Close() =
199196
ignore(MemoryMapping.UnmapViewOfFile start)
200197
ignore(MemoryMapping.CloseHandle hMap)
201198

202199
override m.CountUtf8String i =
203-
let start = m.Addr i
200+
let start = m.Addr i
204201
let mutable p = start
205-
while derefByte p <> 0uy do
202+
while Marshal.ReadByte(p) <> 0uy do
206203
p <- p + 1n
207204
int (p - start)
208205

209206
override m.ReadUTF8String i =
210207
let n = m.CountUtf8String i
211-
#if FX_RESHAPED_REFLECTION
212-
System.Text.Encoding.UTF8.GetString(NativePtr.ofNativeInt (m.Addr i), n)
213-
#else
214-
new System.String(NativePtr.ofNativeInt (m.Addr i), 0, n, System.Text.Encoding.UTF8)
215-
#endif
208+
System.Runtime.InteropServices.Marshal.PtrToStringAnsi((m.Addr i), n)
209+
//#if FX_RESHAPED_REFLECTION
210+
// System.Text.Encoding.UTF8.GetString(NativePtr.ofNativeInt (m.Addr i), n)
211+
//#else
212+
// new System.String(NativePtr.ofNativeInt (m.Addr i), 0, n, System.Text.Encoding.UTF8)
213+
//#endif
216214

217215

218216
//---------------------------------------------------------------------
@@ -1486,7 +1484,7 @@ let dataEndPoints ctxtH =
14861484
let rva = ctxt.resourcesAddr + offset
14871485
res := ("manifest resource", rva) :: !res
14881486
!res
1489-
if isNil dataStartPoints then []
1487+
if List.isEmpty dataStartPoints then []
14901488
else
14911489
let methodRVAs =
14921490
let res = ref []
@@ -2184,7 +2182,7 @@ and seekReadMemberRefAsMethodDataUncached ctxtH (MemberRefAsMspecIdx (numtypars,
21842182

21852183
and seekReadMemberRefAsMethDataNoVarArgs ctxt numtypars idx : MethodData =
21862184
let (VarArgMethodData(enclTyp, cc, nm, argtys,varargs, retty,minst)) = seekReadMemberRefAsMethodData ctxt numtypars idx
2187-
if isSome varargs then dprintf "ignoring sentinel and varargs in ILMethodDef token signature"
2185+
if Option.isSome varargs then dprintf "ignoring sentinel and varargs in ILMethodDef token signature"
21882186
(MethodData(enclTyp, cc, nm, argtys, retty,minst))
21892187

21902188
and seekReadMethodSpecAsMethodData ctxt numtypars idx =
@@ -3964,16 +3962,20 @@ let OpenILModuleReader infile opts =
39643962

39653963
// ++GLOBAL MUTABLE STATE
39663964
let ilModuleReaderCache =
3967-
new Internal.Utilities.Collections.AgedLookup<(string * System.DateTime),ILModuleReader>(0, areSame=(fun (x,y) -> x = y))
3965+
new Internal.Utilities.Collections.AgedLookup<(string * System.DateTime * string * bool),ILModuleReader>(0, areSame=(fun (x,y) -> x = y))
39683966

39693967

39703968
let OpenILModuleReaderAfterReadingAllBytes infile opts =
39713969
// Pseudo-normalize the paths.
39723970
let key,succeeded =
3973-
try (FileSystem.GetFullPathShim(infile), FileSystem.GetLastWriteTimeShim(infile)), true
3971+
try
3972+
(FileSystem.GetFullPathShim(infile),
3973+
FileSystem.GetLastWriteTimeShim(infile),
3974+
opts.ilGlobals.primaryAssemblyName,
3975+
opts.ilGlobals.noDebugData), true
39743976
with e ->
39753977
System.Diagnostics.Debug.Assert(false, "Failed to compute key in OpenILModuleReaderAfterReadingAllBytes cache. Falling back to uncached.")
3976-
("",System.DateTime.Now), false
3978+
("",System.DateTime.Now,"",false), false
39773979
let cacheResult =
39783980
if not succeeded then None // Fall back to uncached.
39793981
else if opts.pdbPath.IsSome then None // can't used a cached entry when reading PDBs, since it makes the returned object IDisposable
@@ -3987,7 +3989,7 @@ let OpenILModuleReaderAfterReadingAllBytes infile opts =
39873989
{ modul = modul
39883990
ilAssemblyRefs = ilAssemblyRefs
39893991
dispose = (fun () -> ClosePdbReader pdb) }
3990-
if isNone pdb && succeeded then
3992+
if Option.isNone pdb && succeeded then
39913993
ilModuleReaderCache.Put(key, ilModuleReader)
39923994
ilModuleReader
39933995

src/absil/ilreflect.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1493,7 +1493,7 @@ let rec buildMethodPass3 cenv tref modB (typB:TypeBuilder) emEnv (mdef : ILMetho
14931493
| ".cctor" | ".ctor" ->
14941494
let consB = envGetConsB emEnv mref
14951495
// Constructors can not have generic parameters
1496-
assert isNil mdef.GenericParams
1496+
assert List.isEmpty mdef.GenericParams
14971497
// Value parameters
14981498
let defineParameter (i,attr,name) = consB.DefineParameterAndLog(i+1,attr,name)
14991499
mdef.Parameters |> ILList.iteri (emitParameter cenv emEnv defineParameter);

0 commit comments

Comments
 (0)