"Fossies" - the Fresh Open Source Software Archive

Member "fsharp-4.5/src/fsharp/symbols/Symbols.fs" (5 Sep 2018, 98273 Bytes) of package /linux/misc/mono-sources/fsharp/fsharp-4.5.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) F# source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "Symbols.fs": 4.1.33_vs_4.5.

    1 // Copyright (c) Microsoft Corporation.  All Rights Reserved.  See License.txt in the project root for license information.
    2 
    3 namespace Microsoft.FSharp.Compiler.SourceCodeServices
    4 
    5 open System.Collections.Generic
    6 open Microsoft.FSharp.Compiler
    7 open Microsoft.FSharp.Compiler.AbstractIL.Internal.Library
    8 open Microsoft.FSharp.Compiler.AbstractIL.IL
    9 open Microsoft.FSharp.Compiler.Infos
   10 open Microsoft.FSharp.Compiler.AttributeChecking
   11 open Microsoft.FSharp.Compiler.AccessibilityLogic
   12 open Microsoft.FSharp.Compiler.InfoReader
   13 open Microsoft.FSharp.Compiler.Range
   14 open Microsoft.FSharp.Compiler.Ast
   15 open Microsoft.FSharp.Compiler.CompileOps
   16 open Microsoft.FSharp.Compiler.Tast
   17 open Microsoft.FSharp.Compiler.NameResolution
   18 open Microsoft.FSharp.Compiler.TcGlobals
   19 open Microsoft.FSharp.Compiler.Lib
   20 open Microsoft.FSharp.Compiler.Tastops
   21 open Internal.Utilities
   22 
   23 type FSharpAccessibility(a:Accessibility, ?isProtected) = 
   24     let isProtected = defaultArg isProtected  false
   25 
   26     let isInternalCompPath x = 
   27         match x with 
   28         | CompPath(ILScopeRef.Local, []) -> true 
   29         | _ -> false
   30 
   31     let (|Public|Internal|Private|) (TAccess p) = 
   32         match p with 
   33         | [] -> Public 
   34         | _ when List.forall isInternalCompPath p  -> Internal 
   35         | _ -> Private
   36 
   37     member __.IsPublic = not isProtected && match a with Public -> true | _ -> false
   38 
   39     member __.IsPrivate = not isProtected && match a with Private -> true | _ -> false
   40 
   41     member __.IsInternal = not isProtected && match a with Internal -> true | _ -> false
   42 
   43     member __.IsProtected = isProtected
   44 
   45     member internal __.Contents = a
   46 
   47     override __.ToString() = 
   48         let (TAccess paths) = a
   49         let mangledTextOfCompPath (CompPath(scoref, path)) = getNameOfScopeRef scoref + "/" + textOfPath (List.map fst path)  
   50         String.concat ";" (List.map mangledTextOfCompPath paths)
   51 
   52 type SymbolEnv(g: TcGlobals, thisCcu: CcuThunk, thisCcuTy: ModuleOrNamespaceType option, tcImports: TcImports, amapV: Import.ImportMap, infoReaderV: InfoReader) = 
   53 
   54     new(g: TcGlobals, thisCcu: CcuThunk, thisCcuTy: ModuleOrNamespaceType option, tcImports: TcImports) =
   55         let amap = tcImports.GetImportMap()
   56         let infoReader = InfoReader(g, amap)
   57         SymbolEnv(g, thisCcu, thisCcuTy, tcImports, amap, infoReader)
   58 
   59     member __.g = g
   60     member __.amap = amapV
   61     member __.thisCcu = thisCcu
   62     member __.thisCcuTy = thisCcuTy
   63     member __.infoReader = infoReaderV
   64     member __.tcImports = tcImports
   65 
   66 [<AutoOpen>]
   67 module Impl = 
   68     let protect f = 
   69        ErrorLogger.protectAssemblyExplorationF  
   70          (fun (asmName, path) -> invalidOp (sprintf "The entity or value '%s' does not exist or is in an unresolved assembly. You may need to add a reference to assembly '%s'" path asmName))
   71          f
   72 
   73     let makeReadOnlyCollection (arr: seq<'T>) = 
   74         System.Collections.ObjectModel.ReadOnlyCollection<_>(Seq.toArray arr) :> IList<_>
   75         
   76     let makeXmlDoc (XmlDoc x) = makeReadOnlyCollection (x)
   77     
   78     let rescopeEntity optViewedCcu (entity: Entity) = 
   79         match optViewedCcu with 
   80         | None -> mkLocalEntityRef entity
   81         | Some viewedCcu -> 
   82         match tryRescopeEntity viewedCcu entity with
   83         | None -> mkLocalEntityRef entity
   84         | Some eref -> eref
   85 
   86     let entityIsUnresolved(entity:EntityRef) = 
   87         match entity with
   88         | ERefNonLocal(NonLocalEntityRef(ccu, _)) -> 
   89             ccu.IsUnresolvedReference && entity.TryDeref.IsNone
   90         | _ -> false
   91 
   92     let checkEntityIsResolved(entity:EntityRef) = 
   93         if entityIsUnresolved(entity) then 
   94             let poorQualifiedName =
   95                 if entity.nlr.AssemblyName = "mscorlib" then 
   96                     entity.nlr.DisplayName + ", mscorlib"
   97                 else 
   98                     entity.nlr.DisplayName + ", " + entity.nlr.Ccu.AssemblyName
   99             invalidOp (sprintf "The entity '%s' does not exist or is in an unresolved assembly." poorQualifiedName)
  100 
  101     /// Checking accessibility that arise from different compilations needs more care - this is a duplicate of the F# compiler code for this case
  102     let checkForCrossProjectAccessibility (thisCcu2:CcuThunk, ad2) (thisCcu1, taccess1) = 
  103         match ad2 with 
  104         | AccessibleFrom(cpaths2, _) ->
  105             let nameOfScoRef (thisCcu:CcuThunk) scoref = 
  106                 match scoref with 
  107                 | ILScopeRef.Local -> thisCcu.AssemblyName 
  108                 | ILScopeRef.Assembly aref -> aref.Name 
  109                 | ILScopeRef.Module mref -> mref.Name
  110             let canAccessCompPathFromCrossProject (CompPath(scoref1, cpath1)) (CompPath(scoref2, cpath2)) =
  111                 let rec loop p1 p2  = 
  112                     match p1, p2 with 
  113                     | (a1, k1)::rest1, (a2, k2)::rest2 -> (a1=a2) && (k1=k2) && loop rest1 rest2
  114                     | [], _ -> true 
  115                     | _ -> false // cpath1 is longer
  116                 loop cpath1 cpath2 &&
  117                 nameOfScoRef thisCcu1 scoref1 = nameOfScoRef thisCcu2 scoref2
  118             let canAccessFromCrossProject (TAccess x1) cpath2 = x1 |> List.forall (fun cpath1 -> canAccessCompPathFromCrossProject cpath1 cpath2)
  119             cpaths2 |> List.exists (canAccessFromCrossProject taccess1) 
  120         | _ -> true // otherwise use the normal check
  121 
  122 
  123     /// Convert an IL member accessibility into an F# accessibility
  124     let getApproxFSharpAccessibilityOfMember (declaringEntity: EntityRef) (ilAccess: ILMemberAccess) = 
  125         match ilAccess with 
  126         | ILMemberAccess.CompilerControlled
  127         | ILMemberAccess.FamilyAndAssembly 
  128         | ILMemberAccess.Assembly -> 
  129             taccessPrivate  (CompPath(declaringEntity.CompilationPath.ILScopeRef, []))
  130 
  131         | ILMemberAccess.Private ->
  132             taccessPrivate  declaringEntity.CompilationPath
  133 
  134         // This is an approximation - the thing may actually be nested in a private class, in which case it is not actually "public"
  135         | ILMemberAccess.Public
  136         // This is an approximation - the thing is actually "protected", but F# accessibilities can't express "protected", so we report it as "public"
  137         | ILMemberAccess.FamilyOrAssembly
  138         | ILMemberAccess.Family ->
  139             taccessPublic 
  140 
  141     /// Convert an IL type definition accessibility into an F# accessibility
  142     let getApproxFSharpAccessibilityOfEntity (entity: EntityRef) = 
  143         match metadataOfTycon entity.Deref with 
  144 #if !NO_EXTENSIONTYPING
  145         | ProvidedTypeMetadata _info -> 
  146             // This is an approximation - for generative type providers some type definitions can be private.
  147             taccessPublic
  148 #endif
  149 
  150         | ILTypeMetadata (TILObjectReprData(_, _, td)) -> 
  151             match td.Access with 
  152             | ILTypeDefAccess.Public 
  153             | ILTypeDefAccess.Nested ILMemberAccess.Public -> taccessPublic 
  154             | ILTypeDefAccess.Private  -> taccessPrivate  (CompPath(entity.CompilationPath.ILScopeRef, []))
  155             | ILTypeDefAccess.Nested nested -> getApproxFSharpAccessibilityOfMember entity nested
  156 
  157         | FSharpOrArrayOrByrefOrTupleOrExnTypeMetadata -> 
  158             entity.Accessibility
  159 
  160     let getLiteralValue = function
  161         | Some lv  ->
  162             match lv with
  163             | Const.Bool    v -> Some(box v)
  164             | Const.SByte   v -> Some(box v)
  165             | Const.Byte    v -> Some(box v)
  166             | Const.Int16   v -> Some(box v)
  167             | Const.UInt16  v -> Some(box v)
  168             | Const.Int32   v -> Some(box v)
  169             | Const.UInt32  v -> Some(box v)
  170             | Const.Int64   v -> Some(box v)
  171             | Const.UInt64  v -> Some(box v)
  172             | Const.IntPtr  v -> Some(box v)
  173             | Const.UIntPtr v -> Some(box v)
  174             | Const.Single  v -> Some(box v)
  175             | Const.Double  v -> Some(box v)
  176             | Const.Char    v -> Some(box v)
  177             | Const.String  v -> Some(box v)
  178             | Const.Decimal v -> Some(box v)
  179             | Const.Unit
  180             | Const.Zero      -> None
  181         | None -> None
  182             
  183 
  184     let getXmlDocSigForEntity (cenv: SymbolEnv) (ent:EntityRef)=
  185         match SymbolHelpers.GetXmlDocSigOfEntityRef cenv.infoReader ent.Range ent with
  186         | Some (_, docsig) -> docsig
  187         | _ -> ""
  188 
  189 type FSharpDisplayContext(denv: TcGlobals -> DisplayEnv) = 
  190     member x.Contents(g) = denv(g)
  191     static member Empty = FSharpDisplayContext(fun g -> DisplayEnv.Empty(g))
  192 
  193 
  194 // delay the realization of 'item' in case it is unresolved
  195 type FSharpSymbol(cenv: SymbolEnv, item: (unit -> Item), access: (FSharpSymbol -> CcuThunk -> AccessorDomain -> bool)) =
  196 
  197     member x.Assembly = 
  198         let ccu = defaultArg (SymbolHelpers.ccuOfItem cenv.g x.Item) cenv.thisCcu 
  199         FSharpAssembly(cenv, ccu)
  200 
  201     member x.IsAccessible(rights: FSharpAccessibilityRights) = access x rights.ThisCcu rights.Contents
  202 
  203     member x.IsExplicitlySuppressed = SymbolHelpers.IsExplicitlySuppressed cenv.g x.Item
  204 
  205     member x.FullName = SymbolHelpers.FullNameOfItem cenv.g x.Item 
  206 
  207     member x.DeclarationLocation = SymbolHelpers.rangeOfItem cenv.g None x.Item
  208 
  209     member x.ImplementationLocation = SymbolHelpers.rangeOfItem cenv.g (Some(false)) x.Item
  210 
  211     member x.SignatureLocation = SymbolHelpers.rangeOfItem cenv.g (Some(true)) x.Item
  212 
  213     member x.IsEffectivelySameAs(y:FSharpSymbol) = 
  214         x.Equals(y) || ItemsAreEffectivelyEqual cenv.g x.Item y.Item
  215 
  216     member x.GetEffectivelySameAsHash() = ItemsAreEffectivelyEqualHash cenv.g x.Item
  217 
  218     member internal x.Item = item()
  219 
  220     member x.DisplayName = item().DisplayName
  221 
  222     // This is actually overridden in all cases below. However some symbols are still just of type FSharpSymbol, 
  223     // see 'FSharpSymbol.Create' further below.
  224     override x.Equals(other: obj) =
  225         box x === other ||
  226         match other with
  227         |   :? FSharpSymbol as otherSymbol -> ItemsAreEffectivelyEqual cenv.g x.Item otherSymbol.Item
  228         |   _ -> false
  229 
  230     override x.GetHashCode() = hash x.ImplementationLocation  
  231 
  232     override x.ToString() = "symbol " + (try item().DisplayName with _ -> "?")
  233 
  234     // TODO: there are several cases where we may need to report more interesting
  235     // symbol information below. By default we return a vanilla symbol.
  236     static member Create(g, thisCcu, thisCcuTye, tcImports, item): FSharpSymbol = 
  237         FSharpSymbol.Create(SymbolEnv(g, thisCcu, Some thisCcuTye, tcImports), item)
  238 
  239     static member Create(cenv, item): FSharpSymbol = 
  240         let dflt() = FSharpSymbol(cenv, (fun () -> item), (fun _ _ _ -> true)) 
  241         match item with 
  242         | Item.Value v -> FSharpMemberOrFunctionOrValue(cenv, V v, item) :> _
  243         | Item.UnionCase (uinfo, _) -> FSharpUnionCase(cenv, uinfo.UnionCaseRef) :> _
  244         | Item.ExnCase tcref -> FSharpEntity(cenv, tcref) :>_
  245         | Item.RecdField rfinfo -> FSharpField(cenv, RecdOrClass rfinfo.RecdFieldRef) :> _
  246 
  247         | Item.ILField finfo -> FSharpField(cenv, ILField finfo) :> _
  248         
  249         | Item.Event einfo -> 
  250             FSharpMemberOrFunctionOrValue(cenv, E einfo, item) :> _
  251             
  252         | Item.Property(_, pinfo :: _) -> 
  253             FSharpMemberOrFunctionOrValue(cenv, P pinfo, item) :> _
  254             
  255         | Item.MethodGroup(_, minfo :: _, _) -> 
  256             FSharpMemberOrFunctionOrValue(cenv, M minfo, item) :> _
  257 
  258         | Item.CtorGroup(_, cinfo :: _) -> 
  259             FSharpMemberOrFunctionOrValue(cenv, C cinfo, item) :> _
  260 
  261         | Item.DelegateCtor (AbbrevOrAppTy tcref) -> 
  262             FSharpEntity(cenv, tcref) :>_ 
  263 
  264         | Item.UnqualifiedType(tcref :: _)  
  265         | Item.Types(_, AbbrevOrAppTy tcref :: _) -> 
  266             FSharpEntity(cenv, tcref) :>_  
  267 
  268         | Item.ModuleOrNamespaces(modref :: _) ->  
  269             FSharpEntity(cenv, modref) :> _
  270 
  271         | Item.SetterArg (_id, item) -> FSharpSymbol.Create(cenv, item)
  272 
  273         | Item.CustomOperation (_customOpName, _, Some minfo) -> 
  274             FSharpMemberOrFunctionOrValue(cenv, M minfo, item) :> _
  275 
  276         | Item.CustomBuilder (_, vref) -> 
  277             FSharpMemberOrFunctionOrValue(cenv, V vref, item) :> _
  278 
  279         | Item.TypeVar (_, tp) ->
  280              FSharpGenericParameter(cenv, tp) :> _
  281 
  282         | Item.ActivePatternCase apref -> 
  283              FSharpActivePatternCase(cenv, apref.ActivePatternInfo, apref.ActivePatternVal.Type, apref.CaseIndex, Some apref.ActivePatternVal, item) :> _
  284 
  285         | Item.ActivePatternResult (apinfo, ty, n, _) ->
  286              FSharpActivePatternCase(cenv, apinfo, ty, n, None, item) :> _
  287 
  288         | Item.ArgName(id, ty, _)  ->
  289              FSharpParameter(cenv, ty, {Attribs=[]; Name=Some id}, Some id.idRange, isParamArrayArg=false, isInArg=false, isOutArg=false, isOptionalArg=false) :> _
  290 
  291         // TODO: the following don't currently return any interesting subtype
  292         | Item.ImplicitOp _
  293         | Item.ILField _ 
  294         | Item.FakeInterfaceCtor _
  295         | Item.NewDef _ -> dflt()
  296         // These cases cover unreachable cases
  297         | Item.CustomOperation (_, _, None) 
  298         | Item.UnqualifiedType []
  299         | Item.ModuleOrNamespaces []
  300         | Item.Property (_, [])
  301         | Item.MethodGroup (_, [], _)
  302         | Item.CtorGroup (_, [])
  303         // These cases cover misc. corned cases (non-symbol types)
  304         | Item.Types _
  305         | Item.DelegateCtor _  -> dflt()
  306 
  307     static member GetAccessibility (symbol: FSharpSymbol) =
  308         match symbol with
  309         | :? FSharpEntity as x -> Some x.Accessibility
  310         | :? FSharpField as x -> Some x.Accessibility
  311         | :? FSharpUnionCase as x -> Some x.Accessibility
  312         | :? FSharpMemberFunctionOrValue as x -> Some x.Accessibility
  313         | _ -> None
  314         
  315 and FSharpEntity(cenv: SymbolEnv, entity:EntityRef) = 
  316     inherit FSharpSymbol(cenv, 
  317                          (fun () -> 
  318                               checkEntityIsResolved(entity); 
  319                               if entity.IsModuleOrNamespace then Item.ModuleOrNamespaces [entity] 
  320                               else Item.UnqualifiedType [entity]), 
  321                          (fun _this thisCcu2 ad -> 
  322                              checkForCrossProjectAccessibility (thisCcu2, ad) (cenv.thisCcu, getApproxFSharpAccessibilityOfEntity entity)) 
  323                              // && AccessibilityLogic.IsEntityAccessible cenv.amap range0 ad entity)
  324                              )
  325 
  326     // If an entity is in an assembly not available to us in the resolution set, 
  327     // we generally return "false" from predicates like IsClass, since we know
  328     // nothing about that type.
  329     let isResolvedAndFSharp() = 
  330         match entity with
  331         | ERefNonLocal(NonLocalEntityRef(ccu, _)) -> not ccu.IsUnresolvedReference && ccu.IsFSharp
  332         | _ -> cenv.thisCcu.IsFSharp
  333 
  334     let isUnresolved() = entityIsUnresolved entity
  335     let isResolved() = not (isUnresolved())
  336     let checkIsResolved() = checkEntityIsResolved entity
  337 
  338     let isDefinedInFSharpCore() =
  339         match ccuOfTyconRef entity with
  340         | None -> false
  341         | Some ccu -> ccuEq ccu cenv.g.fslibCcu
  342 
  343     member __.Entity = entity
  344         
  345     member __.LogicalName = 
  346         checkIsResolved()
  347         entity.LogicalName 
  348 
  349     member __.CompiledName = 
  350         checkIsResolved()
  351         entity.CompiledName 
  352 
  353     member __.DisplayName = 
  354         checkIsResolved()
  355         if entity.IsModuleOrNamespace then entity.DemangledModuleOrNamespaceName
  356         else entity.DisplayName 
  357 
  358     member __.AccessPath  = 
  359         checkIsResolved()
  360         match entity.CompilationPathOpt with 
  361         | None -> "global" 
  362         | Some (CompPath(_, [])) -> "global" 
  363         | Some cp -> buildAccessPath (Some cp)
  364     
  365     member x.DeclaringEntity = 
  366         match entity.CompilationPathOpt with 
  367         | None -> None
  368         | Some (CompPath(_, [])) -> None
  369         | Some cp -> 
  370             match x.Assembly.Contents.FindEntityByPath cp.MangledPath with
  371             | Some res -> Some res
  372             | None -> 
  373             // The declaring entity may be in this assembly, including a type possibly hidden by a signature.
  374             match cenv.thisCcuTy with 
  375             | Some t -> 
  376                 let s = FSharpAssemblySignature(cenv, None, None, t)
  377                 s.FindEntityByPath cp.MangledPath 
  378             | None -> None
  379 
  380     member __.Namespace  = 
  381         checkIsResolved()
  382         match entity.CompilationPathOpt with 
  383         | None -> None
  384         | Some (CompPath(_, [])) -> None
  385         | Some cp when cp.AccessPath |> List.forall (function (_, ModuleOrNamespaceKind.Namespace) -> true | _  -> false) -> 
  386             Some (buildAccessPath (Some cp))
  387         | Some _ -> None
  388 
  389     member x.QualifiedName = 
  390         checkIsResolved()
  391         let fail() = invalidOp (sprintf "the type '%s' does not have a qualified name" x.LogicalName)
  392 #if !NO_EXTENSIONTYPING
  393         if entity.IsTypeAbbrev || entity.IsProvidedErasedTycon || entity.IsNamespace then fail()
  394         #else
  395         if entity.IsTypeAbbrev || entity.IsNamespace then fail()
  396 #endif
  397         match entity.CompiledRepresentation with 
  398         | CompiledTypeRepr.ILAsmNamed(tref, _, _) -> tref.QualifiedName
  399         | CompiledTypeRepr.ILAsmOpen _ -> fail()
  400         
  401     member x.FullName = 
  402         checkIsResolved()
  403         match x.TryFullName with 
  404         | None -> invalidOp (sprintf "the type '%s' does not have a qualified name" x.LogicalName)
  405         | Some nm -> nm
  406     
  407     member x.TryFullName = 
  408         if isUnresolved() then None
  409 #if !NO_EXTENSIONTYPING
  410         elif entity.IsTypeAbbrev || entity.IsProvidedErasedTycon then None
  411         #else
  412         elif entity.IsTypeAbbrev then None
  413 #endif
  414         elif entity.IsNamespace  then Some entity.DemangledModuleOrNamespaceName
  415         else
  416             match entity.CompiledRepresentation with 
  417             | CompiledTypeRepr.ILAsmNamed(tref, _, _) -> Some tref.FullName
  418             | CompiledTypeRepr.ILAsmOpen _ -> None   
  419 
  420     member __.DeclarationLocation = 
  421         checkIsResolved()
  422         entity.Range
  423 
  424     member x.GenericParameters = 
  425         checkIsResolved()
  426         entity.TyparsNoRange |> List.map (fun tp -> FSharpGenericParameter(cenv, tp)) |> makeReadOnlyCollection
  427 
  428     member __.IsMeasure = 
  429         isResolvedAndFSharp() && (entity.TypeOrMeasureKind = TyparKind.Measure)
  430 
  431     member __.IsFSharpModule = 
  432         isResolvedAndFSharp() && entity.IsModule
  433 
  434     member __.HasFSharpModuleSuffix = 
  435         isResolvedAndFSharp() && 
  436         entity.IsModule && 
  437         (entity.ModuleOrNamespaceType.ModuleOrNamespaceKind = ModuleOrNamespaceKind.FSharpModuleWithSuffix)
  438 
  439     member __.IsValueType  = 
  440         isResolved() &&
  441         entity.IsStructOrEnumTycon 
  442 
  443     member x.IsArrayType  = 
  444         isResolved() &&
  445         isArrayTyconRef cenv.g entity
  446 
  447     member __.ArrayRank  = 
  448         checkIsResolved()
  449         rankOfArrayTyconRef cenv.g entity
  450 #if !NO_EXTENSIONTYPING
  451     member __.IsProvided  = 
  452         isResolved() &&
  453         entity.IsProvided
  454 
  455     member __.IsProvidedAndErased  = 
  456         isResolved() &&
  457         entity.IsProvidedErasedTycon
  458 
  459     member __.IsStaticInstantiation  = 
  460         isResolved() &&
  461         entity.IsStaticInstantiationTycon
  462 
  463     member __.IsProvidedAndGenerated  = 
  464         isResolved() &&
  465         entity.IsProvidedGeneratedTycon
  466 #endif
  467     member __.IsClass = 
  468         isResolved() &&
  469         match metadataOfTycon entity.Deref with
  470 #if !NO_EXTENSIONTYPING 
  471         | ProvidedTypeMetadata info -> info.IsClass
  472 #endif
  473         | ILTypeMetadata (TILObjectReprData(_, _, td)) -> td.IsClass
  474         | FSharpOrArrayOrByrefOrTupleOrExnTypeMetadata -> entity.Deref.IsFSharpClassTycon
  475 
  476     member __.IsByRef = 
  477         isResolved() &&
  478         tyconRefEq cenv.g cenv.g.byref_tcr entity
  479 
  480     member __.IsOpaque = 
  481         isResolved() &&
  482         entity.IsHiddenReprTycon
  483 
  484     member __.IsInterface = 
  485         isResolved() &&
  486         isInterfaceTyconRef entity
  487 
  488     member __.IsDelegate = 
  489         isResolved() &&
  490         match metadataOfTycon entity.Deref with 
  491 #if !NO_EXTENSIONTYPING
  492         | ProvidedTypeMetadata info -> info.IsDelegate ()
  493 #endif
  494         | ILTypeMetadata (TILObjectReprData(_, _, td)) -> td.IsDelegate
  495         | FSharpOrArrayOrByrefOrTupleOrExnTypeMetadata -> entity.IsFSharpDelegateTycon
  496 
  497     member __.IsEnum = 
  498         isResolved() &&
  499         entity.IsEnumTycon
  500     
  501     member __.IsFSharpExceptionDeclaration = 
  502         isResolvedAndFSharp() && entity.IsExceptionDecl
  503 
  504     member __.IsUnresolved = 
  505         isUnresolved()
  506 
  507     member __.IsFSharp = 
  508         isResolvedAndFSharp()
  509 
  510     member __.IsFSharpAbbreviation = 
  511         isResolvedAndFSharp() && entity.IsTypeAbbrev 
  512 
  513     member __.IsFSharpRecord = 
  514         isResolvedAndFSharp() && entity.IsRecordTycon
  515 
  516     member __.IsFSharpUnion = 
  517         isResolvedAndFSharp() && entity.IsUnionTycon
  518 
  519     member __.HasAssemblyCodeRepresentation = 
  520         isResolvedAndFSharp() && (entity.IsAsmReprTycon || entity.IsMeasureableReprTycon)
  521 
  522     member __.FSharpDelegateSignature =
  523         checkIsResolved()
  524         match entity.TypeReprInfo with 
  525         | TFSharpObjectRepr r when entity.IsFSharpDelegateTycon -> 
  526             match r.fsobjmodel_kind with 
  527             | TTyconDelegate ss -> FSharpDelegateSignature(cenv, ss)
  528             | _ -> invalidOp "not a delegate type"
  529         | _ -> invalidOp "not a delegate type"
  530       
  531 
  532     member __.Accessibility = 
  533         if isUnresolved() then FSharpAccessibility(taccessPublic) else
  534         FSharpAccessibility(getApproxFSharpAccessibilityOfEntity entity) 
  535 
  536     member __.RepresentationAccessibility = 
  537         if isUnresolved() then FSharpAccessibility(taccessPublic) else
  538         FSharpAccessibility(entity.TypeReprAccessibility)
  539 
  540     member x.DeclaredInterfaces = 
  541         if isUnresolved() then makeReadOnlyCollection [] else
  542         ErrorLogger.protectAssemblyExploration [] (fun () -> 
  543             [ for ty in GetImmediateInterfacesOfType SkipUnrefInterfaces.Yes cenv.g cenv.amap range0 (generalizedTyconRef entity) do 
  544                  yield FSharpType(cenv, ty) ])
  545         |> makeReadOnlyCollection
  546 
  547     member x.AllInterfaces = 
  548         if isUnresolved() then makeReadOnlyCollection [] else
  549         ErrorLogger.protectAssemblyExploration [] (fun () -> 
  550             [ for ty in AllInterfacesOfType  cenv.g cenv.amap range0 AllowMultiIntfInstantiations.Yes (generalizedTyconRef entity) do 
  551                  yield FSharpType(cenv, ty) ])
  552         |> makeReadOnlyCollection
  553     
  554     member x.IsAttributeType =
  555         if isUnresolved() then false else
  556         let ty = generalizedTyconRef entity
  557         ErrorLogger.protectAssemblyExploration false <| fun () -> 
  558         Infos.ExistsHeadTypeInEntireHierarchy cenv.g cenv.amap range0 ty cenv.g.tcref_System_Attribute
  559         
  560     member x.IsDisposableType =
  561         if isUnresolved() then false else
  562         let ty = generalizedTyconRef entity
  563         ErrorLogger.protectAssemblyExploration false <| fun () -> 
  564         Infos.ExistsHeadTypeInEntireHierarchy cenv.g cenv.amap range0 ty cenv.g.tcref_System_IDisposable
  565 
  566     member x.BaseType = 
  567         checkIsResolved()        
  568         GetSuperTypeOfType cenv.g cenv.amap range0 (generalizedTyconRef entity) 
  569         |> Option.map (fun ty -> FSharpType(cenv, ty)) 
  570         
  571     member __.UsesPrefixDisplay = 
  572         if isUnresolved() then true else
  573         not (isResolvedAndFSharp()) || entity.Deref.IsPrefixDisplay
  574 
  575     member x.IsNamespace =  entity.IsNamespace
  576 
  577     member x.MembersOrValues =  x.MembersFunctionsAndValues
  578 
  579     member x.MembersFunctionsAndValues = 
  580       if isUnresolved() then makeReadOnlyCollection[] else
  581       protect <| fun () -> 
  582         ([ let _, entityTy = generalizeTyconRef entity
  583            let createMember (minfo: MethInfo) =
  584                if minfo.IsConstructor then FSharpMemberOrFunctionOrValue(cenv, C minfo, Item.CtorGroup (minfo.DisplayName, [minfo]))
  585                else FSharpMemberOrFunctionOrValue(cenv, M minfo, Item.MethodGroup (minfo.DisplayName, [minfo], None))
  586            if x.IsFSharpAbbreviation then 
  587                ()
  588            elif x.IsFSharp then 
  589                // For F# code we emit methods members in declaration order
  590                for v in entity.MembersOfFSharpTyconSorted do 
  591                  // Ignore members representing the generated .cctor
  592                  if not v.Deref.IsClassConstructor then 
  593                      yield createMember (FSMeth(cenv.g, entityTy, v, None))
  594            else
  595                for minfo in GetImmediateIntrinsicMethInfosOfType (None, AccessibleFromSomeFSharpCode) cenv.g cenv.amap range0 entityTy do
  596                     yield createMember minfo
  597            let props = GetImmediateIntrinsicPropInfosOfType (None, AccessibleFromSomeFSharpCode) cenv.g cenv.amap range0 entityTy
  598            let events = cenv.infoReader.GetImmediateIntrinsicEventsOfType (None, AccessibleFromSomeFSharpCode, range0, entityTy)
  599            for pinfo in props do
  600                 yield FSharpMemberOrFunctionOrValue(cenv, P pinfo, Item.Property (pinfo.PropertyName, [pinfo]))
  601            for einfo in events do
  602                 yield FSharpMemberOrFunctionOrValue(cenv, E einfo, Item.Event einfo)
  603 
  604            // Emit the values, functions and F#-declared extension members in a module
  605            for v in entity.ModuleOrNamespaceType.AllValsAndMembers do
  606                if v.IsExtensionMember then
  607 
  608                    // For F#-declared extension members, yield a value-backed member and a property info if possible
  609                    let vref = mkNestedValRef entity v
  610                    yield FSharpMemberOrFunctionOrValue(cenv, V vref, Item.Value vref) 
  611                    match v.MemberInfo.Value.MemberFlags.MemberKind, v.ApparentEnclosingEntity with
  612                    | MemberKind.PropertyGet, Parent p -> 
  613                         let pinfo = FSProp(cenv.g, generalizedTyconRef p, Some vref, None)
  614                         yield FSharpMemberOrFunctionOrValue(cenv, P pinfo, Item.Property (pinfo.PropertyName, [pinfo]))
  615                    | MemberKind.PropertySet, Parent p -> 
  616                         let pinfo = FSProp(cenv.g, generalizedTyconRef p, None, Some vref)
  617                         yield FSharpMemberOrFunctionOrValue(cenv, P pinfo, Item.Property (pinfo.PropertyName, [pinfo]))
  618                    | _ -> ()
  619 
  620                elif not v.IsMember then
  621                    let vref = mkNestedValRef entity v
  622                    yield FSharpMemberOrFunctionOrValue(cenv, V vref, Item.Value vref) ]  
  623          |> makeReadOnlyCollection)
  624  
  625     member __.XmlDocSig = 
  626         checkIsResolved()
  627         getXmlDocSigForEntity cenv entity
  628  
  629     member __.XmlDoc = 
  630         if isUnresolved() then XmlDoc.Empty  |> makeXmlDoc else
  631         entity.XmlDoc |> makeXmlDoc
  632 
  633     member x.StaticParameters = 
  634         match entity.TypeReprInfo with 
  635 #if !NO_EXTENSIONTYPING
  636         | TProvidedTypeExtensionPoint info -> 
  637             let m = x.DeclarationLocation
  638             let typeBeforeArguments = info.ProvidedType 
  639             let staticParameters = typeBeforeArguments.PApplyWithProvider((fun (typeBeforeArguments, provider) -> typeBeforeArguments.GetStaticParameters(provider)), range=m) 
  640             let staticParameters = staticParameters.PApplyArray(id, "GetStaticParameters", m)
  641             [| for p in staticParameters -> FSharpStaticParameter(cenv, p, m) |]
  642 #endif
  643         | _ -> [| |]
  644       |> makeReadOnlyCollection
  645 
  646     member __.NestedEntities = 
  647         if isUnresolved() then makeReadOnlyCollection[] else
  648         entity.ModuleOrNamespaceType.AllEntities 
  649         |> QueueList.toList
  650         |> List.map (fun x -> FSharpEntity(cenv, entity.NestedTyconRef x))
  651         |> makeReadOnlyCollection
  652 
  653     member x.UnionCases = 
  654         if isUnresolved() then makeReadOnlyCollection[] else
  655         entity.UnionCasesAsRefList
  656         |> List.map (fun x -> FSharpUnionCase(cenv, x)) 
  657         |> makeReadOnlyCollection
  658 
  659     member x.RecordFields = x.FSharpFields
  660 
  661     member x.FSharpFields =
  662         if isUnresolved() then makeReadOnlyCollection[] else
  663     
  664         if entity.IsILEnumTycon then
  665             let (TILObjectReprData(_scoref, _enc, tdef)) = entity.ILTyconInfo
  666             let formalTypars = entity.Typars(range.Zero)
  667             let formalTypeInst = generalizeTypars formalTypars
  668             let ty = TType_app(entity, formalTypeInst)
  669             let formalTypeInfo = ILTypeInfo.FromType cenv.g ty
  670             tdef.Fields.AsList
  671             |> List.map (fun tdef -> let ilFieldInfo = ILFieldInfo(formalTypeInfo, tdef)
  672                                      FSharpField(cenv, FSharpFieldData.ILField(ilFieldInfo) ))
  673             |> makeReadOnlyCollection
  674 
  675         else
  676             entity.AllFieldsAsList
  677             |> List.map (fun x -> FSharpField(cenv, mkRecdFieldRef entity x.Name))
  678             |> makeReadOnlyCollection
  679 
  680     member x.AbbreviatedType   = 
  681         checkIsResolved()
  682 
  683         match entity.TypeAbbrev with
  684         | None -> invalidOp "not a type abbreviation"
  685         | Some ty -> FSharpType(cenv, ty)
  686 
  687     member __.Attributes = 
  688         if isUnresolved() then makeReadOnlyCollection[] else
  689         GetAttribInfosOfEntity cenv.g cenv.amap range0 entity
  690         |> List.map (fun a -> FSharpAttribute(cenv, a))
  691         |> makeReadOnlyCollection
  692 
  693     member __.AllCompilationPaths =
  694         checkIsResolved()
  695         let (CompPath(_, parts)) = entity.CompilationPath
  696         let partsList =
  697             [ yield parts
  698               match parts with
  699               | ("Microsoft", ModuleOrNamespaceKind.Namespace) :: rest when isDefinedInFSharpCore() -> yield rest
  700               | _ -> ()]
  701 
  702         let mapEachCurrentPath (paths: string list list) path =
  703             match paths with
  704             | [] -> [[path]]
  705             | _ -> paths |> List.map (fun x -> path :: x)
  706 
  707         let walkParts (parts: (string * ModuleOrNamespaceKind) list) =
  708             let rec loop (currentPaths: string list list) parts =
  709                 match parts with
  710                 | [] -> currentPaths
  711                 | (name: string, kind) :: rest ->
  712                     match kind with
  713                     | ModuleOrNamespaceKind.FSharpModuleWithSuffix ->
  714                         [ yield! loop (mapEachCurrentPath currentPaths name) rest
  715                           yield! loop (mapEachCurrentPath currentPaths (name.[..name.Length - 7])) rest ]
  716                     | _ -> 
  717                        loop (mapEachCurrentPath currentPaths name) rest
  718             loop [] parts |> List.map (List.rev >> String.concat ".")
  719             
  720         let res =
  721             [ for parts in partsList do
  722                 yield! walkParts parts ]
  723         res
  724 
  725     member x.ActivePatternCases =
  726         protect <| fun () -> 
  727             ActivePatternElemsOfModuleOrNamespace x.Entity
  728             |> Map.toList
  729             |> List.map (fun (_, apref) ->
  730                 let item = Item.ActivePatternCase apref
  731                 FSharpActivePatternCase(cenv, apref.ActivePatternInfo, apref.ActivePatternVal.Type, apref.CaseIndex, Some apref.ActivePatternVal, item))
  732 
  733     override x.Equals(other: obj) =
  734         box x === other ||
  735         match other with
  736         |   :? FSharpEntity as otherEntity -> tyconRefEq cenv.g entity otherEntity.Entity
  737         |   _ -> false
  738 
  739     override x.GetHashCode() =
  740         checkIsResolved()
  741         ((hash entity.Stamp) <<< 1) + 1
  742 
  743     override x.ToString() = x.CompiledName
  744 
  745 and FSharpUnionCase(cenv, v: UnionCaseRef) =
  746     inherit FSharpSymbol (cenv,  
  747                           (fun () -> 
  748                                checkEntityIsResolved v.TyconRef
  749                                Item.UnionCase(UnionCaseInfo(generalizeTypars v.TyconRef.TyparsNoRange, v), false)), 
  750                           (fun _this thisCcu2 ad -> 
  751                                checkForCrossProjectAccessibility (thisCcu2, ad) (cenv.thisCcu, v.UnionCase.Accessibility)) 
  752                                //&& AccessibilityLogic.IsUnionCaseAccessible cenv.amap range0 ad v)
  753                                )
  754 
  755 
  756     let isUnresolved() = 
  757         entityIsUnresolved v.TyconRef || v.TryUnionCase.IsNone 
  758     let checkIsResolved() = 
  759         checkEntityIsResolved v.TyconRef
  760         if v.TryUnionCase.IsNone then 
  761             invalidOp (sprintf "The union case '%s' could not be found in the target type" v.CaseName)
  762 
  763     member __.IsUnresolved = 
  764         isUnresolved()
  765 
  766     member __.Name = 
  767         checkIsResolved()
  768         v.UnionCase.DisplayName
  769 
  770     member __.DeclarationLocation = 
  771         checkIsResolved()
  772         v.Range
  773 
  774     member __.UnionCaseFields = 
  775         if isUnresolved() then makeReadOnlyCollection [] else
  776         v.UnionCase.RecdFields |> List.mapi (fun i _ ->  FSharpField(cenv, FSharpFieldData.Union (v, i))) |> makeReadOnlyCollection
  777 
  778     member __.ReturnType = 
  779         checkIsResolved()
  780         FSharpType(cenv, v.ReturnType)
  781 
  782     member __.CompiledName = 
  783         checkIsResolved()
  784         v.UnionCase.CompiledName
  785 
  786     member __.XmlDocSig = 
  787         checkIsResolved()
  788         let unionCase = UnionCaseInfo(generalizeTypars v.TyconRef.TyparsNoRange, v)
  789         match SymbolHelpers.GetXmlDocSigOfUnionCaseInfo unionCase with
  790         | Some (_, docsig) -> docsig
  791         | _ -> ""
  792 
  793     member __.XmlDoc = 
  794         if isUnresolved() then XmlDoc.Empty  |> makeXmlDoc else
  795         v.UnionCase.XmlDoc |> makeXmlDoc
  796 
  797     member __.Attributes = 
  798         if isUnresolved() then makeReadOnlyCollection [] else
  799         v.Attribs |> List.map (fun a -> FSharpAttribute(cenv, AttribInfo.FSAttribInfo(cenv.g, a))) |> makeReadOnlyCollection
  800 
  801     member __.Accessibility =  
  802         if isUnresolved() then FSharpAccessibility(taccessPublic) else
  803         FSharpAccessibility(v.UnionCase.Accessibility)
  804 
  805     member private x.V = v
  806     override x.Equals(other: obj) =
  807         box x === other ||
  808         match other with
  809         |   :? FSharpUnionCase as uc -> v === uc.V
  810         |   _ -> false
  811     
  812     override x.GetHashCode() = hash v.CaseName
  813 
  814     override x.ToString() = x.CompiledName
  815 
  816 
  817 and FSharpFieldData = 
  818     | ILField of ILFieldInfo
  819     | RecdOrClass of RecdFieldRef
  820     | Union of UnionCaseRef * int
  821 
  822     member x.TryRecdField =
  823         match x with 
  824         | RecdOrClass v -> v.RecdField |> Choice1Of2
  825         | Union (v, n) -> v.FieldByIndex(n) |> Choice1Of2
  826         | ILField f -> f |> Choice2Of2
  827 
  828     member x.DeclaringTyconRef =
  829         match x with 
  830         | RecdOrClass v -> v.TyconRef
  831         | Union (v, _) -> v.TyconRef
  832         | ILField f -> f.DeclaringTyconRef
  833 
  834 and FSharpField(cenv: SymbolEnv, d: FSharpFieldData)  =
  835     inherit FSharpSymbol (cenv, 
  836                           (fun () -> 
  837                                 match d with 
  838                                 | RecdOrClass v -> 
  839                                     checkEntityIsResolved v.TyconRef
  840                                     Item.RecdField(RecdFieldInfo(generalizeTypars v.TyconRef.TyparsNoRange, v))
  841                                 | Union (v, _) -> 
  842                                     // This is not correct: there is no "Item" for a named union case field
  843                                     Item.UnionCase(UnionCaseInfo(generalizeTypars v.TyconRef.TyparsNoRange, v), false)
  844                                 | ILField f -> 
  845                                     Item.ILField f), 
  846                           (fun this thisCcu2 ad -> 
  847                                 checkForCrossProjectAccessibility (thisCcu2, ad) (cenv.thisCcu, (this :?> FSharpField).Accessibility.Contents)) 
  848                                 //&&
  849                                 //match d with 
  850                                 //| Recd v -> AccessibilityLogic.IsRecdFieldAccessible cenv.amap range0 ad v
  851                                 //| Union (v, _) -> AccessibilityLogic.IsUnionCaseAccessible cenv.amap range0 ad v)
  852                                 )
  853 
  854     let isUnresolved() = 
  855         entityIsUnresolved d.DeclaringTyconRef ||
  856         match d with 
  857         | RecdOrClass v ->  v.TryRecdField.IsNone 
  858         | Union (v, _) -> v.TryUnionCase.IsNone 
  859         | ILField _ -> false
  860 
  861     let checkIsResolved() = 
  862         checkEntityIsResolved d.DeclaringTyconRef
  863         match d with 
  864         | RecdOrClass v -> 
  865             if v.TryRecdField.IsNone then 
  866                 invalidOp (sprintf "The record field '%s' could not be found in the target type" v.FieldName)
  867         | Union (v, _) -> 
  868             if v.TryUnionCase.IsNone then 
  869                 invalidOp (sprintf "The union case '%s' could not be found in the target type" v.CaseName)
  870         | ILField _ -> ()
  871 
  872     new (cenv, ucref, n) = FSharpField(cenv, FSharpFieldData.Union(ucref, n))
  873 
  874     new (cenv, rfref) = FSharpField(cenv, FSharpFieldData.RecdOrClass(rfref))
  875 
  876     member __.DeclaringEntity = 
  877         FSharpEntity(cenv, d.DeclaringTyconRef)
  878 
  879     member __.IsUnresolved = 
  880         isUnresolved()
  881 
  882     member __.IsMutable = 
  883         if isUnresolved() then false else 
  884         match d.TryRecdField with 
  885         | Choice1Of2 r -> r.IsMutable
  886         | Choice2Of2 f -> not f.IsInitOnly && f.LiteralValue.IsNone
  887 
  888     member __.IsLiteral = 
  889         if isUnresolved() then false else 
  890         match d.TryRecdField with 
  891         | Choice1Of2 r -> r.LiteralValue.IsSome
  892         | Choice2Of2 f -> f.LiteralValue.IsSome
  893 
  894     member __.LiteralValue = 
  895         if isUnresolved() then None else 
  896         match d.TryRecdField with 
  897         | Choice1Of2 r -> getLiteralValue r.LiteralValue
  898         | Choice2Of2 f -> f.LiteralValue |> Option.map AbstractIL.ILRuntimeWriter.convFieldInit 
  899 
  900     member __.IsVolatile = 
  901         if isUnresolved() then false else 
  902         match d.TryRecdField with 
  903         | Choice1Of2 r -> r.IsVolatile
  904         | Choice2Of2 _ -> false // F# doesn't actually respect "volatile" from other assemblies in any case
  905 
  906     member __.IsDefaultValue = 
  907         if isUnresolved() then false else 
  908         match d.TryRecdField with 
  909         | Choice1Of2 r -> r.IsZeroInit
  910         | Choice2Of2 _ -> false 
  911 
  912     member __.XmlDocSig = 
  913         checkIsResolved()
  914         let xmlsig =
  915             match d with 
  916             | RecdOrClass v -> 
  917                 let recd = RecdFieldInfo(generalizeTypars v.TyconRef.TyparsNoRange, v)
  918                 SymbolHelpers.GetXmlDocSigOfRecdFieldInfo recd
  919             | Union (v, _) -> 
  920                 let unionCase = UnionCaseInfo(generalizeTypars v.TyconRef.TyparsNoRange, v)
  921                 SymbolHelpers.GetXmlDocSigOfUnionCaseInfo unionCase
  922             | ILField f -> 
  923                 SymbolHelpers.GetXmlDocSigOfILFieldInfo cenv.infoReader range0 f
  924         match xmlsig with
  925         | Some (_, docsig) -> docsig
  926         | _ -> ""
  927 
  928     member __.XmlDoc = 
  929         if isUnresolved() then XmlDoc.Empty  |> makeXmlDoc else
  930         match d.TryRecdField with 
  931         | Choice1Of2 r -> r.XmlDoc 
  932         | Choice2Of2 _ -> XmlDoc.Empty
  933         |> makeXmlDoc
  934 
  935     member __.FieldType = 
  936         checkIsResolved()
  937         let fty = 
  938             match d.TryRecdField with 
  939             | Choice1Of2 r -> r.FormalType
  940             | Choice2Of2 f -> f.FieldType(cenv.amap, range0)
  941         FSharpType(cenv, fty)
  942 
  943     member __.IsStatic = 
  944         if isUnresolved() then false else 
  945         match d.TryRecdField with 
  946         | Choice1Of2 r -> r.IsStatic
  947         | Choice2Of2 f -> f.IsStatic
  948 
  949     member __.Name = 
  950         checkIsResolved()
  951         match d.TryRecdField with 
  952         | Choice1Of2 r -> r.Name
  953         | Choice2Of2 f -> f.FieldName
  954 
  955     member __.IsCompilerGenerated = 
  956         if isUnresolved() then false else 
  957         match d.TryRecdField with 
  958         | Choice1Of2 r -> r.IsCompilerGenerated
  959         | Choice2Of2 _ -> false
  960 
  961     member __.IsNameGenerated =
  962         if isUnresolved() then false else
  963         match d.TryRecdField with
  964         | Choice1Of2 r -> r.rfield_name_generated
  965         | _ -> false
  966 
  967     member __.DeclarationLocation = 
  968         checkIsResolved()
  969         match d.TryRecdField with 
  970         | Choice1Of2 r -> r.Range
  971         | Choice2Of2 _ -> range0
  972 
  973     member __.FieldAttributes = 
  974         if isUnresolved() then makeReadOnlyCollection [] else 
  975         match d.TryRecdField with 
  976         | Choice1Of2 r -> r.FieldAttribs |> List.map (fun a -> FSharpAttribute(cenv, AttribInfo.FSAttribInfo(cenv.g, a))) 
  977         | Choice2Of2 _ -> [] 
  978         |> makeReadOnlyCollection
  979 
  980     member __.PropertyAttributes = 
  981         if isUnresolved() then makeReadOnlyCollection [] else 
  982         match d.TryRecdField with 
  983         | Choice1Of2 r -> r.PropertyAttribs |> List.map (fun a -> FSharpAttribute(cenv, AttribInfo.FSAttribInfo(cenv.g, a))) 
  984         | Choice2Of2 _ -> [] 
  985         |> makeReadOnlyCollection
  986 
  987     member __.Accessibility: FSharpAccessibility =  
  988         if isUnresolved() then FSharpAccessibility(taccessPublic) else 
  989         let access = 
  990             match d.TryRecdField with 
  991             | Choice1Of2 r -> r.Accessibility
  992             | Choice2Of2 _ -> taccessPublic
  993         FSharpAccessibility(access) 
  994 
  995     member private x.V = d
  996 
  997     override x.Equals(other: obj) =
  998         box x === other ||
  999         match other with
 1000         |   :? FSharpField as uc -> 
 1001             match d, uc.V with 
 1002             | RecdOrClass r1, RecdOrClass r2 -> recdFieldRefOrder.Compare(r1, r2) = 0
 1003             | Union (u1, n1), Union (u2, n2) -> cenv.g.unionCaseRefEq u1 u2 && n1 = n2
 1004             | _ -> false
 1005         |   _ -> false
 1006 
 1007     override x.GetHashCode() = hash x.Name
 1008 
 1009     override x.ToString() = "field " + x.Name
 1010 
 1011 and [<System.Obsolete("Renamed to FSharpField")>] FSharpRecordField = FSharpField
 1012 
 1013 and [<Class>] FSharpAccessibilityRights(thisCcu: CcuThunk, ad:AccessorDomain) =
 1014     member internal __.ThisCcu = thisCcu
 1015 
 1016     member internal __.Contents = ad
 1017 
 1018 and FSharpActivePatternCase(cenv, apinfo: PrettyNaming.ActivePatternInfo, ty, n, valOpt: ValRef option, item) = 
 1019 
 1020     inherit FSharpSymbol (cenv, 
 1021                           (fun () -> item), 
 1022                           (fun _ _ _ -> true))
 1023 
 1024     member __.Name = apinfo.ActiveTags.[n]
 1025 
 1026     member __.Index = n
 1027 
 1028     member __.DeclarationLocation = snd apinfo.ActiveTagsWithRanges.[n]
 1029 
 1030     member __.Group = FSharpActivePatternGroup(cenv, apinfo, ty, valOpt)
 1031 
 1032     member __.XmlDoc = 
 1033         defaultArg (valOpt |> Option.map (fun vref -> vref.XmlDoc)) XmlDoc.Empty
 1034         |> makeXmlDoc
 1035 
 1036     member __.XmlDocSig = 
 1037         let xmlsig = 
 1038             match valOpt with
 1039             | Some valref -> SymbolHelpers.GetXmlDocSigOfValRef cenv.g valref
 1040             | None -> None
 1041         match xmlsig with
 1042         | Some (_, docsig) -> docsig
 1043         | _ -> ""
 1044 
 1045 and FSharpActivePatternGroup(cenv, apinfo:PrettyNaming.ActivePatternInfo, ty, valOpt) =
 1046 
 1047     member __.Name = valOpt |> Option.map (fun vref -> vref.LogicalName)
 1048 
 1049     member __.Names = makeReadOnlyCollection apinfo.Names
 1050 
 1051     member __.IsTotal = apinfo.IsTotal
 1052 
 1053     member __.OverallType = FSharpType(cenv, ty)
 1054 
 1055     member __.DeclaringEntity = 
 1056         valOpt 
 1057         |> Option.bind (fun vref -> 
 1058             match vref.DeclaringEntity with 
 1059             | ParentNone -> None
 1060             | Parent p -> Some (FSharpEntity(cenv, p)))
 1061 
 1062 and FSharpGenericParameter(cenv, v:Typar) = 
 1063 
 1064     inherit FSharpSymbol (cenv, 
 1065                           (fun () -> Item.TypeVar(v.Name, v)), 
 1066                           (fun _ _ _ad -> true))
 1067 
 1068     member __.Name = v.DisplayName
 1069 
 1070     member __.DeclarationLocation = v.Range
 1071 
 1072     member __.IsCompilerGenerated = v.IsCompilerGenerated
 1073        
 1074     member __.IsMeasure = (v.Kind = TyparKind.Measure)
 1075     member __.XmlDoc = v.XmlDoc |> makeXmlDoc
 1076 
 1077     member __.IsSolveAtCompileTime = (v.StaticReq = TyparStaticReq.HeadTypeStaticReq)
 1078 
 1079     member __.Attributes = 
 1080          // INCOMPLETENESS: If the type parameter comes from .NET then the .NET metadata for the type parameter
 1081          // has been lost (it is not accessible via Typar).  So we can't easily report the attributes in this 
 1082          // case.
 1083          v.Attribs |> List.map (fun a -> FSharpAttribute(cenv, AttribInfo.FSAttribInfo(cenv.g, a))) |> makeReadOnlyCollection
 1084     member __.Constraints = v.Constraints |> List.map (fun a -> FSharpGenericParameterConstraint(cenv, a)) |> makeReadOnlyCollection
 1085     
 1086     member internal x.V = v
 1087 
 1088     override x.Equals(other: obj) =
 1089         box x === other ||
 1090         match other with
 1091         |   :? FSharpGenericParameter as p -> typarRefEq v p.V
 1092         |   _ -> false
 1093 
 1094     override x.GetHashCode() = (hash v.Stamp)
 1095 
 1096     override x.ToString() = "generic parameter " + x.Name
 1097 
 1098 and FSharpDelegateSignature(cenv, info: SlotSig) = 
 1099 
 1100     member __.DelegateArguments = 
 1101         info.FormalParams.Head
 1102         |> List.map (fun (TSlotParam(nm, ty, _, _, _, _)) -> nm, FSharpType(cenv, ty))
 1103         |> makeReadOnlyCollection
 1104 
 1105     member __.DelegateReturnType = 
 1106         match info.FormalReturnType with
 1107         | None -> FSharpType(cenv, cenv.g.unit_ty)
 1108         | Some ty -> FSharpType(cenv, ty)
 1109     override x.ToString() = "<delegate signature>"
 1110 
 1111 and FSharpAbstractParameter(cenv, info: SlotParam) =
 1112 
 1113     member __.Name =    
 1114         let (TSlotParam(name, _, _, _, _, _)) = info
 1115         name
 1116 
 1117     member __.Type = FSharpType(cenv, info.Type)
 1118 
 1119     member __.IsInArg =
 1120         let (TSlotParam(_, _, isIn, _, _, _)) = info
 1121         isIn
 1122 
 1123     member __.IsOutArg =
 1124         let (TSlotParam(_, _, _, isOut, _, _)) = info
 1125         isOut
 1126 
 1127     member __.IsOptionalArg =
 1128         let (TSlotParam(_, _, _, _, isOptional, _)) = info
 1129         isOptional
 1130 
 1131     member __.Attributes =
 1132         let (TSlotParam(_, _, _, _, _, attribs)) = info
 1133         attribs |> List.map (fun a -> FSharpAttribute(cenv, AttribInfo.FSAttribInfo(cenv.g, a)))
 1134         |> makeReadOnlyCollection
 1135 
 1136 and FSharpAbstractSignature(cenv, info: SlotSig) =
 1137 
 1138     member __.AbstractArguments = 
 1139         info.FormalParams
 1140         |> List.map (List.map (fun p -> FSharpAbstractParameter(cenv, p)) >> makeReadOnlyCollection)
 1141         |> makeReadOnlyCollection
 1142 
 1143     member __.AbstractReturnType = 
 1144         match info.FormalReturnType with
 1145         | None -> FSharpType(cenv, cenv.g.unit_ty)
 1146         | Some ty -> FSharpType(cenv, ty)
 1147 
 1148     member __.DeclaringTypeGenericParameters =
 1149         info.ClassTypars 
 1150         |> List.map (fun t -> FSharpGenericParameter(cenv, t))
 1151         |> makeReadOnlyCollection
 1152         
 1153     member __.MethodGenericParameters =
 1154         info.MethodTypars 
 1155         |> List.map (fun t -> FSharpGenericParameter(cenv, t))
 1156         |> makeReadOnlyCollection
 1157 
 1158     member __.Name = info.Name 
 1159     
 1160     member __.DeclaringType = FSharpType(cenv, info.ImplementedType)
 1161 
 1162 and FSharpGenericParameterMemberConstraint(cenv, info: TraitConstraintInfo) = 
 1163     let (TTrait(tys, nm, flags, atys, rty, _)) = info 
 1164     member __.MemberSources = 
 1165         tys   |> List.map (fun ty -> FSharpType(cenv, ty)) |> makeReadOnlyCollection
 1166 
 1167     member __.MemberName = nm
 1168 
 1169     member __.MemberIsStatic = not flags.IsInstance
 1170 
 1171     member __.MemberArgumentTypes = atys   |> List.map (fun ty -> FSharpType(cenv, ty)) |> makeReadOnlyCollection
 1172 
 1173     member x.MemberReturnType =
 1174         match rty with 
 1175         | None -> FSharpType(cenv, cenv.g.unit_ty) 
 1176         | Some ty -> FSharpType(cenv, ty) 
 1177     override x.ToString() = "<member constraint info>"
 1178 
 1179 
 1180 and FSharpGenericParameterDelegateConstraint(cenv, tupledArgTy: TType, rty: TType) = 
 1181     member __.DelegateTupledArgumentType = FSharpType(cenv, tupledArgTy)
 1182     member __.DelegateReturnType =  FSharpType(cenv, rty)
 1183     override x.ToString() = "<delegate constraint info>"
 1184 
 1185 and FSharpGenericParameterDefaultsToConstraint(cenv, pri:int, ty:TType) = 
 1186     member __.DefaultsToPriority = pri 
 1187     member __.DefaultsToTarget = FSharpType(cenv, ty) 
 1188     override x.ToString() = "<defaults-to constraint info>"
 1189 
 1190 and FSharpGenericParameterConstraint(cenv, cx: TyparConstraint) = 
 1191 
 1192     member __.IsCoercesToConstraint = 
 1193         match cx with 
 1194         | TyparConstraint.CoercesTo _ -> true 
 1195         | _ -> false
 1196 
 1197     member __.CoercesToTarget = 
 1198         match cx with 
 1199         | TyparConstraint.CoercesTo(ty, _) -> FSharpType(cenv, ty) 
 1200         | _ -> invalidOp "not a coerces-to constraint"
 1201 
 1202     member __.IsDefaultsToConstraint = 
 1203         match cx with 
 1204         | TyparConstraint.DefaultsTo _ -> true 
 1205         | _ -> false
 1206 
 1207     member __.DefaultsToConstraintData = 
 1208         match cx with 
 1209         | TyparConstraint.DefaultsTo(pri, ty, _) ->  FSharpGenericParameterDefaultsToConstraint(cenv, pri, ty) 
 1210         | _ -> invalidOp "not a 'defaults-to' constraint"
 1211 
 1212     member __.IsSupportsNullConstraint  = match cx with TyparConstraint.SupportsNull _ -> true | _ -> false
 1213 
 1214     member __.IsMemberConstraint = 
 1215         match cx with 
 1216         | TyparConstraint.MayResolveMember _ -> true 
 1217         | _ -> false
 1218 
 1219     member __.MemberConstraintData =  
 1220         match cx with 
 1221         | TyparConstraint.MayResolveMember(info, _) ->  FSharpGenericParameterMemberConstraint(cenv, info) 
 1222         | _ -> invalidOp "not a member constraint"
 1223 
 1224     member __.IsNonNullableValueTypeConstraint = 
 1225         match cx with 
 1226         | TyparConstraint.IsNonNullableStruct _ -> true 
 1227         | _ -> false
 1228     
 1229     member __.IsReferenceTypeConstraint  = 
 1230         match cx with 
 1231         | TyparConstraint.IsReferenceType _ -> true 
 1232         | _ -> false
 1233 
 1234     member __.IsSimpleChoiceConstraint = 
 1235         match cx with 
 1236         | TyparConstraint.SimpleChoice _ -> true 
 1237         | _ -> false
 1238 
 1239     member __.SimpleChoices = 
 1240         match cx with 
 1241         | TyparConstraint.SimpleChoice (tys, _) -> 
 1242             tys   |> List.map (fun ty -> FSharpType(cenv, ty)) |> makeReadOnlyCollection
 1243         | _ -> invalidOp "incorrect constraint kind"
 1244 
 1245     member __.IsRequiresDefaultConstructorConstraint  = 
 1246         match cx with 
 1247         | TyparConstraint.RequiresDefaultConstructor _ -> true 
 1248         | _ -> false
 1249 
 1250     member __.IsEnumConstraint = 
 1251         match cx with 
 1252         | TyparConstraint.IsEnum _ -> true 
 1253         | _ -> false
 1254 
 1255     member __.EnumConstraintTarget = 
 1256         match cx with 
 1257         | TyparConstraint.IsEnum(ty, _) -> FSharpType(cenv, ty)
 1258         | _ -> invalidOp "incorrect constraint kind"
 1259     
 1260     member __.IsComparisonConstraint = 
 1261         match cx with 
 1262         | TyparConstraint.SupportsComparison _ -> true 
 1263         | _ -> false
 1264 
 1265     member __.IsEqualityConstraint = 
 1266         match cx with 
 1267         | TyparConstraint.SupportsEquality _ -> true 
 1268         | _ -> false
 1269 
 1270     member __.IsUnmanagedConstraint = 
 1271         match cx with 
 1272         | TyparConstraint.IsUnmanaged _ -> true 
 1273         | _ -> false
 1274 
 1275     member __.IsDelegateConstraint = 
 1276         match cx with 
 1277         | TyparConstraint.IsDelegate _ -> true 
 1278         | _ -> false
 1279 
 1280     member __.DelegateConstraintData =  
 1281         match cx with 
 1282         | TyparConstraint.IsDelegate(ty1, ty2, _) ->  FSharpGenericParameterDelegateConstraint(cenv, ty1, ty2) 
 1283         | _ -> invalidOp "not a delegate constraint"
 1284 
 1285     override x.ToString() = "<type constraint>"
 1286 
 1287 and FSharpInlineAnnotation = 
 1288    | PseudoValue
 1289    | AlwaysInline 
 1290    | OptionalInline 
 1291    | NeverInline 
 1292    | AggressiveInline 
 1293 
 1294 and FSharpMemberOrValData = 
 1295     | E of EventInfo
 1296     | P of PropInfo
 1297     | M of MethInfo
 1298     | C of MethInfo
 1299     | V of ValRef
 1300 
 1301 and FSharpMemberOrVal = FSharpMemberOrFunctionOrValue
 1302 
 1303 and FSharpMemberFunctionOrValue =  FSharpMemberOrFunctionOrValue
 1304 
 1305 and FSharpMemberOrFunctionOrValue(cenv, d:FSharpMemberOrValData, item) = 
 1306 
 1307     inherit FSharpSymbol(cenv, 
 1308                          (fun () -> item), 
 1309                          (fun this thisCcu2 ad -> 
 1310                               let this = this :?> FSharpMemberOrFunctionOrValue 
 1311                               checkForCrossProjectAccessibility (thisCcu2, ad) (cenv.thisCcu, this.Accessibility.Contents)) 
 1312                               //&& 
 1313                               //match d with 
 1314                               //| E e -> 
 1315                               //    match e with 
 1316                               //    | EventInfo.ILEvent (_, e) -> AccessibilityLogic.IsILEventInfoAccessible g cenv.amap range0 ad e
 1317                               //    | EventInfo.FSEvent (_, _, vref, _) ->  AccessibilityLogic.IsValAccessible ad vref
 1318                               //    | _ -> true
 1319                               //| M m -> AccessibilityLogic.IsMethInfoAccessible cenv.amap range0 ad m
 1320                               //| P p -> AccessibilityLogic.IsPropInfoAccessible g cenv.amap range0 ad p
 1321                               //| V v -> AccessibilityLogic.IsValAccessible ad v
 1322                           )
 1323 
 1324     let fsharpInfo() = 
 1325         match d with 
 1326         | M m | C m -> m.ArbitraryValRef 
 1327         | P p -> p.ArbitraryValRef 
 1328         | E e -> e.ArbitraryValRef 
 1329         | V v -> Some v
 1330     
 1331     let isUnresolved() = 
 1332         match fsharpInfo() with 
 1333         | None -> false
 1334         | Some v -> v.TryDeref.IsNone
 1335 
 1336     let checkIsResolved() = 
 1337         if isUnresolved() then 
 1338             let v = (fsharpInfo()).Value
 1339             let nm = (match v with VRefNonLocal n -> n.ItemKey.PartialKey.LogicalName | _ -> "<local>")
 1340             invalidOp (sprintf "The value or member '%s' does not exist or is in an unresolved assembly." nm)
 1341 
 1342     let mkMethSym minfo = FSharpMemberOrFunctionOrValue(cenv, M minfo, Item.MethodGroup (minfo.DisplayName, [minfo], None))
 1343     let mkEventSym einfo = FSharpMemberOrFunctionOrValue(cenv, E einfo, Item.Event einfo)
 1344 
 1345     new (cenv, vref) = FSharpMemberFunctionOrValue(cenv, V vref, Item.Value vref)
 1346     new (cenv, minfo) =  FSharpMemberFunctionOrValue(cenv, M minfo, Item.MethodGroup(minfo.LogicalName, [minfo], None))
 1347 
 1348     member __.IsUnresolved = 
 1349         isUnresolved()
 1350 
 1351     member __.DeclarationLocationOpt = 
 1352         checkIsResolved()
 1353         match fsharpInfo() with 
 1354         | Some v -> Some v.Range
 1355         | None -> base.DeclarationLocation 
 1356 
 1357     member x.Overloads matchParameterNumber =
 1358         checkIsResolved()
 1359         match d with
 1360         | M m ->
 1361             match item with
 1362             | Item.MethodGroup (_name, methodInfos, _) ->
 1363                 let methods =
 1364                     if matchParameterNumber then
 1365                         methodInfos
 1366                         |> List.filter (fun methodInfo -> not (methodInfo.NumArgs = m.NumArgs) )
 1367                     else methodInfos
 1368                 methods
 1369                 |> List.map (fun mi -> FSharpMemberOrFunctionOrValue(cenv, M mi, item))
 1370                 |> makeReadOnlyCollection
 1371                 |> Some
 1372             | _ -> None
 1373         | _ -> None
 1374 
 1375     member x.DeclarationLocation = 
 1376         checkIsResolved()
 1377         match x.DeclarationLocationOpt with 
 1378         | Some v -> v
 1379         | None -> failwith "DeclarationLocation property not available"
 1380 
 1381     member __.DeclaringEntity = 
 1382         checkIsResolved()
 1383         match d with 
 1384         | E e -> FSharpEntity(cenv, e.DeclaringTyconRef) |> Some
 1385         | P p -> FSharpEntity(cenv, p.DeclaringTyconRef) |> Some
 1386         | M m | C m -> FSharpEntity(cenv, m.DeclaringTyconRef) |> Some
 1387         | V v -> 
 1388         match v.DeclaringEntity with 
 1389         | ParentNone -> None
 1390         | Parent p -> FSharpEntity(cenv, p) |> Some
 1391 
 1392     member __.ApparentEnclosingEntity = 
 1393         checkIsResolved()
 1394         match d with 
 1395         | E e -> FSharpEntity(cenv, e.ApparentEnclosingTyconRef)
 1396         | P p -> FSharpEntity(cenv, p.ApparentEnclosingTyconRef)
 1397         | M m | C m -> FSharpEntity(cenv, m.ApparentEnclosingTyconRef)
 1398         | V v -> 
 1399         match v.ApparentEnclosingEntity with 
 1400         | ParentNone -> invalidOp "the value or member doesn't have a logical parent" 
 1401         | Parent p -> FSharpEntity(cenv, p)
 1402 
 1403     member x.GenericParameters = 
 1404         checkIsResolved()
 1405         let tps = 
 1406             match d with 
 1407             | E _ -> []
 1408             | P _ -> []
 1409             | M m | C m -> m.FormalMethodTypars
 1410             | V v -> v.Typars 
 1411         tps |> List.map (fun tp -> FSharpGenericParameter(cenv, tp)) |> makeReadOnlyCollection
 1412 
 1413     member x.FullType = 
 1414         checkIsResolved()
 1415         let ty = 
 1416             match d with 
 1417             | E e -> e.GetDelegateType(cenv.amap, range0)
 1418             | P p -> p.GetPropertyType(cenv.amap, range0)
 1419             | M m | C m -> 
 1420                 let rty = m.GetFSharpReturnTy(cenv.amap, range0, m.FormalMethodInst)
 1421                 let argtysl = m.GetParamTypes(cenv.amap, range0, m.FormalMethodInst) 
 1422                 mkIteratedFunTy (List.map (mkRefTupledTy cenv.g) argtysl) rty
 1423             | V v -> v.TauType
 1424         FSharpType(cenv, ty)
 1425 
 1426     member __.HasGetterMethod =
 1427         if isUnresolved() then false
 1428         else
 1429             match d with 
 1430             | P p -> p.HasGetter
 1431             | E _
 1432             | M _
 1433             | C _
 1434             | V _ -> false
 1435 
 1436     member __.GetterMethod =
 1437         checkIsResolved()
 1438         match d with 
 1439         | P p -> mkMethSym p.GetterMethod
 1440         | E _ | M _ | C _ | V _ -> invalidOp "the value or member doesn't have an associated getter method" 
 1441 
 1442     member __.HasSetterMethod =
 1443         if isUnresolved() then false
 1444         else
 1445             match d with 
 1446             | P p -> p.HasSetter
 1447             | E _
 1448             | M _
 1449             | C _
 1450             | V _ -> false
 1451 
 1452     member __.SetterMethod =
 1453         checkIsResolved()
 1454         match d with 
 1455         | P p -> mkMethSym p.SetterMethod
 1456         | E _ | M _ | C _ | V _ -> invalidOp "the value or member doesn't have an associated setter method" 
 1457 
 1458     member __.EventAddMethod =
 1459         checkIsResolved()
 1460         match d with 
 1461         | E e -> mkMethSym e.AddMethod
 1462         | P _ | M _ | C _ | V _ -> invalidOp "the value or member doesn't have an associated add method" 
 1463 
 1464     member __.EventRemoveMethod =
 1465         checkIsResolved()
 1466         match d with 
 1467         | E e -> mkMethSym e.RemoveMethod
 1468         | P _ | M _ | C _ | V _ -> invalidOp "the value or member doesn't have an associated remove method" 
 1469 
 1470     member __.EventDelegateType =
 1471         checkIsResolved()
 1472         match d with 
 1473         | E e -> FSharpType(cenv, e.GetDelegateType(cenv.amap, range0))
 1474         | P _ | M _ | C _ | V _ -> invalidOp "the value or member doesn't have an associated event delegate type" 
 1475 
 1476     member __.EventIsStandard =
 1477         checkIsResolved()
 1478         match d with 
 1479         | E e -> 
 1480             let dty = e.GetDelegateType(cenv.amap, range0)
 1481             TryDestStandardDelegateType cenv.infoReader range0 AccessibleFromSomewhere dty |> Option.isSome
 1482         | P _ | M _ | C _ | V _ -> invalidOp "the value or member is not an event" 
 1483 
 1484     member __.IsCompilerGenerated = 
 1485         if isUnresolved() then false else 
 1486         match fsharpInfo() with 
 1487         | None -> false
 1488         | Some v -> 
 1489         v.IsCompilerGenerated
 1490 
 1491     member __.InlineAnnotation = 
 1492         if isUnresolved() then FSharpInlineAnnotation.OptionalInline else 
 1493         match fsharpInfo() with 
 1494         | None -> FSharpInlineAnnotation.OptionalInline
 1495         | Some v -> 
 1496         match v.InlineInfo with 
 1497         | ValInline.PseudoVal -> FSharpInlineAnnotation.PseudoValue
 1498         | ValInline.Always -> FSharpInlineAnnotation.AlwaysInline
 1499         | ValInline.Optional -> FSharpInlineAnnotation.OptionalInline
 1500         | ValInline.Never -> FSharpInlineAnnotation.NeverInline
 1501 
 1502     member __.IsMutable = 
 1503         if isUnresolved() then false else 
 1504         match d with 
 1505         | M _ | C _ | P _ |  E _ -> false
 1506         | V v -> v.IsMutable
 1507 
 1508     member __.IsModuleValueOrMember = 
 1509         if isUnresolved() then false else 
 1510         match d with 
 1511         | M _ | C _ | P _ | E _ -> true
 1512         | V v -> v.IsMember || v.IsModuleBinding
 1513 
 1514     member __.IsMember = 
 1515         if isUnresolved() then false else 
 1516         match d with 
 1517         | M _ | C _ | P _ | E _ -> true
 1518         | V v -> v.IsMember 
 1519     
 1520     member __.IsDispatchSlot = 
 1521         if isUnresolved() then false else 
 1522         match d with 
 1523         | E e -> e.AddMethod.IsDispatchSlot
 1524         | P p -> p.IsDispatchSlot
 1525         | M m | C m -> m.IsDispatchSlot
 1526         | V v -> v.IsDispatchSlot
 1527 
 1528     member x.IsProperty = 
 1529         match d with 
 1530         | P _ -> true
 1531         | _ -> false
 1532 
 1533     member x.IsEvent = 
 1534         match d with 
 1535         | E _ -> true
 1536         | _ -> false
 1537 
 1538     member x.EventForFSharpProperty = 
 1539         match d with 
 1540         | P p when p.IsFSharpEventProperty  ->
 1541             let minfos1 = GetImmediateIntrinsicMethInfosOfType (Some("add_"+p.PropertyName), AccessibleFromSomeFSharpCode) cenv.g cenv.amap range0 p.ApparentEnclosingType 
 1542             let minfos2 = GetImmediateIntrinsicMethInfosOfType (Some("remove_"+p.PropertyName), AccessibleFromSomeFSharpCode) cenv.g cenv.amap range0 p.ApparentEnclosingType
 1543             match  minfos1, minfos2 with 
 1544             | [addMeth], [removeMeth] -> 
 1545                 match addMeth.ArbitraryValRef, removeMeth.ArbitraryValRef with 
 1546                 | Some addVal, Some removeVal -> Some (mkEventSym (FSEvent(cenv.g, p, addVal, removeVal)))
 1547                 | _ -> None
 1548             | _ -> None
 1549         | _ -> None
 1550 
 1551     member __.IsEventAddMethod = 
 1552         if isUnresolved() then false else 
 1553         match d with 
 1554         | M m when m.LogicalName.StartsWithOrdinal("add_") -> 
 1555             let eventName = m.LogicalName.[4..]
 1556             let entityTy = generalizedTyconRef m.DeclaringTyconRef
 1557             not (isNil (cenv.infoReader.GetImmediateIntrinsicEventsOfType (Some eventName, AccessibleFromSomeFSharpCode, range0, entityTy))) ||
 1558             let declaringTy = generalizedTyconRef m.DeclaringTyconRef
 1559             match GetImmediateIntrinsicPropInfosOfType (Some eventName, AccessibleFromSomeFSharpCode) cenv.g cenv.amap range0 declaringTy with 
 1560             | pinfo :: _  -> pinfo.IsFSharpEventProperty
 1561             | _ -> false
 1562 
 1563         | _ -> false
 1564 
 1565     member __.IsEventRemoveMethod = 
 1566         if isUnresolved() then false else 
 1567         match d with 
 1568         | M m when m.LogicalName.StartsWithOrdinal("remove_") -> 
 1569             let eventName = m.LogicalName.[7..]
 1570             let entityTy = generalizedTyconRef m.DeclaringTyconRef
 1571             not (isNil (cenv.infoReader.GetImmediateIntrinsicEventsOfType (Some eventName, AccessibleFromSomeFSharpCode, range0, entityTy))) ||
 1572             let declaringTy = generalizedTyconRef m.DeclaringTyconRef
 1573             match GetImmediateIntrinsicPropInfosOfType (Some eventName, AccessibleFromSomeFSharpCode) cenv.g cenv.amap range0 declaringTy with 
 1574             | pinfo :: _ -> pinfo.IsFSharpEventProperty
 1575             | _ -> false
 1576         | _ -> false
 1577 
 1578     member x.IsGetterMethod =  
 1579         if isUnresolved() then false else 
 1580         x.IsPropertyGetterMethod ||
 1581         match fsharpInfo() with 
 1582         | None -> false
 1583         | Some v -> v.IsPropertyGetterMethod
 1584 
 1585     member x.IsSetterMethod =  
 1586         if isUnresolved() then false else 
 1587         x.IsPropertySetterMethod ||
 1588         match fsharpInfo() with 
 1589         | None -> false
 1590         | Some v -> v.IsPropertySetterMethod
 1591 
 1592     member __.IsPropertyGetterMethod = 
 1593         if isUnresolved() then false else 
 1594         match d with 
 1595         | M m when m.LogicalName.StartsWithOrdinal("get_") -> 
 1596             let propName = PrettyNaming.ChopPropertyName(m.LogicalName) 
 1597             let declaringTy = generalizedTyconRef m.DeclaringTyconRef
 1598             not (isNil (GetImmediateIntrinsicPropInfosOfType (Some propName, AccessibleFromSomeFSharpCode) cenv.g cenv.amap range0 declaringTy))
 1599         | V v -> v.IsPropertyGetterMethod
 1600         | _ -> false
 1601 
 1602     member __.IsPropertySetterMethod = 
 1603         if isUnresolved() then false else 
 1604         match d with 
 1605         // Look for a matching property with the right name. 
 1606         | M m when m.LogicalName.StartsWithOrdinal("set_") -> 
 1607             let propName = PrettyNaming.ChopPropertyName(m.LogicalName) 
 1608             let declaringTy = generalizedTyconRef m.DeclaringTyconRef
 1609             not (isNil (GetImmediateIntrinsicPropInfosOfType (Some propName, AccessibleFromSomeFSharpCode) cenv.g cenv.amap range0 declaringTy))
 1610         | V v -> v.IsPropertySetterMethod
 1611         | _ -> false
 1612 
 1613     member __.IsInstanceMember = 
 1614         if isUnresolved() then false else 
 1615         match d with 
 1616         | E e -> not e.IsStatic
 1617         | P p -> not p.IsStatic
 1618         | M m | C m -> m.IsInstance
 1619         | V v -> v.IsInstanceMember
 1620 
 1621     member x.IsInstanceMemberInCompiledCode = 
 1622         if isUnresolved() then false else 
 1623         x.IsInstanceMember &&
 1624         match d with 
 1625         | E e -> match e.ArbitraryValRef with Some vref -> ValRefIsCompiledAsInstanceMember cenv.g vref | None -> true
 1626         | P p -> match p.ArbitraryValRef with Some vref -> ValRefIsCompiledAsInstanceMember cenv.g vref | None -> true
 1627         | M m | C m -> match m.ArbitraryValRef with Some vref -> ValRefIsCompiledAsInstanceMember cenv.g vref | None -> true
 1628         | V vref -> ValRefIsCompiledAsInstanceMember cenv.g vref 
 1629 
 1630     member __.IsExtensionMember = 
 1631         if isUnresolved() then false else 
 1632         match d with 
 1633         | E e -> e.AddMethod.IsExtensionMember
 1634         | P p -> p.IsExtensionMember
 1635         | M m -> m.IsExtensionMember
 1636         | V v -> v.IsExtensionMember
 1637         | C _ -> false
 1638 
 1639     member x.IsOverrideOrExplicitMember = x.IsOverrideOrExplicitInterfaceImplementation
 1640 
 1641     member __.IsOverrideOrExplicitInterfaceImplementation =
 1642         if isUnresolved() then false else 
 1643         match d with 
 1644         | E e -> e.AddMethod.IsDefiniteFSharpOverride
 1645         | P p -> p.IsDefiniteFSharpOverride
 1646         | M m -> m.IsDefiniteFSharpOverride
 1647         | V v -> 
 1648             v.MemberInfo.IsSome && v.IsDefiniteFSharpOverrideMember
 1649         | C _ -> false
 1650 
 1651     member __.IsExplicitInterfaceImplementation =
 1652         if isUnresolved() then false else 
 1653         match d with 
 1654         | E e -> e.AddMethod.IsFSharpExplicitInterfaceImplementation
 1655         | P p -> p.IsFSharpExplicitInterfaceImplementation
 1656         | M m -> m.IsFSharpExplicitInterfaceImplementation
 1657         | V v -> v.IsFSharpExplicitInterfaceImplementation cenv.g
 1658         | C _ -> false
 1659 
 1660     member __.ImplementedAbstractSignatures =
 1661         checkIsResolved()
 1662         let sigs =
 1663             match d with
 1664             | E e -> e.AddMethod.ImplementedSlotSignatures
 1665             | P p -> p.ImplementedSlotSignatures
 1666             | M m | C m -> m.ImplementedSlotSignatures
 1667             | V v -> v.ImplementedSlotSignatures
 1668         sigs |> List.map (fun s -> FSharpAbstractSignature (cenv, s))
 1669         |> makeReadOnlyCollection
 1670 
 1671     member __.IsImplicitConstructor = 
 1672         if isUnresolved() then false else 
 1673         match fsharpInfo() with 
 1674         | None -> false
 1675         | Some v -> v.IsIncrClassConstructor
 1676     
 1677     member __.IsTypeFunction = 
 1678         if isUnresolved() then false else 
 1679         match fsharpInfo() with 
 1680         | None -> false
 1681         | Some v -> v.IsTypeFunction
 1682 
 1683     member __.IsActivePattern =  
 1684         if isUnresolved() then false else 
 1685         match fsharpInfo() with 
 1686         | Some v -> PrettyNaming.ActivePatternInfoOfValName v.CoreDisplayName v.Range |> Option.isSome
 1687         | None -> false
 1688 
 1689     member x.CompiledName = 
 1690         checkIsResolved()
 1691         match fsharpInfo() with 
 1692         | Some v -> v.CompiledName
 1693         | None -> x.LogicalName
 1694 
 1695     member __.LogicalName = 
 1696         checkIsResolved()
 1697         match d with 
 1698         | E e -> e.EventName
 1699         | P p -> p.PropertyName
 1700         | M m | C m -> m.LogicalName
 1701         | V v -> v.LogicalName
 1702 
 1703     member __.DisplayName = 
 1704         checkIsResolved()
 1705         match d with 
 1706         | E e -> e.EventName
 1707         | P p -> p.PropertyName
 1708         | M m | C m -> m.DisplayName
 1709         | V v -> v.DisplayName
 1710 
 1711     member __.XmlDocSig = 
 1712         checkIsResolved()
 1713  
 1714         match d with 
 1715         | E e ->
 1716             let range = defaultArg __.DeclarationLocationOpt range0
 1717             match SymbolHelpers.GetXmlDocSigOfEvent cenv.infoReader range e with
 1718             | Some (_, docsig) -> docsig
 1719             | _ -> ""
 1720         | P p ->
 1721             let range = defaultArg __.DeclarationLocationOpt range0
 1722             match SymbolHelpers.GetXmlDocSigOfProp cenv.infoReader range p with
 1723             | Some (_, docsig) -> docsig
 1724             | _ -> ""
 1725         | M m | C m -> 
 1726             let range = defaultArg __.DeclarationLocationOpt range0
 1727             match SymbolHelpers.GetXmlDocSigOfMethInfo cenv.infoReader range m with
 1728             | Some (_, docsig) -> docsig
 1729             | _ -> ""
 1730         | V v ->
 1731             match v.DeclaringEntity with 
 1732             | Parent entityRef -> 
 1733                 match SymbolHelpers.GetXmlDocSigOfScopedValRef cenv.g entityRef v with
 1734                 | Some (_, docsig) -> docsig
 1735                 | _ -> ""
 1736             | ParentNone -> "" 
 1737 
 1738     member __.XmlDoc = 
 1739         if isUnresolved() then XmlDoc.Empty  |> makeXmlDoc else
 1740         match d with 
 1741         | E e -> e.XmlDoc |> makeXmlDoc
 1742         | P p -> p.XmlDoc |> makeXmlDoc
 1743         | M m | C m -> m.XmlDoc |> makeXmlDoc
 1744         | V v -> v.XmlDoc |> makeXmlDoc
 1745 
 1746     member x.CurriedParameterGroups = 
 1747         checkIsResolved()
 1748         match d with 
 1749         | P p -> 
 1750             
 1751             [ [ for (ParamData(isParamArrayArg, isInArg, isOutArg, optArgInfo, _callerInfo, nmOpt, _reflArgInfo, pty)) in p.GetParamDatas(cenv.amap, range0) do 
 1752                 // INCOMPLETENESS: Attribs is empty here, so we can't look at attributes for
 1753                 // either .NET or F# parameters
 1754                 let argInfo: ArgReprInfo = { Name=nmOpt; Attribs= [] }
 1755                 yield FSharpParameter(cenv, pty, argInfo, x.DeclarationLocationOpt, isParamArrayArg, isInArg, isOutArg, optArgInfo.IsOptional) ] 
 1756                |> makeReadOnlyCollection  ]
 1757            |> makeReadOnlyCollection
 1758 
 1759         | E _ ->  []  |> makeReadOnlyCollection
 1760         | M m | C m -> 
 1761             [ for argtys in m.GetParamDatas(cenv.amap, range0, m.FormalMethodInst) do 
 1762                  yield
 1763                    [ for (ParamData(isParamArrayArg, isInArg, isOutArg, optArgInfo, _callerInfo, nmOpt, _reflArgInfo, pty)) in argtys do 
 1764                 // INCOMPLETENESS: Attribs is empty here, so we can't look at attributes for
 1765                 // either .NET or F# parameters
 1766                         let argInfo: ArgReprInfo = { Name=nmOpt; Attribs= [] }
 1767                         yield FSharpParameter(cenv, pty, argInfo, x.DeclarationLocationOpt, isParamArrayArg, isInArg, isOutArg, optArgInfo.IsOptional) ] 
 1768                    |> makeReadOnlyCollection ]
 1769              |> makeReadOnlyCollection
 1770 
 1771         | V v -> 
 1772         match v.ValReprInfo with 
 1773         | None ->
 1774             let _, tau = v.TypeScheme
 1775             if isFunTy cenv.g tau then
 1776                 let argtysl, _typ = stripFunTy cenv.g tau
 1777                 [ for ty in argtysl do
 1778                     let allArguments =
 1779                         if isRefTupleTy cenv.g ty
 1780                         then tryDestRefTupleTy cenv.g ty
 1781                         else [ty]
 1782                     yield
 1783                       allArguments
 1784                       |> List.map (fun arg -> FSharpParameter(cenv, arg, { Name=None; Attribs= [] }, x.DeclarationLocationOpt, false, false, false, false))
 1785                       |> makeReadOnlyCollection ]
 1786                 |> makeReadOnlyCollection
 1787             else makeReadOnlyCollection []
 1788         | Some (ValReprInfo(_typars, curriedArgInfos, _retInfo)) -> 
 1789             let tau = v.TauType
 1790             let argtysl, _ = GetTopTauTypeInFSharpForm cenv.g curriedArgInfos tau range0
 1791             let argtysl = if v.IsInstanceMember then argtysl.Tail else argtysl
 1792             [ for argtys in argtysl do 
 1793                  yield 
 1794                    [ for argty, argInfo in argtys do 
 1795                         let isParamArrayArg = HasFSharpAttribute cenv.g cenv.g.attrib_ParamArrayAttribute argInfo.Attribs
 1796                         let isInArg = HasFSharpAttribute cenv.g cenv.g.attrib_InAttribute argInfo.Attribs && isByrefTy cenv.g argty
 1797                         let isOutArg = HasFSharpAttribute cenv.g cenv.g.attrib_OutAttribute argInfo.Attribs && isByrefTy cenv.g argty
 1798                         let isOptionalArg = HasFSharpAttribute cenv.g cenv.g.attrib_OptionalArgumentAttribute argInfo.Attribs
 1799                         yield FSharpParameter(cenv, argty, argInfo, x.DeclarationLocationOpt, isParamArrayArg, isInArg, isOutArg, isOptionalArg) ] 
 1800                    |> makeReadOnlyCollection ]
 1801              |> makeReadOnlyCollection
 1802 
 1803     member x.ReturnParameter = 
 1804         checkIsResolved()
 1805         match d with 
 1806         | E e -> 
 1807                 // INCOMPLETENESS: Attribs is empty here, so we can't look at return attributes for .NET or F# methods
 1808             let retInfo: ArgReprInfo = { Name=None; Attribs= [] }
 1809             let rty = 
 1810                 try PropTypOfEventInfo cenv.infoReader range0 AccessibleFromSomewhere e
 1811                 with _ -> 
 1812                     // For non-standard events, just use the delegate type as the ReturnParameter type
 1813                     e.GetDelegateType(cenv.amap, range0)
 1814 
 1815             FSharpParameter(cenv, rty, retInfo, x.DeclarationLocationOpt, isParamArrayArg=false, isInArg=false, isOutArg=false, isOptionalArg=false) 
 1816 
 1817         | P p -> 
 1818                 // INCOMPLETENESS: Attribs is empty here, so we can't look at return attributes for .NET or F# methods
 1819             let retInfo: ArgReprInfo = { Name=None; Attribs= [] }
 1820             let rty = p.GetPropertyType(cenv.amap, range0)
 1821             FSharpParameter(cenv, rty, retInfo, x.DeclarationLocationOpt, isParamArrayArg=false, isInArg=false, isOutArg=false, isOptionalArg=false) 
 1822         | M m | C m -> 
 1823                 // INCOMPLETENESS: Attribs is empty here, so we can't look at return attributes for .NET or F# methods
 1824             let retInfo: ArgReprInfo = { Name=None; Attribs= [] }
 1825             let rty = m.GetFSharpReturnTy(cenv.amap, range0, m.FormalMethodInst)
 1826             FSharpParameter(cenv, rty, retInfo, x.DeclarationLocationOpt, isParamArrayArg=false, isInArg=false, isOutArg=false, isOptionalArg=false) 
 1827         | V v -> 
 1828         match v.ValReprInfo with 
 1829         | None ->
 1830             let _, tau = v.TypeScheme
 1831             let _argtysl, rty = stripFunTy cenv.g tau
 1832             let empty: ArgReprInfo  = { Name=None; Attribs= [] }
 1833             FSharpParameter(cenv, rty, empty, x.DeclarationLocationOpt, isParamArrayArg=false, isInArg=false, isOutArg=false, isOptionalArg=false)
 1834         | Some (ValReprInfo(_typars, argInfos, retInfo)) -> 
 1835             let tau = v.TauType
 1836             let _c, rty = GetTopTauTypeInFSharpForm cenv.g argInfos tau range0
 1837             FSharpParameter(cenv, rty, retInfo, x.DeclarationLocationOpt, isParamArrayArg=false, isInArg=false, isOutArg=false, isOptionalArg=false) 
 1838 
 1839 
 1840     member __.Attributes = 
 1841         if isUnresolved() then makeReadOnlyCollection [] else 
 1842         let m = range0
 1843         match d with 
 1844         | E einfo -> 
 1845             GetAttribInfosOfEvent cenv.amap m einfo |> List.map (fun a -> FSharpAttribute(cenv, a))
 1846         | P pinfo -> 
 1847             GetAttribInfosOfProp cenv.amap m pinfo |> List.map (fun a -> FSharpAttribute(cenv, a))
 1848         | M minfo | C minfo -> 
 1849             GetAttribInfosOfMethod cenv.amap m minfo |> List.map (fun a -> FSharpAttribute(cenv, a))
 1850         | V v -> 
 1851             v.Attribs |> List.map (fun a -> FSharpAttribute(cenv, AttribInfo.FSAttribInfo(cenv.g, a))) 
 1852      |> makeReadOnlyCollection
 1853      
 1854     /// Is this "base" in "base.M(...)"
 1855     member __.IsBaseValue =
 1856         if isUnresolved() then false else
 1857         match d with
 1858         | M _ | C _ | P _ | E _ -> false
 1859         | V v -> v.BaseOrThisInfo = BaseVal
 1860 
 1861     /// Is this the "x" in "type C() as x = ..."
 1862     member __.IsConstructorThisValue =
 1863         if isUnresolved() then false else
 1864         match d with
 1865         | M _ | C _| P _ | E _ -> false
 1866         | V v -> v.BaseOrThisInfo = CtorThisVal
 1867 
 1868     /// Is this the "x" in "member x.M = ..."
 1869     member __.IsMemberThisValue =
 1870         if isUnresolved() then false else
 1871         match d with
 1872         | M _ | C _ | P _ | E _ -> false
 1873         | V v -> v.BaseOrThisInfo = MemberThisVal
 1874 
 1875     /// Is this a [<Literal>] value, and if so what value? (may be null)
 1876     member __.LiteralValue =
 1877         if isUnresolved() then None else
 1878         match d with
 1879         | M _ | C _ | P _ | E _ -> None
 1880         | V v -> getLiteralValue v.LiteralValue
 1881 
 1882       /// How visible is this? 
 1883     member this.Accessibility: FSharpAccessibility  = 
 1884         if isUnresolved() then FSharpAccessibility(taccessPublic) else 
 1885         match fsharpInfo() with 
 1886         | Some v -> FSharpAccessibility(v.Accessibility)
 1887         | None ->  
 1888         
 1889         // Note, returning "public" is wrong for IL members that are private
 1890         match d with 
 1891         | E e ->  
 1892             // For IL events, we get an approximate accessiblity that at least reports "internal" as "internal" and "private" as "private"
 1893             let access = 
 1894                 match e with 
 1895                 | ILEvent ileinfo -> 
 1896                     let ilAccess = AccessibilityLogic.GetILAccessOfILEventInfo ileinfo
 1897                     getApproxFSharpAccessibilityOfMember this.DeclaringEntity.Value.Entity ilAccess
 1898                 | _ -> taccessPublic
 1899 
 1900             FSharpAccessibility(access)
 1901 
 1902         | P p ->  
 1903             // For IL  properties, we get an approximate accessiblity that at least reports "internal" as "internal" and "private" as "private"
 1904             let access = 
 1905                 match p with 
 1906                 | ILProp ilpinfo -> 
 1907                     let ilAccess = AccessibilityLogic.GetILAccessOfILPropInfo ilpinfo
 1908                     getApproxFSharpAccessibilityOfMember this.DeclaringEntity.Value.Entity  ilAccess
 1909                 | _ -> taccessPublic
 1910 
 1911             FSharpAccessibility(access)
 1912 
 1913         | M m | C m ->  
 1914 
 1915             // For IL  methods, we get an approximate accessiblity that at least reports "internal" as "internal" and "private" as "private"
 1916             let access = 
 1917                 match m with 
 1918                 | ILMeth (_, x, _) -> getApproxFSharpAccessibilityOfMember x.DeclaringTyconRef x.RawMetadata.Access 
 1919                 | _ -> taccessPublic
 1920 
 1921             FSharpAccessibility(access, isProtected=m.IsProtectedAccessiblity)
 1922 
 1923         | V v -> FSharpAccessibility(v.Accessibility)
 1924 
 1925     member x.IsConstructor =
 1926         match d with
 1927         | C _ -> true
 1928         | V v -> v.IsConstructor
 1929         | _ -> false
 1930 
 1931     member x.Data = d
 1932 
 1933     member x.IsValCompiledAsMethod =
 1934         match d with
 1935         | V valRef -> IlxGen.IsValCompiledAsMethod cenv.g valRef.Deref
 1936         | _ -> false
 1937 
 1938     member x.IsValue =
 1939         match d with
 1940         | V valRef -> not (SymbolHelpers.isFunction cenv.g valRef.Type)
 1941         | _ -> false
 1942 
 1943     override x.Equals(other: obj) =
 1944         box x === other ||
 1945         match other with
 1946         |   :? FSharpMemberOrFunctionOrValue as other ->
 1947             match d, other.Data with 
 1948             | E evt1, E evt2 -> EventInfo.EventInfosUseIdenticalDefintions evt1 evt2 
 1949             | P p1, P p2 ->  PropInfo.PropInfosUseIdenticalDefinitions p1 p2
 1950             | M m1, M m2 ->  MethInfo.MethInfosUseIdenticalDefinitions m1 m2
 1951             | V v1, V v2 -> valRefEq cenv.g v1 v2
 1952             | _ -> false
 1953         |   _ -> false
 1954 
 1955     override x.GetHashCode() = hash (box x.LogicalName)
 1956     override x.ToString() = 
 1957         try  
 1958             let prefix = (if x.IsEvent then "event " elif x.IsProperty then "property " elif x.IsMember then "member " else "val ") 
 1959             prefix + x.LogicalName 
 1960         with _  -> "??"
 1961 
 1962     member x.FormatLayout (denv:FSharpDisplayContext) =
 1963         match x.IsMember, d with
 1964         | true, V v ->
 1965             NicePrint.prettyLayoutOfValOrMemberNoInst { (denv.Contents cenv.g) with showMemberContainers=true } v.Deref
 1966         | _,_ ->
 1967             checkIsResolved()
 1968             let ty = 
 1969                 match d with 
 1970                 | E e -> e.GetDelegateType(cenv.amap, range0)
 1971                 | P p -> p.GetPropertyType(cenv.amap, range0)
 1972                 | M m | C m -> 
 1973                     let rty = m.GetFSharpReturnTy(cenv.amap, range0, m.FormalMethodInst)
 1974                     let argtysl = m.GetParamTypes(cenv.amap, range0, m.FormalMethodInst) 
 1975                     mkIteratedFunTy (List.map (mkRefTupledTy cenv.g) argtysl) rty
 1976                 | V v -> v.TauType
 1977             NicePrint.prettyLayoutOfTypeNoCx (denv.Contents cenv.g) ty
 1978 
 1979 
 1980 and FSharpType(cenv, ty:TType) =
 1981 
 1982     let isUnresolved() = 
 1983        ErrorLogger.protectAssemblyExploration true <| fun () -> 
 1984         match stripTyparEqns ty with 
 1985         | TType_app (tcref, _) -> FSharpEntity(cenv, tcref).IsUnresolved
 1986         | TType_measure (Measure.Con tcref) ->  FSharpEntity(cenv, tcref).IsUnresolved
 1987         | TType_measure (Measure.Prod _) ->  FSharpEntity(cenv, cenv.g.measureproduct_tcr).IsUnresolved 
 1988         | TType_measure Measure.One ->  FSharpEntity(cenv, cenv.g.measureone_tcr).IsUnresolved 
 1989         | TType_measure (Measure.Inv _) ->  FSharpEntity(cenv, cenv.g.measureinverse_tcr).IsUnresolved 
 1990         | _ -> false
 1991     
 1992     let isResolved() = not (isUnresolved())
 1993 
 1994     new (g, thisCcu, thisCcuTy, tcImports, ty) = FSharpType(SymbolEnv(g, thisCcu, Some thisCcuTy, tcImports), ty)
 1995 
 1996     member __.IsUnresolved = isUnresolved()
 1997 
 1998     member __.HasTypeDefinition = 
 1999        isResolved() &&
 2000        protect <| fun () -> 
 2001          match stripTyparEqns ty with 
 2002          | TType_app _ | TType_measure (Measure.Con _ | Measure.Prod _ | Measure.Inv _ | Measure.One _) -> true 
 2003          | _ -> false
 2004 
 2005     member __.IsTupleType = 
 2006        isResolved() &&
 2007        protect <| fun () -> 
 2008         match stripTyparEqns ty with 
 2009         | TType_tuple _ -> true 
 2010         | _ -> false
 2011 
 2012     member __.IsStructTupleType = 
 2013        isResolved() &&
 2014        protect <| fun () -> 
 2015         match stripTyparEqns ty with 
 2016         | TType_tuple (tupInfo, _) -> evalTupInfoIsStruct tupInfo
 2017         | _ -> false
 2018 
 2019     member x.IsNamedType = x.HasTypeDefinition
 2020     member x.NamedEntity = x.TypeDefinition
 2021 
 2022     member __.TypeDefinition = 
 2023        protect <| fun () -> 
 2024         match stripTyparEqns ty with 
 2025         | TType_app (tcref, _) -> FSharpEntity(cenv, tcref) 
 2026         | TType_measure (Measure.Con tcref) ->  FSharpEntity(cenv, tcref) 
 2027         | TType_measure (Measure.Prod _) ->  FSharpEntity(cenv, cenv.g.measureproduct_tcr) 
 2028         | TType_measure Measure.One ->  FSharpEntity(cenv, cenv.g.measureone_tcr) 
 2029         | TType_measure (Measure.Inv _) ->  FSharpEntity(cenv, cenv.g.measureinverse_tcr) 
 2030         | _ -> invalidOp "not a named type"
 2031 
 2032     member __.GenericArguments = 
 2033        protect <| fun () -> 
 2034         match stripTyparEqns ty with 
 2035         | TType_app (_, tyargs) 
 2036         | TType_tuple (_, tyargs) -> (tyargs |> List.map (fun ty -> FSharpType(cenv, ty)) |> makeReadOnlyCollection) 
 2037         | TType_fun(d, r) -> [| FSharpType(cenv, d); FSharpType(cenv, r) |] |> makeReadOnlyCollection
 2038         | TType_measure (Measure.Con _) ->  [| |] |> makeReadOnlyCollection
 2039         | TType_measure (Measure.Prod (t1, t2)) ->  [| FSharpType(cenv, TType_measure t1); FSharpType(cenv, TType_measure t2) |] |> makeReadOnlyCollection
 2040         | TType_measure Measure.One ->  [| |] |> makeReadOnlyCollection
 2041         | TType_measure (Measure.Inv t1) ->  [| FSharpType(cenv, TType_measure t1) |] |> makeReadOnlyCollection
 2042         | _ -> invalidOp "not a named type"
 2043 
 2044 (*
 2045     member __.ProvidedArguments = 
 2046         let typeName, argNamesAndValues = 
 2047             try 
 2048                 PrettyNaming.demangleProvidedTypeName typeLogicalName 
 2049             with PrettyNaming.InvalidMangledStaticArg piece -> 
 2050                 error(Error(FSComp.SR.etProvidedTypeReferenceInvalidText(piece), range0)) 
 2051 *)
 2052 
 2053     member ty.IsAbbreviation = 
 2054        isResolved() && ty.HasTypeDefinition && ty.TypeDefinition.IsFSharpAbbreviation
 2055 
 2056     member __.AbbreviatedType = 
 2057        protect <| fun () -> FSharpType(cenv, stripTyEqns cenv.g ty)
 2058 
 2059     member __.IsFunctionType = 
 2060        isResolved() &&
 2061        protect <| fun () -> 
 2062         match stripTyparEqns ty with 
 2063         | TType_fun _ -> true 
 2064         | _ -> false
 2065 
 2066     member __.IsGenericParameter = 
 2067        protect <| fun () -> 
 2068         match stripTyparEqns ty with 
 2069         | TType_var _ -> true 
 2070         | TType_measure (Measure.Var _) -> true 
 2071         | _ -> false
 2072 
 2073     member __.GenericParameter = 
 2074        protect <| fun () -> 
 2075         match stripTyparEqns ty with 
 2076         | TType_var tp 
 2077         | TType_measure (Measure.Var tp) -> 
 2078             FSharpGenericParameter (cenv, tp)
 2079         | _ -> invalidOp "not a generic parameter type"
 2080 
 2081     member x.AllInterfaces = 
 2082         if isUnresolved() then makeReadOnlyCollection [] else
 2083         [ for ty in AllInterfacesOfType  cenv.g cenv.amap range0 AllowMultiIntfInstantiations.Yes ty do 
 2084              yield FSharpType(cenv, ty) ]
 2085         |> makeReadOnlyCollection
 2086 
 2087     member x.BaseType = 
 2088         GetSuperTypeOfType cenv.g cenv.amap range0 ty
 2089         |> Option.map (fun ty -> FSharpType(cenv, ty)) 
 2090 
 2091     member x.Instantiate(instantiation:(FSharpGenericParameter * FSharpType) list) = 
 2092         let typI = instType (instantiation |> List.map (fun (tyv, ty) -> tyv.V, ty.V)) ty
 2093         FSharpType(cenv, typI)
 2094 
 2095     member private x.V = ty
 2096     member private x.cenv = cenv
 2097 
 2098     member private ty.AdjustType(t) = 
 2099         FSharpType(ty.cenv, t)
 2100 
 2101     // Note: This equivalence relation is modulo type abbreviations
 2102     override x.Equals(other: obj) =
 2103         box x === other ||
 2104         match other with
 2105         |   :? FSharpType as t -> typeEquiv cenv.g ty t.V
 2106         |   _ -> false
 2107 
 2108     // Note: This equivalence relation is modulo type abbreviations. The hash is less than perfect.
 2109     override x.GetHashCode() = 
 2110         let rec hashType ty = 
 2111             let ty = stripTyEqnsWrtErasure EraseNone cenv.g ty
 2112             match ty with
 2113             | TType_forall _ ->  10000
 2114             | TType_var tp  -> 10100 + int32 tp.Stamp
 2115             | TType_app (tc1, b1)  -> 10200 + int32 tc1.Stamp + List.sumBy hashType b1
 2116             | TType_ucase _   -> 10300  // shouldn't occur in symbols
 2117             | TType_tuple (_, l1) -> 10400 + List.sumBy hashType l1
 2118             | TType_fun (dty, rty) -> 10500 + hashType dty + hashType rty
 2119             | TType_measure _ -> 10600 
 2120         hashType ty
 2121 
 2122     member x.Format(denv: FSharpDisplayContext) = 
 2123        protect <| fun () -> 
 2124         NicePrint.prettyStringOfTyNoCx (denv.Contents cenv.g) ty 
 2125 
 2126     member x.FormatLayout(denv: FSharpDisplayContext) =
 2127        protect <| fun () -> 
 2128         NicePrint.prettyLayoutOfTypeNoCx (denv.Contents cenv.g) ty
 2129 
 2130     override x.ToString() = 
 2131        protect <| fun () -> 
 2132         "type " + NicePrint.prettyStringOfTyNoCx (DisplayEnv.Empty(cenv.g)) ty 
 2133 
 2134     static member Prettify(ty: FSharpType) = 
 2135         let prettyTy = PrettyTypes.PrettifyType ty.cenv.g ty.V  |> fst
 2136         ty.AdjustType prettyTy
 2137 
 2138     static member Prettify(tys: IList<FSharpType>) = 
 2139         let xs = tys |> List.ofSeq
 2140         match xs with 
 2141         | [] -> []
 2142         | h :: _ -> 
 2143             let cenv = h.cenv
 2144             let prettyTys = PrettyTypes.PrettifyTypes cenv.g [ for t in xs -> t.V ] |> fst
 2145             (xs, prettyTys) ||> List.map2 (fun p pty -> p.AdjustType(pty))
 2146         |> makeReadOnlyCollection
 2147 
 2148     static member Prettify(parameter: FSharpParameter) = 
 2149         let prettyTy = parameter.V |> PrettyTypes.PrettifyType parameter.cenv.g |> fst
 2150         parameter.AdjustType(prettyTy)
 2151 
 2152     static member Prettify(parameters: IList<FSharpParameter>) = 
 2153         let parameters = parameters |> List.ofSeq
 2154         match parameters with 
 2155         | [] -> []
 2156         | h :: _ -> 
 2157             let cenv = h.cenv
 2158             let prettyTys = parameters |> List.map (fun p -> p.V) |> PrettyTypes.PrettifyTypes cenv.g |> fst
 2159             (parameters, prettyTys) ||> List.map2 (fun p pty -> p.AdjustType(pty))
 2160         |> makeReadOnlyCollection
 2161 
 2162     static member Prettify(parameters: IList<IList<FSharpParameter>>) = 
 2163         let xs = parameters |> List.ofSeq |> List.map List.ofSeq
 2164         let hOpt = xs |> List.tryPick (function h :: _ -> Some h | _ -> None) 
 2165         match hOpt with 
 2166         | None -> xs
 2167         | Some h -> 
 2168             let cenv = h.cenv
 2169             let prettyTys = xs |> List.mapSquared (fun p -> p.V) |> PrettyTypes.PrettifyCurriedTypes cenv.g |> fst
 2170             (xs, prettyTys) ||> List.map2 (List.map2 (fun p pty -> p.AdjustType(pty)))
 2171         |> List.map makeReadOnlyCollection |> makeReadOnlyCollection
 2172 
 2173     static member Prettify(parameters: IList<IList<FSharpParameter>>, returnParameter: FSharpParameter) = 
 2174         let xs = parameters |> List.ofSeq |> List.map List.ofSeq
 2175         let cenv = returnParameter.cenv
 2176         let prettyTys, prettyRetTy = xs |> List.mapSquared (fun p -> p.V) |> (fun tys -> PrettyTypes.PrettifyCurriedSigTypes cenv.g (tys, returnParameter.V) )|> fst
 2177         let ps = (xs, prettyTys) ||> List.map2 (List.map2 (fun p pty -> p.AdjustType(pty))) |> List.map makeReadOnlyCollection |> makeReadOnlyCollection
 2178         ps, returnParameter.AdjustType(prettyRetTy)
 2179 
 2180 and FSharpAttribute(cenv: SymbolEnv, attrib: AttribInfo) = 
 2181 
 2182     let rec resolveArgObj (arg: obj) =
 2183         match arg with
 2184         | :? TType as t -> box (FSharpType(cenv, t)) 
 2185         | :? (obj[]) as a -> a |> Array.map resolveArgObj |> box
 2186         | _ -> arg
 2187 
 2188     member __.AttributeType =  
 2189         FSharpEntity(cenv, attrib.TyconRef)
 2190 
 2191     member __.IsUnresolved = entityIsUnresolved(attrib.TyconRef)
 2192 
 2193     member __.ConstructorArguments = 
 2194         attrib.ConstructorArguments 
 2195         |> List.map (fun (ty, obj) -> FSharpType(cenv, ty), resolveArgObj obj)
 2196         |> makeReadOnlyCollection
 2197 
 2198     member __.NamedArguments = 
 2199         attrib.NamedArguments 
 2200         |> List.map (fun (ty, nm, isField, obj) -> FSharpType(cenv, ty), nm, isField, resolveArgObj obj)
 2201         |> makeReadOnlyCollection
 2202 
 2203     member __.Format(denv: FSharpDisplayContext) = 
 2204         protect <| fun () -> 
 2205             match attrib with
 2206             | AttribInfo.FSAttribInfo(g, attrib) ->
 2207                 NicePrint.stringOfFSAttrib (denv.Contents g) attrib
 2208             | AttribInfo.ILAttribInfo (g, _, _scoref, cattr, _) -> 
 2209                 let parms, _args = decodeILAttribData g.ilg cattr 
 2210                 NicePrint.stringOfILAttrib (denv.Contents g) (cattr.Method.DeclaringType, parms)
 2211 
 2212     override __.ToString() = 
 2213         if entityIsUnresolved attrib.TyconRef then "attribute ???" else "attribute " + attrib.TyconRef.CompiledName + "(...)" 
 2214 #if !NO_EXTENSIONTYPING    
 2215 and FSharpStaticParameter(cenv, sp: Tainted< ExtensionTyping.ProvidedParameterInfo >, m) = 
 2216     inherit FSharpSymbol(cenv, 
 2217                          (fun () -> 
 2218                               protect <| fun () -> 
 2219                                 let spKind = Import.ImportProvidedType cenv.amap m (sp.PApply((fun x -> x.ParameterType), m))
 2220                                 let nm = sp.PUntaint((fun p -> p.Name), m)
 2221                                 Item.ArgName((mkSynId m nm, spKind, None))), 
 2222                          (fun _ _ _ -> true))
 2223 
 2224     member __.Name = 
 2225         protect <| fun () -> 
 2226             sp.PUntaint((fun p -> p.Name), m)
 2227 
 2228     member __.DeclarationLocation = m
 2229 
 2230     member __.Kind = 
 2231         protect <| fun () -> 
 2232             let ty = Import.ImportProvidedType cenv.amap m (sp.PApply((fun x -> x.ParameterType), m))
 2233             FSharpType(cenv, ty)
 2234 
 2235     member __.IsOptional = 
 2236         protect <| fun () -> sp.PUntaint((fun x -> x.IsOptional), m)
 2237 
 2238     member __.HasDefaultValue = 
 2239         protect <| fun () -> sp.PUntaint((fun x -> x.HasDefaultValue), m)
 2240 
 2241     member __.DefaultValue = 
 2242         protect <| fun () -> sp.PUntaint((fun x -> x.RawDefaultValue), m)
 2243 
 2244     override x.Equals(other: obj) =
 2245         box x === other || 
 2246         match other with
 2247         |   :? FSharpStaticParameter as p -> x.Name = p.Name && x.DeclarationLocation = p.DeclarationLocation
 2248         |   _ -> false
 2249 
 2250     override x.GetHashCode() = hash x.Name
 2251     override x.ToString() = 
 2252         "static parameter " + x.Name 
 2253 #endif
 2254 and FSharpParameter(cenv, paramTy:TType, topArgInfo:ArgReprInfo, mOpt, isParamArrayArg, isInArg, isOutArg, isOptionalArg) = 
 2255     inherit FSharpSymbol(cenv, 
 2256                          (fun () -> 
 2257                             let m = match mOpt with Some m  -> m | None -> range0
 2258                             Item.ArgName((match topArgInfo.Name with None -> mkSynId m "" | Some v -> v), paramTy, None)), 
 2259                          (fun _ _ _ -> true))
 2260     let attribs = topArgInfo.Attribs
 2261     let idOpt = topArgInfo.Name
 2262     let m = match mOpt with Some m  -> m | None -> range0
 2263 
 2264     member __.Name = match idOpt with None -> None | Some v -> Some v.idText
 2265 
 2266     member __.cenv: SymbolEnv = cenv
 2267 
 2268     member __.AdjustType(t) = FSharpParameter(cenv, t, topArgInfo, mOpt, isParamArrayArg, isInArg, isOutArg, isOptionalArg)
 2269 
 2270     member __.Type: FSharpType = FSharpType(cenv, paramTy)
 2271 
 2272     member __.V = paramTy
 2273 
 2274     member __.DeclarationLocation = match idOpt with None -> m | Some v -> v.idRange
 2275 
 2276     member __.Attributes = 
 2277         attribs |> List.map (fun a -> FSharpAttribute(cenv, AttribInfo.FSAttribInfo(cenv.g, a))) |> makeReadOnlyCollection
 2278 
 2279     member __.IsParamArrayArg = isParamArrayArg
 2280 
 2281     member __.IsInArg = isInArg
 2282 
 2283     member __.IsOutArg = isOutArg
 2284 
 2285     member __.IsOptionalArg = isOptionalArg
 2286     
 2287     member private x.ValReprInfo = topArgInfo
 2288 
 2289     override x.Equals(other: obj) =
 2290         box x === other || 
 2291         match other with
 2292         |   :? FSharpParameter as p -> x.Name = p.Name && x.DeclarationLocation = p.DeclarationLocation
 2293         |   _ -> false
 2294 
 2295     override x.GetHashCode() = hash (box topArgInfo)
 2296 
 2297     override x.ToString() = 
 2298         "parameter " + (match x.Name with None -> "<unnamed" | Some s -> s)
 2299 
 2300 and FSharpAssemblySignature (cenv, topAttribs: TypeChecker.TopAttribs option, optViewedCcu: CcuThunk option, mtyp: ModuleOrNamespaceType) = 
 2301 
 2302     // Assembly signature for a referenced/linked assembly
 2303     new (cenv: SymbolEnv, ccu: CcuThunk) = 
 2304         let cenv = if ccu.IsUnresolvedReference then cenv else SymbolEnv(cenv.g, ccu, None, cenv.tcImports)
 2305         FSharpAssemblySignature(cenv, None, Some ccu, ccu.Contents.ModuleOrNamespaceType)
 2306     
 2307     // Assembly signature for an assembly produced via type-checking.
 2308     new (g, thisCcu, thisCcuTy, tcImports, topAttribs, mtyp) = 
 2309         FSharpAssemblySignature(SymbolEnv(g, thisCcu, Some thisCcuTy, tcImports), topAttribs, None, mtyp)
 2310 
 2311     member __.Entities = 
 2312 
 2313         let rec loop (rmtyp: ModuleOrNamespaceType) = 
 2314             [| for entity in rmtyp.AllEntities do
 2315                    if entity.IsNamespace then 
 2316                        yield! loop entity.ModuleOrNamespaceType
 2317                    else 
 2318                        let entityRef = rescopeEntity optViewedCcu entity 
 2319                        yield FSharpEntity(cenv, entityRef) |]
 2320         
 2321         loop mtyp |> makeReadOnlyCollection
 2322 
 2323     member __.Attributes =
 2324         [ match optViewedCcu with 
 2325           | Some ccu -> 
 2326                 match ccu.TryGetILModuleDef() with 
 2327                 | Some ilModule -> 
 2328                     match ilModule.Manifest with 
 2329                     | None -> ()
 2330                     | Some manifest -> 
 2331                         for a in AttribInfosOfIL cenv.g cenv.amap cenv.thisCcu.ILScopeRef range0 manifest.CustomAttrs do
 2332                             yield FSharpAttribute(cenv, a)
 2333                 | None -> 
 2334                     // If no module is available, then look in the CCU contents. 
 2335                     if ccu.IsFSharp then
 2336                         for a in ccu.Contents.Attribs do 
 2337                             yield FSharpAttribute(cenv, FSAttribInfo (cenv.g, a))
 2338           | None -> 
 2339               match topAttribs with
 2340               | None -> ()
 2341               | Some tA -> for a in tA.assemblyAttrs do yield FSharpAttribute(cenv, AttribInfo.FSAttribInfo(cenv.g, a)) ]
 2342         |> makeReadOnlyCollection
 2343 
 2344     member __.FindEntityByPath path =
 2345         let findNested name entity = 
 2346             match entity with
 2347             | Some (e: Entity) ->e.ModuleOrNamespaceType.AllEntitiesByCompiledAndLogicalMangledNames.TryFind name
 2348             | _ -> None
 2349 
 2350         match path with
 2351         | hd :: tl ->
 2352              (mtyp.AllEntitiesByCompiledAndLogicalMangledNames.TryFind hd, tl) 
 2353              ||> List.fold (fun a x -> findNested x a)  
 2354              |> Option.map (fun e -> FSharpEntity(cenv, rescopeEntity optViewedCcu e))
 2355         | _ -> None
 2356 
 2357     override x.ToString() = "<assembly signature>"
 2358 
 2359 and FSharpAssembly internal (cenv, ccu: CcuThunk) = 
 2360 
 2361     new (g, tcImports, ccu: CcuThunk) = 
 2362         FSharpAssembly(SymbolEnv(g, ccu, None, tcImports), ccu)
 2363 
 2364     member __.RawCcuThunk = ccu
 2365 
 2366     member __.QualifiedName = match ccu.QualifiedName with None -> "" | Some s -> s
 2367 
 2368     member __.CodeLocation = ccu.SourceCodeDirectory
 2369 
 2370     member __.FileName = ccu.FileName
 2371 
 2372     member __.SimpleName = ccu.AssemblyName 
 2373 
 2374 #if !NO_EXTENSIONTYPING
 2375     member __.IsProviderGenerated = ccu.IsProviderGenerated
 2376 #endif
 2377 
 2378     member __.Contents : FSharpAssemblySignature = FSharpAssemblySignature(cenv, ccu)
 2379                  
 2380     override x.ToString() = ccu.ILScopeRef.QualifiedName
 2381 
 2382 /// Represents open declaration in F# code.
 2383 [<Sealed>]
 2384 type FSharpOpenDeclaration(longId: Ident list, range: range option, modules: FSharpEntity list, appliedScope: range, isOwnNamespace: bool) =
 2385 
 2386     member __.LongId = longId
 2387 
 2388     member __.Range = range
 2389 
 2390     member __.Modules = modules
 2391 
 2392     member __.AppliedScope = appliedScope
 2393 
 2394     member __.IsOwnNamespace = isOwnNamespace
 2395 
 2396 [<Sealed>]
 2397 type FSharpSymbolUse(g:TcGlobals, denv: DisplayEnv, symbol:FSharpSymbol, itemOcc, range: range) = 
 2398 
 2399     member __.Symbol  = symbol
 2400 
 2401     member __.DisplayContext  = FSharpDisplayContext(fun _ -> denv)
 2402 
 2403     member x.IsDefinition = x.IsFromDefinition
 2404 
 2405     member __.IsFromDefinition = itemOcc = ItemOccurence.Binding
 2406 
 2407     member __.IsFromPattern = itemOcc = ItemOccurence.Pattern
 2408 
 2409     member __.IsFromType = itemOcc = ItemOccurence.UseInType
 2410 
 2411     member __.IsFromAttribute = itemOcc = ItemOccurence.UseInAttribute
 2412 
 2413     member __.IsFromDispatchSlotImplementation = itemOcc = ItemOccurence.Implemented
 2414 
 2415     member __.IsFromComputationExpression = 
 2416         match symbol.Item, itemOcc with 
 2417         // 'seq' in 'seq { ... }' gets colored as keywords
 2418         | (Item.Value vref), ItemOccurence.Use when valRefEq g g.seq_vref vref ->  true
 2419         // custom builders, custom operations get colored as keywords
 2420         | (Item.CustomBuilder _ | Item.CustomOperation _), ItemOccurence.Use ->  true
 2421         | _ -> false
 2422 
 2423     member __.IsFromOpenStatement = itemOcc = ItemOccurence.Open
 2424 
 2425     member __.FileName = range.FileName
 2426 
 2427     member __.Range = Range.toZ range
 2428 
 2429     member __.RangeAlternate = range
 2430 
 2431     override __.ToString() = sprintf "%O, %O, %O" symbol itemOcc range