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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
485 changes: 485 additions & 0 deletions src/fsharp/.github/agents/fsharp-generic.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* Fix: warn FS0049 on upper union case label. ([PR #19003](https://github.com/dotnet/fsharp/pull/19003))
* Type relations cache: handle potentially "infinite" types ([PR #19010](https://github.com/dotnet/fsharp/pull/19010))
* Disallow recursive structs with lifted type parameters ([Issue #18993](https://github.com/dotnet/fsharp/issues/18993), [PR #19031](https://github.com/dotnet/fsharp/pull/19031))
* Fix units-of-measure changes not invalidating incremental builds. ([Issue #19049](https://github.com/dotnet/fsharp/issues/19049))

### Added

Expand Down
4 changes: 2 additions & 2 deletions src/fsharp/global.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
"tools": {
"dotnet": "10.0.100-rc.1.25420.111",
"vs": {
"version": "17.8",
"version": "17.14",
"components": [
"Microsoft.VisualStudio.Component.FSharp"
]
},
"xcopy-msbuild": "17.13.0"
"xcopy-msbuild": "17.14.16"
},
"native-tools": {
"perl": "5.38.2.2"
Expand Down
19 changes: 14 additions & 5 deletions src/fsharp/src/Compiler/Utilities/TypeHashing.fs
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,22 @@ module rec HashTypes =
|> pipeToHash memberHash

/// Hash a unit of measure expression
let private hashMeasure unt =
let measuresWithExponents =
let private hashMeasure g unt =
let measureVarsWithExponents =
ListMeasureVarOccsWithNonZeroExponents unt
|> List.sortBy (fun (tp: Typar, _) -> tp.DisplayName)

measuresWithExponents
|> hashListOrderIndependent (fun (typar, exp: Rational) -> hashTyparRef typar @@ hash exp)
let measureConsWithExponents = ListMeasureConOccsWithNonZeroExponents g false unt

let varHash =
measureVarsWithExponents
|> hashListOrderIndependent (fun (typar, exp: Rational) -> hashTyparRef typar @@ hash exp)

let conHash =
measureConsWithExponents
|> hashListOrderIndependent (fun (tcref, exp: Rational) -> hashTyconRef tcref @@ hash exp)

varHash @@ conHash

/// Hash a type, taking precedence into account to insert brackets where needed
let hashTType (g: TcGlobals) ty =
Expand All @@ -217,7 +226,7 @@ module rec HashTypes =
let argTys, retTy = stripFunTy g ty
argTys |> hashListOrderMatters (hashTType g) |> pipeToHash (hashTType g retTy)
| TType_var(r, _) -> hashTyparRefWithInfo r
| TType_measure unt -> hashMeasure unt
| TType_measure unt -> hashMeasure g unt

// Hash a single argument, including its name and type
let private hashArgInfo (g: TcGlobals) (ty, argInfo: ArgReprInfo) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,16 @@ type BAttribute() =

let a ([<B>] c: int) : int = 0 """)>]

[<InlineDataAttribute("UnitsOfMeasureChanged",
(*BEFORE*)"""module MyTest
[<Measure>] type kg
[<Measure>] type m
type MyRecord = { Mass: int<kg> }"""
(*AFTER*),"""module MyTest
[<Measure>] type kg
[<Measure>] type m
type MyRecord = { Mass: int<m> }""")>]

//TODO add a lot more negative tests - in which cases should hash in fact change

[<Theory>]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,43 +76,49 @@ type internal AddReturnType [<ImportingConstructor>] () =

override _.ComputeRefactoringsAsync context =
cancellableTask {
let document = context.Document
let position = context.Span.Start
let! sourceText = document.GetTextAsync()
let textLine = sourceText.Lines.GetLineFromPosition position
let textLinePos = sourceText.Lines.GetLinePosition position
let fcsTextLineNumber = Line.fromZ textLinePos.Line

let! lexerSymbol =
document.TryFindFSharpLexerSymbolAsync(position, SymbolLookupKind.Greedy, false, false, nameof (AddReturnType))

let! (parseFileResults, checkFileResults) = document.GetFSharpParseAndCheckResultsAsync(nameof (AddReturnType))

let symbolUseOpt =
lexerSymbol
|> Option.bind (fun lexer ->
checkFileResults.GetSymbolUseAtLocation(
fcsTextLineNumber,
lexer.Ident.idRange.EndColumn,
textLine.ToString(),
lexer.FullIsland
))

let memberFuncOpt =
symbolUseOpt
|> Option.bind (fun sym -> sym.Symbol |> AddReturnType.ofFSharpMemberOrFunctionOrValue)

match (symbolUseOpt, memberFuncOpt) with
| (Some symbolUse, Some memberFunc) ->
let isValidMethod =
memberFunc
|> AddReturnType.isValidMethodWithoutTypeAnnotation symbolUse parseFileResults

match isValidMethod with
| Some(memberFunc, typeRange) -> do AddReturnType.refactor context (memberFunc, typeRange, symbolUse)
| None -> ()
| _ -> ()

return ()
try
let document = context.Document
let position = context.Span.Start
let! sourceText = document.GetTextAsync()
let textLine = sourceText.Lines.GetLineFromPosition position
let textLinePos = sourceText.Lines.GetLinePosition position
let fcsTextLineNumber = Line.fromZ textLinePos.Line

let! lexerSymbol =
document.TryFindFSharpLexerSymbolAsync(position, SymbolLookupKind.Greedy, false, false, nameof (AddReturnType))

let! (parseFileResults, checkFileResults) = document.GetFSharpParseAndCheckResultsAsync(nameof (AddReturnType))

let symbolUseOpt =
lexerSymbol
|> Option.bind (fun lexer ->
checkFileResults.GetSymbolUseAtLocation(
fcsTextLineNumber,
lexer.Ident.idRange.EndColumn,
textLine.ToString(),
lexer.FullIsland
))

let memberFuncOpt =
symbolUseOpt
|> Option.bind (fun sym -> sym.Symbol |> AddReturnType.ofFSharpMemberOrFunctionOrValue)

match (symbolUseOpt, memberFuncOpt) with
| (Some symbolUse, Some memberFunc) ->
let isValidMethod =
memberFunc
|> AddReturnType.isValidMethodWithoutTypeAnnotation symbolUse parseFileResults

match isValidMethod with
| Some(memberFunc, typeRange) -> do AddReturnType.refactor context (memberFunc, typeRange, symbolUse)
| None -> ()
| _ -> ()

return ()
with _ ->
// File is not part of the project yet, or project options are not ready.
// This can happen when files are added/copied before the project system updates.
// Just return without offering any refactorings.
return ()
}
|> CancellableTask.startAsTask context.CancellationToken
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ private void AddOutputPath(Microsoft.Build.Construction.ProjectPropertyGroupElem
string outputBasePath = this.ProjectMgr.OutputBaseRelativePath;
if (outputBasePath.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal))
outputBasePath = Path.GetDirectoryName(outputBasePath);
newConfig.AddProperty("OutputPath", Path.Combine(outputBasePath, configName) + Path.DirectorySeparatorChar.ToString());
newConfig.AddProperty("OutputPath", Path.Combine(outputBasePath, configName) + Path.DirectorySeparatorChar.ToString());

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ open Xunit
open FSharp.Editor.Tests.Refactors.RefactorTestFramework
open FSharp.Test.ProjectGeneration
open FSharp.Editor.Tests.Helpers
open Microsoft.CodeAnalysis
open Microsoft.CodeAnalysis.Text
open Microsoft.CodeAnalysis.CodeRefactorings
open Microsoft.CodeAnalysis.CodeActions

[<Theory>]
[<InlineData(":int")>]
Expand Down Expand Up @@ -479,3 +483,42 @@ let sum a b : MyType = {Value=a+b}

let resultText = newDoc.GetTextAsync() |> GetTaskResult
Assert.Equal(expectedCode.Trim(' ', '\r', '\n'), resultText.ToString().Trim(' ', '\r', '\n'))

[<Fact>]
let ``Should not throw when file is not properly configured`` () =
let symbolName = "sum"

let code =
"""
let sum a b = a + b
"""

use context = TestContext.CreateWithCode code

let spanStart = code.IndexOf symbolName

// Create a document that's not in the F# project options by adding it to solution
// but not to the project's source files list. This simulates the race condition
// where a file is copied but project options haven't been refreshed yet.
let project = context.Solution.Projects |> Seq.head
let newDocId = DocumentId.CreateNewId(project.Id)

let newDoc =
context.Solution.AddDocument(newDocId, "NotInProject.fs", code, filePath = "C:\\NotInProject.fs")

let documentNotInProject = newDoc.GetDocument(newDocId)

let refactoringActions = new System.Collections.Generic.List<CodeAction>()

let refactoringContext =
CodeRefactoringContext(documentNotInProject, TextSpan(spanStart, 1), (fun a -> refactoringActions.Add a), context.CancellationToken)

let refactorProvider = new AddReturnType()

// This should not throw even though the document is not in the project options
let computeTask = refactorProvider.ComputeRefactoringsAsync refactoringContext

computeTask.Wait(context.CancellationToken)

// The test passes if no exception was thrown
Assert.True(true)
4 changes: 2 additions & 2 deletions src/source-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
"commitSha": "987d1a73ea67d323c0fc7537bce8ec65d87eb43f"
},
{
"barId": 289351,
"barId": 289781,
"path": "fsharp",
"remoteUri": "https://github.com/dotnet/fsharp",
"commitSha": "9670f600f7aab99d4b4fe95c41ed83e3e008c489"
"commitSha": "726845e18bb622c07d53797d195f5972f26a36d1"
},
{
"barId": 288357,
Expand Down