Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Compiler/Driver/CompilerConfig.fs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ type ImportedAssembly =
IsProviderGenerated: bool
mutable TypeProviders: Tainted<ITypeProvider> list
#endif
FSharpOptimizationData: Microsoft.FSharp.Control.Lazy<Option<Optimizer.LazyModuleInfo>>
FSharpOptimizationData: Microsoft.FSharp.Control.Lazy<Optimizer.LazyModuleInfo option>
}

type AvailableImportedAssembly =
Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/Driver/CompilerImports.fs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ type ImportedAssembly =
IsProviderGenerated: bool
mutable TypeProviders: Tainted<ITypeProvider> list
#endif
FSharpOptimizationData: Microsoft.FSharp.Control.Lazy<Option<Optimizer.LazyModuleInfo>>
FSharpOptimizationData: Microsoft.FSharp.Control.Lazy<Optimizer.LazyModuleInfo option>
}

type AvailableImportedAssembly =
Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/Driver/CompilerImports.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ type ImportedAssembly =
IsProviderGenerated: bool
mutable TypeProviders: Tainted<ITypeProvider> list
#endif
FSharpOptimizationData: Lazy<Option<LazyModuleInfo>> }
FSharpOptimizationData: Lazy<LazyModuleInfo option> }

/// Tables of assembly resolutions
[<Sealed>]
Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/Driver/CompilerOptions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ and CompilerOption =
name: string *
argumentDescriptionString: string *
actionSpec: OptionSpec *
deprecationError: Option<exn> *
deprecationError: exn option *
helpText: string option

and CompilerOptionBlock =
Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/Driver/CompilerOptions.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ and CompilerOption =
name: string *
argumentDescriptionString: string *
actionSpec: OptionSpec *
deprecationError: Option<exn> *
deprecationError: exn option *
helpText: string option

and CompilerOptionBlock =
Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/Service/FSharpCheckerResults.fs
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,7 @@ type internal TypeCheckInfo
if p >= 0 then Some p else None

/// Build a CompetionItem
let CompletionItem (ty: ValueOption<TyconRef>) (assemblySymbol: ValueOption<AssemblySymbol>) (item: ItemWithInst) =
let CompletionItem (ty: TyconRef voption) (assemblySymbol: AssemblySymbol voption) (item: ItemWithInst) =
let kind =
match item.Item with
| Item.FakeInterfaceCtor _
Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/Service/ServiceParseTreeWalk.fs
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ module SyntaxTraversal =

| SynExpr.TypeApp (synExpr, _, _synTypeList, _commas, _, _, _range) -> traverseSynExpr synExpr

| SynExpr.LetOrUse (_, isRecursive, synBindingList, synExpr, range, _) ->
| SynExpr.LetOrUse (isRecursive, _, synBindingList, synExpr, range, _) ->
match visitor.VisitLetOrUse(path, isRecursive, traverseSynBinding path, synBindingList, range) with
| None ->
[
Expand Down
4 changes: 2 additions & 2 deletions src/Compiler/TypedTree/TypedTreeOps.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1604,13 +1604,13 @@ type TyconRefMultiMap<'T>(contents: TyconRefMap<'T list>) =
//--------------------------------------------------------------------------

/// Try to create a EntityRef suitable for accessing the given Entity from another assembly
let tryRescopeEntity viewedCcu (entity: Entity) : ValueOption<EntityRef> =
let tryRescopeEntity viewedCcu (entity: Entity) : EntityRef voption =
match entity.PublicPath with
| Some pubpath -> ValueSome (ERefNonLocal (rescopePubPath viewedCcu pubpath))
| None -> ValueNone

/// Try to create a ValRef suitable for accessing the given Val from another assembly
let tryRescopeVal viewedCcu (entityRemap: Remap) (vspec: Val) : ValueOption<ValRef> =
let tryRescopeVal viewedCcu (entityRemap: Remap) (vspec: Val) : ValRef voption =
match vspec.PublicPath with
| Some (ValPubPath(p, fullLinkageKey)) ->
// The type information in the val linkage doesn't need to keep any information to trait solutions.
Expand Down
24 changes: 12 additions & 12 deletions src/Compiler/TypedTree/TypedTreeOps.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ val isTyparTy: TcGlobals -> TType -> bool

val isAnyParTy: TcGlobals -> TType -> bool

val tryAnyParTy: TcGlobals -> TType -> ValueOption<Typar>
val tryAnyParTy: TcGlobals -> TType -> Typar voption

val tryAnyParTyOption: TcGlobals -> TType -> Typar option

