/// <summary> /// Attempts to find a driver based on <paramref name="cacheKey"/>. If a matching driver is found in the /// cache, or explicitly passed via <paramref name="driver"/>, the cache is updated so that it is at the /// head of the list. /// </summary> /// <param name="cacheKey">The key to lookup the driver by in the cache</param> /// <param name="driver">An optional driver that should be cached, if not already found in the cache</param> /// <returns></returns> private GeneratorDriver?AddOrUpdateMostRecentlyUsed(string cacheKey, GeneratorDriver?driver) { lock (_cacheLock) { // try and find the driver if it's present int i = 0; for (; i < _cacheSize; i++) { if (_cachedDrivers[i].cacheKey == cacheKey) { driver ??= _cachedDrivers[i].driver; break; } } // if we found it (or were passed a new one), update the cache so its at the head of the list if (driver is not null) { for (i = Math.Min(i, MaxCacheSize - 1); i > 0; i--) { _cachedDrivers[i] = _cachedDrivers[i - 1]; } _cachedDrivers[0] = (cacheKey, driver); _cacheSize = Math.Min(MaxCacheSize, _cacheSize + 1); } return(driver); } }
public CompilationTrackerGeneratorInfo( TextDocumentStates <SourceGeneratedDocumentState> documents, GeneratorDriver?driver, bool documentsAreFinal) { Documents = documents; Driver = driver; DocumentsAreFinal = documentsAreFinal; }
public CompilationTrackerGeneratorInfo( TextDocumentStates <SourceGeneratedDocumentState> documents, GeneratorDriver?driver, bool documentsAreFinal, bool documentsAreFinalAndFrozen = false) { Documents = documents; Driver = driver; DocumentsAreFinal = documentsAreFinal; DocumentsAreFinalAndFrozen = documentsAreFinalAndFrozen; // If we're frozen, that implies final as well Contract.ThrowIfTrue(documentsAreFinalAndFrozen && !documentsAreFinal); }
protected State( ValueSource <Optional <Compilation> >?compilationWithoutGeneratedDocuments, Compilation?declarationOnlyCompilation, TextDocumentStates <SourceGeneratedDocumentState> generatedDocuments, GeneratorDriver?generatorDriver, bool generatedDocumentsAreFinal) { // Declaration-only compilations should never have any references Contract.ThrowIfTrue(declarationOnlyCompilation != null && declarationOnlyCompilation.ExternalReferences.Any()); CompilationWithoutGeneratedDocuments = compilationWithoutGeneratedDocuments; DeclarationOnlyCompilation = declarationOnlyCompilation; GeneratedDocuments = generatedDocuments; GeneratorDriver = generatorDriver; GeneratedDocumentsAreFinal = generatedDocumentsAreFinal; }
public static State Create( Compilation compilation, TextDocumentStates <SourceGeneratedDocumentState> generatedDocuments, GeneratorDriver?generatorDriver, Compilation?compilationWithGeneratedDocuments, ImmutableArray <ValueTuple <ProjectState, CompilationAndGeneratorDriverTranslationAction> > intermediateProjects) { Contract.ThrowIfTrue(intermediateProjects.IsDefault); // If we don't have any intermediate projects to process, just initialize our // DeclarationState now. We'll pass false for generatedDocumentsAreFinal because this is being called // if our referenced projects are changing, so we'll have to rerun to consume changes. return(intermediateProjects.Length == 0 ? new FullDeclarationState(compilation, generatedDocuments, generatorDriver, generatedDocumentsAreFinal: false) : new InProgressState(compilation, generatedDocuments, generatorDriver, compilationWithGeneratedDocuments, intermediateProjects)); }
public CompilationTrackerGeneratorInfo WithDriver(GeneratorDriver?driver) => Driver == driver ? this : new(Documents, driver, DocumentsAreFinal, DocumentsAreFinalAndFrozen);
public TrackedGeneratorDriver(GeneratorDriver?generatorDriver) { GeneratorDriver = generatorDriver; NeedsFullGeneration = true; }
public InProgressState( Compilation inProgressCompilation, TextDocumentStates <SourceGeneratedDocumentState> generatedDocuments, GeneratorDriver?generatorDriver, Compilation?compilationWithGeneratedDocuments, ImmutableArray <(ProjectState state, CompilationAndGeneratorDriverTranslationAction action)> intermediateProjects)