Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assert fires in EnsureMetadataVirtual #73563

Closed
AlekseyTs opened this issue May 17, 2024 · 1 comment · Fixed by #75066
Closed

Assert fires in EnsureMetadataVirtual #73563

AlekseyTs opened this issue May 17, 2024 · 1 comment · Fixed by #75066
Assignees
Labels
4 - In Review A fix for the issue is submitted for review. Area-Compilers New Feature - Async Streams Async Streams
Milestone

Comments

@AlekseyTs
Copy link
Contributor

Assert fires in EnsureMetadataVirtual when the tests below are executed with CompilationExtensions.EnableVerifyUsedAssemblies set to true.

            public void EnsureMetadataVirtual()
            {
                // ACASEY: This assert is here to check that we're not mutating the value of IsMetadataVirtual after
                // someone has consumed it.  The best practice is to not access IsMetadataVirtual before ForceComplete
                // has been called on all SourceNamedTypeSymbols.  If it is necessary to do so, then you can pass
                // ignoreInterfaceImplementationChanges: true, but you must be conscious that seeing "false" may not
                // reflect the final, emitted modifier.
                Debug.Assert(!IsMetadataVirtualLocked);
                if ((_flags & IsMetadataVirtualBit) == 0)
                {
                    ThreadSafeFlagOperations.Set(ref _flags, IsMetadataVirtualBit);
                }
            }

Call stack:

>	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.Symbols.SourceMemberMethodSymbol.Flags.EnsureMetadataVirtual() Line 272	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.Symbols.SourceMemberMethodSymbol.EnsureMetadataVirtual() Line 569	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.Symbols.SourceMemberContainerTypeSymbol.SynthesizeInterfaceMemberImplementation(Microsoft.CodeAnalysis.CSharp.Symbols.TypeSymbol.SymbolAndDiagnostics implementingMemberAndDiagnostics, Microsoft.CodeAnalysis.CSharp.Symbol interfaceMember) Line 1852	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.Symbols.SourceMemberContainerTypeSymbol.ComputeInterfaceImplementations(Microsoft.CodeAnalysis.CSharp.BindingDiagnosticBag diagnostics, System.Threading.CancellationToken cancellationToken) Line 179	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.Symbols.SourceMemberContainerTypeSymbol.GetSynthesizedExplicitImplementations(System.Threading.CancellationToken cancellationToken) Line 52	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.Symbols.SourceMemberContainerTypeSymbol.ForceComplete(Microsoft.CodeAnalysis.SourceLocation locationOpt, System.Predicate<Microsoft.CodeAnalysis.CSharp.Symbol> filter, System.Threading.CancellationToken cancellationToken) Line 610	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.Symbol.ForceCompleteMemberConditionally(Microsoft.CodeAnalysis.SourceLocation locationOpt, System.Predicate<Microsoft.CodeAnalysis.CSharp.Symbol> filter, Microsoft.CodeAnalysis.CSharp.Symbol member, System.Threading.CancellationToken cancellationToken) Line 964	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.Symbols.SourceNamespaceSymbol.ForceComplete(Microsoft.CodeAnalysis.SourceLocation locationOpt, System.Predicate<Microsoft.CodeAnalysis.CSharp.Symbol> filter, System.Threading.CancellationToken cancellationToken) Line 80	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.Symbols.SourceModuleSymbol.ForceComplete(Microsoft.CodeAnalysis.SourceLocation locationOpt, System.Predicate<Microsoft.CodeAnalysis.CSharp.Symbol> filter, System.Threading.CancellationToken cancellationToken) Line 272	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.Symbols.SourceAssemblySymbol.ForceComplete(Microsoft.CodeAnalysis.SourceLocation locationOpt, System.Predicate<Microsoft.CodeAnalysis.CSharp.Symbol> filter, System.Threading.CancellationToken cancellationToken) Line 929	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.CSharpCompilation.GetSourceDeclarationDiagnostics(Microsoft.CodeAnalysis.SyntaxTree syntaxTree, Microsoft.CodeAnalysis.Text.TextSpan? filterSpanWithinTree, System.Func<System.Collections.Generic.IEnumerable<Microsoft.CodeAnalysis.Diagnostic>, Microsoft.CodeAnalysis.SyntaxTree, Microsoft.CodeAnalysis.Text.TextSpan?, System.Collections.Generic.IEnumerable<Microsoft.CodeAnalysis.Diagnostic>> locationFilterOpt, System.Predicate<Microsoft.CodeAnalysis.CSharp.Symbol> symbolFilter, System.Threading.CancellationToken cancellationToken) Line 3214	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.CSharpCompilation.GetDiagnosticsWithoutSeverityFiltering(Microsoft.CodeAnalysis.CompilationStage stage, bool includeEarlierStages, Microsoft.CodeAnalysis.CSharp.BindingDiagnosticBag builder, System.Predicate<Microsoft.CodeAnalysis.CSharp.Symbol> symbolFilter, System.Threading.CancellationToken cancellationToken) Line 2988	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.CSharpCompilation.GetCompleteSetOfUsedAssemblies(System.Threading.CancellationToken cancellationToken) Line 71	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.CSharpCompilation.GetCompleteSetOfUsedAssemblies.__completeTheSetOfUsedAssemblies|339_2(bool seenErrors, System.Threading.CancellationToken cancellationToken) Line 170	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.CSharpCompilation.GetCompleteSetOfUsedAssemblies(System.Threading.CancellationToken cancellationToken) Line 86	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.CSharpCompilation.GetUsedAssemblyReferences(System.Threading.CancellationToken cancellationToken) Line 25	C#
 	Microsoft.CodeAnalysis.CSharp.Test.Utilities.dll!Microsoft.CodeAnalysis.CSharp.Test.Utilities.CSharpTestBase.VerifyUsedAssemblyReferences(System.Func<Microsoft.CodeAnalysis.CSharp.CSharpCompilation> createCompilationLambda) Line 1312	C#
 	Microsoft.CodeAnalysis.CSharp.Test.Utilities.dll!Microsoft.CodeAnalysis.CSharp.Test.Utilities.CSharpTestBase.ValidateCompilation(System.Func<Microsoft.CodeAnalysis.CSharp.CSharpCompilation> createCompilationLambda) Line 1300	C#
 	Microsoft.CodeAnalysis.CSharp.Test.Utilities.dll!Microsoft.CodeAnalysis.CSharp.Test.Utilities.CSharpTestBase.CreateCompilationCore(Microsoft.CodeAnalysis.CSharp.Test.Utilities.CSharpTestSource source, System.Collections.Generic.IEnumerable<Microsoft.CodeAnalysis.MetadataReference> references, Microsoft.CodeAnalysis.CSharp.CSharpCompilationOptions options, Microsoft.CodeAnalysis.CSharp.CSharpParseOptions parseOptions, string assemblyName, string sourceFileName, bool skipUsesIsNullable, Microsoft.CodeAnalysis.CSharp.MessageID? experimentalFeature, bool skipExtraValidation) Line 1275	C#
 	Microsoft.CodeAnalysis.CSharp.Test.Utilities.dll!Microsoft.CodeAnalysis.CSharp.Test.Utilities.CSharpTestBase.CreateEmptyCompilation(Microsoft.CodeAnalysis.CSharp.Test.Utilities.CSharpTestSource source, System.Collections.Generic.IEnumerable<Microsoft.CodeAnalysis.MetadataReference> references, Microsoft.CodeAnalysis.CSharp.CSharpCompilationOptions options, Microsoft.CodeAnalysis.CSharp.CSharpParseOptions parseOptions, string assemblyName, string sourceFileName, bool skipUsesIsNullable, bool skipExtraValidation) Line 1239	C#
 	Microsoft.CodeAnalysis.CSharp.Test.Utilities.dll!Microsoft.CodeAnalysis.CSharp.Test.Utilities.CSharpTestBase.CreateCompilation(Microsoft.CodeAnalysis.CSharp.Test.Utilities.CSharpTestSource source, System.Collections.Generic.IEnumerable<Microsoft.CodeAnalysis.MetadataReference> references, Microsoft.CodeAnalysis.CSharp.CSharpCompilationOptions options, Microsoft.CodeAnalysis.CSharp.CSharpParseOptions parseOptions, Roslyn.Test.Utilities.TargetFramework targetFramework, string assemblyName, string sourceFileName, bool skipUsesIsNullable) Line 1228	C#
 	Microsoft.CodeAnalysis.CSharp.Emit2.UnitTests.dll!Microsoft.CodeAnalysis.CSharp.UnitTests.Semantics.ParamsCollectionTests.Test1() Line 15795	C#

