@@ -2,6 +2,7 @@ package incremental
2
2
3
3
import (
4
4
"context"
5
+ "iter"
5
6
"maps"
6
7
"slices"
7
8
"sync"
@@ -41,8 +42,8 @@ func (h *affectedFilesHandler) getDtsMayChange(affectedFilePath tspath.Path, aff
41
42
42
43
func (h * affectedFilesHandler ) isChangedSignature (path tspath.Path ) bool {
43
44
newSignature , _ := h .updatedSignatures .Load (path )
44
- oldSignature := h .program .snapshot .fileInfos [ path ]. signature
45
- return newSignature != oldSignature
45
+ oldInfo , _ := h .program .snapshot .fileInfos . Load ( path )
46
+ return newSignature != oldInfo . signature
46
47
}
47
48
48
49
func (h * affectedFilesHandler ) removeSemanticDiagnosticsOf (path tspath.Path ) {
@@ -81,7 +82,7 @@ func (h *affectedFilesHandler) updateShapeSignature(file *ast.SourceFile, useFil
81
82
return false
82
83
}
83
84
84
- info := h .program .snapshot .fileInfos [ file .Path ()]
85
+ info , _ := h .program .snapshot .fileInfos . Load ( file .Path ())
85
86
prevSignature := info .signature
86
87
var latestSignature string
87
88
var updateKind SignatureUpdateKind
@@ -110,7 +111,7 @@ func (h *affectedFilesHandler) getFilesAffectedBy(path tspath.Path) []*ast.Sourc
110
111
return []* ast.SourceFile {file }
111
112
}
112
113
113
- if info := h .program .snapshot .fileInfos [ file .Path ()] ; info .affectsGlobalScope {
114
+ if info , _ := h .program .snapshot .fileInfos . Load ( file .Path ()) ; info .affectsGlobalScope {
114
115
h .hasAllFilesExcludingDefaultLibraryFile .Store (true )
115
116
h .program .snapshot .getAllFilesExcludingDefaultLibraryFile (h .program .program , file )
116
117
}
@@ -139,10 +140,10 @@ func (h *affectedFilesHandler) getFilesAffectedBy(path tspath.Path) []*ast.Sourc
139
140
}
140
141
141
142
// Gets the files referenced by the the file path
142
- func (h * affectedFilesHandler ) getReferencedByPaths (file tspath.Path ) map [tspath.Path ]struct {} {
143
+ func (h * affectedFilesHandler ) getReferencedByPaths (file tspath.Path ) iter. Seq [tspath.Path ] {
143
144
keys , ok := h .program .snapshot .referencedMap .GetKeys (file )
144
145
if ! ok {
145
- return nil
146
+ return func ( yield func (tspath. Path ) bool ) {}
146
147
}
147
148
return keys .Keys ()
148
149
}
@@ -154,8 +155,7 @@ func (h *affectedFilesHandler) forEachFileReferencedBy(file *ast.SourceFile, fn
154
155
seenFileNamesMap := map [tspath.Path ]* ast.SourceFile {}
155
156
// Start with the paths this file was referenced by
156
157
seenFileNamesMap [file .Path ()] = file
157
- references := h .getReferencedByPaths (file .Path ())
158
- queue := slices .Collect (maps .Keys (references ))
158
+ queue := slices .Collect (h .getReferencedByPaths (file .Path ()))
159
159
for len (queue ) > 0 {
160
160
currentPath := queue [len (queue )- 1 ]
161
161
queue = queue [:len (queue )- 1 ]
@@ -290,7 +290,7 @@ func (h *affectedFilesHandler) handleDtsMayChangeOfFileAndExportsOfFile(dtsMayCh
290
290
}
291
291
292
292
func (h * affectedFilesHandler ) handleDtsMayChangeOfGlobalScope (dtsMayChange dtsMayChange , filePath tspath.Path , invalidateJsFiles bool ) bool {
293
- if info , ok := h .program .snapshot .fileInfos [ filePath ] ; ! ok || ! info .affectsGlobalScope {
293
+ if info , ok := h .program .snapshot .fileInfos . Load ( filePath ) ; ! ok || ! info .affectsGlobalScope {
294
294
return false
295
295
}
296
296
// Every file needs to be handled
@@ -331,7 +331,9 @@ func (h *affectedFilesHandler) updateSnapshot() {
331
331
return
332
332
}
333
333
h .updatedSignatures .Range (func (filePath tspath.Path , signature string ) bool {
334
- h .program .snapshot .fileInfos [filePath ].signature = signature
334
+ if info , ok := h .program .snapshot .fileInfos .Load (filePath ); ok {
335
+ info .signature = signature
336
+ }
335
337
return true
336
338
})
337
339
if h .updatedSignatureKinds != nil {
@@ -341,33 +343,34 @@ func (h *affectedFilesHandler) updateSnapshot() {
341
343
})
342
344
}
343
345
h .filesToRemoveDiagnostics .Range (func (file tspath.Path ) bool {
344
- delete ( h .program .snapshot .semanticDiagnosticsPerFile , file )
346
+ h .program .snapshot .semanticDiagnosticsPerFile . Delete ( file )
345
347
return true
346
348
})
347
349
for _ , change := range h .dtsMayChange {
348
350
for filePath , emitKind := range change {
349
351
h .program .snapshot .addFileToAffectedFilesPendingEmit (filePath , emitKind )
350
352
}
351
353
}
352
- h .program .snapshot .changedFilesSet = & collections.Set [tspath.Path ]{}
353
- h .program .snapshot .buildInfoEmitPending = true
354
+ h .program .snapshot .changedFilesSet = collections.SyncSet [tspath.Path ]{}
355
+ h .program .snapshot .buildInfoEmitPending . Store ( true )
354
356
}
355
357
356
358
func collectAllAffectedFiles (ctx context.Context , program * Program ) {
357
- if program .snapshot .changedFilesSet .Len () == 0 {
359
+ if program .snapshot .changedFilesSet .Size () == 0 {
358
360
return
359
361
}
360
362
361
363
handler := affectedFilesHandler {ctx : ctx , program : program , updatedSignatureKinds : core .IfElse (program .updatedSignatureKinds == nil , nil , & collections.SyncMap [tspath.Path , SignatureUpdateKind ]{})}
362
364
wg := core .NewWorkGroup (handler .program .program .SingleThreaded ())
363
365
var result collections.SyncSet [* ast.SourceFile ]
364
- for file := range program .snapshot .changedFilesSet .Keys () {
366
+ program .snapshot .changedFilesSet .Range ( func ( file tspath. Path ) bool {
365
367
wg .Queue (func () {
366
368
for _ , affectedFile := range handler .getFilesAffectedBy (file ) {
367
369
result .Add (affectedFile )
368
370
}
369
371
})
370
- }
372
+ return true
373
+ })
371
374
wg .RunAndWait ()
372
375
373
376
if ctx .Err () != nil {
0 commit comments