From 4d1f7c40dd09f805d3de2117e721bd652d51dc6f Mon Sep 17 00:00:00 2001 From: ijklam Date: Sat, 9 Dec 2023 20:51:09 +0800 Subject: [PATCH 01/25] make `remarks` and `returns` visible in quick info --- .../DocComments/XMLDocumentation.fs | 22 +++++++++++++++++-- .../src/FSharp.Editor/FSharp.Editor.resx | 6 +++++ .../FSharp.Editor/xlf/FSharp.Editor.cs.xlf | 10 +++++++++ .../FSharp.Editor/xlf/FSharp.Editor.de.xlf | 10 +++++++++ .../FSharp.Editor/xlf/FSharp.Editor.es.xlf | 10 +++++++++ .../FSharp.Editor/xlf/FSharp.Editor.fr.xlf | 10 +++++++++ .../FSharp.Editor/xlf/FSharp.Editor.it.xlf | 10 +++++++++ .../FSharp.Editor/xlf/FSharp.Editor.ja.xlf | 10 +++++++++ .../FSharp.Editor/xlf/FSharp.Editor.ko.xlf | 10 +++++++++ .../FSharp.Editor/xlf/FSharp.Editor.pl.xlf | 10 +++++++++ .../FSharp.Editor/xlf/FSharp.Editor.pt-BR.xlf | 10 +++++++++ .../FSharp.Editor/xlf/FSharp.Editor.ru.xlf | 10 +++++++++ .../FSharp.Editor/xlf/FSharp.Editor.tr.xlf | 10 +++++++++ .../xlf/FSharp.Editor.zh-Hans.xlf | 10 +++++++++ .../xlf/FSharp.Editor.zh-Hant.xlf | 10 +++++++++ 15 files changed, 156 insertions(+), 2 deletions(-) diff --git a/vsintegration/src/FSharp.Editor/DocComments/XMLDocumentation.fs b/vsintegration/src/FSharp.Editor/DocComments/XMLDocumentation.fs index 1c807bfad91..89a290dbbef 100644 --- a/vsintegration/src/FSharp.Editor/DocComments/XMLDocumentation.fs +++ b/vsintegration/src/FSharp.Editor/DocComments/XMLDocumentation.fs @@ -165,6 +165,7 @@ module internal XmlDocumentation = | "typeref" -> for attr in el.Attributes() do WriteAttribute collector attr "name" (tagParameter >> collector.Add) + | "br" -> AppendHardLine collector | _ -> WriteNodes collector (el.Nodes()) | _ -> () @@ -217,6 +218,23 @@ module internal XmlDocumentation = EnsureHardLine collector WriteElement collector el + match Seq.tryHead (doc.Descendants(XName.op_Implicit "remarks")) with + | None -> () + | Some el -> + AppendHardLine collector + AppendOnNewLine collector (SR.RemarksHeader()) + AppendHardLine collector + WriteElement collector el + + match Seq.tryHead (doc.Descendants(XName.op_Implicit "returns")) with + | None -> () + | Some el -> + AppendHardLine collector + AppendOnNewLine collector (SR.ReturnsHeader()) + AppendHardLine collector + collector.Add(tagSpace " ") + WriteElement collector el + member this.CollectParameter(collector: ITaggedTextCollector, paramName: string) = match tryFindParameter paramName with | None -> () @@ -338,9 +356,9 @@ module internal XmlDocumentation = try match GetMemberIndexOfAssembly(fileName) with | Some(index) -> - let _, idx = index.ParseMemberSignature(signature) + let ok, idx = index.ParseMemberSignature(signature) - if idx <> 0u then + if Com.Succeeded(ok) then let ok, xml = index.GetMemberXML(idx) if Com.Succeeded(ok) then diff --git a/vsintegration/src/FSharp.Editor/FSharp.Editor.resx b/vsintegration/src/FSharp.Editor/FSharp.Editor.resx index 4b41551aac0..6492f005335 100644 --- a/vsintegration/src/FSharp.Editor/FSharp.Editor.resx +++ b/vsintegration/src/FSharp.Editor/FSharp.Editor.resx @@ -355,4 +355,10 @@ Use live (unsaved) buffers for analysis Remove unnecessary parentheses + + Remarks: + + + Returns: + \ No newline at end of file diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.cs.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.cs.xlf index 5db40f51628..55148d4c883 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.cs.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.cs.xlf @@ -206,6 +206,11 @@ Tečkované podtržení; Přerušované podtržení; + + Remarks: + Remarks: + + Remove 'return' Odebrat return @@ -241,6 +246,11 @@ Přerušované podtržení; Přejmenujte {0} na _. + + Returns: + Returns: + + Simplify name Zjednodušte název. diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.de.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.de.xlf index 31ffc4c8342..28f0da28f7c 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.de.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.de.xlf @@ -206,6 +206,11 @@ Punkt unterstrichen; Strich unterstrichen; + + Remarks: + Remarks: + + Remove 'return' "return" entfernen @@ -241,6 +246,11 @@ Strich unterstrichen; "{0}" in "_" umbenennen + + Returns: + Returns: + + Simplify name Namen vereinfachen diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.es.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.es.xlf index dceb8706e99..970764d23d5 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.es.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.es.xlf @@ -208,6 +208,11 @@ Subrayado de punto; Subrayado de guion; + + Remarks: + Remarks: + + Remove 'return' Quitar "return" @@ -243,6 +248,11 @@ Subrayado de guion; Cambiar nombre de "{0}" por "_" + + Returns: + Returns: + + Simplify name Simplificar nombre diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.fr.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.fr.xlf index db53640c9a5..4e2f0f4f26f 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.fr.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.fr.xlf @@ -206,6 +206,11 @@ Soulignement pointé ; Soulignement en tirets ; + + Remarks: + Remarks: + + Remove 'return' Supprimer 'return' @@ -241,6 +246,11 @@ Soulignement en tirets ; Renommer '{0}' en '_' + + Returns: + Returns: + + Simplify name Simplifier le nom diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.it.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.it.xlf index 97feb5816e2..dc380aa10f7 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.it.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.it.xlf @@ -206,6 +206,11 @@ Sottolineatura a punto; Sottolineatura a trattini; + + Remarks: + Remarks: + + Remove 'return' Rimuovi 'return' @@ -241,6 +246,11 @@ Sottolineatura a trattini; Rinomina '{0}' in '_' + + Returns: + Returns: + + Simplify name Semplifica nome diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ja.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ja.xlf index f9682a8d5fd..535d8e37a29 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ja.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ja.xlf @@ -206,6 +206,11 @@ F# 構文規則に準拠するよう、改行を追加して指定された幅 ダッシュ下線; + + Remarks: + Remarks: + + Remove 'return' 'return' の削除 @@ -241,6 +246,11 @@ F# 構文規則に準拠するよう、改行を追加して指定された幅 '{0}' から '_' に名前を変更する + + Returns: + Returns: + + Simplify name 名前を単純化する diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ko.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ko.xlf index 638099fe0fb..916cd46ccd6 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ko.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ko.xlf @@ -207,6 +207,11 @@ F# 구문 규칙에 맞는 줄바꿈을 추가하여 지정된 너비에 서명 대시 밑줄; + + Remarks: + Remarks: + + Remove 'return' 'return' 제거 @@ -242,6 +247,11 @@ F# 구문 규칙에 맞는 줄바꿈을 추가하여 지정된 너비에 서명 '{0}'의 이름을 '_'로 바꾸기 + + Returns: + Returns: + + Simplify name 이름 단순화 diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.pl.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.pl.xlf index cc17e6d540e..666a671e084 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.pl.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.pl.xlf @@ -206,6 +206,11 @@ Podkreślenie kropką; Podkreślenie kreską; + + Remarks: + Remarks: + + Remove 'return' Usuń element „return” @@ -241,6 +246,11 @@ Podkreślenie kreską; Zmień nazwę z „{0}” na „_” + + Returns: + Returns: + + Simplify name Uprość nazwę diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.pt-BR.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.pt-BR.xlf index 492073cacb0..31d6ac6224e 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.pt-BR.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.pt-BR.xlf @@ -206,6 +206,11 @@ Ponto sublinhado; Traço sublinhado; + + Remarks: + Remarks: + + Remove 'return' Remover 'return' @@ -241,6 +246,11 @@ Traço sublinhado; Renomear '{0}' para '_' + + Returns: + Returns: + + Simplify name Simplificar o nome diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ru.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ru.xlf index b8549511a9f..6e1037606f0 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ru.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ru.xlf @@ -206,6 +206,11 @@ Dash underline; Штриховое подчеркивание; + + Remarks: + Remarks: + + Remove 'return' Удалить "return" @@ -241,6 +246,11 @@ Dash underline; Переименовать "{0}" в "_" + + Returns: + Returns: + + Simplify name Упростить имя diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.tr.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.tr.xlf index e6e9332dc33..900381fd586 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.tr.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.tr.xlf @@ -206,6 +206,11 @@ Nokta alt çizgi; Tire alt çizgisi; + + Remarks: + Remarks: + + Remove 'return' 'return' öğesini kaldır @@ -241,6 +246,11 @@ Tire alt çizgisi; '{0}' öğesini '_' olarak yeniden adlandırma + + Returns: + Returns: + + Simplify name Adı basitleştirme diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.zh-Hans.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.zh-Hans.xlf index 6df4f779a61..705a1e08771 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.zh-Hans.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.zh-Hans.xlf @@ -206,6 +206,11 @@ Dash underline; 短划线下划线; + + Remarks: + Remarks: + + Remove 'return' 删除 "return" @@ -241,6 +246,11 @@ Dash underline; 将“{0}”重命名为“_” + + Returns: + Returns: + + Simplify name 简化名称 diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.zh-Hant.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.zh-Hant.xlf index d270271bb75..1845cc6940a 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.zh-Hant.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.zh-Hant.xlf @@ -206,6 +206,11 @@ Dash underline; 虛線底線; + + Remarks: + Remarks: + + Remove 'return' 移除 'return' @@ -241,6 +246,11 @@ Dash underline; 將 '{0}' 重新命名為 '_' + + Returns: + Returns: + + Simplify name 簡化名稱 From a7f5d23bf34b691adc5ee24de7d52e59807133ff Mon Sep 17 00:00:00 2001 From: ijklam Date: Sun, 10 Dec 2023 12:43:28 +0800 Subject: [PATCH 02/25] move `remarks` to the end of summarys add an option to control visibility of `remarks` --- .../Completion/CompletionProvider.fs | 4 +- .../Completion/CompletionService.fs | 2 +- .../FSharp.Editor/Completion/SignatureHelp.fs | 32 ++-- .../DocComments/XMLDocumentation.fs | 59 ++++--- .../src/FSharp.Editor/FSharp.Editor.resx | 3 +- .../FSharp.Editor/Options/EditorOptions.fs | 3 + .../QuickInfo/QuickInfoProvider.fs | 2 +- .../FSharp.Editor/xlf/FSharp.Editor.cs.xlf | 5 +- .../FSharp.Editor/xlf/FSharp.Editor.de.xlf | 5 +- .../FSharp.Editor/xlf/FSharp.Editor.es.xlf | 5 +- .../FSharp.Editor/xlf/FSharp.Editor.fr.xlf | 5 +- .../FSharp.Editor/xlf/FSharp.Editor.it.xlf | 5 +- .../FSharp.Editor/xlf/FSharp.Editor.ja.xlf | 5 +- .../FSharp.Editor/xlf/FSharp.Editor.ko.xlf | 5 +- .../FSharp.Editor/xlf/FSharp.Editor.pl.xlf | 5 +- .../FSharp.Editor/xlf/FSharp.Editor.pt-BR.xlf | 5 +- .../FSharp.Editor/xlf/FSharp.Editor.ru.xlf | 5 +- .../FSharp.Editor/xlf/FSharp.Editor.tr.xlf | 5 +- .../xlf/FSharp.Editor.zh-Hans.xlf | 5 +- .../xlf/FSharp.Editor.zh-Hant.xlf | 5 +- .../QuickInfoOptionControl.xaml | 50 ++++-- .../FSharp.UIResources/Strings.Designer.cs | 147 ++++++++++-------- .../src/FSharp.UIResources/Strings.resx | 3 + .../src/FSharp.UIResources/xlf/Strings.cs.xlf | 5 + .../src/FSharp.UIResources/xlf/Strings.de.xlf | 5 + .../src/FSharp.UIResources/xlf/Strings.es.xlf | 5 + .../src/FSharp.UIResources/xlf/Strings.fr.xlf | 5 + .../src/FSharp.UIResources/xlf/Strings.it.xlf | 5 + .../src/FSharp.UIResources/xlf/Strings.ja.xlf | 5 + .../src/FSharp.UIResources/xlf/Strings.ko.xlf | 5 + .../src/FSharp.UIResources/xlf/Strings.pl.xlf | 5 + .../FSharp.UIResources/xlf/Strings.pt-BR.xlf | 5 + .../src/FSharp.UIResources/xlf/Strings.ru.xlf | 5 + .../src/FSharp.UIResources/xlf/Strings.tr.xlf | 5 + .../xlf/Strings.zh-Hans.xlf | 5 + .../xlf/Strings.zh-Hant.xlf | 5 + 36 files changed, 288 insertions(+), 147 deletions(-) diff --git a/vsintegration/src/FSharp.Editor/Completion/CompletionProvider.fs b/vsintegration/src/FSharp.Editor/Completion/CompletionProvider.fs index 0014f1d2397..09fbc90af46 100644 --- a/vsintegration/src/FSharp.Editor/Completion/CompletionProvider.fs +++ b/vsintegration/src/FSharp.Editor/Completion/CompletionProvider.fs @@ -26,7 +26,7 @@ open CancellableTasks module Logger = Microsoft.VisualStudio.FSharp.Editor.Logger type internal FSharpCompletionProvider - (workspace: Workspace, serviceProvider: SVsServiceProvider, assemblyContentProvider: AssemblyContentProvider) = + (workspace: Workspace, serviceProvider: SVsServiceProvider, assemblyContentProvider: AssemblyContentProvider, editorOptions: EditorOptions) = inherit FSharpCompletionProviderBase() @@ -380,7 +380,7 @@ type internal FSharpCompletionProvider let documentation = List() let collector = RoslynHelpers.CollectTaggedText documentation // mix main description and xmldoc by using one collector - XmlDocumentation.BuildDataTipText(documentationBuilder, collector, collector, collector, collector, collector, description) + XmlDocumentation.BuildDataTipText(documentationBuilder, collector, collector, collector, collector, collector, description, editorOptions.QuickInfo.ShowRemarks) Task.FromResult(CompletionDescription.Create(documentation.ToImmutableArray())) | _ -> diff --git a/vsintegration/src/FSharp.Editor/Completion/CompletionService.fs b/vsintegration/src/FSharp.Editor/Completion/CompletionService.fs index 7975b31b155..13f7e3d3b30 100644 --- a/vsintegration/src/FSharp.Editor/Completion/CompletionService.fs +++ b/vsintegration/src/FSharp.Editor/Completion/CompletionService.fs @@ -24,7 +24,7 @@ type internal FSharpCompletionService let builtInProviders = ImmutableArray.Create( - FSharpCompletionProvider(workspace, serviceProvider, assemblyContentProvider), + FSharpCompletionProvider(workspace, serviceProvider, assemblyContentProvider, settings), FSharpCommonCompletionProvider.Create(HashDirectiveCompletionProvider.Create(workspace, projectInfoManager)) ) diff --git a/vsintegration/src/FSharp.Editor/Completion/SignatureHelp.fs b/vsintegration/src/FSharp.Editor/Completion/SignatureHelp.fs index 595f051900b..b877026000e 100644 --- a/vsintegration/src/FSharp.Editor/Completion/SignatureHelp.fs +++ b/vsintegration/src/FSharp.Editor/Completion/SignatureHelp.fs @@ -58,7 +58,7 @@ type SignatureHelpData = [] [)>] -type internal FSharpSignatureHelpProvider [] (serviceProvider: SVsServiceProvider) = +type internal FSharpSignatureHelpProvider [] (serviceProvider: SVsServiceProvider, editorOptions: EditorOptions) = let documentationBuilder = XmlDocumentation.CreateDocumentationBuilder(serviceProvider.XMLMemberIndexService) @@ -79,7 +79,8 @@ type internal FSharpSignatureHelpProvider [] (serviceProvi documentationBuilder: IDocumentationBuilder, sourceText: SourceText, caretPosition: int, - triggerIsTypedChar: char option + triggerIsTypedChar: char option, + editorOptions: EditorOptions ) = asyncMaybe { let textLines = sourceText.Lines @@ -206,7 +207,8 @@ type internal FSharpSignatureHelpProvider [] (serviceProvi RoslynHelpers.CollectTaggedText mainDescription, RoslynHelpers.CollectTaggedText documentation, method.Description, - false + false, + editorOptions.QuickInfo.ShowRemarks ) let parameters = @@ -225,7 +227,8 @@ type internal FSharpSignatureHelpProvider [] (serviceProvi documentationBuilder, RoslynHelpers.CollectTaggedText doc, method.XmlDoc, - p.ParameterName + p.ParameterName, + editorOptions.QuickInfo.ShowRemarks ) p.Display |> Seq.iter (RoslynHelpers.CollectTaggedText parts) @@ -292,7 +295,8 @@ type internal FSharpSignatureHelpProvider [] (serviceProvi sourceText: SourceText, caretPosition: int, adjustedColumnInSource: int, - filePath: string + filePath: string, + editorOptions: EditorOptions ) = asyncMaybe { let textLine = sourceText.Lines.GetLineFromPosition(adjustedColumnInSource) @@ -430,7 +434,8 @@ type internal FSharpSignatureHelpProvider [] (serviceProvi typeParameterMap.Add, usage.Add, exceptions.Add, - tooltip + tooltip, + editorOptions.QuickInfo.ShowRemarks ) let fsharpDocs = @@ -606,7 +611,8 @@ type internal FSharpSignatureHelpProvider [] (serviceProvi documentationBuilder: IDocumentationBuilder, caretPosition: int, triggerTypedChar: char option, - possibleCurrentSignatureHelpSessionKind: CurrentSignatureHelpSessionKind option + possibleCurrentSignatureHelpSessionKind: CurrentSignatureHelpSessionKind option, + editorOptions: EditorOptions ) = asyncMaybe { @@ -655,7 +661,8 @@ type internal FSharpSignatureHelpProvider [] (serviceProvi sourceText, caretPosition, adjustedColumnInSource, - document.FilePath + document.FilePath, + editorOptions ) | _, Some FunctionApplication when adjustedColumnChar <> ',' @@ -674,7 +681,8 @@ type internal FSharpSignatureHelpProvider [] (serviceProvi sourceText, caretPosition, adjustedColumnInSource, - document.FilePath + document.FilePath, + editorOptions ) | _ -> let! paramInfoLocations = parseResults.FindParameterLocations(Position.fromZ caretLinePos.Line caretLineColumn) @@ -688,7 +696,8 @@ type internal FSharpSignatureHelpProvider [] (serviceProvi documentationBuilder, sourceText, caretPosition, - triggerTypedChar + triggerTypedChar, + editorOptions ) } @@ -722,7 +731,8 @@ type internal FSharpSignatureHelpProvider [] (serviceProvi documentationBuilder, position, triggerTypedChar, - possibleCurrentSignatureHelpSessionKind + possibleCurrentSignatureHelpSessionKind, + editorOptions ) match signatureHelpDataOpt with diff --git a/vsintegration/src/FSharp.Editor/DocComments/XMLDocumentation.fs b/vsintegration/src/FSharp.Editor/DocComments/XMLDocumentation.fs index 89a290dbbef..bd91c5f1212 100644 --- a/vsintegration/src/FSharp.Editor/DocComments/XMLDocumentation.fs +++ b/vsintegration/src/FSharp.Editor/DocComments/XMLDocumentation.fs @@ -100,6 +100,7 @@ type internal IDocumentationBuilder = processedXml: string * showExceptions: bool * showParameters: bool * + showRemarks: bool * paramName: string option -> unit @@ -111,6 +112,7 @@ type internal IDocumentationBuilder = signature: string * showExceptions: bool * showParameters: bool * + showRemarks: bool * paramName: string option -> unit @@ -211,30 +213,34 @@ module internal XmlDocumentation = with _ -> None - member _.CollectSummary(collector: ITaggedTextCollector) = + member _.CollectSummary(collector: ITaggedTextCollector, showRemarks) = match Seq.tryHead (doc.Descendants(XName.op_Implicit "summary")) with | None -> () | Some el -> EnsureHardLine collector WriteElement collector el - match Seq.tryHead (doc.Descendants(XName.op_Implicit "remarks")) with - | None -> () - | Some el -> - AppendHardLine collector - AppendOnNewLine collector (SR.RemarksHeader()) - AppendHardLine collector - WriteElement collector el - match Seq.tryHead (doc.Descendants(XName.op_Implicit "returns")) with | None -> () | Some el -> + AppendHardLine collector AppendHardLine collector AppendOnNewLine collector (SR.ReturnsHeader()) AppendHardLine collector collector.Add(tagSpace " ") WriteElement collector el + if showRemarks then + match Seq.tryHead (doc.Descendants(XName.op_Implicit "remarks")) with + | None -> () + | Some el -> + AppendHardLine collector + AppendHardLine collector + AppendOnNewLine collector (SR.RemarksHeader()) + AppendHardLine collector + collector.Add(tagSpace " ") + WriteElement collector el + member this.CollectParameter(collector: ITaggedTextCollector, paramName: string) = match tryFindParameter paramName with | None -> () @@ -312,11 +318,12 @@ module internal XmlDocumentation = exnCollector: ITaggedTextCollector, xmlDocReader: XmlDocReader, showExceptions, - showParameters + showParameters, + showRemarks ) = AppendHardLine xmlCollector xmlCollector.StartXMLDoc() - xmlDocReader.CollectSummary(xmlCollector) + xmlDocReader.CollectSummary(xmlCollector, showRemarks) if (showParameters) then xmlDocReader.CollectParameters xmlCollector @@ -333,13 +340,14 @@ module internal XmlDocumentation = processedXml, showExceptions, showParameters, + showRemarks, paramName ) = match XmlDocReader.TryCreate processedXml with | Some xmlDocReader -> match paramName with | Some paramName -> xmlDocReader.CollectParameter(xmlCollector, paramName) - | None -> AppendMemberData(xmlCollector, exnCollector, xmlDocReader, showExceptions, showParameters) + | None -> AppendMemberData(xmlCollector, exnCollector, xmlDocReader, showExceptions, showParameters, showRemarks) | None -> () /// Append Xml documentation contents into the StringBuilder @@ -351,6 +359,7 @@ module internal XmlDocumentation = signature: string, showExceptions: bool, showParameters: bool, + showRemarks, paramName: string option ) = try @@ -369,6 +378,7 @@ module internal XmlDocumentation = xml, showExceptions, showParameters, + showRemarks, paramName ) | None -> () @@ -385,6 +395,7 @@ module internal XmlDocumentation = xml, showExceptions, showParameters, + showRemarks, paramName ) = match xml with @@ -397,6 +408,7 @@ module internal XmlDocumentation = signature, showExceptions, showParameters, + showRemarks, paramName ) | FSharpXmlDoc.FromXmlText(xmlDoc) -> @@ -409,6 +421,7 @@ module internal XmlDocumentation = processedXml, showExceptions, showParameters, + showRemarks, paramName ) @@ -435,7 +448,7 @@ module internal XmlDocumentation = OverLoadsLimit = 5 } - let BuildSingleTipText (documentationProvider: IDocumentationBuilder, dataTipElement: ToolTipElement, limits: LineLimits) = + let BuildSingleTipText (documentationProvider: IDocumentationBuilder, dataTipElement: ToolTipElement, limits: LineLimits, showRemarks: bool) = let { LineLimit = lineLimit @@ -499,7 +512,7 @@ module internal XmlDocumentation = AppendHardLine usageCollector r |> Seq.iter usageCollector.Add) - AppendXmlComment(documentationProvider, xmlCollector, exnCollector, item0.XmlDoc, true, false, item0.ParamName) + AppendXmlComment(documentationProvider, xmlCollector, exnCollector, item0.XmlDoc, true, false, showRemarks, item0.ParamName) ProcessGenericParameters item0.TypeMapping @@ -523,7 +536,8 @@ module internal XmlDocumentation = exnCollector, showText, showExceptions, - showParameters + showParameters, + showRemarks ) = let textCollector: ITaggedTextCollector = TextSanitizingCollector(textCollector, lineLimit = 45) :> _ @@ -608,6 +622,7 @@ module internal XmlDocumentation = item0.XmlDoc, showExceptions, showParameters, + showRemarks, item0.ParamName ) @@ -632,7 +647,8 @@ module internal XmlDocumentation = typeParameterMapCollector, usageCollector, exnCollector, - ToolTipText(dataTipText) + ToolTipText(dataTipText), + showRemarks ) = BuildTipText( documentationProvider, @@ -644,10 +660,11 @@ module internal XmlDocumentation = exnCollector, true, true, - false + false, + showRemarks ) - let BuildMethodOverloadTipText (documentationProvider, textCollector, xmlCollector, ToolTipText(dataTipText), showParams) = + let BuildMethodOverloadTipText (documentationProvider, textCollector, xmlCollector, ToolTipText(dataTipText), showParams, showRemarks) = BuildTipText( documentationProvider, dataTipText, @@ -658,10 +675,11 @@ module internal XmlDocumentation = ignore, false, false, - showParams + showParams, + showRemarks ) - let BuildMethodParamText (documentationProvider, xmlCollector, xml, paramName) = + let BuildMethodParamText (documentationProvider, xmlCollector, xml, paramName, showRemarks) = AppendXmlComment( documentationProvider, TextSanitizingCollector(xmlCollector), @@ -669,6 +687,7 @@ module internal XmlDocumentation = xml, false, true, + showRemarks, Some paramName ) diff --git a/vsintegration/src/FSharp.Editor/FSharp.Editor.resx b/vsintegration/src/FSharp.Editor/FSharp.Editor.resx index 6492f005335..41b80965895 100644 --- a/vsintegration/src/FSharp.Editor/FSharp.Editor.resx +++ b/vsintegration/src/FSharp.Editor/FSharp.Editor.resx @@ -180,7 +180,8 @@ Navigation links; Show navigation links as; Solid underline; Dot underline; -Dash underline; +Dash underline; +Show remarks in Quick Info Add an assembly reference to '{0}' diff --git a/vsintegration/src/FSharp.Editor/Options/EditorOptions.fs b/vsintegration/src/FSharp.Editor/Options/EditorOptions.fs index c531d386af3..250565319e7 100644 --- a/vsintegration/src/FSharp.Editor/Options/EditorOptions.fs +++ b/vsintegration/src/FSharp.Editor/Options/EditorOptions.fs @@ -46,6 +46,7 @@ type QuickInfoOptions = DisplayLinks: bool UnderlineStyle: QuickInfoUnderlineStyle DescriptionWidth: int option + ShowRemarks: bool } static member Default = @@ -53,6 +54,7 @@ type QuickInfoOptions = DisplayLinks = true UnderlineStyle = QuickInfoUnderlineStyle.Solid DescriptionWidth = None + ShowRemarks = true } [] @@ -199,6 +201,7 @@ module internal OptionsUI = bindRadioButton view.dash path QuickInfoUnderlineStyle.Dash bindCheckBox view.displayLinks (nameof QuickInfoOptions.Default.DisplayLinks) bindDescriptionWidthTextBox view.descriptionWidth (nameof QuickInfoOptions.Default.DescriptionWidth) + bindCheckBox view.showRemarks (nameof QuickInfoOptions.Default.ShowRemarks) upcast view [] diff --git a/vsintegration/src/FSharp.Editor/QuickInfo/QuickInfoProvider.fs b/vsintegration/src/FSharp.Editor/QuickInfo/QuickInfoProvider.fs index ae79300ee85..e93c6bad038 100644 --- a/vsintegration/src/FSharp.Editor/QuickInfo/QuickInfoProvider.fs +++ b/vsintegration/src/FSharp.Editor/QuickInfo/QuickInfoProvider.fs @@ -31,7 +31,7 @@ type internal FSharpAsyncQuickInfoSource let getSingleContent (data: ToolTipElement) = let symbol, description, documentation = - XmlDocumentation.BuildSingleTipText(documentationBuilder, data, XmlDocumentation.DefaultLineLimits) + XmlDocumentation.BuildSingleTipText(documentationBuilder, data, XmlDocumentation.DefaultLineLimits, editorOptions.QuickInfo.ShowRemarks) let getLinkTooltip filePath = let solutionDir = Path.GetDirectoryName(document.Project.Solution.FilePath) diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.cs.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.cs.xlf index 55148d4c883..7f90ad6a126 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.cs.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.cs.xlf @@ -195,8 +195,9 @@ Navigation links; Show navigation links as; Solid underline; Dot underline; -Dash underline; - Formátování; +Dash underline; +Show remarks in Quick Info + Formátování; Upřednostňovaná šířka popisu ve znacích; Formátování podpisu na danou šířku přidáním konců řádků podle pravidel syntaxe F#; Navigační odkazy; diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.de.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.de.xlf index 28f0da28f7c..5e5261ef993 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.de.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.de.xlf @@ -195,8 +195,9 @@ Navigation links; Show navigation links as; Solid underline; Dot underline; -Dash underline; - Formatierung; +Dash underline; +Show remarks in Quick Info + Formatierung; Bevorzugte Beschreibungsbreite in Zeichen; Signatur in der angegebenen Breite formatieren, indem Zeilenumbrüche hinzugefügt werden, die den F#-Syntaxregeln entsprechen; Navigationslinks; diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.es.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.es.xlf index 970764d23d5..f130a461216 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.es.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.es.xlf @@ -197,8 +197,9 @@ Navigation links; Show navigation links as; Solid underline; Dot underline; -Dash underline; - Formato; +Dash underline; +Show remarks in Quick Info + Formato; Ancho de descripción preferido en caracteres; Dar formato a la firma con el ancho dado agregando saltos de línea que cumplan las reglas de sintaxis de F#; Vínculos de navegación; diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.fr.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.fr.xlf index 4e2f0f4f26f..a3bc317a6af 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.fr.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.fr.xlf @@ -195,8 +195,9 @@ Navigation links; Show navigation links as; Solid underline; Dot underline; -Dash underline; - Formatage; +Dash underline; +Show remarks in Quick Info + Formatage; Largeur de description préférée en caractères ; Mettre en forme la signature à la largeur donnée en ajoutant des sauts de ligne conformes aux règles de syntaxe F# ; Liens de navigation ; diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.it.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.it.xlf index dc380aa10f7..45fbdd6637c 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.it.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.it.xlf @@ -195,8 +195,9 @@ Navigation links; Show navigation links as; Solid underline; Dot underline; -Dash underline; - Formattazione; +Dash underline; +Show remarks in Quick Info + Formattazione; Larghezza descrizione preferita in caratteri; Formatta la firma in base alla larghezza specificata aggiungendo interruzioni di riga conformi alle regole di sintassi F#; Collegamenti di spostamento; diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ja.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ja.xlf index 535d8e37a29..09a35c432c9 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ja.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ja.xlf @@ -195,8 +195,9 @@ Navigation links; Show navigation links as; Solid underline; Dot underline; -Dash underline; - 書式 設定; +Dash underline; +Show remarks in Quick Info + 書式 設定; 希望の説明の幅 (文字数); F# 構文規則に準拠するよう、改行を追加して指定された幅に署名を書式設定します; ナビゲーション リンク; diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ko.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ko.xlf index 916cd46ccd6..32499ff0771 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ko.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ko.xlf @@ -196,8 +196,9 @@ Navigation links; Show navigation links as; Solid underline; Dot underline; -Dash underline; - 서식; +Dash underline; +Show remarks in Quick Info + 서식; 기본 설정 문자 설명 너비; F# 구문 규칙에 맞는 줄바꿈을 추가하여 지정된 너비에 서명 서식 지정; 탐색 링크; diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.pl.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.pl.xlf index 666a671e084..589adf994b9 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.pl.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.pl.xlf @@ -195,8 +195,9 @@ Navigation links; Show navigation links as; Solid underline; Dot underline; -Dash underline; - Formatowanie; +Dash underline; +Show remarks in Quick Info + Formatowanie; Preferowana szerokość opisu w znakach; Sformatuj sygnaturę na daną szerokość, dodając podziały wierszy zgodne z regułami składni języka F#; Linki nawigacji; diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.pt-BR.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.pt-BR.xlf index 31d6ac6224e..8234f5190c7 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.pt-BR.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.pt-BR.xlf @@ -195,8 +195,9 @@ Navigation links; Show navigation links as; Solid underline; Dot underline; -Dash underline; - Formatação; +Dash underline; +Show remarks in Quick Info + Formatação; Largura da descrição preferida em caracteres; Formate a assinatura para a largura especificada adicionando quebras de linha em conformidade com as regras de sintaxe do F#; Links de navegação; diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ru.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ru.xlf index 6e1037606f0..d6447a61572 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ru.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ru.xlf @@ -195,8 +195,9 @@ Navigation links; Show navigation links as; Solid underline; Dot underline; -Dash underline; - Форматирование; +Dash underline; +Show remarks in Quick Info + Форматирование; Предпочитаемая ширина описания в символах; Форматирование подписи до заданной ширины путем добавления разрывов строк в соответствии с правилами синтаксиса F#; Ссылки навигации; diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.tr.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.tr.xlf index 900381fd586..56c3ca4e2d4 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.tr.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.tr.xlf @@ -195,8 +195,9 @@ Navigation links; Show navigation links as; Solid underline; Dot underline; -Dash underline; - Biçimlendirme; +Dash underline; +Show remarks in Quick Info + Biçimlendirme; Karakter olarak tercih edilen açıklama genişliği; F# söz dizimi kurallarına uyan satır sonları ekleyerek imzayı verilen genişliğe biçimlendir; Gezinti bağlantıları; diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.zh-Hans.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.zh-Hans.xlf index 705a1e08771..80d8c8362cc 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.zh-Hans.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.zh-Hans.xlf @@ -195,8 +195,9 @@ Navigation links; Show navigation links as; Solid underline; Dot underline; -Dash underline; - 格式设置; +Dash underline; +Show remarks in Quick Info + 格式设置; 首选描述宽度 (以字符为单位); 通过添加符合 F# 语法规则的换行符,将签名格式设置为指定宽度; 导航链接; diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.zh-Hant.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.zh-Hant.xlf index 1845cc6940a..31b2ea7cec2 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.zh-Hant.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.zh-Hant.xlf @@ -195,8 +195,9 @@ Navigation links; Show navigation links as; Solid underline; Dot underline; -Dash underline; - 格式化; +Dash underline; +Show remarks in Quick Info + 格式化; 慣用描述寬度 (以字元為單位); 透過新增符合 F# 語法規則的分行符號,將簽章格式設定為指定寬度; 瀏覽連結; diff --git a/vsintegration/src/FSharp.UIResources/QuickInfoOptionControl.xaml b/vsintegration/src/FSharp.UIResources/QuickInfoOptionControl.xaml index 528aa32b1cf..6b7c6531f48 100644 --- a/vsintegration/src/FSharp.UIResources/QuickInfoOptionControl.xaml +++ b/vsintegration/src/FSharp.UIResources/QuickInfoOptionControl.xaml @@ -1,16 +1,19 @@ - + - + @@ -20,21 +23,36 @@ - + - - - - + + + + + + + diff --git a/vsintegration/src/FSharp.UIResources/Strings.Designer.cs b/vsintegration/src/FSharp.UIResources/Strings.Designer.cs index a7bcaa08413..57b599de866 100644 --- a/vsintegration/src/FSharp.UIResources/Strings.Designer.cs +++ b/vsintegration/src/FSharp.UIResources/Strings.Designer.cs @@ -1,10 +1,10 @@ //------------------------------------------------------------------------------ // -// This code was generated by a tool. -// Runtime Version:4.0.30319.42000 +// 此代码由工具生成。 +// 运行时版本:4.0.30319.42000 // -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将会丢失。 // //------------------------------------------------------------------------------ @@ -13,12 +13,12 @@ namespace Microsoft.VisualStudio.FSharp.UIResources { /// - /// A strongly-typed resource class, for looking up localized strings, etc. + /// 一个强类型的资源类,用于查找本地化的字符串等。 /// - // This class was auto-generated by the StronglyTypedResourceBuilder - // class via a tool like ResGen or Visual Studio. - // To add or remove a member, edit your .ResX file then rerun ResGen - // with the /str option, or rebuild your VS project. + // 此类是由 StronglyTypedResourceBuilder + // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 + // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen + // (以 /str 作为命令选项),或重新生成 VS 项目。 [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] @@ -33,7 +33,7 @@ internal Strings() { } /// - /// Returns the cached ResourceManager instance used by this class. + /// 返回此类使用的缓存的 ResourceManager 实例。 /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] public static global::System.Resources.ResourceManager ResourceManager { @@ -47,8 +47,8 @@ internal Strings() { } /// - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. + /// 重写当前线程的 CurrentUICulture 属性,对 + /// 使用此强类型资源类的所有资源查找执行重写。 /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] public static global::System.Globalization.CultureInfo Culture { @@ -61,7 +61,7 @@ internal Strings() { } /// - /// Looks up a localized string similar to Additional performance telemetry (experimental). + /// 查找类似 Additional performance telemetry (experimental) 的本地化字符串。 /// public static string AdditionalTelemetry { get { @@ -70,7 +70,7 @@ public static string AdditionalTelemetry { } /// - /// Looks up a localized string similar to Always place open statements at the top level. + /// 查找类似 Always place open statements at the top level 的本地化字符串。 /// public static string Always_place_opens_at_top_level { get { @@ -79,7 +79,7 @@ public static string Always_place_opens_at_top_level { } /// - /// Looks up a localized string similar to Keep analyzing the entire solution for diagnostics as a low priority background task (requires restart). + /// 查找类似 Keep analyzing the entire solution for diagnostics as a low priority background task (requires restart) 的本地化字符串。 /// public static string Analyze_full_solution_on_background { get { @@ -88,7 +88,7 @@ public static string Analyze_full_solution_on_background { } /// - /// Looks up a localized string similar to Background analysis. + /// 查找类似 Background analysis 的本地化字符串。 /// public static string Background_analysis { get { @@ -97,7 +97,7 @@ public static string Background_analysis { } /// - /// Looks up a localized string similar to Block Structure Guides. + /// 查找类似 Block Structure Guides 的本地化字符串。 /// public static string Block_Structure { get { @@ -106,7 +106,7 @@ public static string Block_Structure { } /// - /// Looks up a localized string similar to Code Fixes. + /// 查找类似 Code Fixes 的本地化字符串。 /// public static string Code_Fixes { get { @@ -115,7 +115,7 @@ public static string Code_Fixes { } /// - /// Looks up a localized string similar to Completion Lists. + /// 查找类似 Completion Lists 的本地化字符串。 /// public static string Completion_Lists { get { @@ -124,7 +124,7 @@ public static string Completion_Lists { } /// - /// Looks up a localized string similar to D_ash underline. + /// 查找类似 D_ash underline 的本地化字符串。 /// public static string Dash_underline { get { @@ -133,7 +133,7 @@ public static string Dash_underline { } /// - /// Looks up a localized string similar to Diagnostics. + /// 查找类似 Diagnostics 的本地化字符串。 /// public static string Diagnostics { get { @@ -142,7 +142,7 @@ public static string Diagnostics { } /// - /// Looks up a localized string similar to D_ot underline. + /// 查找类似 D_ot underline 的本地化字符串。 /// public static string Dot_underline { get { @@ -151,7 +151,7 @@ public static string Dot_underline { } /// - /// Looks up a localized string similar to Keep background symbol keys. + /// 查找类似 Keep background symbol keys 的本地化字符串。 /// public static string Enable_Background_ItemKeyStore_And_Semantic_Classification { get { @@ -160,7 +160,7 @@ public static string Enable_Background_ItemKeyStore_And_Semantic_Classification } /// - /// Looks up a localized string similar to Enable fast find references & rename (experimental). + /// 查找类似 Enable fast find references & rename (experimental) 的本地化字符串。 /// public static string Enable_Fast_Find_References { get { @@ -169,7 +169,7 @@ public static string Enable_Fast_Find_References { } /// - /// Looks up a localized string similar to _Enable in-memory cross project references. + /// 查找类似 _Enable in-memory cross project references 的本地化字符串。 /// public static string Enable_in_memory_cross_project_references { get { @@ -178,7 +178,7 @@ public static string Enable_in_memory_cross_project_references { } /// - /// Looks up a localized string similar to Use live (unsaved) buffers for analysis (restart required). + /// 查找类似 Use live (unsaved) buffers for analysis (restart required) 的本地化字符串。 /// public static string Enable_Live_Buffers { get { @@ -187,7 +187,7 @@ public static string Enable_Live_Buffers { } /// - /// Looks up a localized string similar to Enable parallel reference resolution. + /// 查找类似 Enable parallel reference resolution 的本地化字符串。 /// public static string Enable_Parallel_Reference_Resolution { get { @@ -196,7 +196,7 @@ public static string Enable_Parallel_Reference_Resolution { } /// - /// Looks up a localized string similar to Enable partial type checking. + /// 查找类似 Enable partial type checking 的本地化字符串。 /// public static string Enable_partial_type_checking { get { @@ -205,7 +205,7 @@ public static string Enable_partial_type_checking { } /// - /// Looks up a localized string similar to Enable stale data for IntelliSense features. + /// 查找类似 Enable stale data for IntelliSense features 的本地化字符串。 /// public static string Enable_Stale_IntelliSense_Results { get { @@ -214,7 +214,7 @@ public static string Enable_Stale_IntelliSense_Results { } /// - /// Looks up a localized string similar to Always add new line on enter. + /// 查找类似 Always add new line on enter 的本地化字符串。 /// public static string Enter_key_always { get { @@ -223,7 +223,7 @@ public static string Enter_key_always { } /// - /// Looks up a localized string similar to Never add new line on enter. + /// 查找类似 Never add new line on enter 的本地化字符串。 /// public static string Enter_key_never { get { @@ -232,7 +232,7 @@ public static string Enter_key_never { } /// - /// Looks up a localized string similar to Only add new line on enter after end of fully typed word. + /// 查找类似 Only add new line on enter after end of fully typed word 的本地化字符串。 /// public static string Enter_key_only { get { @@ -241,7 +241,7 @@ public static string Enter_key_only { } /// - /// Looks up a localized string similar to Enter key behavior. + /// 查找类似 Enter key behavior 的本地化字符串。 /// public static string Enter_Key_Rule { get { @@ -250,7 +250,7 @@ public static string Enter_Key_Rule { } /// - /// Looks up a localized string similar to Find References Performance Options. + /// 查找类似 Find References Performance Options 的本地化字符串。 /// public static string Find_References_Performance { get { @@ -259,7 +259,7 @@ public static string Find_References_Performance { } /// - /// Looks up a localized string similar to Re-format indentation on paste (Experimental). + /// 查找类似 Re-format indentation on paste (Experimental) 的本地化字符串。 /// public static string Format_on_paste { get { @@ -268,7 +268,7 @@ public static string Format_on_paste { } /// - /// Looks up a localized string similar to Formatting. + /// 查找类似 Formatting 的本地化字符串。 /// public static string Formatting { get { @@ -277,7 +277,7 @@ public static string Formatting { } /// - /// Looks up a localized string similar to Inline Hints. + /// 查找类似 Inline Hints 的本地化字符串。 /// public static string Inline_Hints { get { @@ -286,7 +286,7 @@ public static string Inline_Hints { } /// - /// Looks up a localized string similar to IntelliSense Performance Options. + /// 查找类似 IntelliSense Performance Options 的本地化字符串。 /// public static string IntelliSense_Performance { get { @@ -295,7 +295,7 @@ public static string IntelliSense_Performance { } /// - /// Looks up a localized string similar to Keep all background intermediate resolutions (increases memory usage). + /// 查找类似 Keep all background intermediate resolutions (increases memory usage) 的本地化字符串。 /// public static string Keep_All_Background_Resolutions { get { @@ -304,7 +304,7 @@ public static string Keep_All_Background_Resolutions { } /// - /// Looks up a localized string similar to Keep all background symbol uses (increases memory usage). + /// 查找类似 Keep all background symbol uses (increases memory usage) 的本地化字符串。 /// public static string Keep_All_Background_Symbol_Uses { get { @@ -313,7 +313,7 @@ public static string Keep_All_Background_Symbol_Uses { } /// - /// Looks up a localized string similar to Performance. + /// 查找类似 Performance 的本地化字符串。 /// public static string Language_Service_Performance { get { @@ -322,7 +322,7 @@ public static string Language_Service_Performance { } /// - /// Looks up a localized string similar to Language service settings (advanced). + /// 查找类似 Language service settings (advanced) 的本地化字符串。 /// public static string Language_Service_Settings { get { @@ -331,7 +331,7 @@ public static string Language_Service_Settings { } /// - /// Looks up a localized string similar to Live Buffers. + /// 查找类似 Live Buffers 的本地化字符串。 /// public static string LiveBuffers { get { @@ -340,7 +340,7 @@ public static string LiveBuffers { } /// - /// Looks up a localized string similar to Navigation links. + /// 查找类似 Navigation links 的本地化字符串。 /// public static string Navigation_links { get { @@ -349,7 +349,7 @@ public static string Navigation_links { } /// - /// Looks up a localized string similar to Outlining. + /// 查找类似 Outlining 的本地化字符串。 /// public static string Outlining { get { @@ -358,7 +358,7 @@ public static string Outlining { } /// - /// Looks up a localized string similar to Parallelization (requires restart). + /// 查找类似 Parallelization (requires restart) 的本地化字符串。 /// public static string Parallelization { get { @@ -367,7 +367,7 @@ public static string Parallelization { } /// - /// Looks up a localized string similar to Preferred description width in characters. + /// 查找类似 Preferred description width in characters 的本地化字符串。 /// public static string Preferred_description_width_in_characters { get { @@ -376,7 +376,7 @@ public static string Preferred_description_width_in_characters { } /// - /// Looks up a localized string similar to F# Project and Caching Performance Options. + /// 查找类似 F# Project and Caching Performance Options 的本地化字符串。 /// public static string Project_Performance { get { @@ -385,7 +385,7 @@ public static string Project_Performance { } /// - /// Looks up a localized string similar to Remove unnecessary parentheses (experimental, might affect typing performance). + /// 查找类似 Remove unnecessary parentheses (experimental, might affect typing performance) 的本地化字符串。 /// public static string Remove_parens_code_fix { get { @@ -394,7 +394,7 @@ public static string Remove_parens_code_fix { } /// - /// Looks up a localized string similar to Send additional performance telemetry. + /// 查找类似 Send additional performance telemetry 的本地化字符串。 /// public static string Send_Additional_Telemetry { get { @@ -403,7 +403,7 @@ public static string Send_Additional_Telemetry { } /// - /// Looks up a localized string similar to Show s_ymbols in unopened namespaces. + /// 查找类似 Show s_ymbols in unopened namespaces 的本地化字符串。 /// public static string Show_all_symbols { get { @@ -412,7 +412,7 @@ public static string Show_all_symbols { } /// - /// Looks up a localized string similar to Show completion list after a character is _deleted. + /// 查找类似 Show completion list after a character is _deleted 的本地化字符串。 /// public static string Show_completion_list_after_a_character_is_deleted { get { @@ -421,7 +421,7 @@ public static string Show_completion_list_after_a_character_is_deleted { } /// - /// Looks up a localized string similar to _Show completion list after a character is typed. + /// 查找类似 _Show completion list after a character is typed 的本地化字符串。 /// public static string Show_completion_list_after_a_character_is_typed { get { @@ -430,7 +430,7 @@ public static string Show_completion_list_after_a_character_is_typed { } /// - /// Looks up a localized string similar to Show structure guidelines for F# code. + /// 查找类似 Show structure guidelines for F# code 的本地化字符串。 /// public static string Show_guides { get { @@ -439,7 +439,7 @@ public static string Show_guides { } /// - /// Looks up a localized string similar to Display inline parameter name hints (preview). + /// 查找类似 Display inline parameter name hints (preview) 的本地化字符串。 /// public static string Show_Inline_Parameter_Name_Hints { get { @@ -448,7 +448,7 @@ public static string Show_Inline_Parameter_Name_Hints { } /// - /// Looks up a localized string similar to Display inline type hints (preview). + /// 查找类似 Display inline type hints (preview) 的本地化字符串。 /// public static string Show_Inline_Type_Hints { get { @@ -457,7 +457,7 @@ public static string Show_Inline_Type_Hints { } /// - /// Looks up a localized string similar to S_how navigation links as. + /// 查找类似 S_how navigation links as 的本地化字符串。 /// public static string Show_navigation_links_as { get { @@ -466,7 +466,7 @@ public static string Show_navigation_links_as { } /// - /// Looks up a localized string similar to Show outlining and collapsible nodes for F# code. + /// 查找类似 Show outlining and collapsible nodes for F# code 的本地化字符串。 /// public static string Show_Outlining { get { @@ -475,7 +475,16 @@ public static string Show_Outlining { } /// - /// Looks up a localized string similar to Display return type hints (preview). + /// 查找类似 Show remarks in Quick Info 的本地化字符串。 + /// + public static string Show_remarks_in_Quick_Info { + get { + return ResourceManager.GetString("Show_remarks_in_Quick_Info", resourceCulture); + } + } + + /// + /// 查找类似 Display return type hints (preview) 的本地化字符串。 /// public static string Show_Return_Type_Hints { get { @@ -484,7 +493,7 @@ public static string Show_Return_Type_Hints { } /// - /// Looks up a localized string similar to Simplify names (remove unnecessary qualifiers). + /// 查找类似 Simplify names (remove unnecessary qualifiers) 的本地化字符串。 /// public static string Simplify_name_code_fix { get { @@ -493,7 +502,7 @@ public static string Simplify_name_code_fix { } /// - /// Looks up a localized string similar to _Solid underline. + /// 查找类似 _Solid underline 的本地化字符串。 /// public static string Solid_underline { get { @@ -502,7 +511,7 @@ public static string Solid_underline { } /// - /// Looks up a localized string similar to Suggest names for unresolved identifiers. + /// 查找类似 Suggest names for unresolved identifiers 的本地化字符串。 /// public static string Suggest_names_for_errors_code_fix { get { @@ -511,7 +520,7 @@ public static string Suggest_names_for_errors_code_fix { } /// - /// Looks up a localized string similar to Text hover. + /// 查找类似 Text hover 的本地化字符串。 /// public static string Text_hover { get { @@ -520,7 +529,7 @@ public static string Text_hover { } /// - /// Looks up a localized string similar to Time until stale results are used (in milliseconds). + /// 查找类似 Time until stale results are used (in milliseconds) 的本地化字符串。 /// public static string Time_until_stale_completion { get { @@ -529,7 +538,7 @@ public static string Time_until_stale_completion { } /// - /// Looks up a localized string similar to In-memory cross-project references store project-level data in memory to allow IDE features to work across projects.. + /// 查找类似 In-memory cross-project references store project-level data in memory to allow IDE features to work across projects. 的本地化字符串。 /// public static string Tooltip_in_memory_cross_project_references { get { @@ -538,7 +547,7 @@ public static string Tooltip_in_memory_cross_project_references { } /// - /// Looks up a localized string similar to Format signature to the given width by adding line breaks conforming with F# syntax rules. . + /// 查找类似 Format signature to the given width by adding line breaks conforming with F# syntax rules. 的本地化字符串。 /// public static string Tooltip_preferred_description_width_in_characters { get { @@ -547,7 +556,7 @@ public static string Tooltip_preferred_description_width_in_characters { } /// - /// Looks up a localized string similar to Analyze and suggest fixes for unused values. + /// 查找类似 Analyze and suggest fixes for unused values 的本地化字符串。 /// public static string Unused_declaration_code_fix { get { @@ -556,7 +565,7 @@ public static string Unused_declaration_code_fix { } /// - /// Looks up a localized string similar to Remove unused open statements. + /// 查找类似 Remove unused open statements 的本地化字符串。 /// public static string Unused_opens_code_fix { get { @@ -565,7 +574,7 @@ public static string Unused_opens_code_fix { } /// - /// Looks up a localized string similar to Cache parsing results (experimental). + /// 查找类似 Cache parsing results (experimental) 的本地化字符串。 /// public static string Use_syntax_tree_cache { get { diff --git a/vsintegration/src/FSharp.UIResources/Strings.resx b/vsintegration/src/FSharp.UIResources/Strings.resx index b1362651cb3..7feb60ef6ae 100644 --- a/vsintegration/src/FSharp.UIResources/Strings.resx +++ b/vsintegration/src/FSharp.UIResources/Strings.resx @@ -288,4 +288,7 @@ Remove unnecessary parentheses (experimental, might affect typing performance) + + Show remarks in Quick Info + \ No newline at end of file diff --git a/vsintegration/src/FSharp.UIResources/xlf/Strings.cs.xlf b/vsintegration/src/FSharp.UIResources/xlf/Strings.cs.xlf index 4c1afb7bca0..189f7ab0d47 100644 --- a/vsintegration/src/FSharp.UIResources/xlf/Strings.cs.xlf +++ b/vsintegration/src/FSharp.UIResources/xlf/Strings.cs.xlf @@ -177,6 +177,11 @@ Zo_brazit navigační odkazy jako + + Show remarks in Quick Info + Show remarks in Quick Info + + Simplify names (remove unnecessary qualifiers) Zjednodušit názvy (odebrat nepotřebné kvalifikátory) diff --git a/vsintegration/src/FSharp.UIResources/xlf/Strings.de.xlf b/vsintegration/src/FSharp.UIResources/xlf/Strings.de.xlf index f93c85b0afc..32aec995761 100644 --- a/vsintegration/src/FSharp.UIResources/xlf/Strings.de.xlf +++ b/vsintegration/src/FSharp.UIResources/xlf/Strings.de.xlf @@ -177,6 +177,11 @@ Navigationslink_s anzeigen als + + Show remarks in Quick Info + Show remarks in Quick Info + + Simplify names (remove unnecessary qualifiers) Namen vereinfachen (unnötige Qualifizierer entfernen) diff --git a/vsintegration/src/FSharp.UIResources/xlf/Strings.es.xlf b/vsintegration/src/FSharp.UIResources/xlf/Strings.es.xlf index 3b65a70284b..12f03e3d792 100644 --- a/vsintegration/src/FSharp.UIResources/xlf/Strings.es.xlf +++ b/vsintegration/src/FSharp.UIResources/xlf/Strings.es.xlf @@ -177,6 +177,11 @@ M_ostrar vínculos de navegación como + + Show remarks in Quick Info + Show remarks in Quick Info + + Simplify names (remove unnecessary qualifiers) Simplificar nombres (quitar calificadores innecesarios) diff --git a/vsintegration/src/FSharp.UIResources/xlf/Strings.fr.xlf b/vsintegration/src/FSharp.UIResources/xlf/Strings.fr.xlf index 1fcb58d38a5..2067c3e08fa 100644 --- a/vsintegration/src/FSharp.UIResources/xlf/Strings.fr.xlf +++ b/vsintegration/src/FSharp.UIResources/xlf/Strings.fr.xlf @@ -177,6 +177,11 @@ Affic_her les liens de navigation en tant que + + Show remarks in Quick Info + Show remarks in Quick Info + + Simplify names (remove unnecessary qualifiers) Simplifier les noms (supprimer les qualificateurs inutiles) diff --git a/vsintegration/src/FSharp.UIResources/xlf/Strings.it.xlf b/vsintegration/src/FSharp.UIResources/xlf/Strings.it.xlf index ac84a49ac04..2a1ab80eabf 100644 --- a/vsintegration/src/FSharp.UIResources/xlf/Strings.it.xlf +++ b/vsintegration/src/FSharp.UIResources/xlf/Strings.it.xlf @@ -177,6 +177,11 @@ M_ostra collegamenti di navigazione come + + Show remarks in Quick Info + Show remarks in Quick Info + + Simplify names (remove unnecessary qualifiers) Semplifica nomi (rimuovi qualificatori non necessari) diff --git a/vsintegration/src/FSharp.UIResources/xlf/Strings.ja.xlf b/vsintegration/src/FSharp.UIResources/xlf/Strings.ja.xlf index 76036894dcb..baf5e88d30c 100644 --- a/vsintegration/src/FSharp.UIResources/xlf/Strings.ja.xlf +++ b/vsintegration/src/FSharp.UIResources/xlf/Strings.ja.xlf @@ -177,6 +177,11 @@ 次としてナビゲーション リンクを表示する(_H) + + Show remarks in Quick Info + Show remarks in Quick Info + + Simplify names (remove unnecessary qualifiers) 名前の簡略化する (不要な修飾子の削除) diff --git a/vsintegration/src/FSharp.UIResources/xlf/Strings.ko.xlf b/vsintegration/src/FSharp.UIResources/xlf/Strings.ko.xlf index f166bba08f3..5da24f5085f 100644 --- a/vsintegration/src/FSharp.UIResources/xlf/Strings.ko.xlf +++ b/vsintegration/src/FSharp.UIResources/xlf/Strings.ko.xlf @@ -177,6 +177,11 @@ 탐색 링크를 다음으로 표시(_H) + + Show remarks in Quick Info + Show remarks in Quick Info + + Simplify names (remove unnecessary qualifiers) 이름 단순화(불필요한 한정자 제거) diff --git a/vsintegration/src/FSharp.UIResources/xlf/Strings.pl.xlf b/vsintegration/src/FSharp.UIResources/xlf/Strings.pl.xlf index c4d70ab3a1f..5a91da868dd 100644 --- a/vsintegration/src/FSharp.UIResources/xlf/Strings.pl.xlf +++ b/vsintegration/src/FSharp.UIResources/xlf/Strings.pl.xlf @@ -177,6 +177,11 @@ P_okaż linki nawigacyjne jako + + Show remarks in Quick Info + Show remarks in Quick Info + + Simplify names (remove unnecessary qualifiers) Uprość nazwy (usuń niepotrzebne kwalifikatory) diff --git a/vsintegration/src/FSharp.UIResources/xlf/Strings.pt-BR.xlf b/vsintegration/src/FSharp.UIResources/xlf/Strings.pt-BR.xlf index f1ef03e827e..6070faefdac 100644 --- a/vsintegration/src/FSharp.UIResources/xlf/Strings.pt-BR.xlf +++ b/vsintegration/src/FSharp.UIResources/xlf/Strings.pt-BR.xlf @@ -177,6 +177,11 @@ E_xibir link de navegação como + + Show remarks in Quick Info + Show remarks in Quick Info + + Simplify names (remove unnecessary qualifiers) Simplificar nomes (remover qualificadores desnecessários) diff --git a/vsintegration/src/FSharp.UIResources/xlf/Strings.ru.xlf b/vsintegration/src/FSharp.UIResources/xlf/Strings.ru.xlf index 4db5610e9bb..25fa5e80a5c 100644 --- a/vsintegration/src/FSharp.UIResources/xlf/Strings.ru.xlf +++ b/vsintegration/src/FSharp.UIResources/xlf/Strings.ru.xlf @@ -177,6 +177,11 @@ П_оказать ссылки навигации как + + Show remarks in Quick Info + Show remarks in Quick Info + + Simplify names (remove unnecessary qualifiers) Упростить имена (удалить ненужные квалификаторы) diff --git a/vsintegration/src/FSharp.UIResources/xlf/Strings.tr.xlf b/vsintegration/src/FSharp.UIResources/xlf/Strings.tr.xlf index 95fa383de7e..2cd920230c9 100644 --- a/vsintegration/src/FSharp.UIResources/xlf/Strings.tr.xlf +++ b/vsintegration/src/FSharp.UIResources/xlf/Strings.tr.xlf @@ -177,6 +177,11 @@ Gezinti bağlantılarını farklı _göster + + Show remarks in Quick Info + Show remarks in Quick Info + + Simplify names (remove unnecessary qualifiers) Adları basitleştir (gereksiz niteleyicileri kaldır) diff --git a/vsintegration/src/FSharp.UIResources/xlf/Strings.zh-Hans.xlf b/vsintegration/src/FSharp.UIResources/xlf/Strings.zh-Hans.xlf index 3b45fdaf529..fefc112127e 100644 --- a/vsintegration/src/FSharp.UIResources/xlf/Strings.zh-Hans.xlf +++ b/vsintegration/src/FSharp.UIResources/xlf/Strings.zh-Hans.xlf @@ -177,6 +177,11 @@ 导航链接显示方式(_H) + + Show remarks in Quick Info + Show remarks in Quick Info + + Simplify names (remove unnecessary qualifiers) 简化名称(删除不必要的限定符) diff --git a/vsintegration/src/FSharp.UIResources/xlf/Strings.zh-Hant.xlf b/vsintegration/src/FSharp.UIResources/xlf/Strings.zh-Hant.xlf index 50aede6ee96..099946ca6a7 100644 --- a/vsintegration/src/FSharp.UIResources/xlf/Strings.zh-Hant.xlf +++ b/vsintegration/src/FSharp.UIResources/xlf/Strings.zh-Hant.xlf @@ -177,6 +177,11 @@ 顯示導覽連結為(_H) + + Show remarks in Quick Info + Show remarks in Quick Info + + Simplify names (remove unnecessary qualifiers) 簡化名稱 (移除不必要的限定詞) From d6d7a39a4a1a183e97a7b0714af23797b5cfcaca Mon Sep 17 00:00:00 2001 From: ijklam Date: Sun, 10 Dec 2023 12:57:16 +0800 Subject: [PATCH 03/25] format code --- .../Completion/CompletionProvider.fs | 18 ++++++++++++++++-- .../FSharp.Editor/Completion/SignatureHelp.fs | 2 +- .../DocComments/XMLDocumentation.fs | 8 +++++++- .../QuickInfo/QuickInfoProvider.fs | 7 ++++++- 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/vsintegration/src/FSharp.Editor/Completion/CompletionProvider.fs b/vsintegration/src/FSharp.Editor/Completion/CompletionProvider.fs index 09fbc90af46..a18987ac48c 100644 --- a/vsintegration/src/FSharp.Editor/Completion/CompletionProvider.fs +++ b/vsintegration/src/FSharp.Editor/Completion/CompletionProvider.fs @@ -26,7 +26,12 @@ open CancellableTasks module Logger = Microsoft.VisualStudio.FSharp.Editor.Logger type internal FSharpCompletionProvider - (workspace: Workspace, serviceProvider: SVsServiceProvider, assemblyContentProvider: AssemblyContentProvider, editorOptions: EditorOptions) = + ( + workspace: Workspace, + serviceProvider: SVsServiceProvider, + assemblyContentProvider: AssemblyContentProvider, + editorOptions: EditorOptions + ) = inherit FSharpCompletionProviderBase() @@ -380,7 +385,16 @@ type internal FSharpCompletionProvider let documentation = List() let collector = RoslynHelpers.CollectTaggedText documentation // mix main description and xmldoc by using one collector - XmlDocumentation.BuildDataTipText(documentationBuilder, collector, collector, collector, collector, collector, description, editorOptions.QuickInfo.ShowRemarks) + XmlDocumentation.BuildDataTipText( + documentationBuilder, + collector, + collector, + collector, + collector, + collector, + description, + editorOptions.QuickInfo.ShowRemarks + ) Task.FromResult(CompletionDescription.Create(documentation.ToImmutableArray())) | _ -> diff --git a/vsintegration/src/FSharp.Editor/Completion/SignatureHelp.fs b/vsintegration/src/FSharp.Editor/Completion/SignatureHelp.fs index b877026000e..a6d9a50dd60 100644 --- a/vsintegration/src/FSharp.Editor/Completion/SignatureHelp.fs +++ b/vsintegration/src/FSharp.Editor/Completion/SignatureHelp.fs @@ -611,7 +611,7 @@ type internal FSharpSignatureHelpProvider [] (serviceProvi documentationBuilder: IDocumentationBuilder, caretPosition: int, triggerTypedChar: char option, - possibleCurrentSignatureHelpSessionKind: CurrentSignatureHelpSessionKind option, + possibleCurrentSignatureHelpSessionKind: CurrentSignatureHelpSessionKind option, editorOptions: EditorOptions ) = asyncMaybe { diff --git a/vsintegration/src/FSharp.Editor/DocComments/XMLDocumentation.fs b/vsintegration/src/FSharp.Editor/DocComments/XMLDocumentation.fs index bd91c5f1212..b3228180ff2 100644 --- a/vsintegration/src/FSharp.Editor/DocComments/XMLDocumentation.fs +++ b/vsintegration/src/FSharp.Editor/DocComments/XMLDocumentation.fs @@ -448,7 +448,13 @@ module internal XmlDocumentation = OverLoadsLimit = 5 } - let BuildSingleTipText (documentationProvider: IDocumentationBuilder, dataTipElement: ToolTipElement, limits: LineLimits, showRemarks: bool) = + let BuildSingleTipText + ( + documentationProvider: IDocumentationBuilder, + dataTipElement: ToolTipElement, + limits: LineLimits, + showRemarks: bool + ) = let { LineLimit = lineLimit diff --git a/vsintegration/src/FSharp.Editor/QuickInfo/QuickInfoProvider.fs b/vsintegration/src/FSharp.Editor/QuickInfo/QuickInfoProvider.fs index e93c6bad038..581a6a7fef3 100644 --- a/vsintegration/src/FSharp.Editor/QuickInfo/QuickInfoProvider.fs +++ b/vsintegration/src/FSharp.Editor/QuickInfo/QuickInfoProvider.fs @@ -31,7 +31,12 @@ type internal FSharpAsyncQuickInfoSource let getSingleContent (data: ToolTipElement) = let symbol, description, documentation = - XmlDocumentation.BuildSingleTipText(documentationBuilder, data, XmlDocumentation.DefaultLineLimits, editorOptions.QuickInfo.ShowRemarks) + XmlDocumentation.BuildSingleTipText( + documentationBuilder, + data, + XmlDocumentation.DefaultLineLimits, + editorOptions.QuickInfo.ShowRemarks + ) let getLinkTooltip filePath = let solutionDir = Path.GetDirectoryName(document.Project.Solution.FilePath) From b940c49b72325830fcc746edad20cf1af97dac8b Mon Sep 17 00:00:00 2001 From: ijklam Date: Sun, 10 Dec 2023 14:19:28 +0800 Subject: [PATCH 04/25] fix tests --- .../FSharp.Editor.Tests/QuickInfoTests.fs | 6 ++--- .../SignatureHelpProviderTests.fs | 22 +++++++++++-------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/vsintegration/tests/FSharp.Editor.Tests/QuickInfoTests.fs b/vsintegration/tests/FSharp.Editor.Tests/QuickInfoTests.fs index 083a25a07cf..8b24af5f117 100644 --- a/vsintegration/tests/FSharp.Editor.Tests/QuickInfoTests.fs +++ b/vsintegration/tests/FSharp.Editor.Tests/QuickInfoTests.fs @@ -50,12 +50,12 @@ module QuickInfo = | Some(ToolTipText elements) when not elements.IsEmpty -> let documentationBuilder = { new IDocumentationBuilder with - override _.AppendDocumentationFromProcessedXML(_, _, _, _, _, _) = () - override _.AppendDocumentation(_, _, _, _, _, _, _) = () + override _.AppendDocumentationFromProcessedXML(_, _, _, _, _, _, _) = () + override _.AppendDocumentation(_, _, _, _, _, _, _, _) = () } let _, mainDescription, docs = - XmlDocumentation.BuildSingleTipText(documentationBuilder, elements.Head, XmlDocumentation.DefaultLineLimits) + XmlDocumentation.BuildSingleTipText(documentationBuilder, elements.Head, XmlDocumentation.DefaultLineLimits, true) let mainTextItems = mainDescription |> Seq.map (fun x -> x.Text) let docTextItems = docs |> Seq.map (fun x -> x.Text) diff --git a/vsintegration/tests/FSharp.Editor.Tests/SignatureHelpProviderTests.fs b/vsintegration/tests/FSharp.Editor.Tests/SignatureHelpProviderTests.fs index d062f26a0bd..1432583da08 100644 --- a/vsintegration/tests/FSharp.Editor.Tests/SignatureHelpProviderTests.fs +++ b/vsintegration/tests/FSharp.Editor.Tests/SignatureHelpProviderTests.fs @@ -16,8 +16,8 @@ open Microsoft.VisualStudio.FSharp.Editor.CancellableTasks module SignatureHelpProvider = let private DefaultDocumentationProvider = { new IDocumentationBuilder with - override doc.AppendDocumentationFromProcessedXML(_, _, _, _, _, _) = () - override doc.AppendDocumentation(_, _, _, _, _, _, _) = () + override doc.AppendDocumentationFromProcessedXML(_, _, _, _, _, _, _) = () + override doc.AppendDocumentation(_, _, _, _, _, _, _, _) = () } let checker = FSharpChecker.Create() @@ -56,7 +56,8 @@ module SignatureHelpProvider = DefaultDocumentationProvider, sourceText, caretPosition, - triggerChar + triggerChar, + EditorOptions() ) |> Async.RunSynchronously @@ -102,7 +103,7 @@ module SignatureHelpProvider = let document = RoslynTestHelpers.CreateSolution(fileContents) |> RoslynTestHelpers.GetSingleDocument - + let parseResults, checkFileResults = document.GetFSharpParseAndCheckResultsAsync("assertSignatureHelpForMethodCalls") |> CancellableTask.runSynchronouslyWithoutCancellation @@ -123,7 +124,8 @@ module SignatureHelpProvider = DefaultDocumentationProvider, sourceText, caretPosition, - triggerChar + triggerChar, + EditorOptions() ) |> Async.RunSynchronously @@ -175,7 +177,8 @@ module SignatureHelpProvider = sourceText, caretPosition, adjustedColumnInSource, - filePath + filePath, + EditorOptions() ) |> Async.RunSynchronously @@ -440,8 +443,8 @@ type foo5 = N1.T module ``Function argument applications`` = let private DefaultDocumentationProvider = { new IDocumentationBuilder with - override doc.AppendDocumentationFromProcessedXML(_, _, _, _, _, _) = () - override doc.AppendDocumentation(_, _, _, _, _, _, _) = () + override doc.AppendDocumentationFromProcessedXML(_, _, _, _, _, _, _) = () + override doc.AppendDocumentation(_, _, _, _, _, _, _, _) = () } [] @@ -518,7 +521,8 @@ M.f sourceText, caretPosition, adjustedColumnInSource, - filePath + filePath, + EditorOptions() ) |> Async.RunSynchronously From c5612f313d2cc1c42c4662feca5ba1e8667e5f8e Mon Sep 17 00:00:00 2001 From: ijklam Date: Sun, 10 Dec 2023 14:28:44 +0800 Subject: [PATCH 05/25] format code --- .../tests/FSharp.Editor.Tests/SignatureHelpProviderTests.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vsintegration/tests/FSharp.Editor.Tests/SignatureHelpProviderTests.fs b/vsintegration/tests/FSharp.Editor.Tests/SignatureHelpProviderTests.fs index 1432583da08..d4065f8a2b3 100644 --- a/vsintegration/tests/FSharp.Editor.Tests/SignatureHelpProviderTests.fs +++ b/vsintegration/tests/FSharp.Editor.Tests/SignatureHelpProviderTests.fs @@ -103,7 +103,7 @@ module SignatureHelpProvider = let document = RoslynTestHelpers.CreateSolution(fileContents) |> RoslynTestHelpers.GetSingleDocument - + let parseResults, checkFileResults = document.GetFSharpParseAndCheckResultsAsync("assertSignatureHelpForMethodCalls") |> CancellableTask.runSynchronouslyWithoutCancellation From ec0ae2d7ef6111455e7dcebdc479170b7f73514a Mon Sep 17 00:00:00 2001 From: ijklam Date: Fri, 29 Dec 2023 01:11:39 +0800 Subject: [PATCH 06/25] add bool partial active pattern --- src/Compiler/Checking/CheckExpressions.fs | 18 ++++++++++++++---- src/Compiler/Checking/NameResolution.fs | 6 ++++-- .../Checking/PatternMatchCompilation.fs | 14 +++++++++----- .../Checking/PatternMatchCompilation.fsi | 5 ++++- src/Compiler/FSComp.txt | 1 + src/Compiler/Facilities/LanguageFeatures.fs | 3 +++ src/Compiler/Facilities/LanguageFeatures.fsi | 1 + src/Compiler/TypedTree/TypedTree.fs | 11 +++++++++-- src/Compiler/TypedTree/TypedTree.fsi | 14 +++++++++++--- src/Compiler/TypedTree/TypedTreeOps.fs | 14 ++++++++++++-- src/Compiler/TypedTree/TypedTreeOps.fsi | 8 ++++++-- src/Compiler/xlf/FSComp.txt.cs.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.de.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.es.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.fr.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.it.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.ja.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.ko.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.pl.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.pt-BR.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.ru.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.tr.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.zh-Hans.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.zh-Hant.xlf | 5 +++++ 24 files changed, 139 insertions(+), 21 deletions(-) diff --git a/src/Compiler/Checking/CheckExpressions.fs b/src/Compiler/Checking/CheckExpressions.fs index 6f169d474a8..3aebde77f7a 100644 --- a/src/Compiler/Checking/CheckExpressions.fs +++ b/src/Compiler/Checking/CheckExpressions.fs @@ -10737,14 +10737,24 @@ and TcNormalizedBinding declKind (cenv: cenv) env tpenv overallTy safeThisValOpt | Some (apinfo, apOverallTy, _) -> let activePatResTys = NewInferenceTypes g apinfo.ActiveTags let _, apReturnTy = stripFunTy g apOverallTy + let apRetTy = + if isStructRetTy || isValueOptionTy cenv.g apReturnTy then ActivePatternReturnType.voption + elif isBoolTy cenv.g apReturnTy then ActivePatternReturnType.bool + else ActivePatternReturnType.option - if isStructRetTy && apinfo.IsTotal then + if apRetTy.IsStruct && apinfo.IsTotal then errorR(Error(FSComp.SR.tcInvalidStructReturn(), mBinding)) - - if isStructRetTy then + + match apRetTy with + | ActivePatternReturnType.bool -> + checkLanguageFeatureError g.langVersion LanguageFeature.BoolPartialActivePattern mBinding + | ActivePatternReturnType.voption when not isStructRetTy -> + checkLanguageFeatureError g.langVersion LanguageFeature.BoolPartialActivePattern mBinding + | ActivePatternReturnType.voption -> checkLanguageFeatureError g.langVersion LanguageFeature.StructActivePattern mBinding + | ActivePatternReturnType.option -> () - UnifyTypes cenv env mBinding (apinfo.ResultType g rhsExpr.Range activePatResTys isStructRetTy) apReturnTy + UnifyTypes cenv env mBinding (apinfo.ResultType g rhsExpr.Range activePatResTys apRetTy) apReturnTy | None -> if isStructRetTy then diff --git a/src/Compiler/Checking/NameResolution.fs b/src/Compiler/Checking/NameResolution.fs index 7b660d3d21d..abd975dac40 100644 --- a/src/Compiler/Checking/NameResolution.fs +++ b/src/Compiler/Checking/NameResolution.fs @@ -89,7 +89,7 @@ let ActivePatternElemsOfValRef g (vref: ValRef) = let isStructRetTy = if apinfo.IsTotal then - false + ActivePatternReturnType.option else let _, apReturnTy = stripFunTy g vref.TauType let hasStructAttribute() = @@ -97,7 +97,9 @@ let ActivePatternElemsOfValRef g (vref: ValRef) = |> List.exists (function | Attrib(targetsOpt = Some(System.AttributeTargets.ReturnValue)) as a -> IsMatchingFSharpAttribute g g.attrib_StructAttribute a | _ -> false) - isStructTy g apReturnTy || hasStructAttribute() + if isValueOptionTy g apReturnTy || hasStructAttribute() then ActivePatternReturnType.voption + elif isBoolTy g apReturnTy then ActivePatternReturnType.bool + else ActivePatternReturnType.option apinfo.ActiveTags |> List.mapi (fun i _ -> APElemRef(apinfo, vref, i, isStructRetTy)) | None -> [] diff --git a/src/Compiler/Checking/PatternMatchCompilation.fs b/src/Compiler/Checking/PatternMatchCompilation.fs index 3caacecb982..4ef531b4439 100644 --- a/src/Compiler/Checking/PatternMatchCompilation.fs +++ b/src/Compiler/Checking/PatternMatchCompilation.fs @@ -43,7 +43,7 @@ type Pattern = | TPat_as of Pattern * PatternValBinding * range (* note: can be replaced by TPat_var, i.e. equals TPat_conjs([TPat_var; pat]) *) | TPat_disjs of Pattern list * range | TPat_conjs of Pattern list * range - | TPat_query of (Expr * TType list * bool * (ValRef * TypeInst) option * int * ActivePatternInfo) * Pattern * range + | TPat_query of (Expr * TType list * ActivePatternReturnType * (ValRef * TypeInst) option * int * ActivePatternInfo) * Pattern * range | TPat_unioncase of UnionCaseRef * TypeInst * Pattern list * range | TPat_exnconstr of TyconRef * Pattern list * range | TPat_tuple of TupInfo * Pattern list * TType list * range @@ -1298,7 +1298,7 @@ let CompilePatternBasic let argExpr = GetSubExprOfInput subexpr let appExpr = mkApps g ((activePatExpr, tyOfExpr g activePatExpr), [], [argExpr], m) - let vOpt, addrExp, _readonly, _writeonly = mkExprAddrOfExprAux g isStructRetTy false NeverMutates appExpr None mMatch + let vOpt, addrExp, _readonly, _writeonly = mkExprAddrOfExprAux g (isStructRetTy = ActivePatternReturnType.voption) false NeverMutates appExpr None mMatch match vOpt with | None -> let v, vExpr = mkCompGenLocal m ("activePatternResult" + string (newUnique())) resTy @@ -1360,7 +1360,9 @@ let CompilePatternBasic if not total && aparity > 1 then error(Error(FSComp.SR.patcPartialActivePatternsGenerateOneResult(), m)) - if not total then DecisionTreeTest.UnionCase(mkAnySomeCase g isStructRetTy, resTys) + if not total then + if isStructRetTy = ActivePatternReturnType.bool then DecisionTreeTest.Const(Const.Bool true) + else DecisionTreeTest.UnionCase(mkAnySomeCase g isStructRetTy.IsStruct, resTys) elif aparity <= 1 then DecisionTreeTest.Const(Const.Unit) else DecisionTreeTest.UnionCase(mkChoiceCaseRef g m aparity idx, resTys) | _ -> discrim @@ -1460,10 +1462,12 @@ let CompilePatternBasic if i = iInvestigated then let subAccess _j tpinst _ = let expr = Option.get inpExprOpt - if isStructRetTy then + match isStructRetTy with + | ActivePatternReturnType.bool -> expr + | ActivePatternReturnType.voption -> // In this case, the inpExprOpt is already an address-of expression mkUnionCaseFieldGetProvenViaExprAddr (expr, mkValueSomeCase g, instTypes tpinst resTys, 0, mExpr) - else + | ActivePatternReturnType.option -> mkUnionCaseFieldGetUnprovenViaExprAddr (expr, mkSomeCase g, instTypes tpinst resTys, 0, mExpr) mkSubFrontiers path subAccess newActives [p] (fun path j -> PathQuery(path, int64 j)) else diff --git a/src/Compiler/Checking/PatternMatchCompilation.fsi b/src/Compiler/Checking/PatternMatchCompilation.fsi index 5b2d94c8ff5..d6ffc6e116e 100644 --- a/src/Compiler/Checking/PatternMatchCompilation.fsi +++ b/src/Compiler/Checking/PatternMatchCompilation.fsi @@ -27,7 +27,10 @@ type Pattern = | TPat_as of Pattern * PatternValBinding * range | TPat_disjs of Pattern list * range | TPat_conjs of Pattern list * range - | TPat_query of (Expr * TType list * bool * (ValRef * TypeInst) option * int * ActivePatternInfo) * Pattern * range + | TPat_query of + (Expr * TType list * ActivePatternReturnType * (ValRef * TypeInst) option * int * ActivePatternInfo) * + Pattern * + range | TPat_unioncase of UnionCaseRef * TypeInst * Pattern list * range | TPat_exnconstr of TyconRef * Pattern list * range | TPat_tuple of TupInfo * Pattern list * TType list * range diff --git a/src/Compiler/FSComp.txt b/src/Compiler/FSComp.txt index d0fad76ab36..06a19adb6a5 100644 --- a/src/Compiler/FSComp.txt +++ b/src/Compiler/FSComp.txt @@ -1592,6 +1592,7 @@ featurePreferExtensionMethodOverPlainProperty,"prefer extension method over plai featureWarningIndexedPropertiesGetSetSameType,"Indexed properties getter and setter must have the same type" featureChkTailCallAttrOnNonRec,"Raises warnings if the 'TailCall' attribute is used on non-recursive functions." featureUnionIsPropertiesVisible,"Union case test properties" +featureBoolPartialActivePattern,"bool representation for partial pctive pattern" 3354,tcNotAFunctionButIndexerNamedIndexingNotYetEnabled,"This value supports indexing, e.g. '%s.[index]'. The syntax '%s[index]' requires /langversion:preview. See https://aka.ms/fsharp-index-notation." 3354,tcNotAFunctionButIndexerIndexingNotYetEnabled,"This expression supports indexing, e.g. 'expr.[index]'. The syntax 'expr[index]' requires /langversion:preview. See https://aka.ms/fsharp-index-notation." 3355,tcNotAnIndexerNamedIndexingNotYetEnabled,"The value '%s' is not a function and does not support index notation." diff --git a/src/Compiler/Facilities/LanguageFeatures.fs b/src/Compiler/Facilities/LanguageFeatures.fs index 643224b904a..3a70ae6fb04 100644 --- a/src/Compiler/Facilities/LanguageFeatures.fs +++ b/src/Compiler/Facilities/LanguageFeatures.fs @@ -84,6 +84,7 @@ type LanguageFeature = | PreferExtensionMethodOverPlainProperty | WarningIndexedPropertiesGetSetSameType | WarningWhenTailCallAttrOnNonRec + | BoolPartialActivePattern /// LanguageVersion management type LanguageVersion(versionText) = @@ -195,6 +196,7 @@ type LanguageVersion(versionText) = LanguageFeature.WarningIndexedPropertiesGetSetSameType, previewVersion LanguageFeature.WarningWhenTailCallAttrOnNonRec, previewVersion LanguageFeature.UnionIsPropertiesVisible, previewVersion + LanguageFeature.BoolPartialActivePattern, previewVersion ] static let defaultLanguageVersion = LanguageVersion("default") @@ -336,6 +338,7 @@ type LanguageVersion(versionText) = | LanguageFeature.PreferExtensionMethodOverPlainProperty -> FSComp.SR.featurePreferExtensionMethodOverPlainProperty () | LanguageFeature.WarningIndexedPropertiesGetSetSameType -> FSComp.SR.featureWarningIndexedPropertiesGetSetSameType () | LanguageFeature.WarningWhenTailCallAttrOnNonRec -> FSComp.SR.featureChkTailCallAttrOnNonRec () + | LanguageFeature.BoolPartialActivePattern -> FSComp.SR.featureBoolPartialActivePattern () /// Get a version string associated with the given feature. static member GetFeatureVersionString feature = diff --git a/src/Compiler/Facilities/LanguageFeatures.fsi b/src/Compiler/Facilities/LanguageFeatures.fsi index 7af2317e3c3..e013215199b 100644 --- a/src/Compiler/Facilities/LanguageFeatures.fsi +++ b/src/Compiler/Facilities/LanguageFeatures.fsi @@ -75,6 +75,7 @@ type LanguageFeature = | PreferExtensionMethodOverPlainProperty | WarningIndexedPropertiesGetSetSameType | WarningWhenTailCallAttrOnNonRec + | BoolPartialActivePattern /// LanguageVersion management type LanguageVersion = diff --git a/src/Compiler/TypedTree/TypedTree.fs b/src/Compiler/TypedTree/TypedTree.fs index a0665d32212..7087252b79b 100644 --- a/src/Compiler/TypedTree/TypedTree.fs +++ b/src/Compiler/TypedTree/TypedTree.fs @@ -4553,6 +4553,13 @@ type DecisionTreeCase = member x.DebugText = x.ToString() override x.ToString() = sprintf "DecisionTreeCase(...)" + +[] +type ActivePatternReturnType = + | option + | voption + | bool + member this.IsStruct with get () = this <> option [] type DecisionTreeTest = @@ -4586,7 +4593,7 @@ type DecisionTreeTest = | ActivePatternCase of activePatExpr: Expr * activePatResTys: TTypes * - isStructRetTy: bool * + isStructRetTy: ActivePatternReturnType * activePatIdentity: (ValRef * TypeInst) option * idx: int * activePatternInfo: ActivePatternInfo @@ -4655,7 +4662,7 @@ type ActivePatternElemRef = activePatternInfo: ActivePatternInfo * activePatternVal: ValRef * caseIndex: int * - isStructRetTy: bool + isStructRetTy: ActivePatternReturnType /// Get the full information about the active pattern being referred to member x.ActivePatternInfo = (let (APElemRef(info, _, _, _)) = x in info) diff --git a/src/Compiler/TypedTree/TypedTree.fsi b/src/Compiler/TypedTree/TypedTree.fsi index 61674b35fa1..71981e9c776 100644 --- a/src/Compiler/TypedTree/TypedTree.fsi +++ b/src/Compiler/TypedTree/TypedTree.fsi @@ -3261,6 +3261,14 @@ type DecisionTreeCase = /// Get the discriminator associated with the case member Discriminator: DecisionTreeTest +[] +type ActivePatternReturnType = + | option + | voption + | bool + + member IsStruct: bool + [] type DecisionTreeTest = @@ -3294,7 +3302,7 @@ type DecisionTreeTest = | ActivePatternCase of activePatExpr: Expr * activePatResTys: TTypes * - isStructRetTy: bool * + isStructRetTy: ActivePatternReturnType * activePatIdentity: (ValRef * TypeInst) option * idx: int * activePatternInfo: Syntax.PrettyNaming.ActivePatternInfo @@ -3353,7 +3361,7 @@ type ActivePatternElemRef = activePatternInfo: Syntax.PrettyNaming.ActivePatternInfo * activePatternVal: ValRef * caseIndex: int * - isStructRetTy: bool + isStructRetTy: ActivePatternReturnType override ToString: unit -> string @@ -3370,7 +3378,7 @@ type ActivePatternElemRef = member DebugText: string /// Get a reference to the value for the active pattern being referred to - member IsStructReturn: bool + member IsStructReturn: ActivePatternReturnType /// Records the "extra information" for a value compiled as a method (rather /// than a closure or a local), including argument names, attributes etc. diff --git a/src/Compiler/TypedTree/TypedTreeOps.fs b/src/Compiler/TypedTree/TypedTreeOps.fs index 76e730eab6c..72ab507429a 100644 --- a/src/Compiler/TypedTree/TypedTreeOps.fs +++ b/src/Compiler/TypedTree/TypedTreeOps.fs @@ -3671,6 +3671,13 @@ let mkNullableTy (g: TcGlobals) ty = TType_app (g.system_Nullable_tcref, [ty], g let mkListTy (g: TcGlobals) ty = TType_app (g.list_tcr_nice, [ty], g.knownWithoutNull) +let isBoolTy (g: TcGlobals) ty = + match tryTcrefOfAppTy g ty with + | ValueNone -> false + | ValueSome tcref -> + tyconRefEq g g.system_Bool_tcref tcref || + tyconRefEq g g.bool_tcr tcref + let isValueOptionTy (g: TcGlobals) ty = match tryTcrefOfAppTy g ty with | ValueNone -> false @@ -9229,8 +9236,11 @@ type ActivePatternInfo with member apinfo.ResultType g m retTys isStruct = let choicety = mkChoiceTy g m retTys if apinfo.IsTotal then choicety - elif isStruct then mkValueOptionTy g choicety - else mkOptionTy g choicety + else + match isStruct with + | ActivePatternReturnType.option -> mkOptionTy g choicety + | ActivePatternReturnType.voption -> mkValueOptionTy g choicety + | ActivePatternReturnType.bool -> g.bool_ty member apinfo.OverallType g m argTy retTys isStruct = mkFunTy g argTy (apinfo.ResultType g m retTys isStruct) diff --git a/src/Compiler/TypedTree/TypedTreeOps.fsi b/src/Compiler/TypedTree/TypedTreeOps.fsi index 2345ac5eb40..4f08c1fced2 100755 --- a/src/Compiler/TypedTree/TypedTreeOps.fsi +++ b/src/Compiler/TypedTree/TypedTreeOps.fsi @@ -1528,6 +1528,9 @@ val mkVoidPtrTy: TcGlobals -> TType /// Build a single-dimensional array type val mkArrayType: TcGlobals -> TType -> TType +/// Determine if a type is a bool type +val isBoolTy: TcGlobals -> TType -> bool + /// Determine if a type is a value option type val isValueOptionTy: TcGlobals -> TType -> bool @@ -2449,10 +2452,11 @@ type PrettyNaming.ActivePatternInfo with member DisplayNameByIdx: idx: int -> string /// Get the result type for the active pattern - member ResultType: g: TcGlobals -> range -> TType list -> bool -> TType + member ResultType: g: TcGlobals -> range -> TType list -> ActivePatternReturnType -> TType /// Get the overall type for a function that implements the active pattern - member OverallType: g: TcGlobals -> m: range -> argTy: TType -> retTys: TType list -> isStruct: bool -> TType + member OverallType: + g: TcGlobals -> m: range -> argTy: TType -> retTys: TType list -> isStruct: ActivePatternReturnType -> TType val doesActivePatternHaveFreeTypars: TcGlobals -> ValRef -> bool diff --git a/src/Compiler/xlf/FSComp.txt.cs.xlf b/src/Compiler/xlf/FSComp.txt.cs.xlf index 07cccc56186..525f04dc252 100644 --- a/src/Compiler/xlf/FSComp.txt.cs.xlf +++ b/src/Compiler/xlf/FSComp.txt.cs.xlf @@ -242,6 +242,11 @@ automatické generování vlastnosti Message pro deklarace exception + + bool representation for partial pctive pattern + bool representation for partial pctive pattern + + Allow implicit Extension attribute on declaring types, modules Povolit implicitní atribut Extension pro deklarující typy, moduly diff --git a/src/Compiler/xlf/FSComp.txt.de.xlf b/src/Compiler/xlf/FSComp.txt.de.xlf index d9def2b9c6a..6f1a3aa3a4e 100644 --- a/src/Compiler/xlf/FSComp.txt.de.xlf +++ b/src/Compiler/xlf/FSComp.txt.de.xlf @@ -242,6 +242,11 @@ Automatische Generierung der Eigenschaft „Message“ für „exception“-Deklarationen + + bool representation for partial pctive pattern + bool representation for partial pctive pattern + + Allow implicit Extension attribute on declaring types, modules Implizites Erweiterungsattribut für deklarierende Typen und Module zulassen diff --git a/src/Compiler/xlf/FSComp.txt.es.xlf b/src/Compiler/xlf/FSComp.txt.es.xlf index 6a6959dc583..9f7dcb6c0f8 100644 --- a/src/Compiler/xlf/FSComp.txt.es.xlf +++ b/src/Compiler/xlf/FSComp.txt.es.xlf @@ -242,6 +242,11 @@ generación automática de la propiedad 'Message' para declaraciones 'exception' + + bool representation for partial pctive pattern + bool representation for partial pctive pattern + + Allow implicit Extension attribute on declaring types, modules Permitir atributo Extension implícito en tipos declarativo, módulos diff --git a/src/Compiler/xlf/FSComp.txt.fr.xlf b/src/Compiler/xlf/FSComp.txt.fr.xlf index 8bf1b97e9bc..78544ccefd9 100644 --- a/src/Compiler/xlf/FSComp.txt.fr.xlf +++ b/src/Compiler/xlf/FSComp.txt.fr.xlf @@ -242,6 +242,11 @@ génération automatique de la propriété « Message » pour les déclarations « exception » + + bool representation for partial pctive pattern + bool representation for partial pctive pattern + + Allow implicit Extension attribute on declaring types, modules Autoriser l’attribut implicite Extension lors de la déclaration des types, modules diff --git a/src/Compiler/xlf/FSComp.txt.it.xlf b/src/Compiler/xlf/FSComp.txt.it.xlf index 135dbc86cf4..d6ab1eaae62 100644 --- a/src/Compiler/xlf/FSComp.txt.it.xlf +++ b/src/Compiler/xlf/FSComp.txt.it.xlf @@ -242,6 +242,11 @@ generazione automatica della proprietà 'Messaggio' per le dichiarazioni 'eccezione' + + bool representation for partial pctive pattern + bool representation for partial pctive pattern + + Allow implicit Extension attribute on declaring types, modules Consentire l'attributo estensione implicito per i tipi dichiarabili, i moduli diff --git a/src/Compiler/xlf/FSComp.txt.ja.xlf b/src/Compiler/xlf/FSComp.txt.ja.xlf index c4e1d71a82f..72100254380 100644 --- a/src/Compiler/xlf/FSComp.txt.ja.xlf +++ b/src/Compiler/xlf/FSComp.txt.ja.xlf @@ -242,6 +242,11 @@ `exception` 宣言の `Message` プロパティの自動生成 + + bool representation for partial pctive pattern + bool representation for partial pctive pattern + + Allow implicit Extension attribute on declaring types, modules 型、モジュールの宣言で暗黙的な拡張属性を許可する diff --git a/src/Compiler/xlf/FSComp.txt.ko.xlf b/src/Compiler/xlf/FSComp.txt.ko.xlf index 4751ad79ebc..54f04c886f0 100644 --- a/src/Compiler/xlf/FSComp.txt.ko.xlf +++ b/src/Compiler/xlf/FSComp.txt.ko.xlf @@ -242,6 +242,11 @@ 'exception' 선언에 대한 'Message' 속성 자동 생성 + + bool representation for partial pctive pattern + bool representation for partial pctive pattern + + Allow implicit Extension attribute on declaring types, modules 유형, 모듈 선언에 암시적 확장 속성 허용 diff --git a/src/Compiler/xlf/FSComp.txt.pl.xlf b/src/Compiler/xlf/FSComp.txt.pl.xlf index 81d62979a4e..d00f903b21b 100644 --- a/src/Compiler/xlf/FSComp.txt.pl.xlf +++ b/src/Compiler/xlf/FSComp.txt.pl.xlf @@ -242,6 +242,11 @@ Automatyczne generowanie właściwości „Wiadomość“ dla deklaracji „Wyjątek“ + + bool representation for partial pctive pattern + bool representation for partial pctive pattern + + Allow implicit Extension attribute on declaring types, modules Zezwalaj na niejawny atrybut Rozszerzenie dla deklarujących typów, modułów diff --git a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf index 8cdbcdb29c4..2007cb0472b 100644 --- a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf +++ b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf @@ -242,6 +242,11 @@ geração automática da propriedade 'Message' para declarações de 'exception' + + bool representation for partial pctive pattern + bool representation for partial pctive pattern + + Allow implicit Extension attribute on declaring types, modules Permitir atributo de Extensão implícito em tipos declarativos, módulos diff --git a/src/Compiler/xlf/FSComp.txt.ru.xlf b/src/Compiler/xlf/FSComp.txt.ru.xlf index 1319210fbc9..462bf408caa 100644 --- a/src/Compiler/xlf/FSComp.txt.ru.xlf +++ b/src/Compiler/xlf/FSComp.txt.ru.xlf @@ -242,6 +242,11 @@ автоматическое создание свойства “Message” для объявлений “exception” + + bool representation for partial pctive pattern + bool representation for partial pctive pattern + + Allow implicit Extension attribute on declaring types, modules Разрешить атрибут неявного расширения для объявляющих типов, модулей diff --git a/src/Compiler/xlf/FSComp.txt.tr.xlf b/src/Compiler/xlf/FSComp.txt.tr.xlf index d9143a0db5d..da387d0268e 100644 --- a/src/Compiler/xlf/FSComp.txt.tr.xlf +++ b/src/Compiler/xlf/FSComp.txt.tr.xlf @@ -242,6 +242,11 @@ 'exception' bildirimleri için 'Message' özelliğinin otomatik olarak oluşturulması + + bool representation for partial pctive pattern + bool representation for partial pctive pattern + + Allow implicit Extension attribute on declaring types, modules Türler, modüller bildirirken örtük Extension özniteliğine izin ver diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf index c62c1e73f6c..2af5ce65b64 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf @@ -242,6 +242,11 @@ 自动生成“异常”声明的“消息”属性 + + bool representation for partial pctive pattern + bool representation for partial pctive pattern + + Allow implicit Extension attribute on declaring types, modules 允许对声明类型、模块使用隐式扩展属性 diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf index 5f66fcae4ea..83acbb641ec 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf @@ -242,6 +242,11 @@ 自動產生 'exception' 宣告的 'Message' 屬性 + + bool representation for partial pctive pattern + bool representation for partial pctive pattern + + Allow implicit Extension attribute on declaring types, modules 允許宣告類型、模組上的隱含擴充屬性 From ad146ce00f51ff3886434dc7be79445030487031 Mon Sep 17 00:00:00 2001 From: ijklam Date: Fri, 29 Dec 2023 23:15:15 +0800 Subject: [PATCH 07/25] fix cannot pass arguments to bool AP --- src/Compiler/Checking/CheckExpressions.fs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Compiler/Checking/CheckExpressions.fs b/src/Compiler/Checking/CheckExpressions.fs index bf23186ae9f..0ceb2fdad27 100644 --- a/src/Compiler/Checking/CheckExpressions.fs +++ b/src/Compiler/Checking/CheckExpressions.fs @@ -5085,7 +5085,8 @@ and TcPatLongIdentActivePatternCase warnOnUpper (cenv: cenv) (env: TcEnv) vFlags if dtys.Length = args.Length + 1 && ((isOptionTy g retTy && isUnitTy g (destOptionTy g retTy)) || - (isValueOptionTy g retTy && isUnitTy g (destValueOptionTy g retTy))) then + (isValueOptionTy g retTy && isUnitTy g (destValueOptionTy g retTy)) || + isBoolTy g retTy) then args, SynPat.Const(SynConst.Unit, m) else List.frontAndBack args From 8d5842b23648460d12ec3bd1afeb1b6b8d4bd8cc Mon Sep 17 00:00:00 2001 From: ijklam Date: Sat, 30 Dec 2023 10:07:13 +0800 Subject: [PATCH 08/25] `bool` partial AP always be treated as `unit option` --- src/Compiler/Checking/CheckExpressions.fs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Compiler/Checking/CheckExpressions.fs b/src/Compiler/Checking/CheckExpressions.fs index 0ceb2fdad27..85df7acb54a 100644 --- a/src/Compiler/Checking/CheckExpressions.fs +++ b/src/Compiler/Checking/CheckExpressions.fs @@ -5085,8 +5085,9 @@ and TcPatLongIdentActivePatternCase warnOnUpper (cenv: cenv) (env: TcEnv) vFlags if dtys.Length = args.Length + 1 && ((isOptionTy g retTy && isUnitTy g (destOptionTy g retTy)) || - (isValueOptionTy g retTy && isUnitTy g (destValueOptionTy g retTy)) || - isBoolTy g retTy) then + (isValueOptionTy g retTy && isUnitTy g (destValueOptionTy g retTy))) || + // `bool` partial AP always be treated as `unit option` + isBoolTy g retTy then args, SynPat.Const(SynConst.Unit, m) else List.frontAndBack args From 32432082616082dae9eeffaf18406fd61170d887 Mon Sep 17 00:00:00 2001 From: ijklam Date: Sat, 30 Dec 2023 22:45:52 +0800 Subject: [PATCH 09/25] rename code, add and fix tests --- src/Compiler/Checking/CheckExpressions.fs | 23 ++-- src/Compiler/Checking/NameResolution.fs | 8 +- .../Checking/PatternMatchCompilation.fs | 20 +-- .../Checking/PatternMatchCompilation.fsi | 2 +- src/Compiler/TypedTree/TypedTree.fs | 22 ++-- src/Compiler/TypedTree/TypedTree.fsi | 24 ++-- src/Compiler/TypedTree/TypedTreeOps.fs | 14 +-- src/Compiler/TypedTree/TypedTreeOps.fsi | 4 +- .../Types/StructTypes/StructActivePatterns.fs | 30 ++--- .../Language/BoolPartialActivePatternTests.fs | 115 ++++++++++++++++++ tests/fsharp/FSharpSuite.Tests.fsproj | 1 + 11 files changed, 192 insertions(+), 71 deletions(-) create mode 100644 tests/fsharp/Compiler/Language/BoolPartialActivePatternTests.fs diff --git a/src/Compiler/Checking/CheckExpressions.fs b/src/Compiler/Checking/CheckExpressions.fs index 85df7acb54a..a38826a392e 100644 --- a/src/Compiler/Checking/CheckExpressions.fs +++ b/src/Compiler/Checking/CheckExpressions.fs @@ -5087,7 +5087,7 @@ and TcPatLongIdentActivePatternCase warnOnUpper (cenv: cenv) (env: TcEnv) vFlags ((isOptionTy g retTy && isUnitTy g (destOptionTy g retTy)) || (isValueOptionTy g retTy && isUnitTy g (destValueOptionTy g retTy))) || // `bool` partial AP always be treated as `unit option` - isBoolTy g retTy then + (not apinfo.IsTotal && isBoolTy g retTy) then args, SynPat.Const(SynConst.Unit, m) else List.frontAndBack args @@ -10747,21 +10747,22 @@ and TcNormalizedBinding declKind (cenv: cenv) env tpenv overallTy safeThisValOpt let activePatResTys = NewInferenceTypes g apinfo.ActiveTags let _, apReturnTy = stripFunTy g apOverallTy let apRetTy = - if isStructRetTy || isValueOptionTy cenv.g apReturnTy then ActivePatternReturnType.voption - elif isBoolTy cenv.g apReturnTy then ActivePatternReturnType.bool - else ActivePatternReturnType.option - - if apRetTy.IsStruct && apinfo.IsTotal then - errorR(Error(FSComp.SR.tcInvalidStructReturn(), mBinding)) + if apinfo.IsTotal then + if isStructRetTy then errorR(Error(FSComp.SR.tcInvalidStructReturn(), mBinding)) + ActivePatternReturnKind.WrapByRefType + else + if isStructRetTy || isValueOptionTy cenv.g apReturnTy then ActivePatternReturnKind.WrapByStruct + elif isBoolTy cenv.g apReturnTy then ActivePatternReturnKind.SimpleReturn + else ActivePatternReturnKind.WrapByRefType match apRetTy with - | ActivePatternReturnType.bool -> + | ActivePatternReturnKind.SimpleReturn -> checkLanguageFeatureError g.langVersion LanguageFeature.BoolPartialActivePattern mBinding - | ActivePatternReturnType.voption when not isStructRetTy -> + | ActivePatternReturnKind.WrapByStruct when not isStructRetTy -> checkLanguageFeatureError g.langVersion LanguageFeature.BoolPartialActivePattern mBinding - | ActivePatternReturnType.voption -> + | ActivePatternReturnKind.WrapByStruct -> checkLanguageFeatureError g.langVersion LanguageFeature.StructActivePattern mBinding - | ActivePatternReturnType.option -> () + | ActivePatternReturnKind.WrapByRefType -> () UnifyTypes cenv env mBinding (apinfo.ResultType g rhsExpr.Range activePatResTys apRetTy) apReturnTy diff --git a/src/Compiler/Checking/NameResolution.fs b/src/Compiler/Checking/NameResolution.fs index fd31d444b45..bcf83f95bd3 100644 --- a/src/Compiler/Checking/NameResolution.fs +++ b/src/Compiler/Checking/NameResolution.fs @@ -89,7 +89,7 @@ let ActivePatternElemsOfValRef g (vref: ValRef) = let isStructRetTy = if apinfo.IsTotal then - ActivePatternReturnType.option + ActivePatternReturnKind.WrapByRefType else let _, apReturnTy = stripFunTy g vref.TauType let hasStructAttribute() = @@ -97,9 +97,9 @@ let ActivePatternElemsOfValRef g (vref: ValRef) = |> List.exists (function | Attrib(targetsOpt = Some(System.AttributeTargets.ReturnValue)) as a -> IsMatchingFSharpAttribute g g.attrib_StructAttribute a | _ -> false) - if isValueOptionTy g apReturnTy || hasStructAttribute() then ActivePatternReturnType.voption - elif isBoolTy g apReturnTy then ActivePatternReturnType.bool - else ActivePatternReturnType.option + if isValueOptionTy g apReturnTy || hasStructAttribute() then ActivePatternReturnKind.WrapByStruct + elif isBoolTy g apReturnTy then ActivePatternReturnKind.SimpleReturn + else ActivePatternReturnKind.WrapByRefType apinfo.ActiveTags |> List.mapi (fun i _ -> APElemRef(apinfo, vref, i, isStructRetTy)) | None -> [] diff --git a/src/Compiler/Checking/PatternMatchCompilation.fs b/src/Compiler/Checking/PatternMatchCompilation.fs index 4ef531b4439..9dcba3f472c 100644 --- a/src/Compiler/Checking/PatternMatchCompilation.fs +++ b/src/Compiler/Checking/PatternMatchCompilation.fs @@ -43,7 +43,7 @@ type Pattern = | TPat_as of Pattern * PatternValBinding * range (* note: can be replaced by TPat_var, i.e. equals TPat_conjs([TPat_var; pat]) *) | TPat_disjs of Pattern list * range | TPat_conjs of Pattern list * range - | TPat_query of (Expr * TType list * ActivePatternReturnType * (ValRef * TypeInst) option * int * ActivePatternInfo) * Pattern * range + | TPat_query of (Expr * TType list * ActivePatternReturnKind * (ValRef * TypeInst) option * int * ActivePatternInfo) * Pattern * range | TPat_unioncase of UnionCaseRef * TypeInst * Pattern list * range | TPat_exnconstr of TyconRef * Pattern list * range | TPat_tuple of TupInfo * Pattern list * TType list * range @@ -1298,7 +1298,7 @@ let CompilePatternBasic let argExpr = GetSubExprOfInput subexpr let appExpr = mkApps g ((activePatExpr, tyOfExpr g activePatExpr), [], [argExpr], m) - let vOpt, addrExp, _readonly, _writeonly = mkExprAddrOfExprAux g (isStructRetTy = ActivePatternReturnType.voption) false NeverMutates appExpr None mMatch + let vOpt, addrExp, _readonly, _writeonly = mkExprAddrOfExprAux g (isStructRetTy = ActivePatternReturnKind.WrapByStruct) false NeverMutates appExpr None mMatch match vOpt with | None -> let v, vExpr = mkCompGenLocal m ("activePatternResult" + string (newUnique())) resTy @@ -1354,15 +1354,15 @@ let CompilePatternBasic // Convert active pattern edges to tests on results data let discrim' = match discrim with - | DecisionTreeTest.ActivePatternCase(_pexp, resTys, isStructRetTy, _apatVrefOpt, idx, apinfo) -> + | DecisionTreeTest.ActivePatternCase(_pexp, resTys, retKind, _apatVrefOpt, idx, apinfo) -> let aparity = apinfo.ActiveTags.Length let total = apinfo.IsTotal if not total && aparity > 1 then error(Error(FSComp.SR.patcPartialActivePatternsGenerateOneResult(), m)) if not total then - if isStructRetTy = ActivePatternReturnType.bool then DecisionTreeTest.Const(Const.Bool true) - else DecisionTreeTest.UnionCase(mkAnySomeCase g isStructRetTy.IsStruct, resTys) + if retKind = ActivePatternReturnKind.SimpleReturn then DecisionTreeTest.Const(Const.Bool true) + else DecisionTreeTest.UnionCase(mkAnySomeCase g retKind.IsStruct, resTys) elif aparity <= 1 then DecisionTreeTest.Const(Const.Unit) else DecisionTreeTest.UnionCase(mkChoiceCaseRef g m aparity idx, resTys) | _ -> discrim @@ -1434,7 +1434,7 @@ let CompilePatternBasic let newActives = removeActive path actives match patAtActive with | TPat_wild _ | TPat_as _ | TPat_tuple _ | TPat_disjs _ | TPat_conjs _ | TPat_recd _ -> failwith "Unexpected projection pattern" - | TPat_query ((_, resTys, isStructRetTy, apatVrefOpt, idx, apinfo), p, m) -> + | TPat_query ((_, resTys, retKind, apatVrefOpt, idx, apinfo), p, m) -> if apinfo.IsTotal then // Total active patterns always return choice values let hasParam = (match apatVrefOpt with None -> true | Some (vref, _) -> doesActivePatternHaveFreeTypars g vref) @@ -1462,12 +1462,12 @@ let CompilePatternBasic if i = iInvestigated then let subAccess _j tpinst _ = let expr = Option.get inpExprOpt - match isStructRetTy with - | ActivePatternReturnType.bool -> expr - | ActivePatternReturnType.voption -> + match retKind with + | ActivePatternReturnKind.SimpleReturn -> expr + | ActivePatternReturnKind.WrapByStruct -> // In this case, the inpExprOpt is already an address-of expression mkUnionCaseFieldGetProvenViaExprAddr (expr, mkValueSomeCase g, instTypes tpinst resTys, 0, mExpr) - | ActivePatternReturnType.option -> + | ActivePatternReturnKind.WrapByRefType -> mkUnionCaseFieldGetUnprovenViaExprAddr (expr, mkSomeCase g, instTypes tpinst resTys, 0, mExpr) mkSubFrontiers path subAccess newActives [p] (fun path j -> PathQuery(path, int64 j)) else diff --git a/src/Compiler/Checking/PatternMatchCompilation.fsi b/src/Compiler/Checking/PatternMatchCompilation.fsi index d6ffc6e116e..b4d68aa320c 100644 --- a/src/Compiler/Checking/PatternMatchCompilation.fsi +++ b/src/Compiler/Checking/PatternMatchCompilation.fsi @@ -28,7 +28,7 @@ type Pattern = | TPat_disjs of Pattern list * range | TPat_conjs of Pattern list * range | TPat_query of - (Expr * TType list * ActivePatternReturnType * (ValRef * TypeInst) option * int * ActivePatternInfo) * + (Expr * TType list * ActivePatternReturnKind * (ValRef * TypeInst) option * int * ActivePatternInfo) * Pattern * range | TPat_unioncase of UnionCaseRef * TypeInst * Pattern list * range diff --git a/src/Compiler/TypedTree/TypedTree.fs b/src/Compiler/TypedTree/TypedTree.fs index ab89f50110b..259acf050c0 100644 --- a/src/Compiler/TypedTree/TypedTree.fs +++ b/src/Compiler/TypedTree/TypedTree.fs @@ -4566,12 +4566,12 @@ type DecisionTreeCase = override x.ToString() = sprintf "DecisionTreeCase(...)" -[] -type ActivePatternReturnType = - | option - | voption - | bool - member this.IsStruct with get () = this <> option +[] +type ActivePatternReturnKind = + | WrapByRefType + | WrapByStruct + | SimpleReturn + member this.IsStruct with get () = this <> WrapByRefType [] type DecisionTreeTest = @@ -4592,20 +4592,20 @@ type DecisionTreeTest = /// Test if the input to a decision tree is an instance of the given type | IsInst of source: TType * target: TType - /// Test.ActivePatternCase(activePatExpr, activePatResTys, isStructRetTy, activePatIdentity, idx, activePatInfo) + /// Test.ActivePatternCase(activePatExpr, activePatResTys, activePatRetKind, activePatIdentity, idx, activePatInfo) /// /// Run the active pattern and bind a successful result to a /// variable in the remaining tree. /// activePatExpr -- The active pattern function being called, perhaps applied to some active pattern parameters. /// activePatResTys -- The result types (case types) of the active pattern. - /// isStructRetTy -- Is the active pattern a struct return + /// activePatRetKind -- Indicating what is returning from the active pattern /// activePatIdentity -- The value and the types it is applied to. If there are any active pattern parameters then this is empty. /// idx -- The case number of the active pattern which the test relates to. /// activePatternInfo -- The extracted info for the active pattern. | ActivePatternCase of activePatExpr: Expr * activePatResTys: TTypes * - isStructRetTy: ActivePatternReturnType * + activePatRetKind: ActivePatternReturnKind * activePatIdentity: (ValRef * TypeInst) option * idx: int * activePatternInfo: ActivePatternInfo @@ -4674,7 +4674,7 @@ type ActivePatternElemRef = activePatternInfo: ActivePatternInfo * activePatternVal: ValRef * caseIndex: int * - isStructRetTy: ActivePatternReturnType + activePatRetKind: ActivePatternReturnKind /// Get the full information about the active pattern being referred to member x.ActivePatternInfo = (let (APElemRef(info, _, _, _)) = x in info) @@ -4683,7 +4683,7 @@ type ActivePatternElemRef = member x.ActivePatternVal = (let (APElemRef(_, vref, _, _)) = x in vref) /// Get a reference to the value for the active pattern being referred to - member x.IsStructReturn = (let (APElemRef(_, _, _, isStructRetTy)) = x in isStructRetTy) + member x.ActivePatternRetKind = (let (APElemRef(_, _, _, activePatRetKind)) = x in activePatRetKind) /// Get the index of the active pattern element within the overall active pattern member x.CaseIndex = (let (APElemRef(_, _, n, _)) = x in n) diff --git a/src/Compiler/TypedTree/TypedTree.fsi b/src/Compiler/TypedTree/TypedTree.fsi index 31b204ee3ca..bc2e7b63a4d 100644 --- a/src/Compiler/TypedTree/TypedTree.fsi +++ b/src/Compiler/TypedTree/TypedTree.fsi @@ -3267,11 +3267,15 @@ type DecisionTreeCase = /// Get the discriminator associated with the case member Discriminator: DecisionTreeTest -[] -type ActivePatternReturnType = - | option - | voption - | bool +/// Indicating what is returning from an AP +[] +type ActivePatternReturnKind = + /// Returning `_ option` or `Choice<_, _, .., _>` + | WrapByRefType + /// Returning `_ voption` + | WrapByStruct + /// Returning bool + | SimpleReturn member IsStruct: bool @@ -3295,20 +3299,20 @@ type DecisionTreeTest = /// Test if the input to a decision tree is an instance of the given type | IsInst of source: TType * target: TType - /// Test.ActivePatternCase(activePatExpr, activePatResTys, isStructRetTy, activePatIdentity, idx, activePatInfo) + /// Test.ActivePatternCase(activePatExpr, activePatResTys, activePatRetKind, activePatIdentity, idx, activePatInfo) /// /// Run the active pattern type bind a successful result to a /// variable in the remaining tree. /// activePatExpr -- The active pattern function being called, perhaps applied to some active pattern parameters. /// activePatResTys -- The result types (case types) of the active pattern. - /// isStructRetTy -- Is the active pattern a struct return + /// activePatRetKind -- Indicating what is returning from the active pattern /// activePatIdentity -- The value type the types it is applied to. If there are any active pattern parameters then this is empty. /// idx -- The case number of the active pattern which the test relates to. /// activePatternInfo -- The extracted info for the active pattern. | ActivePatternCase of activePatExpr: Expr * activePatResTys: TTypes * - isStructRetTy: ActivePatternReturnType * + activePatRetKind: ActivePatternReturnKind * activePatIdentity: (ValRef * TypeInst) option * idx: int * activePatternInfo: Syntax.PrettyNaming.ActivePatternInfo @@ -3367,7 +3371,7 @@ type ActivePatternElemRef = activePatternInfo: Syntax.PrettyNaming.ActivePatternInfo * activePatternVal: ValRef * caseIndex: int * - isStructRetTy: ActivePatternReturnType + activePatRetKind: ActivePatternReturnKind override ToString: unit -> string @@ -3384,7 +3388,7 @@ type ActivePatternElemRef = member DebugText: string /// Get a reference to the value for the active pattern being referred to - member IsStructReturn: ActivePatternReturnType + member ActivePatternRetKind: ActivePatternReturnKind /// Records the "extra information" for a value compiled as a method (rather /// than a closure or a local), including argument names, attributes etc. diff --git a/src/Compiler/TypedTree/TypedTreeOps.fs b/src/Compiler/TypedTree/TypedTreeOps.fs index 6a0d6c02cdb..9cf22ffffec 100644 --- a/src/Compiler/TypedTree/TypedTreeOps.fs +++ b/src/Compiler/TypedTree/TypedTreeOps.fs @@ -9234,17 +9234,17 @@ type ActivePatternInfo with member x.DisplayNameByIdx idx = x.ActiveTags[idx] |> ConvertLogicalNameToDisplayName - member apinfo.ResultType g m retTys isStruct = + member apinfo.ResultType g m retTys retKind = let choicety = mkChoiceTy g m retTys if apinfo.IsTotal then choicety else - match isStruct with - | ActivePatternReturnType.option -> mkOptionTy g choicety - | ActivePatternReturnType.voption -> mkValueOptionTy g choicety - | ActivePatternReturnType.bool -> g.bool_ty + match retKind with + | ActivePatternReturnKind.WrapByRefType -> mkOptionTy g choicety + | ActivePatternReturnKind.WrapByStruct -> mkValueOptionTy g choicety + | ActivePatternReturnKind.SimpleReturn -> g.bool_ty - member apinfo.OverallType g m argTy retTys isStruct = - mkFunTy g argTy (apinfo.ResultType g m retTys isStruct) + member apinfo.OverallType g m argTy retTys retKind = + mkFunTy g argTy (apinfo.ResultType g m retTys retKind) //--------------------------------------------------------------------------- // Active pattern validation diff --git a/src/Compiler/TypedTree/TypedTreeOps.fsi b/src/Compiler/TypedTree/TypedTreeOps.fsi index 4f08c1fced2..bec1e031185 100755 --- a/src/Compiler/TypedTree/TypedTreeOps.fsi +++ b/src/Compiler/TypedTree/TypedTreeOps.fsi @@ -2452,11 +2452,11 @@ type PrettyNaming.ActivePatternInfo with member DisplayNameByIdx: idx: int -> string /// Get the result type for the active pattern - member ResultType: g: TcGlobals -> range -> TType list -> ActivePatternReturnType -> TType + member ResultType: g: TcGlobals -> range -> TType list -> ActivePatternReturnKind -> TType /// Get the overall type for a function that implements the active pattern member OverallType: - g: TcGlobals -> m: range -> argTy: TType -> retTys: TType list -> isStruct: ActivePatternReturnType -> TType + g: TcGlobals -> m: range -> argTy: TType -> retTys: TType list -> retKind: ActivePatternReturnKind -> TType val doesActivePatternHaveFreeTypars: TcGlobals -> ValRef -> bool diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/Types/StructTypes/StructActivePatterns.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/Types/StructTypes/StructActivePatterns.fs index 2d9a31d2c7b..6930393e0bd 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/Types/StructTypes/StructActivePatterns.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/Types/StructTypes/StructActivePatterns.fs @@ -38,21 +38,21 @@ let rec (|IsOne|_|) someNumber = but here has type 'int option' """) - [] - let ``Voption active pattern fails if not using return:Struct attribute`` () = - Fs """ -let rec (|IsOne|_|) someNumber = - match someNumber with - | 1 -> ValueSome 1 - | _ -> ValueNone -""" - |> withOptions ["--warnaserror+"] - |> typecheck - |> shouldFail - |> withSingleDiagnostic (Error 1,Line 2, Col 9 , Line 2, Col 31, """This expression was expected to have type - ''a option' -but here has type - 'int voption' """) +// [] +// let ``Voption active pattern fails if not using return:Struct attribute`` () = +// Fs """ +// let rec (|IsOne|_|) someNumber = +// match someNumber with +// | 1 -> ValueSome 1 +// | _ -> ValueNone +// """ +// |> withOptions ["--warnaserror+"] +// |> typecheck +// |> shouldFail +// |> withSingleDiagnostic (Error 1,Line 2, Col 9 , Line 2, Col 31, """This expression was expected to have type +// ''a option' +// but here has type +// 'int voption' """) [] let ``Rec struct active pattern is possible`` () = diff --git a/tests/fsharp/Compiler/Language/BoolPartialActivePatternTests.fs b/tests/fsharp/Compiler/Language/BoolPartialActivePatternTests.fs new file mode 100644 index 00000000000..859b254e750 --- /dev/null +++ b/tests/fsharp/Compiler/Language/BoolPartialActivePatternTests.fs @@ -0,0 +1,115 @@ +// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. + +namespace FSharp.Compiler.UnitTests + +open NUnit.Framework +open FSharp.Compiler.Diagnostics +open FSharp.Test + +[] +module BoolPartialActivePatternTests = + + let private pass = CompilerAssert.PassWithOptions [| "--langversion:preview" |] + let private fail = CompilerAssert.TypeCheckWithErrorsAndOptions [| "--langversion:preview" |] + let private run src = CompilerAssert.CompileExeAndRunWithOptions( + [| "--langversion:preview" |], + (""" +let fail msg = + printfn "%s" msg + failwith msg +""" + src)) + + [] + let ``Partial struct active pattern returns ValueOption`1 without []`` () = + pass "let (|P1|_|) x = ValueNone" + + [] + let ``Partial struct active pattern returns bool`` () = + pass "let (|P1|_|) x = false" + + [] + let ``Partial struct active pattern results can be retrieved`` () = + run """ +let (|P1|_|) x = x <> 0 +let (|EqualTo|_|) y x = x = y + +match 0, 1 with +| P1, _ -> fail "unit" +| _, P1 -> () +| _ -> fail "unit" + +match "x" with +| EqualTo "y" -> fail "with argument" +| EqualTo "x" -> () +| _ -> fail "with argument" + """ + +// negative tests + + [] + let ``bool active pattern (-langversion:8.0)`` () = + CompilerAssert.TypeCheckWithErrorsAndOptions [| "--langversion:8.0" |] + """ +let (|OddBool|_|) x = x % 2 = 1 +let (|OddVOption|_|) x = if x % 2 = 1 then ValueSome() else ValueNone + """ + [|(FSharpDiagnosticSeverity.Error, 3350, (1, 5, 1, 20), + "Feature 'bool representation for partial pctive pattern' is not available in F# 8.0. Please use language version 'PREVIEW' or greater") + (FSharpDiagnosticSeverity.Error, 3350, (2, 5, 2, 23), + "Feature 'bool representation for partial pctive pattern' is not available in F# 8.0. Please use language version 'PREVIEW' or greater")|] + + [] + let ``StructAttribute must explicitly target active pattern return value`` () = + fail + """ +let (|IsA|_|) x = x = "A" + +match "A" with +| IsA result -> "A" +| _ -> "Not A" + +match "A" with +| IsA result -> result +| _ -> "Not A" + +match "A" with +| IsA "to match return value" -> "Matched" +| _ -> "not Matched" +""" + [|(FSharpDiagnosticSeverity.Error, 1, (4, 3, 4, 13), + "This expression was expected to have type + 'string -> bool' +but here has type + 'bool'"); + (FSharpDiagnosticSeverity.Error, 39, (4, 7, 4, 13), + "The value or constructor 'result' is not defined. Maybe you want one of the following: + Result"); + (FSharpDiagnosticSeverity.Error, 1, (4, 3, 4, 13), + "This expression was expected to have type +'string -> bool' +but here has type +'bool'"); + (FSharpDiagnosticSeverity.Error, 1, (8, 3, 8, 13), + "This expression was expected to have type + 'string -> bool' +but here has type + 'bool'"); + (FSharpDiagnosticSeverity.Error, 39, (8, 7, 8, 13), + "The value or constructor 'result' is not defined. Maybe you want one of the following: + Result"); + (FSharpDiagnosticSeverity.Error, 1, (8, 3, 8, 13), + "This expression was expected to have type + 'string -> bool' +but here has type + 'bool'"); + (FSharpDiagnosticSeverity.Error, 1, (12, 3, 12, 30), + "This expression was expected to have type + 'string -> bool' +but here has type + 'bool'"); + (FSharpDiagnosticSeverity.Error, 1, (12, 3, 12, 30), + "This expression was expected to have type + 'string -> bool' +but here has type + 'bool'"); + |] diff --git a/tests/fsharp/FSharpSuite.Tests.fsproj b/tests/fsharp/FSharpSuite.Tests.fsproj index b6d69d8ae1a..5d0a0c5e698 100644 --- a/tests/fsharp/FSharpSuite.Tests.fsproj +++ b/tests/fsharp/FSharpSuite.Tests.fsproj @@ -71,6 +71,7 @@ + From 47a70d81afe6693a1687e42975912ac10b52bf57 Mon Sep 17 00:00:00 2001 From: ijklam Date: Sat, 30 Dec 2023 22:51:01 +0800 Subject: [PATCH 10/25] add tests and release note --- docs/release-notes/.Language/preview.md | 1 + .../Compiler/Language/BoolPartialActivePatternTests.fs | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/docs/release-notes/.Language/preview.md b/docs/release-notes/.Language/preview.md index 0fce580b51e..832dd924a44 100644 --- a/docs/release-notes/.Language/preview.md +++ b/docs/release-notes/.Language/preview.md @@ -3,6 +3,7 @@ * Better generic unmanaged structs handling. ([Language suggestion #692](https://github.com/fsharp/fslang-suggestions/issues/692), [PR #12154](https://github.com/dotnet/fsharp/pull/12154)) * Bidirectional F#/C# interop for 'unmanaged' constraint. ([PR #12154](https://github.com/dotnet/fsharp/pull/12154)) * Make `.Is*` discriminated union properties visible. ([Language suggestion #222](https://github.com/fsharp/fslang-suggestions/issues/222), [PR #16341](https://github.com/dotnet/fsharp/pull/16341)) +* Allow returning bool instead of unit option for partial active patterns. ([Language suggestion #1041](https://github.com/fsharp/fslang-suggestions/issues/1041), [PR #16473](https://github.com/dotnet/fsharp/pull/16473)) ### Fixed diff --git a/tests/fsharp/Compiler/Language/BoolPartialActivePatternTests.fs b/tests/fsharp/Compiler/Language/BoolPartialActivePatternTests.fs index 859b254e750..056c5abe0e1 100644 --- a/tests/fsharp/Compiler/Language/BoolPartialActivePatternTests.fs +++ b/tests/fsharp/Compiler/Language/BoolPartialActivePatternTests.fs @@ -27,6 +27,13 @@ let fail msg = let ``Partial struct active pattern returns bool`` () = pass "let (|P1|_|) x = false" + [] + let ``Single case active pattern returning bool should success`` () = + pass """ +let (|IsA|) x = x = "A" +let (IsA r) = "A" + """ + [] let ``Partial struct active pattern results can be retrieved`` () = run """ From 337f169995a203a4d9a42e2674a637f856f403dc Mon Sep 17 00:00:00 2001 From: ijklam Date: Sat, 30 Dec 2023 23:41:24 +0800 Subject: [PATCH 11/25] fix test --- .../Language/BoolPartialActivePatternTests.fs | 23 +++---------------- .../Language/StructActivePatternTests.fs | 5 +--- 2 files changed, 4 insertions(+), 24 deletions(-) diff --git a/tests/fsharp/Compiler/Language/BoolPartialActivePatternTests.fs b/tests/fsharp/Compiler/Language/BoolPartialActivePatternTests.fs index 056c5abe0e1..38462f6182d 100644 --- a/tests/fsharp/Compiler/Language/BoolPartialActivePatternTests.fs +++ b/tests/fsharp/Compiler/Language/BoolPartialActivePatternTests.fs @@ -56,8 +56,7 @@ match "x" with [] let ``bool active pattern (-langversion:8.0)`` () = CompilerAssert.TypeCheckWithErrorsAndOptions [| "--langversion:8.0" |] - """ -let (|OddBool|_|) x = x % 2 = 1 + """let (|OddBool|_|) x = x % 2 = 1 let (|OddVOption|_|) x = if x % 2 = 1 then ValueSome() else ValueNone """ [|(FSharpDiagnosticSeverity.Error, 3350, (1, 5, 1, 20), @@ -66,10 +65,9 @@ let (|OddVOption|_|) x = if x % 2 = 1 then ValueSome() else ValueNone "Feature 'bool representation for partial pctive pattern' is not available in F# 8.0. Please use language version 'PREVIEW' or greater")|] [] - let ``StructAttribute must explicitly target active pattern return value`` () = + let ``Can not receive result from bool active pattern`` () = fail - """ -let (|IsA|_|) x = x = "A" + """let (|IsA|_|) x = x = "A" match "A" with | IsA result -> "A" @@ -91,11 +89,6 @@ but here has type (FSharpDiagnosticSeverity.Error, 39, (4, 7, 4, 13), "The value or constructor 'result' is not defined. Maybe you want one of the following: Result"); - (FSharpDiagnosticSeverity.Error, 1, (4, 3, 4, 13), - "This expression was expected to have type -'string -> bool' -but here has type -'bool'"); (FSharpDiagnosticSeverity.Error, 1, (8, 3, 8, 13), "This expression was expected to have type 'string -> bool' @@ -104,16 +97,6 @@ but here has type (FSharpDiagnosticSeverity.Error, 39, (8, 7, 8, 13), "The value or constructor 'result' is not defined. Maybe you want one of the following: Result"); - (FSharpDiagnosticSeverity.Error, 1, (8, 3, 8, 13), - "This expression was expected to have type - 'string -> bool' -but here has type - 'bool'"); - (FSharpDiagnosticSeverity.Error, 1, (12, 3, 12, 30), - "This expression was expected to have type - 'string -> bool' -but here has type - 'bool'"); (FSharpDiagnosticSeverity.Error, 1, (12, 3, 12, 30), "This expression was expected to have type 'string -> bool' diff --git a/tests/fsharp/Compiler/Language/StructActivePatternTests.fs b/tests/fsharp/Compiler/Language/StructActivePatternTests.fs index 8780e6c8469..72615f0b883 100644 --- a/tests/fsharp/Compiler/Language/StructActivePatternTests.fs +++ b/tests/fsharp/Compiler/Language/StructActivePatternTests.fs @@ -180,10 +180,7 @@ let (|Foo|_|) x = ValueNone [|(FSharpDiagnosticSeverity.Error, 842, (2, 3, 2, 9), "This attribute is not valid for use on this language element"); (FSharpDiagnosticSeverity.Error, 1, (2, 1, 3, 16), - "This expression was expected to have type - ''a option' -but here has type - ''b voption' ")|] + "Feature 'bool representation for partial pctive pattern' is not available in F# 8.0. Please use language version 'PREVIEW' or greater")|] [] let ``StructAttribute not allowed on other bindings than partial active pattern definitions`` () = From 7241ec1dc57ac0562fe9e61575eae477810f2ab2 Mon Sep 17 00:00:00 2001 From: ijklam Date: Sun, 31 Dec 2023 00:32:56 +0800 Subject: [PATCH 12/25] fix test --- .../Language/BoolPartialActivePatternTests.fs | 16 ++++++++-------- .../Language/StructActivePatternTests.fs | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/fsharp/Compiler/Language/BoolPartialActivePatternTests.fs b/tests/fsharp/Compiler/Language/BoolPartialActivePatternTests.fs index 38462f6182d..009262a04ab 100644 --- a/tests/fsharp/Compiler/Language/BoolPartialActivePatternTests.fs +++ b/tests/fsharp/Compiler/Language/BoolPartialActivePatternTests.fs @@ -60,9 +60,9 @@ match "x" with let (|OddVOption|_|) x = if x % 2 = 1 then ValueSome() else ValueNone """ [|(FSharpDiagnosticSeverity.Error, 3350, (1, 5, 1, 20), - "Feature 'bool representation for partial pctive pattern' is not available in F# 8.0. Please use language version 'PREVIEW' or greater") + "Feature 'bool representation for partial pctive pattern' is not available in F# 8.0. Please use language version 'PREVIEW' or greater.") (FSharpDiagnosticSeverity.Error, 3350, (2, 5, 2, 23), - "Feature 'bool representation for partial pctive pattern' is not available in F# 8.0. Please use language version 'PREVIEW' or greater")|] + "Feature 'bool representation for partial pctive pattern' is not available in F# 8.0. Please use language version 'PREVIEW' or greater.")|] [] let ``Can not receive result from bool active pattern`` () = @@ -83,23 +83,23 @@ match "A" with """ [|(FSharpDiagnosticSeverity.Error, 1, (4, 3, 4, 13), "This expression was expected to have type - 'string -> bool' + 'string -> bool' but here has type - 'bool'"); + 'bool' "); (FSharpDiagnosticSeverity.Error, 39, (4, 7, 4, 13), "The value or constructor 'result' is not defined. Maybe you want one of the following: Result"); (FSharpDiagnosticSeverity.Error, 1, (8, 3, 8, 13), "This expression was expected to have type - 'string -> bool' + 'string -> bool' but here has type - 'bool'"); + 'bool' "); (FSharpDiagnosticSeverity.Error, 39, (8, 7, 8, 13), "The value or constructor 'result' is not defined. Maybe you want one of the following: Result"); (FSharpDiagnosticSeverity.Error, 1, (12, 3, 12, 30), "This expression was expected to have type - 'string -> bool' + 'string -> bool' but here has type - 'bool'"); + 'bool' "); |] diff --git a/tests/fsharp/Compiler/Language/StructActivePatternTests.fs b/tests/fsharp/Compiler/Language/StructActivePatternTests.fs index 72615f0b883..305c659faaf 100644 --- a/tests/fsharp/Compiler/Language/StructActivePatternTests.fs +++ b/tests/fsharp/Compiler/Language/StructActivePatternTests.fs @@ -179,8 +179,8 @@ let (|Foo|_|) x = ValueNone """ [|(FSharpDiagnosticSeverity.Error, 842, (2, 3, 2, 9), "This attribute is not valid for use on this language element"); - (FSharpDiagnosticSeverity.Error, 1, (2, 1, 3, 16), - "Feature 'bool representation for partial pctive pattern' is not available in F# 8.0. Please use language version 'PREVIEW' or greater")|] + (FSharpDiagnosticSeverity.Error, 3350, (2, 1, 3, 16), + "Feature 'bool representation for partial pctive pattern' is not available in F# 8.0. Please use language version 'PREVIEW' or greater.")|] [] let ``StructAttribute not allowed on other bindings than partial active pattern definitions`` () = From ab2cff0cd8272329d56d1aa2c8e9718b5e8c647b Mon Sep 17 00:00:00 2001 From: ijklam Date: Mon, 1 Jan 2024 13:24:22 +0800 Subject: [PATCH 13/25] rename and fix typo --- src/Compiler/Checking/CheckExpressions.fs | 16 +++++++------- src/Compiler/Checking/NameResolution.fs | 12 +++++----- .../Checking/PatternMatchCompilation.fs | 22 +++++++++---------- src/Compiler/FSComp.txt | 2 +- src/Compiler/TypedTree/TypedTree.fs | 8 +++---- src/Compiler/TypedTree/TypedTree.fsi | 6 ++--- src/Compiler/TypedTree/TypedTreeOps.fs | 6 ++--- src/Compiler/xlf/FSComp.txt.cs.xlf | 4 ++-- src/Compiler/xlf/FSComp.txt.de.xlf | 4 ++-- src/Compiler/xlf/FSComp.txt.es.xlf | 4 ++-- src/Compiler/xlf/FSComp.txt.fr.xlf | 4 ++-- src/Compiler/xlf/FSComp.txt.it.xlf | 4 ++-- src/Compiler/xlf/FSComp.txt.ja.xlf | 4 ++-- src/Compiler/xlf/FSComp.txt.ko.xlf | 4 ++-- src/Compiler/xlf/FSComp.txt.pl.xlf | 4 ++-- src/Compiler/xlf/FSComp.txt.pt-BR.xlf | 4 ++-- src/Compiler/xlf/FSComp.txt.ru.xlf | 4 ++-- src/Compiler/xlf/FSComp.txt.tr.xlf | 4 ++-- src/Compiler/xlf/FSComp.txt.zh-Hans.xlf | 4 ++-- src/Compiler/xlf/FSComp.txt.zh-Hant.xlf | 4 ++-- .../Language/BoolPartialActivePatternTests.fs | 4 ++-- .../Language/StructActivePatternTests.fs | 2 +- 22 files changed, 65 insertions(+), 65 deletions(-) diff --git a/src/Compiler/Checking/CheckExpressions.fs b/src/Compiler/Checking/CheckExpressions.fs index a38826a392e..6e5cd772397 100644 --- a/src/Compiler/Checking/CheckExpressions.fs +++ b/src/Compiler/Checking/CheckExpressions.fs @@ -10749,20 +10749,20 @@ and TcNormalizedBinding declKind (cenv: cenv) env tpenv overallTy safeThisValOpt let apRetTy = if apinfo.IsTotal then if isStructRetTy then errorR(Error(FSComp.SR.tcInvalidStructReturn(), mBinding)) - ActivePatternReturnKind.WrapByRefType + ActivePatternReturnKind.RefTypeWrapper else - if isStructRetTy || isValueOptionTy cenv.g apReturnTy then ActivePatternReturnKind.WrapByStruct - elif isBoolTy cenv.g apReturnTy then ActivePatternReturnKind.SimpleReturn - else ActivePatternReturnKind.WrapByRefType + if isStructRetTy || isValueOptionTy cenv.g apReturnTy then ActivePatternReturnKind.StructTypeWrapper + elif isBoolTy cenv.g apReturnTy then ActivePatternReturnKind.Boolean + else ActivePatternReturnKind.RefTypeWrapper match apRetTy with - | ActivePatternReturnKind.SimpleReturn -> + | ActivePatternReturnKind.Boolean -> checkLanguageFeatureError g.langVersion LanguageFeature.BoolPartialActivePattern mBinding - | ActivePatternReturnKind.WrapByStruct when not isStructRetTy -> + | ActivePatternReturnKind.StructTypeWrapper when not isStructRetTy -> checkLanguageFeatureError g.langVersion LanguageFeature.BoolPartialActivePattern mBinding - | ActivePatternReturnKind.WrapByStruct -> + | ActivePatternReturnKind.StructTypeWrapper -> checkLanguageFeatureError g.langVersion LanguageFeature.StructActivePattern mBinding - | ActivePatternReturnKind.WrapByRefType -> () + | ActivePatternReturnKind.RefTypeWrapper -> () UnifyTypes cenv env mBinding (apinfo.ResultType g rhsExpr.Range activePatResTys apRetTy) apReturnTy diff --git a/src/Compiler/Checking/NameResolution.fs b/src/Compiler/Checking/NameResolution.fs index bcf83f95bd3..035620febdf 100644 --- a/src/Compiler/Checking/NameResolution.fs +++ b/src/Compiler/Checking/NameResolution.fs @@ -87,9 +87,9 @@ let ActivePatternElemsOfValRef g (vref: ValRef) = match TryGetActivePatternInfo vref with | Some apinfo -> - let isStructRetTy = + let retKind = if apinfo.IsTotal then - ActivePatternReturnKind.WrapByRefType + ActivePatternReturnKind.RefTypeWrapper else let _, apReturnTy = stripFunTy g vref.TauType let hasStructAttribute() = @@ -97,10 +97,10 @@ let ActivePatternElemsOfValRef g (vref: ValRef) = |> List.exists (function | Attrib(targetsOpt = Some(System.AttributeTargets.ReturnValue)) as a -> IsMatchingFSharpAttribute g g.attrib_StructAttribute a | _ -> false) - if isValueOptionTy g apReturnTy || hasStructAttribute() then ActivePatternReturnKind.WrapByStruct - elif isBoolTy g apReturnTy then ActivePatternReturnKind.SimpleReturn - else ActivePatternReturnKind.WrapByRefType - apinfo.ActiveTags |> List.mapi (fun i _ -> APElemRef(apinfo, vref, i, isStructRetTy)) + if isValueOptionTy g apReturnTy || hasStructAttribute() then ActivePatternReturnKind.StructTypeWrapper + elif isBoolTy g apReturnTy then ActivePatternReturnKind.Boolean + else ActivePatternReturnKind.RefTypeWrapper + apinfo.ActiveTags |> List.mapi (fun i _ -> APElemRef(apinfo, vref, i, retKind)) | None -> [] /// Try to make a reference to a value in a module. diff --git a/src/Compiler/Checking/PatternMatchCompilation.fs b/src/Compiler/Checking/PatternMatchCompilation.fs index 9dcba3f472c..d6f04b1eb00 100644 --- a/src/Compiler/Checking/PatternMatchCompilation.fs +++ b/src/Compiler/Checking/PatternMatchCompilation.fs @@ -618,8 +618,8 @@ let getDiscrimOfPattern (g: TcGlobals) tpinst t = Some(DecisionTreeTest.UnionCase (c, instTypes tpinst tyargs')) | TPat_array (args, ty, _m) -> Some(DecisionTreeTest.ArrayLength (args.Length, ty)) - | TPat_query ((activePatExpr, resTys, isStructRetTy, apatVrefOpt, idx, apinfo), _, _m) -> - Some (DecisionTreeTest.ActivePatternCase (activePatExpr, instTypes tpinst resTys, isStructRetTy, apatVrefOpt, idx, apinfo)) + | TPat_query ((activePatExpr, resTys, retKind, apatVrefOpt, idx, apinfo), _, _m) -> + Some (DecisionTreeTest.ActivePatternCase (activePatExpr, instTypes tpinst resTys, retKind, apatVrefOpt, idx, apinfo)) | TPat_error range -> Some (DecisionTreeTest.Error range) @@ -938,8 +938,8 @@ let rec investigationPoints inpPat = let rec erasePartialPatterns inpPat = match inpPat with - | TPat_query ((expr, resTys, isStructRetTy, apatVrefOpt, idx, apinfo), p, m) -> - if apinfo.IsTotal then TPat_query ((expr, resTys, isStructRetTy, apatVrefOpt, idx, apinfo), erasePartialPatterns p, m) + | TPat_query ((expr, resTys, retKind, apatVrefOpt, idx, apinfo), p, m) -> + if apinfo.IsTotal then TPat_query ((expr, resTys, retKind, apatVrefOpt, idx, apinfo), erasePartialPatterns p, m) else TPat_disjs ([], m) (* always fail *) | TPat_as (p, x, m) -> TPat_as (erasePartialPatterns p, x, m) | TPat_disjs (subPats, m) -> TPat_disjs(erasePartials subPats, m) @@ -1290,15 +1290,15 @@ let CompilePatternBasic // Active pattern matches: create a variable to hold the results of executing the active pattern. // If a struct return we continue with an expression for taking the address of that location. - | EdgeDiscrim(_, DecisionTreeTest.ActivePatternCase(activePatExpr, resTys, isStructRetTy, _apatVrefOpt, _, apinfo), m) :: _ -> + | EdgeDiscrim(_, DecisionTreeTest.ActivePatternCase(activePatExpr, resTys, retKind, _apatVrefOpt, _, apinfo), m) :: _ -> if not (isNil origInputValTypars) then error(InternalError("Unexpected generalized type variables when compiling an active pattern", m)) - let resTy = apinfo.ResultType g m resTys isStructRetTy + let resTy = apinfo.ResultType g m resTys retKind let argExpr = GetSubExprOfInput subexpr let appExpr = mkApps g ((activePatExpr, tyOfExpr g activePatExpr), [], [argExpr], m) - let vOpt, addrExp, _readonly, _writeonly = mkExprAddrOfExprAux g (isStructRetTy = ActivePatternReturnKind.WrapByStruct) false NeverMutates appExpr None mMatch + let vOpt, addrExp, _readonly, _writeonly = mkExprAddrOfExprAux g (retKind = ActivePatternReturnKind.StructTypeWrapper) false NeverMutates appExpr None mMatch match vOpt with | None -> let v, vExpr = mkCompGenLocal m ("activePatternResult" + string (newUnique())) resTy @@ -1361,7 +1361,7 @@ let CompilePatternBasic error(Error(FSComp.SR.patcPartialActivePatternsGenerateOneResult(), m)) if not total then - if retKind = ActivePatternReturnKind.SimpleReturn then DecisionTreeTest.Const(Const.Bool true) + if retKind = ActivePatternReturnKind.Boolean then DecisionTreeTest.Const(Const.Bool true) else DecisionTreeTest.UnionCase(mkAnySomeCase g retKind.IsStruct, resTys) elif aparity <= 1 then DecisionTreeTest.Const(Const.Unit) else DecisionTreeTest.UnionCase(mkChoiceCaseRef g m aparity idx, resTys) @@ -1463,11 +1463,11 @@ let CompilePatternBasic let subAccess _j tpinst _ = let expr = Option.get inpExprOpt match retKind with - | ActivePatternReturnKind.SimpleReturn -> expr - | ActivePatternReturnKind.WrapByStruct -> + | ActivePatternReturnKind.Boolean -> expr + | ActivePatternReturnKind.StructTypeWrapper -> // In this case, the inpExprOpt is already an address-of expression mkUnionCaseFieldGetProvenViaExprAddr (expr, mkValueSomeCase g, instTypes tpinst resTys, 0, mExpr) - | ActivePatternReturnKind.WrapByRefType -> + | ActivePatternReturnKind.RefTypeWrapper -> mkUnionCaseFieldGetUnprovenViaExprAddr (expr, mkSomeCase g, instTypes tpinst resTys, 0, mExpr) mkSubFrontiers path subAccess newActives [p] (fun path j -> PathQuery(path, int64 j)) else diff --git a/src/Compiler/FSComp.txt b/src/Compiler/FSComp.txt index d58c514bac6..d66cd8cfa9e 100644 --- a/src/Compiler/FSComp.txt +++ b/src/Compiler/FSComp.txt @@ -1593,7 +1593,7 @@ featurePreferExtensionMethodOverPlainProperty,"prefer extension method over plai featureWarningIndexedPropertiesGetSetSameType,"Indexed properties getter and setter must have the same type" featureChkTailCallAttrOnNonRec,"Raises warnings if the 'TailCall' attribute is used on non-recursive functions." featureUnionIsPropertiesVisible,"Union case test properties" -featureBoolPartialActivePattern,"bool representation for partial pctive pattern" +featureBoolPartialActivePattern,"bool representation for partial active patterns" 3354,tcNotAFunctionButIndexerNamedIndexingNotYetEnabled,"This value supports indexing, e.g. '%s.[index]'. The syntax '%s[index]' requires /langversion:preview. See https://aka.ms/fsharp-index-notation." 3354,tcNotAFunctionButIndexerIndexingNotYetEnabled,"This expression supports indexing, e.g. 'expr.[index]'. The syntax 'expr[index]' requires /langversion:preview. See https://aka.ms/fsharp-index-notation." 3355,tcNotAnIndexerNamedIndexingNotYetEnabled,"The value '%s' is not a function and does not support index notation." diff --git a/src/Compiler/TypedTree/TypedTree.fs b/src/Compiler/TypedTree/TypedTree.fs index 259acf050c0..cbcabf1a5df 100644 --- a/src/Compiler/TypedTree/TypedTree.fs +++ b/src/Compiler/TypedTree/TypedTree.fs @@ -4568,10 +4568,10 @@ type DecisionTreeCase = [] type ActivePatternReturnKind = - | WrapByRefType - | WrapByStruct - | SimpleReturn - member this.IsStruct with get () = this <> WrapByRefType + | RefTypeWrapper + | StructTypeWrapper + | Boolean + member this.IsStruct with get () = this <> RefTypeWrapper [] type DecisionTreeTest = diff --git a/src/Compiler/TypedTree/TypedTree.fsi b/src/Compiler/TypedTree/TypedTree.fsi index bc2e7b63a4d..a916c6fec83 100644 --- a/src/Compiler/TypedTree/TypedTree.fsi +++ b/src/Compiler/TypedTree/TypedTree.fsi @@ -3271,11 +3271,11 @@ type DecisionTreeCase = [] type ActivePatternReturnKind = /// Returning `_ option` or `Choice<_, _, .., _>` - | WrapByRefType + | RefTypeWrapper /// Returning `_ voption` - | WrapByStruct + | StructTypeWrapper /// Returning bool - | SimpleReturn + | Boolean member IsStruct: bool diff --git a/src/Compiler/TypedTree/TypedTreeOps.fs b/src/Compiler/TypedTree/TypedTreeOps.fs index 9cf22ffffec..69365ba0cb4 100644 --- a/src/Compiler/TypedTree/TypedTreeOps.fs +++ b/src/Compiler/TypedTree/TypedTreeOps.fs @@ -9239,9 +9239,9 @@ type ActivePatternInfo with if apinfo.IsTotal then choicety else match retKind with - | ActivePatternReturnKind.WrapByRefType -> mkOptionTy g choicety - | ActivePatternReturnKind.WrapByStruct -> mkValueOptionTy g choicety - | ActivePatternReturnKind.SimpleReturn -> g.bool_ty + | ActivePatternReturnKind.RefTypeWrapper -> mkOptionTy g choicety + | ActivePatternReturnKind.StructTypeWrapper -> mkValueOptionTy g choicety + | ActivePatternReturnKind.Boolean -> g.bool_ty member apinfo.OverallType g m argTy retTys retKind = mkFunTy g argTy (apinfo.ResultType g m retTys retKind) diff --git a/src/Compiler/xlf/FSComp.txt.cs.xlf b/src/Compiler/xlf/FSComp.txt.cs.xlf index f79cb21e40c..b2a87fdda47 100644 --- a/src/Compiler/xlf/FSComp.txt.cs.xlf +++ b/src/Compiler/xlf/FSComp.txt.cs.xlf @@ -248,8 +248,8 @@ - bool representation for partial pctive pattern - bool representation for partial pctive pattern + bool representation for partial active patterns + bool representation for partial active patterns diff --git a/src/Compiler/xlf/FSComp.txt.de.xlf b/src/Compiler/xlf/FSComp.txt.de.xlf index 4dea90152e2..aa7ccc5a974 100644 --- a/src/Compiler/xlf/FSComp.txt.de.xlf +++ b/src/Compiler/xlf/FSComp.txt.de.xlf @@ -248,8 +248,8 @@ - bool representation for partial pctive pattern - bool representation for partial pctive pattern + bool representation for partial active patterns + bool representation for partial active patterns diff --git a/src/Compiler/xlf/FSComp.txt.es.xlf b/src/Compiler/xlf/FSComp.txt.es.xlf index 6b9794b5924..d0918d00717 100644 --- a/src/Compiler/xlf/FSComp.txt.es.xlf +++ b/src/Compiler/xlf/FSComp.txt.es.xlf @@ -248,8 +248,8 @@ - bool representation for partial pctive pattern - bool representation for partial pctive pattern + bool representation for partial active patterns + bool representation for partial active patterns diff --git a/src/Compiler/xlf/FSComp.txt.fr.xlf b/src/Compiler/xlf/FSComp.txt.fr.xlf index 250be4728ab..7406b1746ce 100644 --- a/src/Compiler/xlf/FSComp.txt.fr.xlf +++ b/src/Compiler/xlf/FSComp.txt.fr.xlf @@ -248,8 +248,8 @@ - bool representation for partial pctive pattern - bool representation for partial pctive pattern + bool representation for partial active patterns + bool representation for partial active patterns diff --git a/src/Compiler/xlf/FSComp.txt.it.xlf b/src/Compiler/xlf/FSComp.txt.it.xlf index affbca2dc17..c6b13b37a3d 100644 --- a/src/Compiler/xlf/FSComp.txt.it.xlf +++ b/src/Compiler/xlf/FSComp.txt.it.xlf @@ -248,8 +248,8 @@ - bool representation for partial pctive pattern - bool representation for partial pctive pattern + bool representation for partial active patterns + bool representation for partial active patterns diff --git a/src/Compiler/xlf/FSComp.txt.ja.xlf b/src/Compiler/xlf/FSComp.txt.ja.xlf index ac065ddca05..aa395f82f45 100644 --- a/src/Compiler/xlf/FSComp.txt.ja.xlf +++ b/src/Compiler/xlf/FSComp.txt.ja.xlf @@ -248,8 +248,8 @@ - bool representation for partial pctive pattern - bool representation for partial pctive pattern + bool representation for partial active patterns + bool representation for partial active patterns diff --git a/src/Compiler/xlf/FSComp.txt.ko.xlf b/src/Compiler/xlf/FSComp.txt.ko.xlf index 1d751357d3b..415c4fab7aa 100644 --- a/src/Compiler/xlf/FSComp.txt.ko.xlf +++ b/src/Compiler/xlf/FSComp.txt.ko.xlf @@ -248,8 +248,8 @@ - bool representation for partial pctive pattern - bool representation for partial pctive pattern + bool representation for partial active patterns + bool representation for partial active patterns diff --git a/src/Compiler/xlf/FSComp.txt.pl.xlf b/src/Compiler/xlf/FSComp.txt.pl.xlf index 9f1555c4ef6..f8c6c0e9845 100644 --- a/src/Compiler/xlf/FSComp.txt.pl.xlf +++ b/src/Compiler/xlf/FSComp.txt.pl.xlf @@ -248,8 +248,8 @@ - bool representation for partial pctive pattern - bool representation for partial pctive pattern + bool representation for partial active patterns + bool representation for partial active patterns diff --git a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf index f45c281301b..634f50f708f 100644 --- a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf +++ b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf @@ -248,8 +248,8 @@ - bool representation for partial pctive pattern - bool representation for partial pctive pattern + bool representation for partial active patterns + bool representation for partial active patterns diff --git a/src/Compiler/xlf/FSComp.txt.ru.xlf b/src/Compiler/xlf/FSComp.txt.ru.xlf index b221ce6c8c6..5d7a2432a1d 100644 --- a/src/Compiler/xlf/FSComp.txt.ru.xlf +++ b/src/Compiler/xlf/FSComp.txt.ru.xlf @@ -248,8 +248,8 @@ - bool representation for partial pctive pattern - bool representation for partial pctive pattern + bool representation for partial active patterns + bool representation for partial active patterns diff --git a/src/Compiler/xlf/FSComp.txt.tr.xlf b/src/Compiler/xlf/FSComp.txt.tr.xlf index 692043c148b..dc3f7da5cc8 100644 --- a/src/Compiler/xlf/FSComp.txt.tr.xlf +++ b/src/Compiler/xlf/FSComp.txt.tr.xlf @@ -248,8 +248,8 @@ - bool representation for partial pctive pattern - bool representation for partial pctive pattern + bool representation for partial active patterns + bool representation for partial active patterns diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf index 759b7ba161b..425f9c9ffd7 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf @@ -248,8 +248,8 @@ - bool representation for partial pctive pattern - bool representation for partial pctive pattern + bool representation for partial active patterns + bool representation for partial active patterns diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf index 852cf7f12ef..fdd0db2e3f2 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf @@ -248,8 +248,8 @@ - bool representation for partial pctive pattern - bool representation for partial pctive pattern + bool representation for partial active patterns + bool representation for partial active patterns diff --git a/tests/fsharp/Compiler/Language/BoolPartialActivePatternTests.fs b/tests/fsharp/Compiler/Language/BoolPartialActivePatternTests.fs index 009262a04ab..6a4e92e3bd4 100644 --- a/tests/fsharp/Compiler/Language/BoolPartialActivePatternTests.fs +++ b/tests/fsharp/Compiler/Language/BoolPartialActivePatternTests.fs @@ -60,9 +60,9 @@ match "x" with let (|OddVOption|_|) x = if x % 2 = 1 then ValueSome() else ValueNone """ [|(FSharpDiagnosticSeverity.Error, 3350, (1, 5, 1, 20), - "Feature 'bool representation for partial pctive pattern' is not available in F# 8.0. Please use language version 'PREVIEW' or greater.") + "Feature 'bool representation for partial active patterns' is not available in F# 8.0. Please use language version 'PREVIEW' or greater.") (FSharpDiagnosticSeverity.Error, 3350, (2, 5, 2, 23), - "Feature 'bool representation for partial pctive pattern' is not available in F# 8.0. Please use language version 'PREVIEW' or greater.")|] + "Feature 'bool representation for partial active patterns' is not available in F# 8.0. Please use language version 'PREVIEW' or greater.")|] [] let ``Can not receive result from bool active pattern`` () = diff --git a/tests/fsharp/Compiler/Language/StructActivePatternTests.fs b/tests/fsharp/Compiler/Language/StructActivePatternTests.fs index 305c659faaf..c85ce458ee4 100644 --- a/tests/fsharp/Compiler/Language/StructActivePatternTests.fs +++ b/tests/fsharp/Compiler/Language/StructActivePatternTests.fs @@ -180,7 +180,7 @@ let (|Foo|_|) x = ValueNone [|(FSharpDiagnosticSeverity.Error, 842, (2, 3, 2, 9), "This attribute is not valid for use on this language element"); (FSharpDiagnosticSeverity.Error, 3350, (2, 1, 3, 16), - "Feature 'bool representation for partial pctive pattern' is not available in F# 8.0. Please use language version 'PREVIEW' or greater.")|] + "Feature 'bool representation for partial active patterns' is not available in F# 8.0. Please use language version 'PREVIEW' or greater.")|] [] let ``StructAttribute not allowed on other bindings than partial active pattern definitions`` () = From 5ceb20e1abaaaa8ec6fc36e88d9cb16c83ec1ec4 Mon Sep 17 00:00:00 2001 From: ijklam Date: Tue, 2 Jan 2024 21:59:38 +0800 Subject: [PATCH 14/25] modify `ActivePatternReturnKind.IsStruct` --- src/Compiler/TypedTree/TypedTree.fs | 8 ++++++-- src/Compiler/TypedTree/TypedTree.fsi | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Compiler/TypedTree/TypedTree.fs b/src/Compiler/TypedTree/TypedTree.fs index cbcabf1a5df..da8e43bfba5 100644 --- a/src/Compiler/TypedTree/TypedTree.fs +++ b/src/Compiler/TypedTree/TypedTree.fs @@ -4566,12 +4566,16 @@ type DecisionTreeCase = override x.ToString() = sprintf "DecisionTreeCase(...)" -[] +[] type ActivePatternReturnKind = | RefTypeWrapper | StructTypeWrapper | Boolean - member this.IsStruct with get () = this <> RefTypeWrapper + member this.IsStruct with get () = + match this with + | RefTypeWrapper -> false + | StructTypeWrapper + | Boolean -> true [] type DecisionTreeTest = diff --git a/src/Compiler/TypedTree/TypedTree.fsi b/src/Compiler/TypedTree/TypedTree.fsi index a916c6fec83..7f0a0ef4ed3 100644 --- a/src/Compiler/TypedTree/TypedTree.fsi +++ b/src/Compiler/TypedTree/TypedTree.fsi @@ -3268,7 +3268,7 @@ type DecisionTreeCase = member Discriminator: DecisionTreeTest /// Indicating what is returning from an AP -[] +[] type ActivePatternReturnKind = /// Returning `_ option` or `Choice<_, _, .., _>` | RefTypeWrapper From 53a0d6ce7bc89c0f852a84a659bc3c0547298650 Mon Sep 17 00:00:00 2001 From: ijklam Date: Tue, 2 Jan 2024 22:11:59 +0800 Subject: [PATCH 15/25] fix build error --- src/Compiler/Checking/PatternMatchCompilation.fs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Compiler/Checking/PatternMatchCompilation.fs b/src/Compiler/Checking/PatternMatchCompilation.fs index d6f04b1eb00..e7d7146292b 100644 --- a/src/Compiler/Checking/PatternMatchCompilation.fs +++ b/src/Compiler/Checking/PatternMatchCompilation.fs @@ -1298,7 +1298,12 @@ let CompilePatternBasic let argExpr = GetSubExprOfInput subexpr let appExpr = mkApps g ((activePatExpr, tyOfExpr g activePatExpr), [], [argExpr], m) - let vOpt, addrExp, _readonly, _writeonly = mkExprAddrOfExprAux g (retKind = ActivePatternReturnKind.StructTypeWrapper) false NeverMutates appExpr None mMatch + let mustTakeAddress = + match retKind with + | ActivePatternReturnKind.StructTypeWrapper -> true + | ActivePatternReturnKind.RefTypeWrapper + | ActivePatternReturnKind.Boolean -> false + let vOpt, addrExp, _readonly, _writeonly = mkExprAddrOfExprAux g mustTakeAddress false NeverMutates appExpr None mMatch match vOpt with | None -> let v, vExpr = mkCompGenLocal m ("activePatternResult" + string (newUnique())) resTy @@ -1361,8 +1366,10 @@ let CompilePatternBasic error(Error(FSComp.SR.patcPartialActivePatternsGenerateOneResult(), m)) if not total then - if retKind = ActivePatternReturnKind.Boolean then DecisionTreeTest.Const(Const.Bool true) - else DecisionTreeTest.UnionCase(mkAnySomeCase g retKind.IsStruct, resTys) + match retKind with + | ActivePatternReturnKind.Boolean -> DecisionTreeTest.Const(Const.Bool true) + | ActivePatternReturnKind.RefTypeWrapper -> DecisionTreeTest.UnionCase(mkAnySomeCase g false, resTys) + | ActivePatternReturnKind.StructTypeWrapper -> DecisionTreeTest.UnionCase(mkAnySomeCase g true, resTys) elif aparity <= 1 then DecisionTreeTest.Const(Const.Unit) else DecisionTreeTest.UnionCase(mkChoiceCaseRef g m aparity idx, resTys) | _ -> discrim From eff53af2ad2e9308884f4937fe0319c646af8f89 Mon Sep 17 00:00:00 2001 From: ijklam Date: Sat, 20 Jan 2024 00:01:37 +0800 Subject: [PATCH 16/25] rename the feature --- src/Compiler/Checking/CheckExpressions.fs | 4 ++-- src/Compiler/FSComp.txt | 2 +- src/Compiler/Facilities/LanguageFeatures.fs | 6 +++--- src/Compiler/Facilities/LanguageFeatures.fsi | 2 +- src/Compiler/xlf/FSComp.txt.cs.xlf | 6 +++--- src/Compiler/xlf/FSComp.txt.de.xlf | 6 +++--- src/Compiler/xlf/FSComp.txt.es.xlf | 6 +++--- src/Compiler/xlf/FSComp.txt.fr.xlf | 6 +++--- src/Compiler/xlf/FSComp.txt.it.xlf | 6 +++--- src/Compiler/xlf/FSComp.txt.ja.xlf | 6 +++--- src/Compiler/xlf/FSComp.txt.ko.xlf | 6 +++--- src/Compiler/xlf/FSComp.txt.pl.xlf | 6 +++--- src/Compiler/xlf/FSComp.txt.pt-BR.xlf | 6 +++--- src/Compiler/xlf/FSComp.txt.ru.xlf | 6 +++--- src/Compiler/xlf/FSComp.txt.tr.xlf | 6 +++--- src/Compiler/xlf/FSComp.txt.zh-Hans.xlf | 6 +++--- src/Compiler/xlf/FSComp.txt.zh-Hant.xlf | 6 +++--- .../Compiler/Language/BoolPartialActivePatternTests.fs | 4 ++-- tests/fsharp/Compiler/Language/StructActivePatternTests.fs | 2 +- 19 files changed, 49 insertions(+), 49 deletions(-) diff --git a/src/Compiler/Checking/CheckExpressions.fs b/src/Compiler/Checking/CheckExpressions.fs index b5c66cd1946..81ec759c7ab 100644 --- a/src/Compiler/Checking/CheckExpressions.fs +++ b/src/Compiler/Checking/CheckExpressions.fs @@ -10765,9 +10765,9 @@ and TcNormalizedBinding declKind (cenv: cenv) env tpenv overallTy safeThisValOpt match apRetTy with | ActivePatternReturnKind.Boolean -> - checkLanguageFeatureError g.langVersion LanguageFeature.BoolPartialActivePattern mBinding + checkLanguageFeatureError g.langVersion LanguageFeature.BooleanReturningAndReturnTypeDirectedPartialActivePattern mBinding | ActivePatternReturnKind.StructTypeWrapper when not isStructRetTy -> - checkLanguageFeatureError g.langVersion LanguageFeature.BoolPartialActivePattern mBinding + checkLanguageFeatureError g.langVersion LanguageFeature.BooleanReturningAndReturnTypeDirectedPartialActivePattern mBinding | ActivePatternReturnKind.StructTypeWrapper -> checkLanguageFeatureError g.langVersion LanguageFeature.StructActivePattern mBinding | ActivePatternReturnKind.RefTypeWrapper -> () diff --git a/src/Compiler/FSComp.txt b/src/Compiler/FSComp.txt index 986a77acfc4..a9fc2692157 100644 --- a/src/Compiler/FSComp.txt +++ b/src/Compiler/FSComp.txt @@ -1593,7 +1593,7 @@ featurePreferExtensionMethodOverPlainProperty,"prefer extension method over plai featureWarningIndexedPropertiesGetSetSameType,"Indexed properties getter and setter must have the same type" featureChkTailCallAttrOnNonRec,"Raises warnings if the 'TailCall' attribute is used on non-recursive functions." featureUnionIsPropertiesVisible,"Union case test properties" -featureBoolPartialActivePattern,"bool representation for partial active patterns" +featureBooleanReturningAndReturnTypeDirectedPartialActivePattern,"Boolean-returning and return-type-directed partial active patterns" 3354,tcNotAFunctionButIndexerNamedIndexingNotYetEnabled,"This value supports indexing, e.g. '%s.[index]'. The syntax '%s[index]' requires /langversion:preview. See https://aka.ms/fsharp-index-notation." 3354,tcNotAFunctionButIndexerIndexingNotYetEnabled,"This expression supports indexing, e.g. 'expr.[index]'. The syntax 'expr[index]' requires /langversion:preview. See https://aka.ms/fsharp-index-notation." 3355,tcNotAnIndexerNamedIndexingNotYetEnabled,"The value '%s' is not a function and does not support index notation." diff --git a/src/Compiler/Facilities/LanguageFeatures.fs b/src/Compiler/Facilities/LanguageFeatures.fs index 3a70ae6fb04..687141aa04e 100644 --- a/src/Compiler/Facilities/LanguageFeatures.fs +++ b/src/Compiler/Facilities/LanguageFeatures.fs @@ -84,7 +84,7 @@ type LanguageFeature = | PreferExtensionMethodOverPlainProperty | WarningIndexedPropertiesGetSetSameType | WarningWhenTailCallAttrOnNonRec - | BoolPartialActivePattern + | BooleanReturningAndReturnTypeDirectedPartialActivePattern /// LanguageVersion management type LanguageVersion(versionText) = @@ -196,7 +196,7 @@ type LanguageVersion(versionText) = LanguageFeature.WarningIndexedPropertiesGetSetSameType, previewVersion LanguageFeature.WarningWhenTailCallAttrOnNonRec, previewVersion LanguageFeature.UnionIsPropertiesVisible, previewVersion - LanguageFeature.BoolPartialActivePattern, previewVersion + LanguageFeature.BooleanReturningAndReturnTypeDirectedPartialActivePattern, previewVersion ] static let defaultLanguageVersion = LanguageVersion("default") @@ -338,7 +338,7 @@ type LanguageVersion(versionText) = | LanguageFeature.PreferExtensionMethodOverPlainProperty -> FSComp.SR.featurePreferExtensionMethodOverPlainProperty () | LanguageFeature.WarningIndexedPropertiesGetSetSameType -> FSComp.SR.featureWarningIndexedPropertiesGetSetSameType () | LanguageFeature.WarningWhenTailCallAttrOnNonRec -> FSComp.SR.featureChkTailCallAttrOnNonRec () - | LanguageFeature.BoolPartialActivePattern -> FSComp.SR.featureBoolPartialActivePattern () + | LanguageFeature.BooleanReturningAndReturnTypeDirectedPartialActivePattern -> FSComp.SR.featureBooleanReturningAndReturnTypeDirectedPartialActivePattern () /// Get a version string associated with the given feature. static member GetFeatureVersionString feature = diff --git a/src/Compiler/Facilities/LanguageFeatures.fsi b/src/Compiler/Facilities/LanguageFeatures.fsi index e013215199b..29d6c2c33a3 100644 --- a/src/Compiler/Facilities/LanguageFeatures.fsi +++ b/src/Compiler/Facilities/LanguageFeatures.fsi @@ -75,7 +75,7 @@ type LanguageFeature = | PreferExtensionMethodOverPlainProperty | WarningIndexedPropertiesGetSetSameType | WarningWhenTailCallAttrOnNonRec - | BoolPartialActivePattern + | BooleanReturningAndReturnTypeDirectedPartialActivePattern /// LanguageVersion management type LanguageVersion = diff --git a/src/Compiler/xlf/FSComp.txt.cs.xlf b/src/Compiler/xlf/FSComp.txt.cs.xlf index 4dced26ce73..c7dbc64bac7 100644 --- a/src/Compiler/xlf/FSComp.txt.cs.xlf +++ b/src/Compiler/xlf/FSComp.txt.cs.xlf @@ -247,9 +247,9 @@ automatické generování vlastnosti Message pro deklarace exception - - bool representation for partial active patterns - bool representation for partial active patterns + + Boolean-returning and return-type-directed partial active patterns + Boolean-returning and return-type-directed partial active patterns diff --git a/src/Compiler/xlf/FSComp.txt.de.xlf b/src/Compiler/xlf/FSComp.txt.de.xlf index 8583da8c79b..d5800420f00 100644 --- a/src/Compiler/xlf/FSComp.txt.de.xlf +++ b/src/Compiler/xlf/FSComp.txt.de.xlf @@ -247,9 +247,9 @@ Automatische Generierung der Eigenschaft „Message“ für „exception“-Deklarationen - - bool representation for partial active patterns - bool representation for partial active patterns + + Boolean-returning and return-type-directed partial active patterns + Boolean-returning and return-type-directed partial active patterns diff --git a/src/Compiler/xlf/FSComp.txt.es.xlf b/src/Compiler/xlf/FSComp.txt.es.xlf index dedb0db4791..dcfce175697 100644 --- a/src/Compiler/xlf/FSComp.txt.es.xlf +++ b/src/Compiler/xlf/FSComp.txt.es.xlf @@ -247,9 +247,9 @@ generación automática de la propiedad 'Message' para declaraciones 'exception' - - bool representation for partial active patterns - bool representation for partial active patterns + + Boolean-returning and return-type-directed partial active patterns + Boolean-returning and return-type-directed partial active patterns diff --git a/src/Compiler/xlf/FSComp.txt.fr.xlf b/src/Compiler/xlf/FSComp.txt.fr.xlf index 11b3677997d..590c4fb8e15 100644 --- a/src/Compiler/xlf/FSComp.txt.fr.xlf +++ b/src/Compiler/xlf/FSComp.txt.fr.xlf @@ -247,9 +247,9 @@ génération automatique de la propriété « Message » pour les déclarations « exception » - - bool representation for partial active patterns - bool representation for partial active patterns + + Boolean-returning and return-type-directed partial active patterns + Boolean-returning and return-type-directed partial active patterns diff --git a/src/Compiler/xlf/FSComp.txt.it.xlf b/src/Compiler/xlf/FSComp.txt.it.xlf index 2f8f0f8b408..70613984b76 100644 --- a/src/Compiler/xlf/FSComp.txt.it.xlf +++ b/src/Compiler/xlf/FSComp.txt.it.xlf @@ -247,9 +247,9 @@ generazione automatica della proprietà 'Messaggio' per le dichiarazioni 'eccezione' - - bool representation for partial active patterns - bool representation for partial active patterns + + Boolean-returning and return-type-directed partial active patterns + Boolean-returning and return-type-directed partial active patterns diff --git a/src/Compiler/xlf/FSComp.txt.ja.xlf b/src/Compiler/xlf/FSComp.txt.ja.xlf index 21aa06ffd18..84a9ca6ef70 100644 --- a/src/Compiler/xlf/FSComp.txt.ja.xlf +++ b/src/Compiler/xlf/FSComp.txt.ja.xlf @@ -247,9 +247,9 @@ `exception` 宣言の `Message` プロパティの自動生成 - - bool representation for partial active patterns - bool representation for partial active patterns + + Boolean-returning and return-type-directed partial active patterns + Boolean-returning and return-type-directed partial active patterns diff --git a/src/Compiler/xlf/FSComp.txt.ko.xlf b/src/Compiler/xlf/FSComp.txt.ko.xlf index 94298ccfad6..38ffac7d32d 100644 --- a/src/Compiler/xlf/FSComp.txt.ko.xlf +++ b/src/Compiler/xlf/FSComp.txt.ko.xlf @@ -247,9 +247,9 @@ 'exception' 선언에 대한 'Message' 속성 자동 생성 - - bool representation for partial active patterns - bool representation for partial active patterns + + Boolean-returning and return-type-directed partial active patterns + Boolean-returning and return-type-directed partial active patterns diff --git a/src/Compiler/xlf/FSComp.txt.pl.xlf b/src/Compiler/xlf/FSComp.txt.pl.xlf index a5e46ad703e..ac1d54f63c4 100644 --- a/src/Compiler/xlf/FSComp.txt.pl.xlf +++ b/src/Compiler/xlf/FSComp.txt.pl.xlf @@ -247,9 +247,9 @@ Automatyczne generowanie właściwości „Wiadomość“ dla deklaracji „Wyjątek“ - - bool representation for partial active patterns - bool representation for partial active patterns + + Boolean-returning and return-type-directed partial active patterns + Boolean-returning and return-type-directed partial active patterns diff --git a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf index c67c21ed987..6beb1946267 100644 --- a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf +++ b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf @@ -247,9 +247,9 @@ geração automática da propriedade 'Message' para declarações de 'exception' - - bool representation for partial active patterns - bool representation for partial active patterns + + Boolean-returning and return-type-directed partial active patterns + Boolean-returning and return-type-directed partial active patterns diff --git a/src/Compiler/xlf/FSComp.txt.ru.xlf b/src/Compiler/xlf/FSComp.txt.ru.xlf index 5eb428732ef..1b83dc7cc6b 100644 --- a/src/Compiler/xlf/FSComp.txt.ru.xlf +++ b/src/Compiler/xlf/FSComp.txt.ru.xlf @@ -247,9 +247,9 @@ автоматическое создание свойства “Message” для объявлений “exception” - - bool representation for partial active patterns - bool representation for partial active patterns + + Boolean-returning and return-type-directed partial active patterns + Boolean-returning and return-type-directed partial active patterns diff --git a/src/Compiler/xlf/FSComp.txt.tr.xlf b/src/Compiler/xlf/FSComp.txt.tr.xlf index 3f46a5df013..43f5069b2eb 100644 --- a/src/Compiler/xlf/FSComp.txt.tr.xlf +++ b/src/Compiler/xlf/FSComp.txt.tr.xlf @@ -247,9 +247,9 @@ 'exception' bildirimleri için 'Message' özelliğinin otomatik olarak oluşturulması - - bool representation for partial active patterns - bool representation for partial active patterns + + Boolean-returning and return-type-directed partial active patterns + Boolean-returning and return-type-directed partial active patterns diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf index dd82f84b8da..91cad01e99e 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf @@ -247,9 +247,9 @@ 自动生成“异常”声明的“消息”属性 - - bool representation for partial active patterns - bool representation for partial active patterns + + Boolean-returning and return-type-directed partial active patterns + Boolean-returning and return-type-directed partial active patterns diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf index 4980cbb3e46..f12b3fd0b5e 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf @@ -247,9 +247,9 @@ 自動產生 'exception' 宣告的 'Message' 屬性 - - bool representation for partial active patterns - bool representation for partial active patterns + + Boolean-returning and return-type-directed partial active patterns + Boolean-returning and return-type-directed partial active patterns diff --git a/tests/fsharp/Compiler/Language/BoolPartialActivePatternTests.fs b/tests/fsharp/Compiler/Language/BoolPartialActivePatternTests.fs index 6a4e92e3bd4..bbd346032a9 100644 --- a/tests/fsharp/Compiler/Language/BoolPartialActivePatternTests.fs +++ b/tests/fsharp/Compiler/Language/BoolPartialActivePatternTests.fs @@ -60,9 +60,9 @@ match "x" with let (|OddVOption|_|) x = if x % 2 = 1 then ValueSome() else ValueNone """ [|(FSharpDiagnosticSeverity.Error, 3350, (1, 5, 1, 20), - "Feature 'bool representation for partial active patterns' is not available in F# 8.0. Please use language version 'PREVIEW' or greater.") + "Feature 'Boolean-returning and return-type-directed partial active patterns' is not available in F# 8.0. Please use language version 'PREVIEW' or greater.") (FSharpDiagnosticSeverity.Error, 3350, (2, 5, 2, 23), - "Feature 'bool representation for partial active patterns' is not available in F# 8.0. Please use language version 'PREVIEW' or greater.")|] + "Feature 'Boolean-returning and return-type-directed partial active patterns' is not available in F# 8.0. Please use language version 'PREVIEW' or greater.")|] [] let ``Can not receive result from bool active pattern`` () = diff --git a/tests/fsharp/Compiler/Language/StructActivePatternTests.fs b/tests/fsharp/Compiler/Language/StructActivePatternTests.fs index c85ce458ee4..c1e71755e1b 100644 --- a/tests/fsharp/Compiler/Language/StructActivePatternTests.fs +++ b/tests/fsharp/Compiler/Language/StructActivePatternTests.fs @@ -180,7 +180,7 @@ let (|Foo|_|) x = ValueNone [|(FSharpDiagnosticSeverity.Error, 842, (2, 3, 2, 9), "This attribute is not valid for use on this language element"); (FSharpDiagnosticSeverity.Error, 3350, (2, 1, 3, 16), - "Feature 'bool representation for partial active patterns' is not available in F# 8.0. Please use language version 'PREVIEW' or greater.")|] + "Feature 'Boolean-returning and return-type-directed partial active patterns' is not available in F# 8.0. Please use language version 'PREVIEW' or greater.")|] [] let ``StructAttribute not allowed on other bindings than partial active pattern definitions`` () = From 3c58a1a90db36dfe8425b7ae5da8faae6dd72f8d Mon Sep 17 00:00:00 2001 From: ijklam Date: Sat, 20 Jan 2024 00:15:09 +0800 Subject: [PATCH 17/25] update comment --- src/Compiler/Checking/CheckExpressions.fs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Compiler/Checking/CheckExpressions.fs b/src/Compiler/Checking/CheckExpressions.fs index 81ec759c7ab..b527ac875f0 100644 --- a/src/Compiler/Checking/CheckExpressions.fs +++ b/src/Compiler/Checking/CheckExpressions.fs @@ -5095,6 +5095,8 @@ and TcPatLongIdentActivePatternCase warnOnUpper (cenv: cenv) (env: TcEnv) vFlags ((isOptionTy g retTy && isUnitTy g (destOptionTy g retTy)) || (isValueOptionTy g retTy && isUnitTy g (destValueOptionTy g retTy))) || // `bool` partial AP always be treated as `unit option` + // For `val (|P|_|) : _ -> bool`, only allow `match x with | P -> ...` + // For `val (|P|_|) : _ -> _ -> bool`, only allow `match x with | P parameter -> ...` (not apinfo.IsTotal && isBoolTy g retTy) then args, SynPat.Const(SynConst.Unit, m) else From 17fe616106d7691958305dca3c4508535abf154b Mon Sep 17 00:00:00 2001 From: ijklam Date: Sat, 20 Jan 2024 00:47:44 +0800 Subject: [PATCH 18/25] move tests --- .../FSharp.Compiler.ComponentTests.fsproj | 7 +- ...rnTypeDirectedPartialActivePatternTests.fs | 112 ++++++++++++++++++ .../Language/BoolPartialActivePatternTests.fs | 105 ---------------- tests/fsharp/FSharpSuite.Tests.fsproj | 1 - 4 files changed, 116 insertions(+), 109 deletions(-) create mode 100644 tests/FSharp.Compiler.ComponentTests/Language/BooleanReturningAndReturnTypeDirectedPartialActivePatternTests.fs delete mode 100644 tests/fsharp/Compiler/Language/BoolPartialActivePatternTests.fs diff --git a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj index a9dd5382893..ec4fc441f29 100644 --- a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj +++ b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj @@ -220,9 +220,10 @@ - - - + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/Language/BooleanReturningAndReturnTypeDirectedPartialActivePatternTests.fs b/tests/FSharp.Compiler.ComponentTests/Language/BooleanReturningAndReturnTypeDirectedPartialActivePatternTests.fs new file mode 100644 index 00000000000..343f0179d47 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/Language/BooleanReturningAndReturnTypeDirectedPartialActivePatternTests.fs @@ -0,0 +1,112 @@ +// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. + +module Language.BooleanReturningAndReturnTypeDirectedPartialActivePatternTests + +open Xunit +open FSharp.Test.Compiler +open FSharp.Test.ScriptHelpers + +let fsiSession = getSessionForEval [||] LangVersion.Preview + +let runCode = evalInSharedSession fsiSession + +[] +let ``Partial struct active pattern returns ValueOption`1 without []`` () = + FSharp "let (|P1|_|) x = ValueNone" + |> typecheck + |> shouldSucceed + +[] +let ``Partial struct active pattern returns bool`` () = + FSharp "let (|P1|_|) x = false" + |> typecheck + |> shouldSucceed + +[] +let ``Single case active pattern returning bool should success`` () = + FSharp """ +let (|IsA|) x = x = "A" +let (IsA r) = "A" + """ + |> typecheck + |> shouldSucceed + +[] +let ``Partial struct active pattern results can be retrieved`` () = + Fsx """ +let fail msg = + printfn "%s" msg + failwith msg + +let (|P1|_|) x = x <> 0 +let (|EqualTo|_|) y x = x = y + +match 0, 1 with +| P1, _ -> fail "unit" +| _, P1 -> () +| _ -> fail "unit" + +match "x" with +| EqualTo "y" -> fail "with argument" +| EqualTo "x" -> () +| _ -> fail "with argument" + """ + |> runCode + |> shouldSucceed + +// negative tests + +[] +let ``bool active pattern (-langversion:8.0)`` () = + FSharp """let (|OddBool|_|) x = x % 2 = 1 +let (|OddVOption|_|) x = if x % 2 = 1 then ValueSome() else ValueNone + """ + |> withLangVersion80 + |> typecheck + |> shouldSucceed + |> withDiagnostics [ + (Warning 3350, Line 1, Col 5, Line 1, Col 20, "Feature 'Boolean-returning and return-type-directed partial active patterns' is not available in F# 8.0. Please use language version 'PREVIEW' or greater.") + (Warning 3350, Line 2, Col 5, Line 2, Col 23, "Feature 'Boolean-returning and return-type-directed partial active patterns' is not available in F# 8.0. Please use language version 'PREVIEW' or greater.") + ] + +[] +let ``Can not receive result from bool active pattern`` () = + FSharp """let (|IsA|_|) x = x = "A" + +match "A" with +| IsA result -> "A" +| _ -> "Not A" + +match "A" with +| IsA result -> result +| _ -> "Not A" + +match "A" with +| IsA "to match return value" -> "Matched" +| _ -> "not Matched" +""" + |> typecheck + |> shouldSucceed + |> withDiagnostics [ + (Error 1, Line 4, Col 3, Line 4, Col 13, + "This expression was expected to have type + 'string -> bool' +but here has type + 'bool' ") + (Error 39, Line 4, Col 7, Line 4, Col 13, + "The value or constructor 'result' is not defined. Maybe you want one of the following: + Result") + (Error 1, Line 8, Col 3, Line 8, Col 13, + "This expression was expected to have type + 'string -> bool' +but here has type + 'bool' ") + (Error 39, Line 8, Col 7, Line 8, Col 13, + "The value or constructor 'result' is not defined. Maybe you want one of the following: + Result") + (Error 1, Line 12, Col 3, Line 12, Col 30, + "This expression was expected to have type + 'string -> bool' +but here has type + 'bool' ") + ] diff --git a/tests/fsharp/Compiler/Language/BoolPartialActivePatternTests.fs b/tests/fsharp/Compiler/Language/BoolPartialActivePatternTests.fs deleted file mode 100644 index bbd346032a9..00000000000 --- a/tests/fsharp/Compiler/Language/BoolPartialActivePatternTests.fs +++ /dev/null @@ -1,105 +0,0 @@ -// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. - -namespace FSharp.Compiler.UnitTests - -open NUnit.Framework -open FSharp.Compiler.Diagnostics -open FSharp.Test - -[] -module BoolPartialActivePatternTests = - - let private pass = CompilerAssert.PassWithOptions [| "--langversion:preview" |] - let private fail = CompilerAssert.TypeCheckWithErrorsAndOptions [| "--langversion:preview" |] - let private run src = CompilerAssert.CompileExeAndRunWithOptions( - [| "--langversion:preview" |], - (""" -let fail msg = - printfn "%s" msg - failwith msg -""" + src)) - - [] - let ``Partial struct active pattern returns ValueOption`1 without []`` () = - pass "let (|P1|_|) x = ValueNone" - - [] - let ``Partial struct active pattern returns bool`` () = - pass "let (|P1|_|) x = false" - - [] - let ``Single case active pattern returning bool should success`` () = - pass """ -let (|IsA|) x = x = "A" -let (IsA r) = "A" - """ - - [] - let ``Partial struct active pattern results can be retrieved`` () = - run """ -let (|P1|_|) x = x <> 0 -let (|EqualTo|_|) y x = x = y - -match 0, 1 with -| P1, _ -> fail "unit" -| _, P1 -> () -| _ -> fail "unit" - -match "x" with -| EqualTo "y" -> fail "with argument" -| EqualTo "x" -> () -| _ -> fail "with argument" - """ - -// negative tests - - [] - let ``bool active pattern (-langversion:8.0)`` () = - CompilerAssert.TypeCheckWithErrorsAndOptions [| "--langversion:8.0" |] - """let (|OddBool|_|) x = x % 2 = 1 -let (|OddVOption|_|) x = if x % 2 = 1 then ValueSome() else ValueNone - """ - [|(FSharpDiagnosticSeverity.Error, 3350, (1, 5, 1, 20), - "Feature 'Boolean-returning and return-type-directed partial active patterns' is not available in F# 8.0. Please use language version 'PREVIEW' or greater.") - (FSharpDiagnosticSeverity.Error, 3350, (2, 5, 2, 23), - "Feature 'Boolean-returning and return-type-directed partial active patterns' is not available in F# 8.0. Please use language version 'PREVIEW' or greater.")|] - - [] - let ``Can not receive result from bool active pattern`` () = - fail - """let (|IsA|_|) x = x = "A" - -match "A" with -| IsA result -> "A" -| _ -> "Not A" - -match "A" with -| IsA result -> result -| _ -> "Not A" - -match "A" with -| IsA "to match return value" -> "Matched" -| _ -> "not Matched" -""" - [|(FSharpDiagnosticSeverity.Error, 1, (4, 3, 4, 13), - "This expression was expected to have type - 'string -> bool' -but here has type - 'bool' "); - (FSharpDiagnosticSeverity.Error, 39, (4, 7, 4, 13), - "The value or constructor 'result' is not defined. Maybe you want one of the following: - Result"); - (FSharpDiagnosticSeverity.Error, 1, (8, 3, 8, 13), - "This expression was expected to have type - 'string -> bool' -but here has type - 'bool' "); - (FSharpDiagnosticSeverity.Error, 39, (8, 7, 8, 13), - "The value or constructor 'result' is not defined. Maybe you want one of the following: - Result"); - (FSharpDiagnosticSeverity.Error, 1, (12, 3, 12, 30), - "This expression was expected to have type - 'string -> bool' -but here has type - 'bool' "); - |] diff --git a/tests/fsharp/FSharpSuite.Tests.fsproj b/tests/fsharp/FSharpSuite.Tests.fsproj index 5d0a0c5e698..b6d69d8ae1a 100644 --- a/tests/fsharp/FSharpSuite.Tests.fsproj +++ b/tests/fsharp/FSharpSuite.Tests.fsproj @@ -71,7 +71,6 @@ - From 1859fe035ea9c1a8b51bb4e9a058a402c777c12a Mon Sep 17 00:00:00 2001 From: ijklam Date: Sat, 20 Jan 2024 00:51:55 +0800 Subject: [PATCH 19/25] format code --- src/Compiler/Facilities/LanguageFeatures.fs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Compiler/Facilities/LanguageFeatures.fs b/src/Compiler/Facilities/LanguageFeatures.fs index 687141aa04e..e7c2a25ee3d 100644 --- a/src/Compiler/Facilities/LanguageFeatures.fs +++ b/src/Compiler/Facilities/LanguageFeatures.fs @@ -338,7 +338,8 @@ type LanguageVersion(versionText) = | LanguageFeature.PreferExtensionMethodOverPlainProperty -> FSComp.SR.featurePreferExtensionMethodOverPlainProperty () | LanguageFeature.WarningIndexedPropertiesGetSetSameType -> FSComp.SR.featureWarningIndexedPropertiesGetSetSameType () | LanguageFeature.WarningWhenTailCallAttrOnNonRec -> FSComp.SR.featureChkTailCallAttrOnNonRec () - | LanguageFeature.BooleanReturningAndReturnTypeDirectedPartialActivePattern -> FSComp.SR.featureBooleanReturningAndReturnTypeDirectedPartialActivePattern () + | LanguageFeature.BooleanReturningAndReturnTypeDirectedPartialActivePattern -> + FSComp.SR.featureBooleanReturningAndReturnTypeDirectedPartialActivePattern () /// Get a version string associated with the given feature. static member GetFeatureVersionString feature = From 2d675277a1198684ed03e5c94125069df32ddc14 Mon Sep 17 00:00:00 2001 From: ijklam Date: Sat, 20 Jan 2024 01:30:42 +0800 Subject: [PATCH 20/25] fix test --- ...eturningAndReturnTypeDirectedPartialActivePatternTests.fs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/FSharp.Compiler.ComponentTests/Language/BooleanReturningAndReturnTypeDirectedPartialActivePatternTests.fs b/tests/FSharp.Compiler.ComponentTests/Language/BooleanReturningAndReturnTypeDirectedPartialActivePatternTests.fs index 343f0179d47..f1858deba4c 100644 --- a/tests/FSharp.Compiler.ComponentTests/Language/BooleanReturningAndReturnTypeDirectedPartialActivePatternTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Language/BooleanReturningAndReturnTypeDirectedPartialActivePatternTests.fs @@ -13,12 +13,14 @@ let runCode = evalInSharedSession fsiSession [] let ``Partial struct active pattern returns ValueOption`1 without []`` () = FSharp "let (|P1|_|) x = ValueNone" + |> withLangVersionPreview |> typecheck |> shouldSucceed [] let ``Partial struct active pattern returns bool`` () = FSharp "let (|P1|_|) x = false" + |> withLangVersionPreview |> typecheck |> shouldSucceed @@ -28,6 +30,7 @@ let ``Single case active pattern returning bool should success`` () = let (|IsA|) x = x = "A" let (IsA r) = "A" """ + |> withLangVersionPreview |> typecheck |> shouldSucceed @@ -51,6 +54,7 @@ match "x" with | EqualTo "x" -> () | _ -> fail "with argument" """ + |> withLangVersionPreview |> runCode |> shouldSucceed @@ -85,6 +89,7 @@ match "A" with | IsA "to match return value" -> "Matched" | _ -> "not Matched" """ + |> withLangVersionPreview |> typecheck |> shouldSucceed |> withDiagnostics [ From 5438fa2fd3ecdd3ade65cf2443b25a5b113d992d Mon Sep 17 00:00:00 2001 From: ijklam Date: Sat, 20 Jan 2024 10:23:06 +0800 Subject: [PATCH 21/25] fix tests --- ...dReturnTypeDirectedPartialActivePatternTests.fs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/FSharp.Compiler.ComponentTests/Language/BooleanReturningAndReturnTypeDirectedPartialActivePatternTests.fs b/tests/FSharp.Compiler.ComponentTests/Language/BooleanReturningAndReturnTypeDirectedPartialActivePatternTests.fs index f1858deba4c..7d70f08b1c4 100644 --- a/tests/FSharp.Compiler.ComponentTests/Language/BooleanReturningAndReturnTypeDirectedPartialActivePatternTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Language/BooleanReturningAndReturnTypeDirectedPartialActivePatternTests.fs @@ -69,8 +69,8 @@ let (|OddVOption|_|) x = if x % 2 = 1 then ValueSome() else ValueNone |> typecheck |> shouldSucceed |> withDiagnostics [ - (Warning 3350, Line 1, Col 5, Line 1, Col 20, "Feature 'Boolean-returning and return-type-directed partial active patterns' is not available in F# 8.0. Please use language version 'PREVIEW' or greater.") - (Warning 3350, Line 2, Col 5, Line 2, Col 23, "Feature 'Boolean-returning and return-type-directed partial active patterns' is not available in F# 8.0. Please use language version 'PREVIEW' or greater.") + (Warning 3350, Line 1, Col 4, Line 1, Col 19, "Feature 'Boolean-returning and return-type-directed partial active patterns' is not available in F# 8.0. Please use language version 'PREVIEW' or greater.") + (Warning 3350, Line 2, Col 4, Line 2, Col 22, "Feature 'Boolean-returning and return-type-directed partial active patterns' is not available in F# 8.0. Please use language version 'PREVIEW' or greater.") ] [] @@ -93,23 +93,23 @@ match "A" with |> typecheck |> shouldSucceed |> withDiagnostics [ - (Error 1, Line 4, Col 3, Line 4, Col 13, + (Error 1, Line 4, Col 2, Line 4, Col 12, "This expression was expected to have type 'string -> bool' but here has type 'bool' ") - (Error 39, Line 4, Col 7, Line 4, Col 13, + (Error 39, Line 4, Col 6, Line 4, Col 12, "The value or constructor 'result' is not defined. Maybe you want one of the following: Result") - (Error 1, Line 8, Col 3, Line 8, Col 13, + (Error 1, Line 8, Col 2, Line 8, Col 12, "This expression was expected to have type 'string -> bool' but here has type 'bool' ") - (Error 39, Line 8, Col 7, Line 8, Col 13, + (Error 39, Line 8, Col 6, Line 8, Col 12, "The value or constructor 'result' is not defined. Maybe you want one of the following: Result") - (Error 1, Line 12, Col 3, Line 12, Col 30, + (Error 1, Line 12, Col 2, Line 12, Col 29, "This expression was expected to have type 'string -> bool' but here has type From f443d8795444e7ee6eead806df1a72477bd16a91 Mon Sep 17 00:00:00 2001 From: ijklam Date: Sat, 20 Jan 2024 14:34:37 +0800 Subject: [PATCH 22/25] fix tests --- ...ReturningAndReturnTypeDirectedPartialActivePatternTests.fs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/FSharp.Compiler.ComponentTests/Language/BooleanReturningAndReturnTypeDirectedPartialActivePatternTests.fs b/tests/FSharp.Compiler.ComponentTests/Language/BooleanReturningAndReturnTypeDirectedPartialActivePatternTests.fs index 7d70f08b1c4..c66c6906767 100644 --- a/tests/FSharp.Compiler.ComponentTests/Language/BooleanReturningAndReturnTypeDirectedPartialActivePatternTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Language/BooleanReturningAndReturnTypeDirectedPartialActivePatternTests.fs @@ -67,7 +67,7 @@ let (|OddVOption|_|) x = if x % 2 = 1 then ValueSome() else ValueNone """ |> withLangVersion80 |> typecheck - |> shouldSucceed + |> shouldFail |> withDiagnostics [ (Warning 3350, Line 1, Col 4, Line 1, Col 19, "Feature 'Boolean-returning and return-type-directed partial active patterns' is not available in F# 8.0. Please use language version 'PREVIEW' or greater.") (Warning 3350, Line 2, Col 4, Line 2, Col 22, "Feature 'Boolean-returning and return-type-directed partial active patterns' is not available in F# 8.0. Please use language version 'PREVIEW' or greater.") @@ -91,7 +91,7 @@ match "A" with """ |> withLangVersionPreview |> typecheck - |> shouldSucceed + |> shouldFail |> withDiagnostics [ (Error 1, Line 4, Col 2, Line 4, Col 12, "This expression was expected to have type From b86dd321b9b45227726fc72eeb027e30fb751eac Mon Sep 17 00:00:00 2001 From: ijklam Date: Sat, 20 Jan 2024 17:33:51 +0800 Subject: [PATCH 23/25] fix tests --- ...dReturnTypeDirectedPartialActivePatternTests.fs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/FSharp.Compiler.ComponentTests/Language/BooleanReturningAndReturnTypeDirectedPartialActivePatternTests.fs b/tests/FSharp.Compiler.ComponentTests/Language/BooleanReturningAndReturnTypeDirectedPartialActivePatternTests.fs index c66c6906767..ce630714e64 100644 --- a/tests/FSharp.Compiler.ComponentTests/Language/BooleanReturningAndReturnTypeDirectedPartialActivePatternTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Language/BooleanReturningAndReturnTypeDirectedPartialActivePatternTests.fs @@ -69,8 +69,8 @@ let (|OddVOption|_|) x = if x % 2 = 1 then ValueSome() else ValueNone |> typecheck |> shouldFail |> withDiagnostics [ - (Warning 3350, Line 1, Col 4, Line 1, Col 19, "Feature 'Boolean-returning and return-type-directed partial active patterns' is not available in F# 8.0. Please use language version 'PREVIEW' or greater.") - (Warning 3350, Line 2, Col 4, Line 2, Col 22, "Feature 'Boolean-returning and return-type-directed partial active patterns' is not available in F# 8.0. Please use language version 'PREVIEW' or greater.") + (Error 3350, Line 1, Col 5, Line 1, Col 20, "Feature 'Boolean-returning and return-type-directed partial active patterns' is not available in F# 8.0. Please use language version 'PREVIEW' or greater.") + (Error 3350, Line 2, Col 5, Line 2, Col 23, "Feature 'Boolean-returning and return-type-directed partial active patterns' is not available in F# 8.0. Please use language version 'PREVIEW' or greater.") ] [] @@ -93,23 +93,23 @@ match "A" with |> typecheck |> shouldFail |> withDiagnostics [ - (Error 1, Line 4, Col 2, Line 4, Col 12, + (Error 1, Line 4, Col 3, Line 4, Col 13, "This expression was expected to have type 'string -> bool' but here has type 'bool' ") - (Error 39, Line 4, Col 6, Line 4, Col 12, + (Error 39, Line 4, Col 7, Line 4, Col 13, "The value or constructor 'result' is not defined. Maybe you want one of the following: Result") - (Error 1, Line 8, Col 2, Line 8, Col 12, + (Error 1, Line 8, Col 3, Line 8, Col 13, "This expression was expected to have type 'string -> bool' but here has type 'bool' ") - (Error 39, Line 8, Col 6, Line 8, Col 12, + (Error 39, Line 8, Col 7, Line 8, Col 13, "The value or constructor 'result' is not defined. Maybe you want one of the following: Result") - (Error 1, Line 12, Col 2, Line 12, Col 29, + (Error 1, Line 12, Col 3, Line 12, Col 30, "This expression was expected to have type 'string -> bool' but here has type From 5a882c9d200c8038314798feb3cbbd047648ff57 Mon Sep 17 00:00:00 2001 From: Vlad Zarytovskii Date: Tue, 23 Jan 2024 12:41:39 +0100 Subject: [PATCH 24/25] Updated FCS release notes as well --- docs/release-notes/.FSharp.Compiler.Service/8.0.300.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/release-notes/.FSharp.Compiler.Service/8.0.300.md b/docs/release-notes/.FSharp.Compiler.Service/8.0.300.md index dce836b32be..5a16ed1d5a1 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/8.0.300.md +++ b/docs/release-notes/.FSharp.Compiler.Service/8.0.300.md @@ -8,6 +8,7 @@ * Parser recovers on complex primary constructor patterns, better tree representation for primary constructor patterns. ([PR #16425](https://github.com/dotnet/fsharp/pull/16425)) * Name resolution: keep type vars in subsequent checks ([PR #16456](https://github.com/dotnet/fsharp/pull/16456)) * Higher-order-function-based API for working with the untyped abstract syntax tree. ([PR #16462](https://github.com/dotnet/fsharp/pull/16462)) +* Allow returning bool instead of unit option for partial active patterns. ([Language suggestion #1041](https://github.com/fsharp/fslang-suggestions/issues/1041), [PR #16473](https://github.com/dotnet/fsharp/pull/16473)) ### Changed From 721056c0340e9b33fc897d15230f768afac1e8c9 Mon Sep 17 00:00:00 2001 From: ijklam Date: Fri, 2 Feb 2024 19:03:59 +0800 Subject: [PATCH 25/25] update test --- .../Types/StructTypes/StructActivePatterns.fs | 28 +++++++++---------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/Types/StructTypes/StructActivePatterns.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/Types/StructTypes/StructActivePatterns.fs index 6930393e0bd..1b121b27766 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/Types/StructTypes/StructActivePatterns.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/Types/StructTypes/StructActivePatterns.fs @@ -38,21 +38,19 @@ let rec (|IsOne|_|) someNumber = but here has type 'int option' """) -// [] -// let ``Voption active pattern fails if not using return:Struct attribute`` () = -// Fs """ -// let rec (|IsOne|_|) someNumber = -// match someNumber with -// | 1 -> ValueSome 1 -// | _ -> ValueNone -// """ -// |> withOptions ["--warnaserror+"] -// |> typecheck -// |> shouldFail -// |> withSingleDiagnostic (Error 1,Line 2, Col 9 , Line 2, Col 31, """This expression was expected to have type -// ''a option' -// but here has type -// 'int voption' """) + [] + let ``Voption active pattern fails if not using return:Struct attribute`` () = + Fs """ +let rec (|IsOne|_|) someNumber = + match someNumber with + | 1 -> ValueSome 1 + | _ -> ValueNone +""" + |> withLangVersion80 + |> withOptions ["--warnaserror+"] + |> typecheck + |> shouldFail + |> withSingleDiagnostic (Error 3350, Line 2, Col 9, Line 2, Col 31, "Feature 'Boolean-returning and return-type-directed partial active patterns' is not available in F# 8.0. Please use language version 'PREVIEW' or greater.") [] let ``Rec struct active pattern is possible`` () =