Skip to content

Commit

Permalink
integrate master
Browse files Browse the repository at this point in the history
  • Loading branch information
dsyme committed Jan 20, 2020
2 parents 87eda62 + e07132b commit 9a04217
Show file tree
Hide file tree
Showing 13 changed files with 91 additions and 65 deletions.
4 changes: 2 additions & 2 deletions src/absil/bytes.fs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ type ByteArrayMemory(bytes: byte[], offset, length) =
inherit ByteMemory()

do
if length <= 0 || length > bytes.Length then
if length < 0 || length > bytes.Length then
raise (ArgumentOutOfRangeException("length"))

if offset < 0 || (offset + length) > bytes.Length then
Expand Down Expand Up @@ -155,7 +155,7 @@ type RawByteMemory(addr: nativeptr<byte>, length: int, hold: obj) =
raise (ArgumentOutOfRangeException("i"))

do
if length <= 0 then
if length < 0 then
raise (ArgumentOutOfRangeException("length"))

override _.Item
Expand Down
60 changes: 39 additions & 21 deletions src/fsharp/CompileOps.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3756,6 +3756,38 @@ type TcConfigProvider =
// TcImports
//--------------------------------------------------------------------------

[<Sealed>]
type TcImportsSafeDisposal
(disposeActions: ResizeArray<unit -> unit>,
#if !NO_EXTENSIONTYPING
disposeTypeProviderActions: ResizeArray<unit -> unit>,
#endif
compilationThread: ICompilationThread) =

let mutable isDisposed = false

let dispose () =
// disposing deliberately only closes this tcImports, not the ones up the chain
isDisposed <- true
if verbose then
dprintf "disposing of TcImports, %d binaries\n" disposeActions.Count
#if !NO_EXTENSIONTYPING
let actions = disposeTypeProviderActions
if actions.Count > 0 then
compilationThread.EnqueueWork (fun _ -> for action in actions do action())
#endif
for action in disposeActions do action()

override _.Finalize() =
dispose ()

interface IDisposable with

member this.Dispose() =
if not isDisposed then
GC.SuppressFinalize this
dispose ()

