Skip to content

Commit 69cbc83

Browse files
authored
Merge pull request #11338 from dotnet/merges/main-to-release/dev16.10
2 parents f5413a7 + f35cf5f commit 69cbc83

39 files changed

+851
-322
lines changed

src/fsharp/CheckComputationExpressions.fs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ let TcComputationExpression cenv env overallTy tpenv (mWhole, interpExpr: Expr,
601601
| _ ->
602602
None
603603

604-
let (|ForEachThenJoinOrGroupJoinOrZipClause|_|) e =
604+
let (|ForEachThenJoinOrGroupJoinOrZipClause|_|) strict e =
605605
match e with
606606
| ForEachThen (isFromSource, firstSourcePat, firstSource, JoinOrGroupJoinOrZipClause(nm, secondSourcePat, secondSource, keySelectorsOpt, pat3opt, mOpCore), innerComp)
607607
when
@@ -612,7 +612,7 @@ let TcComputationExpression cenv env overallTy tpenv (mWhole, interpExpr: Expr,
612612

613613
-> Some (isFromSource, firstSourcePat, firstSource, nm, secondSourcePat, secondSource, keySelectorsOpt, pat3opt, mOpCore, innerComp)
614614

615-
| JoinOrGroupJoinOrZipClause(nm, pat2, expr2, expr3, pat3opt, mOpCore) ->
615+
| JoinOrGroupJoinOrZipClause(nm, pat2, expr2, expr3, pat3opt, mOpCore) when strict ->
616616
errorR(Error(FSComp.SR.tcBinaryOperatorRequiresBody(nm.idText, Option.get (customOpUsageText nm)), nm.idRange))
617617
Some (true, arbPat e.Range, arbExpr("_outerSource", e.Range), nm, pat2, expr2, expr3, pat3opt, mOpCore, arbExpr("_innerComp", e.Range))
618618

@@ -754,7 +754,7 @@ let TcComputationExpression cenv env overallTy tpenv (mWhole, interpExpr: Expr,
754754
// ...
755755
// -->
756756
// zip expr1 expr2 (fun pat1 pat3 -> ...)
757-
| ForEachThenJoinOrGroupJoinOrZipClause (isFromSource, firstSourcePat, firstSource, nm, secondSourcePat, secondSource, keySelectorsOpt, secondResultPatOpt, mOpCore, innerComp) ->
757+
| ForEachThenJoinOrGroupJoinOrZipClause true (isFromSource, firstSourcePat, firstSource, nm, secondSourcePat, secondSource, keySelectorsOpt, secondResultPatOpt, mOpCore, innerComp) ->
758758

759759

760760
if q = CustomOperationsMode.Denied then error(Error(FSComp.SR.tcCustomOperationMayNotBeUsedHere(), nm.idRange))
@@ -1562,7 +1562,7 @@ let TcComputationExpression cenv env overallTy tpenv (mWhole, interpExpr: Expr,
15621562
and isSimpleExpr comp =
15631563

15641564
match comp with
1565-
| ForEachThenJoinOrGroupJoinOrZipClause _ -> false
1565+
| ForEachThenJoinOrGroupJoinOrZipClause false _ -> false
15661566
| SynExpr.ForEach _ -> false
15671567
| SynExpr.For _ -> false
15681568
| SynExpr.While _ -> false

src/fsharp/NicePrint.fs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1424,7 +1424,7 @@ module private TastDefinitionPrinting =
14241424

14251425
let nameL = eventTag |> wordL
14261426
let typL = layoutType denv (e.GetDelegateType(amap, m))
1427-
staticL ^^ WordL.keywordEvent ^^ nameL ^^ WordL.colon ^^ typL
1427+
staticL ^^ WordL.keywordMember ^^ nameL ^^ WordL.colon ^^ typL
14281428

14291429
let private layoutPropInfo denv amap m (p: PropInfo) =
14301430
match p.ArbitraryValRef with
@@ -1783,6 +1783,17 @@ module private TastDefinitionPrinting =
17831783
let xs = List.map (layoutTycon denv infoReader ad m false (wordL (tagKeyword "and"))) t
17841784
aboveListL (x :: xs)
17851785

1786+
let layoutEntity (denv: DisplayEnv) (infoReader: InfoReader) ad m (entity: Entity) =
1787+
if entity.IsModule then
1788+
// TODO: Implementation of layoutTycon isn't correct for module.
1789+
layoutTycon denv infoReader ad m false (wordL (tagKeyword "module")) entity
1790+
elif entity.IsNamespace then
1791+
emptyL
1792+
elif entity.IsExceptionDecl then
1793+
layoutExnDefn denv entity
1794+
else
1795+
layoutTycon denv infoReader ad m true WordL.keywordType entity
1796+
17861797
//--------------------------------------------------------------------------
17871798

17881799
module private InferredSigPrinting =
@@ -1976,6 +1987,8 @@ let stringOfTyparConstraints denv x = x |> PrintTypes.layoutConstraintsWithInfo
19761987

19771988
let layoutTycon denv infoReader ad m (* width *) x = TastDefinitionPrinting.layoutTycon denv infoReader ad m true WordL.keywordType x (* |> Display.squashTo width *)
19781989

1990+
let layoutEntity denv infoReader ad m x = TastDefinitionPrinting.layoutEntity denv infoReader ad m x
1991+
19791992
let layoutUnionCases denv x = x |> TastDefinitionPrinting.layoutUnionCaseFields denv true
19801993

19811994
/// Pass negative number as pos in case of single cased discriminated unions

src/fsharp/NicePrint.fsi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ val stringOfTyparConstraints: denv:DisplayEnv -> x:(Typar * TyparConstraint) lis
7070

7171
val layoutTycon: denv:DisplayEnv -> infoReader:InfoReader -> ad:AccessorDomain -> m:range -> x:Tycon -> Layout
7272

73+
val layoutEntity: denv:DisplayEnv -> infoReader:InfoReader -> ad:AccessorDomain -> m:range -> x:Entity -> Layout
74+
7375
val layoutUnionCases: denv:DisplayEnv -> x:RecdField list -> Layout
7476

7577
val isGeneratedUnionCaseField: pos:int -> f:RecdField -> bool

src/fsharp/symbols/Symbols.fs

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ open FSharp.Compiler.TypedTree
2424
open FSharp.Compiler.TypedTreeBasics
2525
open FSharp.Compiler.TcGlobals
2626
open FSharp.Compiler.TypedTreeOps
27+
open FSharp.Compiler.Syntax.PrettyNaming
28+
open FSharp.Compiler.AbstractIL
2729

2830
type FSharpAccessibility(a:Accessibility, ?isProtected) =
2931
let isProtected = defaultArg isProtected false
@@ -806,6 +808,108 @@ type FSharpEntity(cenv: SymbolEnv, entity:EntityRef) =
806808
member x.TryGetMembersFunctionsAndValues() =
807809
try x.MembersFunctionsAndValues with _ -> [||] :> _
808810

811+
member this.TryGetMetadataText() =
812+
match entity.TryDeref with
813+
| ValueSome entity ->
814+
if entity.IsNamespace then None
815+
else
816+
817+
let denv = DisplayEnv.Empty cenv.g
818+
let denv =
819+
{ denv with
820+
showImperativeTyparAnnotations=true
821+
showHiddenMembers=true
822+
showObsoleteMembers=true
823+
showAttributes=true
824+
shrinkOverloads=false
825+
printVerboseSignatures=false }
826+
827+
let extraOpenPath =
828+
match entity.CompilationPathOpt with
829+
| Some cpath ->
830+
let rec getOpenPath accessPath acc =
831+
match accessPath with
832+
| [] -> acc
833+
| (name, ModuleOrNamespaceKind.ModuleOrType) :: accessPath ->
834+
getOpenPath accessPath (name :: acc)
835+
| (name, ModuleOrNamespaceKind.Namespace) :: accessPath ->
836+
getOpenPath accessPath (name :: acc)
837+
| (name, ModuleOrNamespaceKind.FSharpModuleWithSuffix) :: accessPath ->
838+
getOpenPath accessPath (name :: acc)
839+
840+
getOpenPath cpath.AccessPath []
841+
| _ ->
842+
[]
843+
|> List.rev
844+
845+
let needOpenType =
846+
match entity.CompilationPathOpt with
847+
| Some cpath ->
848+
match cpath.AccessPath with
849+
| (_, ModuleOrNamespaceKind.ModuleOrType) :: _ ->
850+
match this.DeclaringEntity with
851+
| Some (declaringEntity: FSharpEntity) -> not declaringEntity.IsFSharpModule
852+
| _ -> false
853+
| _ -> false
854+
| _ ->
855+
false
856+
857+
let denv =
858+
denv.SetOpenPaths
859+
([ FSharpLib.RootPath
860+
FSharpLib.CorePath
861+
FSharpLib.CollectionsPath
862+
FSharpLib.ControlPath
863+
(IL.splitNamespace FSharpLib.ExtraTopLevelOperatorsName)
864+
extraOpenPath
865+
])
866+
867+
let infoReader = cenv.infoReader
868+
869+
let openPathL =
870+
extraOpenPath
871+
|> List.map (fun x -> Layout.wordL (TaggedText.tagUnknownEntity x))
872+
873+
let pathL =
874+
if List.isEmpty extraOpenPath then
875+
Layout.emptyL
876+
else
877+
Layout.sepListL (Layout.sepL TaggedText.dot) openPathL
878+
879+
let headerL =
880+
if List.isEmpty extraOpenPath then
881+
Layout.emptyL
882+
else
883+
Layout.(^^)
884+
(Layout.wordL (TaggedText.tagKeyword "namespace"))
885+
pathL
886+
887+
let openL =
888+
if List.isEmpty openPathL then Layout.emptyL
889+
else
890+
let openKeywordL =
891+
if needOpenType then
892+
Layout.(^^)
893+
(Layout.wordL (TaggedText.tagKeyword "open"))
894+
(Layout.wordL TaggedText.keywordType)
895+
else
896+
Layout.wordL (TaggedText.tagKeyword "open")
897+
Layout.(^^)
898+
openKeywordL
899+
pathL
900+
901+
Layout.aboveListL
902+
[
903+
(Layout.(^^) headerL (Layout.sepL TaggedText.lineBreak))
904+
(Layout.(^^) openL (Layout.sepL TaggedText.lineBreak))
905+
(NicePrint.layoutEntity denv infoReader AccessibleFromSomewhere range0 entity)
906+
]
907+
|> LayoutRender.showL
908+
|> SourceText.ofString
909+
|> Some
910+
| _ ->
911+
None
912+
809913
override x.Equals(other: obj) =
810914
box x === other ||
811915
match other with

src/fsharp/symbols/Symbols.fsi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,9 @@ type FSharpEntity =
359359
/// Safe version of `GetMembersFunctionsAndValues`.
360360
member TryGetMembersFunctionsAndValues: unit -> IList<FSharpMemberOrFunctionOrValue>
361361

362+
/// Get the source text of the entity's signature to be used as metadata.
363+
member TryGetMetadataText: unit -> ISourceText option
364+
362365
/// Represents a delegate signature in an F# symbol
363366
[<Class>]
364367
type FSharpDelegateSignature =

tests/FSharp.Compiler.Service.Tests/SurfaceArea.netstandard.fs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1494,11 +1494,11 @@ FSharp.Compiler.CodeAnalysis.FSharpParseFileResults: FSharp.Compiler.Syntax.Pars
14941494
FSharp.Compiler.CodeAnalysis.FSharpParseFileResults: FSharp.Compiler.Syntax.ParsedInput get_ParseTree()
14951495
FSharp.Compiler.CodeAnalysis.FSharpParseFileResults: Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.EditorServices.ParameterLocations] FindParameterLocations(FSharp.Compiler.Text.Position)
14961496
FSharp.Compiler.CodeAnalysis.FSharpParseFileResults: Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Text.Range] TryRangeOfExprInYieldOrReturn(FSharp.Compiler.Text.Position)
1497+
FSharp.Compiler.CodeAnalysis.FSharpParseFileResults: Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Text.Range] TryRangeOfExpressionBeingDereferencedContainingPos(FSharp.Compiler.Text.Position)
14971498
FSharp.Compiler.CodeAnalysis.FSharpParseFileResults: Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Text.Range] TryRangeOfFunctionOrMethodBeingApplied(FSharp.Compiler.Text.Position)
14981499
FSharp.Compiler.CodeAnalysis.FSharpParseFileResults: Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Text.Range] TryRangeOfNameOfNearestOuterBindingContainingPos(FSharp.Compiler.Text.Position)
14991500
FSharp.Compiler.CodeAnalysis.FSharpParseFileResults: Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Text.Range] TryRangeOfRecordExpressionContainingPos(FSharp.Compiler.Text.Position)
15001501
FSharp.Compiler.CodeAnalysis.FSharpParseFileResults: Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Text.Range] TryRangeOfRefCellDereferenceContainingPos(FSharp.Compiler.Text.Position)
1501-
FSharp.Compiler.CodeAnalysis.FSharpParseFileResults: Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Text.Range] TryRangeOfExpressionBeingDereferencedContainingPos(FSharp.Compiler.Text.Position)
15021502
FSharp.Compiler.CodeAnalysis.FSharpParseFileResults: Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Text.Range] ValidateBreakpointLocation(FSharp.Compiler.Text.Position)
15031503
FSharp.Compiler.CodeAnalysis.FSharpParseFileResults: Microsoft.FSharp.Core.FSharpOption`1[Microsoft.FSharp.Collections.FSharpList`1[FSharp.Compiler.Text.Range]] GetAllArgumentsForFunctionApplicationAtPostion(FSharp.Compiler.Text.Position)
15041504
FSharp.Compiler.CodeAnalysis.FSharpParseFileResults: Microsoft.FSharp.Core.FSharpOption`1[System.Tuple`2[FSharp.Compiler.Syntax.Ident,System.Int32]] TryIdentOfPipelineContainingPosAndNumArgsApplied(FSharp.Compiler.Text.Position)
@@ -3821,6 +3821,7 @@ FSharp.Compiler.Symbols.FSharpEntity: Microsoft.FSharp.Core.FSharpOption`1[FShar
38213821
FSharp.Compiler.Symbols.FSharpEntity: Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Symbols.FSharpEntity] get_DeclaringEntity()
38223822
FSharp.Compiler.Symbols.FSharpEntity: Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Symbols.FSharpType] BaseType
38233823
FSharp.Compiler.Symbols.FSharpEntity: Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Symbols.FSharpType] get_BaseType()
3824+
FSharp.Compiler.Symbols.FSharpEntity: Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Text.ISourceText] TryGetMetadataText()
38243825
FSharp.Compiler.Symbols.FSharpEntity: Microsoft.FSharp.Core.FSharpOption`1[System.String] Namespace
38253826
FSharp.Compiler.Symbols.FSharpEntity: Microsoft.FSharp.Core.FSharpOption`1[System.String] TryFullName
38263827
FSharp.Compiler.Symbols.FSharpEntity: Microsoft.FSharp.Core.FSharpOption`1[System.String] TryGetFullCompiledName()

0 commit comments

Comments
 (0)