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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/release-notes/.FSharp.Compiler.Service/11.0.0.md
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
19 changes: 14 additions & 5 deletions 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
Loading