#if !NO_EXTENSIONTYPING
// These are hacks in order to allow TcImports to be held as a weak reference inside a type provider.
// The reason is due to older type providers compiled using an older TypeProviderSDK, that SDK used reflection on fields and properties to determine the contract.
Expand Down Expand Up @@ -3800,34 +3832,24 @@ and [<Sealed>] TcImports(tcConfigP: TcConfigProvider, initialResolutions: TcAsse
let mutable dllTable: NameMap<ImportedBinary> = NameMap.empty
let mutable ccuInfos: ImportedAssembly list = []
let mutable ccuTable: NameMap<ImportedAssembly> = NameMap.empty
let mutable disposeActions = []
let disposeActions = ResizeArray()
let mutable disposed = false
let mutable ilGlobalsOpt = ilGlobalsOpt
let mutable tcGlobals = None
#if !NO_EXTENSIONTYPING
let mutable disposeTypeProviderActions = []
let disposeTypeProviderActions = ResizeArray()
let mutable generatedTypeRoots = new System.Collections.Generic.Dictionary<ILTypeRef, int * ProviderGeneratedType>()
let mutable tcImportsWeak = TcImportsWeakHack (WeakReference<_> this)
#endif

let disposal = new TcImportsSafeDisposal(disposeActions, disposeTypeProviderActions, compilationThread)

let CheckDisposed() =
if disposed then assert false

let dispose () =
CheckDisposed()
// disposing deliberately only closes this tcImports, not the ones up the chain
disposed <- true
if verbose then
dprintf "disposing of TcImports, %d binaries\n" disposeActions.Length
#if !NO_EXTENSIONTYPING
let actions = disposeTypeProviderActions
disposeTypeProviderActions <- []
if actions.Length > 0 then
compilationThread.EnqueueWork (fun _ -> for action in actions do action())
#endif
let actions = disposeActions
disposeActions <- []
for action in actions do action()
(disposal :> IDisposable).Dispose()

static let ccuHasType (ccu: CcuThunk) (nsname: string list) (tname: string) =
let matchNameSpace (entityOpt: Entity option) n =
Expand Down Expand Up @@ -4043,12 +4065,12 @@ and [<Sealed>] TcImports(tcConfigP: TcConfigProvider, initialResolutions: TcAsse

member private tcImports.AttachDisposeAction action =
CheckDisposed()
disposeActions <- action :: disposeActions
disposeActions.Add action

#if !NO_EXTENSIONTYPING
member private tcImports.AttachDisposeTypeProviderAction action =
CheckDisposed()
disposeTypeProviderActions <- action :: disposeTypeProviderActions
disposeTypeProviderActions.Add action
#endif

// Note: the returned binary reader is associated with the tcImports, i.e. when the tcImports are closed
Expand Down Expand Up @@ -4781,9 +4803,6 @@ and [<Sealed>] TcImports(tcConfigP: TcConfigProvider, initialResolutions: TcAsse
knownUnresolved
|> List.map (function UnresolvedAssemblyReference(file, originalReferences) -> file, originalReferences)
|> List.iter reportAssemblyNotResolved

override tcImports.Finalize () =
dispose ()

static member BuildNonFrameworkTcImports (ctok, tcConfigP: TcConfigProvider, tcGlobals: TcGlobals, baseTcImports, nonFrameworkReferences, knownUnresolved) =
cancellable {
Expand All @@ -4809,7 +4828,6 @@ and [<Sealed>] TcImports(tcConfigP: TcConfigProvider, initialResolutions: TcAsse
interface System.IDisposable with
member tcImports.Dispose() =
dispose ()
GC.SuppressFinalize tcImports

override tcImports.ToString() = "TcImports(...)"

Expand Down
8 changes: 4 additions & 4 deletions src/fsharp/FSharp.Core/list.fs
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,13 @@ namespace Microsoft.FSharp.Collections
[<CompiledName("Initialize")>]
let init length initializer = Microsoft.FSharp.Primitives.Basics.List.init length initializer

let rec initConstAcc n x acc =
if n <= 0 then acc else initConstAcc (n-1) x (x :: acc)

[<CompiledName("Replicate")>]
let replicate count initial =
if count < 0 then invalidArg "count" (SR.GetString(SR.inputMustBeNonNegative))
initConstAcc count initial []
let mutable result = []
for i in 0..count-1 do
result <- initial :: result
result

[<CompiledName("Iterate2")>]
let iter2 action list1 list2 =
Expand Down
2 changes: 1 addition & 1 deletion src/fsharp/FSharp.Core/local.fs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ open System.Collections.Generic

module internal List =

let arrayZeroCreate (n:int) = (# "newarr !0" type ('T) n : 'T array #)
let inline arrayZeroCreate (n:int) = (# "newarr !0" type ('T) n : 'T array #)

[<SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")>]
let nonempty x = match x with [] -> false | _ -> true
Expand Down
7 changes: 3 additions & 4 deletions src/fsharp/MethodCalls.fs
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,6 @@ type CalledMeth<'T>

override x.ToString() = "call to " + minfo.ToString()


let NamesOfCalledArgs (calledArgs: CalledArg list) =
calledArgs |> List.choose (fun x -> x.NameOpt)

Expand Down Expand Up @@ -1056,16 +1055,16 @@ let MakeMethInfoCall amap m minfo minst args =

match minfo with

| ILMeth(g,ilminfo,_) ->
| ILMeth(g, ilminfo, _) ->
let direct = not minfo.IsVirtual
let isProp = false // not necessarily correct, but this is only used post-creflect where this flag is irrelevant
BuildILMethInfoCall g amap m isProp ilminfo valUseFlags minst direct args |> fst

| FSMeth(g, _, vref, _) ->
BuildFSharpMethodCall g m vref valUseFlags minfo.DeclaringTypeInst minst args |> fst

| DefaultStructCtor(_,ty) ->
mkDefault (m,ty)
| DefaultStructCtor(_, ty) ->
mkDefault (m, ty)

#if !NO_EXTENSIONTYPING
| ProvidedMeth(amap, mi, _, m) ->
Expand Down
10 changes: 7 additions & 3 deletions src/fsharp/NameResolution.fs
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,7 @@ let SelectMethInfosFromExtMembers (infoReader: InfoReader) optFilter apparentTy
| Some m -> yield m
| _ -> ()
| ILExtMem (actualParent, minfo, pri) when (match optFilter with None -> true | Some nm -> nm = minfo.LogicalName) ->
// Make a reference to the type containing the extension members
match TrySelectExtensionMethInfoOfILExtMem m infoReader.amap apparentTy (actualParent, minfo, pri) with
| Some minfo -> yield minfo
| None -> ()
Expand Down Expand Up @@ -1731,6 +1732,8 @@ type TcSymbolUses(g, capturedNameResolutions: ResizeArray<CapturedNameResolution

member this.GetFormatSpecifierLocationsAndArity() = formatSpecifierLocations

static member Empty = TcSymbolUses(Unchecked.defaultof<_>, ResizeArray(), Array.empty)

/// An accumulator for the results being emitted into the tcSink.
type TcResultsSinkImpl(g, ?sourceText: ISourceText) =
let capturedEnvs = ResizeArray<_>()
Expand Down Expand Up @@ -3236,11 +3239,12 @@ let ResolveFieldPrim sink (ncenv: NameResolver) nenv ad ty (mp, id: Ident) allFi
|> ListSet.setify (fun fref1 fref2 -> tyconRefEq g fref1.TyconRef fref2.TyconRef)
|> List.map (fun x -> ResolutionInfo.Empty, FieldResolution(x, false))

if isAppTy g ty then
match tryDestAppTy g ty with
| ValueSome tcref ->
match ncenv.InfoReader.TryFindRecdOrClassFieldInfoOfType(id.idText, m, ty) with
| ValueSome (RecdFieldInfo(_, rfref)) -> [ResolutionInfo.Empty, FieldResolution(rfref, false)]
| _ ->
if isRecdTy g ty then
if tcref.IsRecordTycon then
// record label doesn't belong to record type -> suggest other labels of same record
let suggestLabels (addToBuffer: string -> unit) =
for label in SuggestOtherLabelsOfSameRecordType g nenv ty id allFields do
Expand All @@ -3251,7 +3255,7 @@ let ResolveFieldPrim sink (ncenv: NameResolver) nenv ad ty (mp, id: Ident) allFi
error(ErrorWithSuggestions(errorText, m, id.idText, suggestLabels))
else
lookup()
else
| _ ->
lookup()
| _ ->
let lid = (mp@[id])
Expand Down
6 changes: 4 additions & 2 deletions src/fsharp/NameResolution.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ type NameResolutionEnv =
/// Adding a module abbreviation adds it a local entry to this List.map.
/// Likewise adding a ccu or opening a path adds entries to this List.map.

/// REVIEW (old comment)
/// "The boolean flag is means the namespace or module entry shouldn't 'really' be in the
/// map, and if it is ever used to resolve a name then we give a warning.
Expand Down Expand Up @@ -387,6 +386,9 @@ type internal TcSymbolUses =
/// Get the locations of all the printf format specifiers in the file
member GetFormatSpecifierLocationsAndArity : unit -> (range * int)[]

/// Empty collection of symbol uses
static member Empty : TcSymbolUses

/// Represents open declaration statement.
type internal OpenDeclaration =
{ /// Long identifier as it's presented in source code.
Expand Down Expand Up @@ -604,4 +606,4 @@ val GetVisibleNamespacesAndModulesAtPoint : NameResolver -> NameResolutionEnv ->

val IsItemResolvable : NameResolver -> NameResolutionEnv -> range -> AccessorDomain -> string list -> Item -> bool

val TrySelectExtensionMethInfoOfILExtMem : range -> ImportMap -> TType -> TyconRef * MethInfo * ExtensionMethodPriority -> MethInfo option
val TrySelectExtensionMethInfoOfILExtMem : range -> ImportMap -> TType -> TyconRef * MethInfo * ExtensionMethodPriority -> MethInfo option
6 changes: 3 additions & 3 deletions src/fsharp/TastOps.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2561,7 +2561,7 @@ module PrettyTypes =
let tauThings = mapTys getTauStayTau things

let prettyThings = mapTys (instType renaming) tauThings
let tpconstraints = niceTypars |> List.collect (fun tpnice -> List.map (fun tpc -> tpnice, tpc) tpnice.Constraints)
let tpconstraints = niceTypars |> List.collect (fun tpnice -> List.map (fun tpc -> tpnice, tpc) tpnice.Constraints)

prettyThings, tpconstraints

Expand Down Expand Up @@ -4306,9 +4306,9 @@ let IsHidden setF accessF remapF =
fun mrmi x ->
check mrmi x

let IsHiddenTycon mrmi x = IsHidden (fun mhi -> mhi.HiddenTycons) (fun tc -> tc.Accessibility) (fun rpi x -> (remapTyconRef rpi.tyconRefRemap (mkLocalTyconRef x)).Deref) mrmi x
let IsHiddenTycon mrmi x = IsHidden (fun mhi -> mhi.HiddenTycons) (fun tc -> tc.Accessibility) (fun rpi x -> (remapTyconRef rpi.tyconRefRemap (mkLocalTyconRef x)).Deref) mrmi x

let IsHiddenTyconRepr mrmi x = IsHidden (fun mhi -> mhi.HiddenTyconReprs) (fun v -> v.TypeReprAccessibility) (fun rpi x -> (remapTyconRef rpi.tyconRefRemap (mkLocalTyconRef x)).Deref) mrmi x
let IsHiddenTyconRepr mrmi x = IsHidden (fun mhi -> mhi.HiddenTyconReprs) (fun v -> v.TypeReprAccessibility) (fun rpi x -> (remapTyconRef rpi.tyconRefRemap (mkLocalTyconRef x)).Deref) mrmi x

let IsHiddenVal mrmi x = IsHidden (fun mhi -> mhi.HiddenVals) (fun v -> v.Accessibility) (fun rpi x -> (remapValRef rpi (mkLocalValRef x)).Deref) mrmi x

Expand Down
26 changes: 13 additions & 13 deletions src/fsharp/TypeChecker.fs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ let AddLocalValMap tcSink scopem (vals: Val NameMap) env =
{ env with
eNameResEnv = AddValMapToNameEnv vals env.eNameResEnv
eUngeneralizableItems = NameMap.foldBackRange (typeOfVal >> addFreeItemOfTy) vals env.eUngeneralizableItems }
CallEnvSink tcSink (scopem, env.NameEnv, env.eAccessRights)
CallEnvSink tcSink (scopem, env.NameEnv, env.AccessRights)
env

/// Add a list of local values to TcEnv and report them to the sink
Expand All @@ -340,7 +340,7 @@ let AddLocalVals tcSink scopem (vals: Val list) env =
{ env with
eNameResEnv = AddValListToNameEnv vals env.eNameResEnv
eUngeneralizableItems = List.foldBack (typeOfVal >> addFreeItemOfTy) vals env.eUngeneralizableItems }
CallEnvSink tcSink (scopem, env.NameEnv, env.eAccessRights)
CallEnvSink tcSink (scopem, env.NameEnv, env.AccessRights)
env

/// Add a local value to TcEnv and report it to the sink
Expand All @@ -355,8 +355,8 @@ let AddLocalVal tcSink scopem v env =
let AddLocalExnDefnAndReport tcSink scopem env (exnc: Tycon) =
let env = { env with eNameResEnv = AddExceptionDeclsToNameEnv BulkAdd.No env.eNameResEnv (mkLocalEntityRef exnc) }
// Also make VisualStudio think there is an identifier in scope at the range of the identifier text of its binding location
CallEnvSink tcSink (exnc.Range, env.NameEnv, env.eAccessRights)
CallEnvSink tcSink (scopem, env.NameEnv, env.eAccessRights)
CallEnvSink tcSink (exnc.Range, env.NameEnv, env.AccessRights)
CallEnvSink tcSink (scopem, env.NameEnv, env.AccessRights)
env

/// Add a list of type definitions to TcEnv
Expand Down Expand Up @@ -4653,7 +4653,7 @@ and TcTypeOrMeasure optKind cenv newOk checkCxs occ env (tpenv: SyntacticUnscope
| SynType.LongIdent(LongIdentWithDots(tc, _) as lidwd) ->
let m = lidwd.Range
let ad = env.eAccessRights
let tcref = ForceRaise(ResolveTypeLongIdent cenv.tcSink cenv.nameResolver occ OpenQualified env.NameEnv ad tc TypeNameResolutionStaticArgsInfo.DefiniteEmpty PermitDirectReferenceToGeneratedType.No)
let tcref = ForceRaise(ResolveTypeLongIdent cenv.tcSink cenv.nameResolver occ OpenQualified env.NameEnv ad tc TypeNameResolutionStaticArgsInfo.DefiniteEmpty PermitDirectReferenceToGeneratedType.No)
match optKind, tcref.TypeOrMeasureKind with
| Some TyparKind.Type, TyparKind.Measure ->
error(Error(FSComp.SR.tcExpectedTypeNotUnitOfMeasure(), m))
Expand Down Expand Up @@ -5487,7 +5487,7 @@ and TcPat warnOnUpper cenv env topValInfo vFlags (tpenv, names, takenNames) ty p
| [SynPatErrorSkip(SynPat.Tuple (false, args, _)) | SynPatErrorSkip(SynPat.Paren(SynPatErrorSkip(SynPat.Tuple (false, args, _)), _))] when numArgTys > 1 -> args

// note: we allow both 'C _' and 'C (_)' regardless of number of argument of the pattern
| [SynPatErrorSkip(SynPat.Wild _ as e) | SynPatErrorSkip(SynPat.Paren(SynPatErrorSkip(SynPat.Wild _ as e), _))] -> Array.toList (Array.create numArgTys e)
| [SynPatErrorSkip(SynPat.Wild _ as e) | SynPatErrorSkip(SynPat.Paren(SynPatErrorSkip(SynPat.Wild _ as e), _))] -> List.replicate numArgTys e
| [arg] -> [arg]
| _ when numArgTys = 0 -> error(Error(FSComp.SR.tcUnionCaseDoesNotTakeArguments(), m))
| _ when numArgTys = 1 -> error(Error(FSComp.SR.tcUnionCaseRequiresOneArgument(), m))
Expand Down Expand Up @@ -5831,7 +5831,7 @@ and TcExprUndelayed cenv overallTy env tpenv (synExpr: SynExpr) =
TcConstStringExpr cenv overallTy env m tpenv s

| SynExpr.Const (synConst, m) ->
CallExprHasTypeSink cenv.tcSink (m, env.NameEnv, overallTy, env.DisplayEnv, env.eAccessRights)
CallExprHasTypeSink cenv.tcSink (m, env.NameEnv, overallTy, env.DisplayEnv, env.AccessRights)
TcConstExpr cenv overallTy env m tpenv synConst

| SynExpr.Lambda _ ->
Expand Down Expand Up @@ -6880,7 +6880,7 @@ and TcObjectExpr cenv overallTy env tpenv (synObjTy, argopt, binds, extraImpls,
match tryDestAppTy cenv.g objTy with
| ValueNone -> error(Error(FSComp.SR.tcNewMustBeUsedWithNamedType(), mNewExpr))
| ValueSome tcref ->
let isRecordTy = isRecdTy cenv.g objTy
let isRecordTy = tcref.IsRecordTycon
if not isRecordTy && not (isInterfaceTy cenv.g objTy) && isSealedTy cenv.g objTy then errorR(Error(FSComp.SR.tcCannotCreateExtensionOfSealedType(), mNewExpr))

CheckSuperType cenv objTy synObjTy.Range
Expand Down Expand Up @@ -7269,12 +7269,12 @@ and TcAnonRecdExpr cenv overallTy env tpenv (isStruct, optOrigSynExpr, unsortedF
for (i, id) in Array.indexed anonInfo.SortedIds do
yield id, Choice2Of2 (mkAnonRecdFieldGetViaExprAddr (anonInfo, oldveaddr, tinst, i, mOrigExpr))
| ValueNone ->
if isRecdTy cenv.g origExprTy then
let tcref, tinst = destAppTy cenv.g origExprTy
match tryAppTy cenv.g origExprTy with
| ValueSome(tcref, tinst) when tcref.IsRecordTycon ->
let fspecs = tcref.Deref.TrueInstanceFieldsAsList
for fspec in fspecs do
yield fspec.Id, Choice2Of2 (mkRecdFieldGetViaExprAddr (oldveaddr, tcref.MakeNestedRecdFieldRef fspec, tinst, mOrigExpr))
else
| _ ->
error (Error (FSComp.SR.tcCopyAndUpdateNeedsRecordType(), mOrigExpr)) |]
|> Array.distinctBy (fst >> textOfId)

Expand Down Expand Up @@ -9449,10 +9449,10 @@ and TcItemThen cenv overallTy env tpenv (item, mItem, rest, afterResolution) del
// Mutable value set: 'v <- e'
| DelayedSet(e2, mStmt) :: otherDelayed ->
if not (isNil otherDelayed) then error(Error(FSComp.SR.tcInvalidAssignment(), mStmt))
UnifyTypes cenv env mStmt overallTy cenv.g.unit_ty
UnifyTypes cenv env mStmt overallTy g.unit_ty
vref.Deref.SetHasBeenReferenced()
CheckValAccessible mItem env.AccessRights vref
CheckValAttributes cenv.g vref mItem |> CommitOperationResult
CheckValAttributes g vref mItem |> CommitOperationResult
let vty = vref.Type
let vty2 =
if isByrefTy g vty then
Expand Down
Loading

0 comments on commit 9a04217

Please sign in to comment.