public static MetadataOnlyImage Create(Workspace workspace, ITemporaryStorageService service, Compilation compilation, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); try { workspace.LogTestMessage($"Beginning to create a skeleton assembly for {compilation.AssemblyName}..."); using (Logger.LogBlock(FunctionId.Workspace_SkeletonAssembly_EmitMetadataOnlyImage, cancellationToken)) { // TODO: make it to use SerializableBytes.WritableStream rather than MemoryStream so that // we don't allocate anything for skeleton assembly. using (var stream = SerializableBytes.CreateWritableStream()) { // note: cloning compilation so we don't retain all the generated symbols after its emitted. // * REVIEW * is cloning clone p2p reference compilation as well? var emitResult = compilation.Clone().Emit(stream, options: s_emitOptions, cancellationToken: cancellationToken); if (emitResult.Success) { workspace.LogTestMessage($"Successfully emitted a skeleton assembly for {compilation.AssemblyName}"); var storage = service.CreateTemporaryStreamStorage(cancellationToken); stream.Position = 0; storage.WriteStream(stream, cancellationToken); return(new MetadataOnlyImage(storage, compilation.AssemblyName)); } else { workspace.LogTestMessage($"Failed to create a skeleton assembly for {compilation.AssemblyName}:"); foreach (var diagnostic in emitResult.Diagnostics) { workspace.LogTestMessage(" " + diagnostic.GetMessage()); } // log emit failures so that we can improve most common cases Logger.Log(FunctionId.MetadataOnlyImage_EmitFailure, KeyValueLogMessage.Create(m => { // log errors in the format of // CS0001:1;CS002:10;... var groups = emitResult.Diagnostics.GroupBy(d => d.Id).Select(g => $"{g.Key}:{g.Count()}"); m["Errors"] = string.Join(";", groups); })); } } } } finally { workspace.LogTestMessage($"Done trying to create a skeleton assembly for {compilation.AssemblyName}"); } return(Empty); }
public static MetadataOnlyImage Create(Workspace workspace, ITemporaryStorageService service, Compilation compilation, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); try { workspace.LogTestMessage($"Beginning to create a skeleton assembly for {compilation.AssemblyName}..."); using (Logger.LogBlock(FunctionId.Workspace_SkeletonAssembly_EmitMetadataOnlyImage, cancellationToken)) { // TODO: make it to use SerializableBytes.WritableStream rather than MemoryStream so that // we don't allocate anything for skeleton assembly. using (var stream = SerializableBytes.CreateWritableStream()) { // note: cloning compilation so we don't retain all the generated symbols after its emitted. // * REVIEW * is cloning clone p2p reference compilation as well? var emitResult = compilation.Clone().Emit(stream, options: s_emitOptions, cancellationToken: cancellationToken); if (emitResult.Success) { workspace.LogTestMessage($"Successfully emitted a skeleton assembly for {compilation.AssemblyName}"); var storage = service.CreateTemporaryStreamStorage(cancellationToken); stream.Position = 0; storage.WriteStream(stream, cancellationToken); return(new MetadataOnlyImage(storage, compilation.AssemblyName)); } else { workspace.LogTestMessage($"Failed to create a skeleton assembly for {compilation.AssemblyName}:"); foreach (var diagnostic in emitResult.Diagnostics) { workspace.LogTestMessage(" " + diagnostic.GetMessage()); } } } } } finally { workspace.LogTestMessage($"Done trying to create a skeleton assembly for {compilation.AssemblyName}"); } return(Empty); }
public static MetadataOnlyImage Create(Workspace workspace, ITemporaryStorageService service, Compilation compilation, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); try { workspace.LogTestMessage($"Beginning to create a skeleton assembly for {compilation.AssemblyName}..."); using (Logger.LogBlock(FunctionId.Workspace_SkeletonAssembly_EmitMetadataOnlyImage, cancellationToken)) { // TODO: make it to use SerializableBytes.WritableStream rather than MemoryStream so that // we don't allocate anything for skeleton assembly. using (var stream = SerializableBytes.CreateWritableStream()) { // note: cloning compilation so we don't retain all the generated symbols after its emitted. // * REVIEW * is cloning clone p2p reference compilation as well? var emitResult = compilation.Clone().Emit(stream, options: s_emitOptions, cancellationToken: cancellationToken); if (emitResult.Success) { workspace.LogTestMessage($"Successfully emitted a skeleton assembly for {compilation.AssemblyName}"); var storage = service.CreateTemporaryStreamStorage(cancellationToken); stream.Position = 0; storage.WriteStream(stream, cancellationToken); return new MetadataOnlyImage(storage, compilation.AssemblyName); } else { workspace.LogTestMessage($"Failed to create a skeleton assembly for {compilation.AssemblyName}:"); foreach (var diagnostic in emitResult.Diagnostics) { workspace.LogTestMessage(" " + diagnostic.GetMessage()); } } } } } finally { workspace.LogTestMessage($"Done trying to create a skeleton assembly for {compilation.AssemblyName}"); } return Empty; }