Expand All @@ -679,26 +679,26 @@ val isProvenUnionCaseTy: TType -> bool

val isAppTy: TcGlobals -> TType -> bool

val tryAppTy: TcGlobals -> TType -> ValueOption<TyconRef * TypeInst>
val tryAppTy: TcGlobals -> TType -> (TyconRef * TypeInst) voption

val destAppTy: TcGlobals -> TType -> TyconRef * TypeInst

val tcrefOfAppTy: TcGlobals -> TType -> TyconRef

val tryTcrefOfAppTy: TcGlobals -> TType -> ValueOption<TyconRef>
val tryTcrefOfAppTy: TcGlobals -> TType -> TyconRef voption

val tryDestTyparTy: TcGlobals -> TType -> ValueOption<Typar>
val tryDestTyparTy: TcGlobals -> TType -> Typar voption

val tryDestFunTy: TcGlobals -> TType -> ValueOption<TType * TType>
val tryDestFunTy: TcGlobals -> TType -> (TType * TType) voption

val tryDestAnonRecdTy: TcGlobals -> TType -> ValueOption<AnonRecdTypeInfo * TType list>
val tryDestAnonRecdTy: TcGlobals -> TType -> (AnonRecdTypeInfo * TType list) voption

val argsOfAppTy: TcGlobals -> TType -> TypeInst

val mkInstForAppTy: TcGlobals -> TType -> TyparInstantiation

/// Try to get a TyconRef for a type without erasing type abbreviations
val tryNiceEntityRefOfTy: TType -> ValueOption<TyconRef>
val tryNiceEntityRefOfTy: TType -> TyconRef voption

val tryNiceEntityRefOfTyOption: TType -> TyconRef option

Expand Down Expand Up @@ -1089,7 +1089,7 @@ val tagEntityRefName: xref: EntityRef -> name: string -> TaggedText
/// Return the full text for an item as we want it displayed to the user as a fully qualified entity
val fullDisplayTextOfModRef: ModuleOrNamespaceRef -> string

val fullDisplayTextOfParentOfModRef: ModuleOrNamespaceRef -> ValueOption<string>
val fullDisplayTextOfParentOfModRef: ModuleOrNamespaceRef -> string voption

val fullDisplayTextOfValRef: ValRef -> string

Expand Down Expand Up @@ -1303,10 +1303,10 @@ val wrapModuleOrNamespaceTypeInNamespace:
val wrapModuleOrNamespaceType: Ident -> CompilationPath -> ModuleOrNamespaceType -> ModuleOrNamespace

/// Given a namespace, module or type definition, try to produce a reference to that entity.
val tryRescopeEntity: CcuThunk -> Entity -> ValueOption<EntityRef>
val tryRescopeEntity: CcuThunk -> Entity -> EntityRef voption

/// Given a value definition, try to produce a reference to that value. Fails for local values.
val tryRescopeVal: CcuThunk -> Remap -> Val -> ValueOption<ValRef>
val tryRescopeVal: CcuThunk -> Remap -> Val -> ValRef voption

/// Make the substitution (remapping) table for viewing a module or namespace 'from the outside'
///
Expand Down Expand Up @@ -1526,7 +1526,7 @@ val isOptionTy: TcGlobals -> TType -> bool
val destOptionTy: TcGlobals -> TType -> TType

/// Try to take apart an option type
val tryDestOptionTy: TcGlobals -> TType -> ValueOption<TType>
val tryDestOptionTy: TcGlobals -> TType -> TType voption

/// Try to take apart an option type
val destValueOptionTy: TcGlobals -> TType -> TType
Expand All @@ -1535,7 +1535,7 @@ val destValueOptionTy: TcGlobals -> TType -> TType
val isNullableTy: TcGlobals -> TType -> bool

/// Try to take apart a System.Nullable type
val tryDestNullableTy: TcGlobals -> TType -> ValueOption<TType>
val tryDestNullableTy: TcGlobals -> TType -> TType voption

/// Take apart a System.Nullable type
val destNullableTy: TcGlobals -> TType -> TType
Expand Down
44 changes: 1 addition & 43 deletions src/FSharp.Core/fslib-extra-pervasives.fs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ module ExtraTopLevelOperators =
makeSafeKey: 'Key -> 'SafeKey,
getKey: 'SafeKey -> 'Key
) =
#if NETSTANDARD
static let emptyEnumerator =
(Array.empty<KeyValuePair<'Key, 'T>> :> seq<_>).GetEnumerator()
#endif

member _.Count = t.Count

// Give a read-only view of the dictionary
Expand Down Expand Up @@ -169,47 +166,8 @@ module ExtraTopLevelOperators =
member _.GetEnumerator() =
// We use an array comprehension here instead of seq {} as otherwise we get incorrect
// IEnumerator.Reset() and IEnumerator.Current semantics.
// Coreclr has a bug with SZGenericEnumerators --- implement a correct enumerator. On desktop use the desktop implementation because it's ngened.
#if !NETSTANDARD
let kvps = [| for (KeyValue (k, v)) in t -> KeyValuePair(getKey k, v) |] :> seq<_>
kvps.GetEnumerator()
#else
let endIndex = t.Count

if endIndex = 0 then
emptyEnumerator
else
let kvps = [| for (KeyValue (k, v)) in t -> KeyValuePair(getKey k, v) |]
let mutable index = -1

let current () =
if index < 0 then
raise <| InvalidOperationException(SR.GetString(SR.enumerationNotStarted))

if index >= endIndex then
raise <| InvalidOperationException(SR.GetString(SR.enumerationAlreadyFinished))

kvps.[index]

{ new IEnumerator<_> with
member _.Current = current ()
interface System.Collections.IEnumerator with
member _.Current = box (current ())

member _.MoveNext() =
if index < endIndex then
index <- index + 1
index < endIndex
else
false

member _.Reset() =
index <- -1
interface System.IDisposable with
member _.Dispose() =
()
}
#endif

interface System.Collections.IEnumerable with
member _.GetEnumerator() =
Expand Down
6 changes: 3 additions & 3 deletions src/FSharp.Core/result.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ module Result =
/// </code>
/// </example>
[<CompiledName("ToList")>]
val toList: result: Result<'T, 'Error> -> List<'T>
val toList: result: Result<'T, 'Error> -> 'T list

/// <summary>Convert the result to an Option value.</summary>
///
Expand All @@ -296,7 +296,7 @@ module Result =
/// </code>
/// </example>
[<CompiledName("ToOption")>]
val toOption: result: Result<'T, 'Error> -> Option<'T>
val toOption: result: Result<'T, 'Error> -> 'T option

/// <summary>Convert the result to an Option value.</summary>
///
Expand All @@ -311,4 +311,4 @@ module Result =
/// </code>
/// </example>
[<CompiledName("ToValueOption")>]
val toValueOption: result: Result<'T, 'Error> -> ValueOption<'T>
val toValueOption: result: Result<'T, 'Error> -> 'T voption
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ open System.Collections.Generic
type DictTests () =

[<Fact>]
member this.IEnumerable() =
member this.IEnumerableOnDict() =
// Legit IE
let ie = (dict [|(1,1);(2,4);(3,9)|]) :> IEnumerable
let enum = ie.GetEnumerator()
Expand Down Expand Up @@ -38,7 +38,7 @@ type DictTests () =
CheckThrowsInvalidOperationExn(fun () -> enum.Current |> ignore)

[<Fact>]
member this.IEnumerable_T() =
member this.IEnumerable_T_OnDict() =
// Legit IE
let ie = (dict [|(1,1);(2,4);(3,9)|]) :> IEnumerable<KeyValuePair<_,_>>
let enum = ie.GetEnumerator()
Expand Down
18 changes: 17 additions & 1 deletion tests/service/TreeVisitorTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,20 @@ let ``Visit enum definition test`` () =

match SyntaxTraversal.Traverse(pos0, parseTree, visitor) with
| Some [ SynEnumCase (_, SynIdent(id1,_), _, _, _, _, _); SynEnumCase (_, SynIdent(id2,_), _, _, _, _, _) ] when id1.idText = "A" && id2.idText = "B" -> ()
| _ -> failwith "Did not visit enum definition"
| _ -> failwith "Did not visit enum definition"

[<Test>]
let ``Visit recursive let binding`` () =
let visitor =
{ new SyntaxVisitorBase<_>() with
member x.VisitExpr(_, _, defaultTraverse, expr) = defaultTraverse expr
member x.VisitLetOrUse(_, isRecursive, _, bindings, _) =
if not isRecursive then failwith $"{nameof isRecursive} should be true"
Some bindings }

let source = "let rec fib n = if n < 2 then n else fib (n - 1) + fib (n - 2) in fib 10"
let parseTree = parseSourceCode("C:\\test.fs", source)

match SyntaxTraversal.Traverse(pos0, parseTree, visitor) with
| Some [ SynBinding(valData = SynValData(valInfo = SynValInfo(curriedArgInfos = [ [ SynArgInfo(ident = Some id) ] ]))) ] when id.idText = "n" -> ()
| _ -> failwith "Did not visit recursive let binding"