@@ -115,6 +115,7 @@ type internal BootstrapInfo =
115115
116116 LoadClosure: LoadClosure option
117117 LastFileName: string
118+ ImportsInvalidatedByTypeProvider: Event < unit >
118119 }
119120
120121type internal TcIntermediateResult = TcInfo * TcResultsSinkImpl * CheckedImplFile option * string
@@ -742,9 +743,10 @@ type internal TransparentCompiler
742743
743744 /// Bootstrap info that does not depend source files
744745 let ComputeBootstrapInfoStatic ( projectSnapshot : ProjectCore , tcConfig : TcConfig , assemblyName : string , loadClosureOpt ) =
746+ let cacheKey = projectSnapshot.CacheKeyWith( " BootstrapInfoStatic" , assemblyName)
745747
746748 caches.BootstrapInfoStatic.Get(
747- projectSnapshot.CacheKeyWith ( " BootstrapInfoStatic " , assemblyName ) ,
749+ cacheKey ,
748750 node {
749751 use _ =
750752 Activity.start
@@ -816,6 +818,11 @@ type internal TransparentCompiler
816818
817819 let bootstrapId = Interlocked.Increment & BootstrapInfoIdCounter
818820
821+ // TODO: In the future it might make sense to expose the event on the ProjectSnapshot and let the consumer deal with this.
822+ // We could include a timestamp as part of the ProjectSnapshot key that represents the last time since the TypeProvider assembly was invalidated.
823+ // When the event trigger, the consumer could then create a new snapshot based on the updated time.
824+ importsInvalidatedByTypeProvider.Publish.Add( fun () -> caches.Clear( Set.singleton projectSnapshot.Identifier))
825+
819826 return bootstrapId, tcImports, tcGlobals, initialTcInfo, importsInvalidatedByTypeProvider
820827 }
821828 )
@@ -865,7 +872,7 @@ type internal TransparentCompiler
865872 let tcConfig = TcConfig.Create( tcConfigB, validate = true )
866873 let outFile , _ , assemblyName = tcConfigB.DecideNames sourceFiles
867874
868- let! bootstrapId , tcImports , tcGlobals , initialTcInfo , _importsInvalidatedByTypeProvider =
875+ let! bootstrapId , tcImports , tcGlobals , initialTcInfo , importsInvalidatedByTypeProvider =
869876 ComputeBootstrapInfoStatic( projectSnapshot.ProjectCore, tcConfig, assemblyName, loadClosureOpt)
870877
871878 // Check for the existence of loaded sources and prepend them to the sources list if present.
@@ -889,7 +896,7 @@ type internal TransparentCompiler
889896 LoadedSources = loadedSources
890897 LoadClosure = loadClosureOpt
891898 LastFileName = sourceFiles |> List.tryLast |> Option.defaultValue " "
892- // ImportsInvalidatedByTypeProvider = importsInvalidatedByTypeProvider
899+ ImportsInvalidatedByTypeProvider = importsInvalidatedByTypeProvider
893900 }
894901 }
895902
@@ -1719,7 +1726,6 @@ type internal TransparentCompiler
17191726 | None, creationDiags ->
17201727 return FSharpCheckProjectResults( projectSnapshot.ProjectFileName, None, keepAssemblyContents, creationDiags, None)
17211728 | Some bootstrapInfo, creationDiags ->
1722-
17231729 let! snapshotWithSources = LoadSources bootstrapInfo projectSnapshot
17241730
17251731 let! tcInfo , ilAssemRef , assemblyDataResult , checkedImplFiles = ComputeProjectExtras bootstrapInfo snapshotWithSources
0 commit comments