Skip to content

Add BoundNode.Source() method. Improve AssertEx.SetEqual() method#31526

Merged
jcouv merged 2 commits intodotnet:masterfrom
jcouv:test-infra
Dec 19, 2018
Merged

Add BoundNode.Source() method. Improve AssertEx.SetEqual() method#31526
jcouv merged 2 commits intodotnet:masterfrom
jcouv:test-infra

Conversation

@jcouv
Copy link
Member

@jcouv jcouv commented Dec 4, 2018

  • Source() is similar to Dump(), but it produces a C#-like format. It's not meant to be complete or valid code, but I found it extremely useful for working on lowering async-iterator methods. Below is an example.
  • SetEqual() produces an error message which respects the original ordering of the expectations (more usable diff).

Example of output of Source() on the following BoundTryStatement after async rewriting:

        try
        {
            yield return 1;
            Write(""Try "");
            yield return 2;
        }
        finally
        {
            Write(""Finally "");
            await System.Threading.Tasks.Task.CompletedTask;
        }
{
    int temp1;
    temp1 = this.<>1__state;
    try
    {
        switch (temp1)
        {
            case 0:
            case 1:
                goto <tryDispatch-47>;
                break;
            case 2:
                goto <stateMachine-51>;
                break;
        }
        {
            {
                {
                    this.<>s__1 = default;
                    this.<>s__2 = default;
                    {
                        <tryDispatch-47>: ;
                        try
                        {
                            switch (temp1)
                            {
                                case 0:
                                    goto <stateMachine-43>;
                                    break;
                                case 1:
                                    goto <stateMachine-45>;
                                    break;
                            }
                            {
                                {
                                    {
                                        this.<>2__current = 1;
                                        this.<>1__state = temp1 = 0;
                                        goto <yieldReturn-42>;
                                        <stateMachine-43>: ;
                                        this.<>1__state = temp1 = -1;
                                        {
                                            if (!this.<>w__disposeMode) goto <afterif-44>;
                                            goto <finallyLabel-37>;
                                            <afterif-44>: ;
                                        }
                                    }
                                    Write("Try ");
                                    {
                                        this.<>2__current = 2;
                                        this.<>1__state = temp1 = 1;
                                        goto <yieldReturn-42>;
                                        <stateMachine-45>: ;
                                        this.<>1__state = temp1 = -1;
                                        {
                                            if (!this.<>w__disposeMode) goto <afterif-46>;
                                            goto <finallyLabel-37>;
                                            <afterif-46>: ;
                                        }
                                    }
                                }
                                goto <finallyLabel-37>;
                                {
                                }
                            }
                        }
                        catch (Object) 
                        {
                        }
                    }
                    {
                        {
                            <finallyLabel-37>: ;
                            {
                                Write("Finally ");
                                {
                                    System.Runtime.CompilerServices.TaskAwaiter temp2;
                                    {
                                        temp2 = Task.get_CompletedTask().GetAwaiter();
                                        {
                                            if (! BoolLogicalNegation temp2.get_IsCompleted()) goto <afterif-52>;
                                            {
                                                this.<>1__state = temp1 = 2;
                                                this.<>u__1 = temp2;
                                                { temp3 = this; this.<>t__builder.AwaitUnsafeOnCompleted(temp2, temp3) };
                                                goto <exitLabel-41>;
                                                <stateMachine-51>: ;
                                                temp2 = this.<>u__1;
                                                this.<>u__1 = default;
                                                this.<>1__state = temp1 = -1;
                                            }
                                            <afterif-52>: ;
                                        }
                                    }
                                    temp2.GetResult();
                                }
                            }
                            {
                                object temp4;
                                temp4 = this.<>s__1;
                                {
                                    if (!temp4 ObjectNotEqual null) goto <afterif-39>;
                                    {
                                        System.Exception temp5;
                                        temp5 = AsOperator
                                        ;
                                        {
                                            if (!temp5 ObjectEqual null) goto <afterif-38>;
                                            throw temp4;
                                            <afterif-38>: ;
                                        }
                                        Capture(temp5).Throw();
                                    }
                                    <afterif-39>: ;
                                }
                            }
                            this.<>s__2;
                        }
                        {
                            if (!this.<>w__disposeMode) goto <afterif-53>;
                            goto <exprReturn-40>;
                            <afterif-53>: ;
                        }
                    }
                }
                this.<>s__1 = null;
            }
            goto <exprReturn-40>;
        }
    }
    catch (Exception) 
    {
        this.<>1__state = -2;
        this.<>v__promiseOfValueOrEnd.SetException(temp6);
        goto <exitLabel-41>;
    }
    <exprReturn-40>: ;
    this.<>1__state = -2;
    {
        this.<>v__promiseOfValueOrEnd.SetResult(False);
        return;
        <yieldReturn-42>: ;
        this.<>v__promiseOfValueOrEnd.SetResult(True);
    }
    <exitLabel-41>: ;
    return;
}

@jcouv jcouv added Area-Compilers Test Test failures in roslyn-CI labels Dec 4, 2018
@jcouv jcouv added this to the 16.0.P2 milestone Dec 4, 2018
@jcouv jcouv self-assigned this Dec 4, 2018
@jcouv jcouv requested a review from a team as a code owner December 4, 2018 21:43
@jcouv
Copy link
Member Author

jcouv commented Dec 7, 2018

test roslyn-CI please

@jcouv jcouv added the PR For Personal Review Only The PR doesn’t require anyone other than the developer to review it. label Dec 10, 2018
@jcouv jcouv removed the PR For Personal Review Only The PR doesn’t require anyone other than the developer to review it. label Dec 10, 2018
@jcouv jcouv added the PR For Personal Review Only The PR doesn’t require anyone other than the developer to review it. label Dec 13, 2018
@jcouv
Copy link
Member Author

jcouv commented Dec 13, 2018

Hiding this PR for now. Our review pipeline is clogged as it is, with higher priority changes.

/// <summary>
/// Gives an approximate printout of a bound node as C# code.
/// </summary>
internal string Source()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel like this should be GetSource or CalculateSource. Given it's not a property expecting some verb.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is meant to be similar to Dump(). I'll change to DumpSource().


void incrementIndent()
{
indent += 4;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of hard coding 4 everywhere consider making indent size a constant for the outer function.


public static void SetEqual(IEnumerable<string> expected, IEnumerable<string> actual, IEqualityComparer<string> comparer = null, string message = null, string itemSeparator = "\r\n", Func<string, string> itemInspector = null)
{
var indexes = new Dictionary<string, int>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this take comparer as a parameter (after calculating a default value when null).


public static void SetEqual<T>(IEnumerable<T> expected, IEnumerable<T> actual, IEqualityComparer<T> comparer = null, string message = null, string itemSeparator = "\r\n", Func<T, string> itemInspector = null)
{
var expectedSet = new HashSet<T>(expected, comparer);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we be calculating a default here ...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not necessary. Passing null is ok.
That's existing logic and HashSet and Dictionary can handle null comparers.

@jaredpar
Copy link
Member

Done with review pass (iteration 1)

@jcouv jcouv removed the PR For Personal Review Only The PR doesn’t require anyone other than the developer to review it. label Dec 18, 2018
@jcouv
Copy link
Member Author

jcouv commented Dec 18, 2018

@jaredpar Please take another look when you get the chance. Addressed your feedback. Thanks

@jcouv jcouv merged commit b001793 into dotnet:master Dec 19, 2018
@jcouv jcouv deleted the test-infra branch December 19, 2018 19:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-Compilers Test Test failures in roslyn-CI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants