Skip to content

Commit 6ec56c2

Browse files
authored
Fix units-of-measure changes not invalidating incremental builds (#19050)
1 parent 2d08fc4 commit 6ec56c2

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

docs/release-notes/.FSharp.Compiler.Service/11.0.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* Fix: warn FS0049 on upper union case label. ([PR #19003](https://github.com/dotnet/fsharp/pull/19003))
88
* Type relations cache: handle potentially "infinite" types ([PR #19010](https://github.com/dotnet/fsharp/pull/19010))
99
* 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))
10+
* Fix units-of-measure changes not invalidating incremental builds. ([Issue #19049](https://github.com/dotnet/fsharp/issues/19049))
1011

1112
### Added
1213

src/Compiler/Utilities/TypeHashing.fs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,13 +188,22 @@ module rec HashTypes =
188188
|> pipeToHash memberHash
189189

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

196-
measuresWithExponents
197-
|> hashListOrderIndependent (fun (typar, exp: Rational) -> hashTyparRef typar @@ hash exp)
196+
let measureConsWithExponents = ListMeasureConOccsWithNonZeroExponents g false unt
197+
198+
let varHash =
199+
measureVarsWithExponents
200+
|> hashListOrderIndependent (fun (typar, exp: Rational) -> hashTyparRef typar @@ hash exp)
201+
202+
let conHash =
203+
measureConsWithExponents
204+
|> hashListOrderIndependent (fun (tcref, exp: Rational) -> hashTyconRef tcref @@ hash exp)
205+
206+
varHash @@ conHash
198207

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

222231
// Hash a single argument, including its name and type
223232
let private hashArgInfo (g: TcGlobals) (ty, argInfo: ArgReprInfo) =

tests/FSharp.Compiler.ComponentTests/Signatures/ImpliedSignatureHashTests.fs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,16 @@ type BAttribute() =
288288
289289
let a ([<B>] c: int) : int = 0 """)>]
290290

291+
[<InlineDataAttribute("UnitsOfMeasureChanged",
292+
(*BEFORE*)"""module MyTest
293+
[<Measure>] type kg
294+
[<Measure>] type m
295+
type MyRecord = { Mass: int<kg> }"""
296+
(*AFTER*),"""module MyTest
297+
[<Measure>] type kg
298+
[<Measure>] type m
299+
type MyRecord = { Mass: int<m> }""")>]
300+
291301
//TODO add a lot more negative tests - in which cases should hash in fact change
292302

293303
[<Theory>]

0 commit comments

Comments
 (0)