Skip to content
Open
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.200.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* `FsiEvaluationSession.EvalInteraction` and `EvalInteractionNonThrowing` evaluate every `;;`-separated interaction in the text they are given, as their documentation has always said, instead of silently discarding everything after the first. ([PR #20396](https://github.com/dotnet/fsharp/pull/20396))
* Fix runtime-async callbacks chosen by a branch rerunning their setup and losing shared state on each call, `Await` inlined into a `with` handler not being rewritten, and `Await` in an object-expression base constructor call not being reported. ([Issue #20577](https://github.com/dotnet/fsharp/issues/20577), [PR #20647](https://github.com/dotnet/fsharp/pull/20647))
* Inline members can now call inline base-class members with optimizations off while retaining debugger step-into. Uneliminated `base` references report FS3925 instead of an internal error. ([Issue #20614](https://github.com/dotnet/fsharp/issues/20614), [PR #20639](https://github.com/dotnet/fsharp/pull/20639))
* Fix intermittent FS0073 "Undefined or unsolved type variable" (and, since the codegen fallback was added, silently miscompiled closures) in Release builds with parallel compilation. Lambda lifting rewrote the type parameters of every type definition in place, so another file optimized concurrently could see a type whose type parameters no longer matched its field types. ([Issue #20812](https://github.com/dotnet/fsharp/issues/20812), [PR #20879](https://github.com/dotnet/fsharp/pull/20879))
* Prevent `InvalidProgramException` when runtime async awaits a `Task<T>` upcast to `Task`, including through `ConfigureAwait`. ([Issue #20686](https://github.com/dotnet/fsharp/issues/20686), [PR #20726](https://github.com/dotnet/fsharp/pull/20726))
* Struct/reference anonymous-record mismatches now name anonymous records rather than tuples. ([Issue #6110](https://github.com/dotnet/fsharp/issues/6110), [PR #20681](https://github.com/dotnet/fsharp/pull/20681))
* Preserve constraint inference order when explicit generic arguments share a caller type parameter, avoiding spurious FS0001 errors with multiply implemented generic interfaces. ([PR #20491](https://github.com/dotnet/fsharp/pull/20491))
Expand Down
16 changes: 11 additions & 5 deletions src/Compiler/TypedTree/TypedTreeOps.Remapping.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2339,10 +2339,10 @@ module internal ExprRemapping =

tcref.Deref

(tycons, tyconsR)
||> List.iter2 (fun tcd tcdR ->
let lookupTycon tycon = lookupTycon tycon
let remapModulType (tcd: Tycon) (tcdR: Tycon) =
tcdR.entity_modul_type <- MaybeLazy.Strict(tcd.entity_modul_type.Value |> mapImmediateValsAndTycons lookupTycon lookupVal)

let remapClonedTycon (tcd: Tycon) (tcdR: Tycon) =
let tpsR, tmenvinner2 =
tmenvCopyRemapAndBindTypars (remapAttribs ctxt tmenvinner) tmenvinner tcd.Typars

Expand All @@ -2351,7 +2351,7 @@ module internal ExprRemapping =
tcdR.entity_tycon_repr <- tcd.entity_tycon_repr |> remapTyconRepr ctxt tmenvinner2
let typeAbbrevR = tcd.TypeAbbrev |> Option.map (remapType tmenvinner2)
tcdR.entity_tycon_tcaug <- tcd.entity_tycon_tcaug |> remapTyconAug tmenvinner2
tcdR.entity_modul_type <- MaybeLazy.Strict(tcd.entity_modul_type.Value |> mapImmediateValsAndTycons lookupTycon lookupVal)
remapModulType tcd tcdR
let exnInfoR = tcd.ExceptionInfo |> remapTyconExnInfo ctxt tmenvinner2

match tcdR.entity_opt_data with
Expand All @@ -2364,7 +2364,13 @@ module internal ExprRemapping =
}
| _ ->
tcdR.SetTypeAbbrev typeAbbrevR
tcdR.SetExceptionInfo exnInfoR)
tcdR.SetExceptionInfo exnInfoR

match compgen with
// copyTycon returned each tycon itself. Other files' optimization may be reading it concurrently,
// so its typars and representation stay untouched; only its vals may have been copied.
| OnlyCloneExprVals -> List.iter2 remapModulType tycons tyconsR
| _ -> List.iter2 remapClonedTycon tycons tyconsR

tyconsR, vsR, tmenvinner

Expand Down
33 changes: 33 additions & 0 deletions tests/FSharp.Compiler.Service.Tests/ExprTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4007,3 +4007,36 @@ let ``ImmediateSubExpressions`` (case: ImmediateSubExpressionsTestCase) =
// on auto-generated comparison code for generic DUs/records.
// Before the fix for #19118, this would crash with ConstraintSolverMissingConstraint.
ProjectForWitnessConditionalComparison.walkAllExpressions case.Source

[<Fact>]
let ``Issue 20812 - optimization leaves the type parameters of checked type definitions untouched`` () =
let source = """
module M

type R<'T> = { F: int -> 'T }

let apply (r: R<'T>) = r.F 1
"""
let options = createProjectOptions [ source ] [ "--optimize+" ]
let exprChecker = FSharpChecker.Create(keepAssemblyContents=true, useTransparentCompiler=CompilerAssertHelpers.UseTransparentCompiler)
let wholeProjectResults = exprChecker.ParseAndCheckProject(options) |> Async.RunSynchronouslyImmediate
wholeProjectResults.Diagnostics |> shouldBeEmpty

let rec tryFindEntity name decls =
decls
|> Seq.tryPick (function
| FSharpImplementationFileDeclaration.Entity(e, _) when e.DisplayName = name -> Some e
| FSharpImplementationFileDeclaration.Entity(_, subDecls) -> tryFindEntity name subDecls
| _ -> None)

let record =
wholeProjectResults.AssemblyContents.ImplementationFiles[0].Declarations
|> tryFindEntity "R"
|> Option.get

let typarsBefore = record.GenericParameters |> Seq.map _.TypeParameter |> List.ofSeq
wholeProjectResults.GetOptimizedAssemblyContents() |> ignore
let typarsAfter = record.GenericParameters |> Seq.map _.TypeParameter |> List.ofSeq

List.forall2 (fun before after -> obj.ReferenceEquals(before, after)) typarsBefore typarsAfter
|> shouldEqual true
Loading