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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/release-notes/.FSharp.Compiler.Service/11.0.200.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
### Added

* Completion: respect EditorBrowsableAttribute ([PR #20729](https://github.com/dotnet/fsharp/pull/20729))
* Runtime-async sequences allow awaits inside `try/with` bodies, filters and handlers, and reject overlapping `MoveNextAsync` calls. ([PR #20655](https://github.com/dotnet/fsharp/pull/20655))
* F# Interactive gains a JSON-RPC server mode, `--fsi-server-jsonrpc:<pipe name>`, in which a host submits interactions over a named pipe and receives structured results — diagnostics with positions, escaping exceptions, the values each interaction bound, and the session's own process id — instead of recovering them by looking for a `SERVER-PROMPT>` marker in the output text. Program output continues to flow through the redirected console streams. The pipe admits only the user running the session; `--fsi-server-client-pid:<pid>` names the host process whose exit ends the session. `FsiEvaluationSession` exposes both options as `JsonRpcServerPipeName` and `JsonRpcClientProcessId`. The mode is part of the .NET fsi only. ([PR #20396](https://github.com/dotnet/fsharp/pull/20396))

Expand Down
2 changes: 2 additions & 0 deletions src/Compiler/AbstractIL/il.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1309,6 +1309,8 @@ type WellKnownILAttributes =
| NotNullIfNotNullAttribute = (1u <<< 25)
| OverloadResolutionPriorityAttribute = (1u <<< 26)
| RequireNamedArgumentsAttribute = (1u <<< 27)
| EditorBrowsableNever = (1u <<< 28)
| EditorBrowsableAdvanced = (1u <<< 29)
| NotComputed = (1u <<< 31)

[<Sealed; NoEquality; NoComparison>]
Expand Down
4 changes: 4 additions & 0 deletions src/Compiler/AbstractIL/il.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,8 @@ type WellKnownILAttributes =
| NotNullIfNotNullAttribute = (1u <<< 25)
| OverloadResolutionPriorityAttribute = (1u <<< 26)
| RequireNamedArgumentsAttribute = (1u <<< 27)
| EditorBrowsableNever = (1u <<< 28)
| EditorBrowsableAdvanced = (1u <<< 29)
| NotComputed = (1u <<< 31)

/// Represents the efficiency-oriented storage of ILAttributes in another item.
Expand All @@ -930,6 +932,8 @@ type ILAttributesStored =

member HasWellKnownAttribute: flag: WellKnownILAttributes * compute: (ILAttributes -> WellKnownILAttributes) -> bool

member GetOrComputeWellKnownFlags: compute: (ILAttributes -> WellKnownILAttributes) -> WellKnownILAttributes

static member CreateReader: idx: int32 * f: (int32 -> ILAttribute[]) -> ILAttributesStored
static member CreateGiven: attrs: ILAttributes -> ILAttributesStored

Expand Down
134 changes: 82 additions & 52 deletions src/Compiler/Checking/AttributeChecking.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module internal FSharp.Compiler.AttributeChecking

open System
open System.Collections.Generic
open System.ComponentModel
open FSharp.Compiler.Text.Range
open Internal.Utilities.Library
open FSharp.Compiler.AbstractIL.IL
Expand Down Expand Up @@ -471,32 +472,47 @@ let private CheckProvidedAttributes (g: TcGlobals) m (provAttribs: Tainted<IProv
TryGetProvidedObsoleteInfo g m provAttribs |> reportObsoleteDiagnostic m
#endif

/// Indicate if IL attributes contain 'ObsoleteAttribute'. Used to suppress the item in intellisense.
/// Uses cached well-known flags for O(1) check when ILAttributesStored is available.
/// See also: CheckILAttributesForUnseen for the non-cached variant on ILAttributes.
let CheckILAttributesForUnseenStored (g: TcGlobals) (cattrsStored: ILAttributesStored) =
if cattrsStored.HasWellKnownAttribute(g, WellKnownILAttributes.ObsoleteAttribute) then
not (cattrsStored.HasWellKnownAttribute(g, WellKnownILAttributes.IsByRefLikeAttribute))
else
false

/// Indicate if a list of IL attributes contains 'ObsoleteAttribute'. Used to suppress the item in intellisense.
/// Non-cached variant operating on ILAttributes directly. See CheckILAttributesForUnseenStored for cached version.
let CheckILAttributesForUnseen (cattrs: ILAttributes) =
cattrs.HasWellKnownAttribute(WellKnownILAttributes.ObsoleteAttribute)
&& not (cattrs.HasWellKnownAttribute(WellKnownILAttributes.IsByRefLikeAttribute))

/// Checks the attributes for CompilerMessageAttribute, which has an IsHidden argument that allows
/// items to be suppressed from intellisense.
let CheckFSharpAttributesForHidden g attribs =
not (isNil attribs) &&
(match attribs with
| EntityAttrib g WellKnownEntityAttributes.CompilerMessageAttribute (Attrib(_, _, _, ExtractAttribNamedArg "IsHidden" (AttribBoolArg v), _, _, _)) -> v
| _ -> false)
||
(match attribs with
| EntityAttrib g WellKnownEntityAttributes.EditorBrowsableAttribute (Attrib(_, _, [AttribInt32Arg state], _, _, _, _)) -> state = int System.ComponentModel.EditorBrowsableState.Never
| _ -> false)
[<Flags>]
type UnseenItems =
| None = 0
| Obsolete = 1
| EditorBrowsableNever = 2
| CompilerMessageHidden = 4
| EditorBrowsableAdvanced = 8

module UnseenItems =
let All = ~~~UnseenItems.None

let ofBool cond unseen = if cond then unseen else UnseenItems.None

let IsUnseen (allowUnseen: UnseenItems) (unseen: UnseenItems) =
unseen &&& ~~~allowUnseen <> UnseenItems.None

let private ILWellKnownFlagsUnseenItems (flags: WellKnownILAttributes) =
let has flag = flags &&& flag <> WellKnownILAttributes.None
UnseenItems.ofBool (has WellKnownILAttributes.ObsoleteAttribute && not (has WellKnownILAttributes.IsByRefLikeAttribute)) UnseenItems.Obsolete
||| UnseenItems.ofBool (has WellKnownILAttributes.EditorBrowsableNever) UnseenItems.EditorBrowsableNever
||| UnseenItems.ofBool (has WellKnownILAttributes.EditorBrowsableAdvanced) UnseenItems.EditorBrowsableAdvanced

let ILAttributesStoredUnseenItems (g: TcGlobals) (cattrsStored: ILAttributesStored) =
cattrsStored.GetOrComputeWellKnownFlags(computeILWellKnownFlags g) |> ILWellKnownFlagsUnseenItems

let ILAttributesUnseenItems (g: TcGlobals) (cattrs: ILAttributes) =
computeILWellKnownFlags g cattrs |> ILWellKnownFlagsUnseenItems

let private FSharpAttributesEditorBrowsableUnseenItems g attribs =
match attribs with
| EntityAttribInt g WellKnownEntityAttributes.EditorBrowsableAttribute state ->
match enum<EditorBrowsableState> state with
| EditorBrowsableState.Never -> UnseenItems.EditorBrowsableNever
| EditorBrowsableState.Advanced -> UnseenItems.EditorBrowsableAdvanced
| _ -> UnseenItems.None
| _ -> UnseenItems.None

let private CheckFSharpAttributesForCompilerMessageHidden g attribs =
match attribs with
| EntityAttrib g WellKnownEntityAttributes.CompilerMessageAttribute (Attrib(_, _, _, ExtractAttribNamedArg "IsHidden" (AttribBoolArg v), _, _, _)) -> v
| _ -> false

/// Indicate if a list of F# attributes contains 'ObsoleteAttribute'. Used to suppress the item in intellisense.
let CheckFSharpAttributesForObsolete (g: TcGlobals) attribs =
Expand All @@ -507,16 +523,30 @@ let CheckFSharpAttributesForObsolete (g: TcGlobals) attribs =
// like Span and ReadOnlySpan in completion lists due to their dual attributes.
not (attribsHaveEntityFlag g WellKnownEntityAttributes.IsByRefLikeAttribute attribs)

/// Indicates if a list of F# attributes contains 'ObsoleteAttribute' or CompilerMessageAttribute', which has an IsHidden argument
/// May be used to suppress items from intellisense.
let CheckFSharpAttributesForUnseen g attribs allowObsolete =
not (isNil attribs) &&
(not allowObsolete && CheckFSharpAttributesForObsolete g attribs || CheckFSharpAttributesForHidden g attribs)
let FSharpAttributesUnseenItems g attribs =
if isNil attribs then
UnseenItems.None
else
let flags = computeEntityWellKnownFlags g attribs
let has flag = flags &&& flag <> WellKnownEntityAttributes.None

UnseenItems.ofBool (has WellKnownEntityAttributes.ObsoleteAttribute && not (has WellKnownEntityAttributes.IsByRefLikeAttribute)) UnseenItems.Obsolete
||| (if has WellKnownEntityAttributes.EditorBrowsableAttribute then FSharpAttributesEditorBrowsableUnseenItems g attribs else UnseenItems.None)
||| UnseenItems.ofBool (has WellKnownEntityAttributes.CompilerMessageAttribute && CheckFSharpAttributesForCompilerMessageHidden g attribs) UnseenItems.CompilerMessageHidden

let CheckFSharpAttributesForUnseen g attribs allowUnseen =
FSharpAttributesUnseenItems g attribs |> IsUnseen allowUnseen

let CheckFSharpAttributesForHidden g attribs =
CheckFSharpAttributesForUnseen g attribs (UnseenItems.Obsolete ||| UnseenItems.EditorBrowsableAdvanced)

#if !NO_TYPEPROVIDERS
/// Indicate if a list of provided attributes contains 'ObsoleteAttribute'. Used to suppress the item in intellisense.
let CheckProvidedAttributesForUnseen (provAttribs: Tainted<IProvidedCustomAttributeProvider>) m =
provAttribs.PUntaint((fun a -> a.GetAttributeConstructorArgs(provAttribs.TypeProvider.PUntaintNoFailure(id), !! typeof<ObsoleteAttribute>.FullName).IsSome), m)
let ProvidedAttributesUnseenItems (provAttribs: Tainted<IProvidedCustomAttributeProvider>) m =
if provAttribs.PUntaint((fun a -> a.GetAttributeConstructorArgs(provAttribs.TypeProvider.PUntaintNoFailure(id), !! typeof<ObsoleteAttribute>.FullName).IsSome), m) then
UnseenItems.Obsolete
else
UnseenItems.None
#endif

/// Check the attributes associated with a property, returning warnings and errors as data.
Expand Down Expand Up @@ -642,21 +672,21 @@ let TryGetMethodObsoleteInfo minfo =

/// Indicate if a method has 'Obsolete', 'CompilerMessageAttribute' or 'TypeProviderEditorHideMethodsAttribute'.
/// Used to suppress the item in intellisense.
let MethInfoIsUnseen g (m: range) (ty: TType) minfo allowObsolete =
let isUnseenByObsoleteAttrib () =
let MethInfoIsUnseen g (m: range) (ty: TType) minfo allowUnseen =
let isUnseenItemsObsoleteAttrib () =
match BindMethInfoAttributes m minfo
(fun ilAttribs -> Some(not allowObsolete && CheckILAttributesForUnseen ilAttribs))
(fun fsAttribs -> Some(CheckFSharpAttributesForUnseen g fsAttribs allowObsolete))
(fun ilAttribs -> Some(ILAttributesUnseenItems g ilAttribs))
(fun fsAttribs -> Some(FSharpAttributesUnseenItems g fsAttribs))
#if !NO_TYPEPROVIDERS
(fun provAttribs -> Some(not allowObsolete && CheckProvidedAttributesForUnseen provAttribs m))
(fun provAttribs -> Some(ProvidedAttributesUnseenItems provAttribs m))
#else
(fun _provAttribs -> None)
#endif
with
| Some res -> res
| Some unseen -> IsUnseen allowUnseen unseen
| None -> false

let isUnseenByHidingAttribute () =
let isUnseenItemsHidingAttribute () =
#if !NO_TYPEPROVIDERS
not (isObjTyAnyNullness g ty) &&
isAppTy g ty &&
Expand All @@ -681,43 +711,43 @@ let MethInfoIsUnseen g (m: range) (ty: TType) minfo allowObsolete =
false
#endif

isUnseenByObsoleteAttrib () || isUnseenByHidingAttribute ()
isUnseenItemsObsoleteAttrib () || isUnseenItemsHidingAttribute ()

/// Indicate if a property has 'Obsolete' or 'CompilerMessageAttribute'.
/// Used to suppress the item in intellisense.
let PropInfoIsUnseen _m allowObsolete pinfo =
let PropInfoIsUnseen _m allowUnseen pinfo =
match pinfo with
| ILProp (ILPropInfo(_, pdef) as ilpinfo) ->
// Properties on .NET tuple types are resolvable but unseen
isAnyTupleTy pinfo.TcGlobals ilpinfo.ILTypeInfo.ToType ||
CheckILAttributesForUnseen pdef.CustomAttrs
(ILAttributesUnseenItems pinfo.TcGlobals pdef.CustomAttrs |> IsUnseen allowUnseen)
| FSProp (g, _, Some vref, _)
| FSProp (g, _, _, Some vref) -> CheckFSharpAttributesForUnseen g vref.Attribs allowObsolete
| FSProp (g, _, _, Some vref) -> CheckFSharpAttributesForUnseen g vref.Attribs allowUnseen
| FSProp _ -> failwith "CheckPropInfoAttributes: unreachable"
#if !NO_TYPEPROVIDERS
| ProvidedProp (_amap, pi, m) ->
CheckProvidedAttributesForUnseen (pi.PApply((fun st -> (st :> IProvidedCustomAttributeProvider)), m)) m
ProvidedAttributesUnseenItems (pi.PApply((fun st -> (st :> IProvidedCustomAttributeProvider)), m)) m |> IsUnseen allowUnseen
#endif

/// Indicate if an ILFieldInfo has 'Obsolete' attribute.
/// Used to suppress the item in intellisense.
let ILFieldInfoIsUnseen (finfo: ILFieldInfo) =
let ILFieldInfoIsUnseen allowUnseen (finfo: ILFieldInfo) =
match finfo with
| ILFieldInfo(_, fdef) -> CheckILAttributesForUnseen fdef.CustomAttrs
| ILFieldInfo(_, fdef) -> ILAttributesUnseenItems finfo.TcGlobals fdef.CustomAttrs |> IsUnseen allowUnseen
#if !NO_TYPEPROVIDERS
| ProvidedField(_amap, fi, m) ->
CheckProvidedAttributesForUnseen (fi.PApply((fun st -> (st :> IProvidedCustomAttributeProvider)), m)) m
ProvidedAttributesUnseenItems (fi.PApply((fun st -> (st :> IProvidedCustomAttributeProvider)), m)) m |> IsUnseen allowUnseen
#endif

/// Indicate if an EventInfo has 'Obsolete' or 'CompilerMessageAttribute'.
/// Used to suppress the item in intellisense.
let EventInfoIsUnseen allowObsolete (einfo: EventInfo) =
let EventInfoIsUnseen allowUnseen (einfo: EventInfo) =
match einfo with
| ILEvent(ILEventInfo(_, ilEventDef)) -> CheckILAttributesForUnseen ilEventDef.CustomAttrs
| FSEvent(g, _, addValRef, _) -> CheckFSharpAttributesForUnseen g addValRef.Attribs allowObsolete
| ILEvent(ILEventInfo(_, ilEventDef)) -> ILAttributesUnseenItems einfo.TcGlobals ilEventDef.CustomAttrs |> IsUnseen allowUnseen
| FSEvent(g, _, addValRef, _) -> CheckFSharpAttributesForUnseen g addValRef.Attribs allowUnseen
#if !NO_TYPEPROVIDERS
| ProvidedEvent(_amap, ei, m) ->
CheckProvidedAttributesForUnseen (ei.PApply((fun st -> (st :> IProvidedCustomAttributeProvider)), m)) m
ProvidedAttributesUnseenItems (ei.PApply((fun st -> (st :> IProvidedCustomAttributeProvider)), m)) m |> IsUnseen allowUnseen
#endif

/// Check the attributes on a union case, returning errors and warnings as data.
Expand Down
34 changes: 27 additions & 7 deletions src/Compiler/Checking/AttributeChecking.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
/// on items from name resolution
module internal FSharp.Compiler.AttributeChecking

open System
open System.Collections.Generic
open FSharp.Compiler.AbstractIL.IL
open FSharp.Compiler
Expand Down Expand Up @@ -82,17 +83,36 @@ val MethInfoHasWellKnownAttributeSpec:

val CheckFSharpAttributes: g: TcGlobals -> attribs: Attrib list -> m: range -> OperationResult<unit>

val CheckILAttributesForUnseen: cattrs: ILAttributes -> bool
/// Kinds of item that attributes hide from intellisense; also the set of them a caller still shows
[<Flags>]
type UnseenItems =
| None = 0
| Obsolete = 1
| EditorBrowsableNever = 2
| CompilerMessageHidden = 4
| EditorBrowsableAdvanced = 8

val CheckILAttributesForUnseenStored: g: TcGlobals -> cattrsStored: ILAttributesStored -> bool
module UnseenItems =
/// For a path segment the user has already written
val All: UnseenItems

val ofBool: cond: bool -> unseen: UnseenItems -> UnseenItems

val IsUnseen: allowUnseen: UnseenItems -> unseen: UnseenItems -> bool

val ILAttributesStoredUnseenItems: g: TcGlobals -> cattrsStored: ILAttributesStored -> UnseenItems

val ILAttributesUnseenItems: g: TcGlobals -> cattrs: ILAttributes -> UnseenItems

val FSharpAttributesUnseenItems: g: TcGlobals -> attribs: Attrib list -> UnseenItems

val CheckFSharpAttributesForHidden: g: TcGlobals -> attribs: Attrib list -> bool

val TryGetFSharpObsoleteInfo: g: TcGlobals -> attribs: Attrib list -> ObsoleteDiagnosticInfo option

val CheckFSharpAttributesForObsolete: g: TcGlobals -> attribs: Attribs -> bool

val CheckFSharpAttributesForUnseen: g: TcGlobals -> attribs: Attrib list -> allowObsolete: bool -> bool
val CheckFSharpAttributesForUnseen: g: TcGlobals -> attribs: Attrib list -> allowUnseen: UnseenItems -> bool

val CheckPropInfoAttributes: pinfo: PropInfo -> m: range -> OperationResult<unit>

Expand All @@ -105,13 +125,13 @@ val TryGetILFieldObsoleteInfo: g: TcGlobals -> finfo: ILFieldInfo -> ObsoleteDia
val CheckMethInfoAttributes:
g: TcGlobals -> m: range -> tyargsOpt: 'a option -> minfo: MethInfo -> OperationResult<unit>

val MethInfoIsUnseen: g: TcGlobals -> m: range -> ty: TType -> minfo: MethInfo -> allowObsolete: bool -> bool
val MethInfoIsUnseen: g: TcGlobals -> m: range -> ty: TType -> minfo: MethInfo -> allowUnseen: UnseenItems -> bool

val PropInfoIsUnseen: _m: 'a -> allowObsolete: bool -> pinfo: PropInfo -> bool
val PropInfoIsUnseen: _m: 'a -> allowUnseen: UnseenItems -> pinfo: PropInfo -> bool

val ILFieldInfoIsUnseen: finfo: ILFieldInfo -> bool
val ILFieldInfoIsUnseen: allowUnseen: UnseenItems -> finfo: ILFieldInfo -> bool

val EventInfoIsUnseen: allowObsolete: bool -> einfo: EventInfo -> bool
val EventInfoIsUnseen: allowUnseen: UnseenItems -> einfo: EventInfo -> bool

val CheckEntityAttributes: g: TcGlobals -> tcref: TyconRef -> m: range -> OperationResult<unit>

Expand Down
Loading
Loading