The tests:

        [Fact]
        public void Test1()
        {
            var src1 = @"
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

public struct S : IAsyncEnumerable<int>
{
    public IAsyncEnumerator<int> GetAsyncEnumerator(CancellationToken token = default) => throw null;
}
";

            var comp1 = CreateCompilation(src1, targetFramework: TargetFramework.Net80);

            var src2 = @"
using System.Threading.Tasks;

class C
{
    static async Task Main()
    {
        await foreach (var i in new S())
        {
        }
    }
}
";
            var comp2 = CreateCompilation(src2, references: [comp1.ToMetadataReference()], targetFramework: TargetFramework.Net80);
            comp2.VerifyEmitDiagnostics();
        }

        [Fact]
        public void Test2()
        {
            var src1 = @"
using System;
using System.Threading.Tasks;

public struct S2 : IAsyncDisposable
{
    public ValueTask DisposeAsync()
    {
        return ValueTask.CompletedTask;
    }
}
";

            var comp1 = CreateCompilation(src1, targetFramework: TargetFramework.Net80);

            var src2 = @"
class C
{
    static async System.Threading.Tasks.Task Main()
    {
        await using (new S2())
        {
        }

        await using (var s = new S2())
        {
        }
    }
}
";
            var comp2 = CreateCompilation(src2, references: [comp1.ToMetadataReference()], targetFramework: TargetFramework.Net80);
            comp2.VerifyEmitDiagnostics();
        }
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels May 17, 2024
@jaredpar jaredpar added New Feature - Async Streams Async Streams and removed untriaged Issues and PRs which have not yet been triaged by a lead labels May 20, 2024
@jaredpar jaredpar added this to the 17.11 milestone May 20, 2024
@jaredpar
Copy link
Member

@jcouv to assess impact of potential async issue.

@jaredpar jaredpar modified the milestones: 17.11, 17.12 Jul 23, 2024
@jcouv jcouv added the 4 - In Review A fix for the issue is submitted for review. label Sep 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4 - In Review A fix for the issue is submitted for review. Area-Compilers New Feature - Async Streams Async Streams
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants