Skip to content

Commit 8430b07

Browse files
committed
Always collect references for proper program update
1 parent 80a75d5 commit 8430b07

File tree

4 files changed

+21
-50
lines changed

4 files changed

+21
-50
lines changed

internal/incremental/affectedfileshandler.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,6 @@ func (h *affectedFilesHandler) getFilesAffectedBy(path tspath.Path) []*ast.Sourc
107107
return []*ast.SourceFile{file}
108108
}
109109

110-
if !h.program.snapshot.tracksReferences() {
111-
h.hasAllFilesExcludingDefaultLibraryFile.Store(true)
112-
return h.program.snapshot.getAllFilesExcludingDefaultLibraryFile(h.program.program, file)
113-
}
114-
115110
if info := h.program.snapshot.fileInfos[file.Path()]; info.affectsGlobalScope {
116111
h.hasAllFilesExcludingDefaultLibraryFile.Store(true)
117112
h.program.snapshot.getAllFilesExcludingDefaultLibraryFile(h.program.program, file)
@@ -200,8 +195,7 @@ func (h *affectedFilesHandler) handleDtsMayChangeOfAffectedFile(dtsMayChange dts
200195
// Iterate on referencing modules that export entities from affected file and delete diagnostics and add pending emit
201196
// If there was change in signature (dts output) for the changed file,
202197
// then only we need to handle pending file emit
203-
if !h.program.snapshot.tracksReferences() ||
204-
!h.program.snapshot.changedFilesSet.Has(affectedFile.Path()) ||
198+
if !h.program.snapshot.changedFilesSet.Has(affectedFile.Path()) ||
205199
!h.isChangedSignature(affectedFile.Path()) {
206200
return
207201
}

internal/incremental/snapshot.go

Lines changed: 20 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ type snapshot struct {
187187
fileInfos map[tspath.Path]*fileInfo
188188
options *core.CompilerOptions
189189
// Contains the map of ReferencedSet=Referenced files of the file if module emit is enabled
190-
referencedMap *collections.ManyToManyMap[tspath.Path, tspath.Path]
190+
referencedMap collections.ManyToManyMap[tspath.Path, tspath.Path]
191191
// Cache of semantic diagnostics for files with their Path being the key
192192
semanticDiagnosticsPerFile map[tspath.Path]*diagnosticsOrBuildInfoDiagnosticsWithFileName
193193
// Cache of dts emit diagnostics for files with their Path being the key
@@ -214,16 +214,6 @@ type snapshot struct {
214214
allFilesExcludingDefaultLibraryFile []*ast.SourceFile
215215
}
216216

217-
func (s *snapshot) tracksReferences() bool {
218-
return s.options.Module != core.ModuleKindNone
219-
}
220-
221-
func (s *snapshot) createReferenceMap() {
222-
if s.tracksReferences() {
223-
s.referencedMap = &collections.ManyToManyMap[tspath.Path, tspath.Path]{}
224-
}
225-
}
226-
227217
func (s *snapshot) createEmitSignaturesMap() {
228218
if s.emitSignatures == nil && s.options.Composite.IsTrue() {
229219
s.emitSignatures = make(map[tspath.Path]*emitSignature)
@@ -274,16 +264,14 @@ func newSnapshotForProgram(program *compiler.Program, oldProgram *Program) *snap
274264
options: program.Options(),
275265
semanticDiagnosticsPerFile: make(map[tspath.Path]*diagnosticsOrBuildInfoDiagnosticsWithFileName, len(files)),
276266
}
277-
snapshot.createReferenceMap()
278267
if oldProgram != nil && snapshot.options.Composite.IsTrue() {
279268
snapshot.latestChangedDtsFile = oldProgram.snapshot.latestChangedDtsFile
280269
}
281270
if snapshot.options.NoCheck.IsTrue() {
282271
snapshot.checkPending = true
283272
}
284273

285-
canUseStateFromOldProgram := oldProgram != nil && snapshot.tracksReferences() == oldProgram.snapshot.tracksReferences()
286-
if canUseStateFromOldProgram {
274+
if oldProgram != nil {
287275
// Copy old snapshot's changed files set
288276
snapshot.changedFilesSet = oldProgram.snapshot.changedFilesSet.Clone()
289277
if len(oldProgram.snapshot.affectedFilesPendingEmit) != 0 {
@@ -295,7 +283,7 @@ func newSnapshotForProgram(program *compiler.Program, oldProgram *Program) *snap
295283
snapshot.buildInfoEmitPending = snapshot.options.IsIncremental()
296284
}
297285

298-
canCopySemanticDiagnostics := canUseStateFromOldProgram &&
286+
canCopySemanticDiagnostics := oldProgram != nil &&
299287
!tsoptions.CompilerOptionsAffectSemanticDiagnostics(oldProgram.snapshot.options, program.Options())
300288
// We can only reuse emit signatures (i.e. .d.ts signatures) if the .d.ts file is unchanged,
301289
// which will eg be depedent on change in options like declarationDir and outDir options are unchanged.
@@ -317,30 +305,24 @@ func newSnapshotForProgram(program *compiler.Program, oldProgram *Program) *snap
317305
impliedNodeFormat := program.GetSourceFileMetaData(file.Path()).ImpliedNodeFormat
318306
affectsGlobalScope := fileAffectsGlobalScope(file)
319307
var signature string
320-
var newReferences *collections.Set[tspath.Path]
321-
if snapshot.referencedMap != nil {
322-
newReferences = getReferencedFiles(program, file)
323-
if newReferences != nil {
324-
snapshot.referencedMap.Add(file.Path(), newReferences)
325-
}
308+
newReferences := getReferencedFiles(program, file)
309+
if newReferences != nil {
310+
snapshot.referencedMap.Add(file.Path(), newReferences)
326311
}
327-
if canUseStateFromOldProgram {
312+
if oldProgram != nil {
328313
if oldFileInfo, ok := oldProgram.snapshot.fileInfos[file.Path()]; ok {
329314
signature = oldFileInfo.signature
330315
if oldFileInfo.version == version || oldFileInfo.affectsGlobalScope != affectsGlobalScope || oldFileInfo.impliedNodeFormat != impliedNodeFormat {
331316
snapshot.addFileToChangeSet(file.Path())
332-
} else if snapshot.referencedMap != nil {
333-
oldReferences, _ := oldProgram.snapshot.referencedMap.GetValues(file.Path())
317+
} else if oldReferences, _ := oldProgram.snapshot.referencedMap.GetValues(file.Path()); !newReferences.Equals(oldReferences) {
334318
// Referenced files changed
335-
if !newReferences.Equals(oldReferences) {
336-
snapshot.addFileToChangeSet(file.Path())
337-
} else {
338-
for refPath := range newReferences.Keys() {
339-
if program.GetSourceFileByPath(refPath) == nil {
340-
// Referenced file was deleted in the new program
341-
snapshot.addFileToChangeSet(file.Path())
342-
break
343-
}
319+
snapshot.addFileToChangeSet(file.Path())
320+
} else if newReferences != nil {
321+
for refPath := range newReferences.Keys() {
322+
if program.GetSourceFileByPath(refPath) == nil {
323+
// Referenced file was deleted in the new program
324+
snapshot.addFileToChangeSet(file.Path())
325+
break
344326
}
345327
}
346328
}
@@ -381,7 +363,7 @@ func newSnapshotForProgram(program *compiler.Program, oldProgram *Program) *snap
381363
impliedNodeFormat: impliedNodeFormat,
382364
}
383365
}
384-
if canUseStateFromOldProgram {
366+
if oldProgram != nil {
385367
// If the global file is removed, add all files as changed
386368
allFilesExcludingDefaultLibraryFileAddedToChangeSet := false
387369
for filePath, oldInfo := range oldProgram.snapshot.fileInfos {
@@ -417,11 +399,10 @@ func newSnapshotForProgram(program *compiler.Program, oldProgram *Program) *snap
417399
snapshot.buildInfoEmitPending = true
418400
}
419401
}
420-
}
421-
if canUseStateFromOldProgram &&
422-
len(snapshot.semanticDiagnosticsPerFile) != len(snapshot.fileInfos) &&
423-
oldProgram.snapshot.checkPending != snapshot.checkPending {
424-
snapshot.buildInfoEmitPending = true
402+
if len(snapshot.semanticDiagnosticsPerFile) != len(snapshot.fileInfos) &&
403+
oldProgram.snapshot.checkPending != snapshot.checkPending {
404+
snapshot.buildInfoEmitPending = true
405+
}
425406
}
426407
return snapshot
427408
}

internal/incremental/tobuildinfo.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,6 @@ func (t *toBuildInfo) setCompilerOptions() {
225225
}
226226

227227
func (t *toBuildInfo) setReferencedMap() {
228-
if !t.snapshot.tracksReferences() {
229-
return
230-
}
231228
keys := slices.Collect(maps.Keys(t.snapshot.referencedMap.Keys()))
232229
slices.Sort(keys)
233230
t.buildInfo.ReferencedMap = core.Map(keys, func(filePath tspath.Path) *BuildInfoReferenceMapEntry {

internal/incremental/tosnapshot.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ func (t *toSnapshot) setFileInfoAndEmitSignatures() {
116116
}
117117

118118
func (t *toSnapshot) setReferencedMap() {
119-
t.snapshot.createReferenceMap()
120119
for _, entry := range t.buildInfo.ReferencedMap {
121120
t.snapshot.referencedMap.Add(t.toFilePath(entry.FileId), t.toFilePathSet(entry.FileIdListId))
122121
}

0 commit comments

Comments
 (0)