public void DriverCache_Returns_Null_For_No_Match() { var driverCache = new GeneratorDriverCache(); var driver = driverCache.TryGetDriver("0"); Assert.Null(driver); }
public void DriverCache_Returns_Cached_Driver() { var drivers = GetDrivers(1); var driverCache = new GeneratorDriverCache(); driverCache.CacheGenerator("0", drivers[0]); var driver = driverCache.TryGetDriver("0"); Assert.Same(driver, drivers[0]); }
public void DriverCache_Evicts_Least_Recently_Used() { var drivers = GetDrivers(GeneratorDriverCache.MaxCacheSize + 2); var driverCache = new GeneratorDriverCache(); // put n+1 drivers into the cache for (int i = 0; i < GeneratorDriverCache.MaxCacheSize + 1; i++) { driverCache.CacheGenerator(i.ToString(), drivers[i]); } // current cache state is // (10, 9, 8, 7, 6, 5, 4, 3, 2, 1) // now try and retrieve the first driver which should no longer be in the cache var driver = driverCache.TryGetDriver("0"); Assert.Null(driver); // add it back driverCache.CacheGenerator("0", drivers[0]); // current cache state is // (0, 10, 9, 8, 7, 6, 5, 4, 3, 2) // access some drivers in the middle driver = driverCache.TryGetDriver("7"); driver = driverCache.TryGetDriver("4"); driver = driverCache.TryGetDriver("2"); // current cache state is // (2, 4, 7, 0, 10, 9, 8, 6, 5, 3) // try and get a new driver that was never in the cache driver = driverCache.TryGetDriver("11"); Assert.Null(driver); driverCache.CacheGenerator("11", drivers[11]); // current cache state is // (11, 2, 4, 7, 0, 10, 9, 8, 6, 5) // get a driver that has been evicted driver = driverCache.TryGetDriver("3"); Assert.Null(driver); }
public void DriverCache_Can_Cache_Multiple_Drivers() { var drivers = GetDrivers(3); var driverCache = new GeneratorDriverCache(); driverCache.CacheGenerator("0", drivers[0]); driverCache.CacheGenerator("1", drivers[1]); driverCache.CacheGenerator("2", drivers[2]); var driver = driverCache.TryGetDriver("0"); Assert.Same(driver, drivers[0]); driver = driverCache.TryGetDriver("1"); Assert.Same(driver, drivers[1]); driver = driverCache.TryGetDriver("2"); Assert.Same(driver, drivers[2]); }
internal CSharpCompilerServer(Func <string, MetadataReferenceProperties, PortableExecutableReference> metadataProvider, string?responseFile, string[] args, BuildPaths buildPaths, string?libDirectory, IAnalyzerAssemblyLoader analyzerLoader, GeneratorDriverCache driverCache) : base(CSharpCommandLineParser.Default, responseFile, args, buildPaths, libDirectory, analyzerLoader, driverCache) { _metadataProvider = metadataProvider; }
internal CSharpCompilerServer(Func <string, MetadataReferenceProperties, PortableExecutableReference> metadataProvider, string[] args, BuildPaths buildPaths, string?libDirectory, IAnalyzerAssemblyLoader analyzerLoader, GeneratorDriverCache driverCache) : this(metadataProvider, Path.Combine(buildPaths.ClientDirectory, ResponseFileName), args, buildPaths, libDirectory, analyzerLoader, driverCache) { }
public MockCSharpCompiler(string responseFile, BuildPaths buildPaths, string[] args, ImmutableArray <DiagnosticAnalyzer> analyzers = default, ImmutableArray <ISourceGenerator> generators = default, AnalyzerAssemblyLoader loader = null, GeneratorDriverCache driverCache = null) : base(CSharpCommandLineParser.Default, responseFile, args, buildPaths, Environment.GetEnvironmentVariable("LIB"), loader ?? new DefaultAnalyzerAssemblyLoader(), driverCache) { _analyzers = analyzers.NullToEmpty(); _generators = generators.NullToEmpty(); }
internal MockCSharpCompiler CreateCSharpCompiler(string responseFile, string workingDirectory, string[] args, ImmutableArray <DiagnosticAnalyzer> analyzers = default, ImmutableArray <ISourceGenerator> generators = default, AnalyzerAssemblyLoader loader = null, GeneratorDriverCache driverCache = null) { var buildPaths = RuntimeUtilities.CreateBuildPaths(workingDirectory, sdkDirectory: SdkDirectory); return(new MockCSharpCompiler(responseFile, buildPaths, args, analyzers, generators, loader, driverCache)); }
internal MockCSharpCompiler CreateCSharpCompiler(string[] args, ImmutableArray <DiagnosticAnalyzer> analyzers = default, ImmutableArray <ISourceGenerator> generators = default, AnalyzerAssemblyLoader loader = null, GeneratorDriverCache driverCache = null) { return(CreateCSharpCompiler(null, WorkingDirectory, args, analyzers, generators, loader, driverCache)); }