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

Definite assignment, initial nullable, IOperation, and some cleanup #54585

Merged
merged 14 commits into from Jul 8, 2021

Conversation

333fred
Copy link
Member

@333fred 333fred commented Jul 3, 2021

Implements support for definite assignment, initial nullable support, initial IOperation support, and does a bit of prototype comment cleanup. Next week I'll add some additional commits cleaning up the rest of the prototype comments in this branch, they're mainly around adding tests for dynamic to be sure of behavior, ref escape behavior custom interpolated string handler arguments, and condensing message numbers for merge.

Test plan: #51499

@333fred 333fred requested a review from a team as a code owner July 3, 2021 01:04
@jcouv
Copy link
Member

jcouv commented Jul 6, 2021

    public void DefiniteAssignment(bool useBoolReturns, bool trailingOutParameter)

It would be good to include a region analysis test as well.


Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs:10243 in 1db9ee9. [](commit_id = 1db9ee9, deletion_comment = False)

Copy link
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

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

Done with review pass (iteration 5)

@333fred
Copy link
Member Author

333fred commented Jul 7, 2021

    public void DefiniteAssignment(bool useBoolReturns, bool trailingOutParameter)

Is this something you want to block on, or can it be added later?


In reply to: 874428443


Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs:10243 in 1db9ee9. [](commit_id = 1db9ee9, deletion_comment = False)

@333fred
Copy link
Member Author

333fred commented Jul 7, 2021

Done with review pass (iteration 5)


In reply to: 699512610

@jcouv
Copy link
Member

jcouv commented Jul 7, 2021

@333fred There seems to be legitimate test failures

}
else
{
Join(ref State, ref beforePartsState);
Copy link
Member

@jcouv jcouv Jul 7, 2021

Choose a reason for hiding this comment

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

I didn't understand this case. Why do we need to Join when none of the evaluations are conditional?
Feels like State is already correct when we get here. #Closed

Copy link
Member Author

Choose a reason for hiding this comment

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

It is not. hasTrailingValidityParameter will be true in that case.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the clarification

Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: this also confused me. Consider adding a comment.

@jcouv
Copy link
Member

jcouv commented Jul 7, 2021

    public void DefiniteAssignment(bool useBoolReturns, bool trailingOutParameter)

I'm okay to do later. I think the nullability scenarios cover the parts of AbstractFlowPass that I was worried about.


In reply to: 875184267


Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs:10243 in 1db9ee9. [](commit_id = 1db9ee9, deletion_comment = False)

{
// We assume non-bool returns if there was no parts to the string, and code below is predicated on that.
Debug.Assert(!node.Parts.IsEmpty);
// Start the sequence with appendProceedLocal, if appropriate
BoundExpression? currentExpression = appendShouldProceedLocal;

var boolType = _compilation.GetSpecialType(SpecialType.System_Boolean);
Copy link
Member

@jcouv jcouv Jul 7, 2021

Choose a reason for hiding this comment

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

nit (ie. not blocking): we'll want a test where we make the type missing

Copy link
Member Author

Choose a reason for hiding this comment

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

Of note, we required this type during initial binding.

@jcouv
Copy link
Member

jcouv commented Jul 7, 2021

                // (6,5): error CS0165: Use of unassigned local variable 'i'

This seems unexpected when trailingOutParameter is false.


In reply to: 875882504


In reply to: 875882504


In reply to: 875882504


Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs:10267 in 73be92a. [](commit_id = 73be92a, deletion_comment = False)

@jcouv
Copy link
Member

jcouv commented Jul 7, 2021

    }

You've covered the definite assignments that I could think of :-)
Just to confirm, usage of argument attribute would not modify affects those scenarios in interesting ways, is that correct?


In reply to: 875883536


In reply to: 875883536


Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs:10310 in 73be92a. [](commit_id = 73be92a, deletion_comment = False)

@jcouv
Copy link
Member

jcouv commented Jul 7, 2021

";

nit: all the ref escape tests have this odd spacing (extra blank line)


Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs:11013 in 73be92a. [](commit_id = 73be92a, deletion_comment = False)

Copy link
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

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

Done with review pass (iteration 9)

@jcouv jcouv self-assigned this Jul 7, 2021
@333fred
Copy link
Member Author

333fred commented Jul 7, 2021

                // (6,5): error CS0165: Use of unassigned local variable 'i'

That would be the failing test.


In reply to: 875882504


Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs:10267 in 73be92a. [](commit_id = 73be92a, deletion_comment = False)

@333fred
Copy link
Member Author

333fred commented Jul 7, 2021

    }

That is correct.


In reply to: 875883536


Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs:10310 in 73be92a. [](commit_id = 73be92a, deletion_comment = False)

@jcouv
Copy link
Member

jcouv commented Jul 7, 2021

    }

nit: Not blocking, but I'd consider adding a CustomHandler c = $""{M(out var o)}{o}""; test with bool returns (should give definite assignment error on second hole/expression).


In reply to: 875936424 #Closed


Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs:10293 in 73be92a. [](commit_id = 73be92a, deletion_comment = False)

{
Debug.Assert(interpolatedString.InterpolationData != null);
var data = interpolatedString.InterpolationData.GetValueOrDefault();
return GetValEscape(data.Construction, scopeOfTheContainingExpression);
Copy link
Member

Choose a reason for hiding this comment

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

Just to confirm we don't need to deal with GetRefEscape here in some cases?
The escapes rules are complicated enough that I'm having trouble reloading this on the fly...

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't believe so, but this is not my strongest area.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree here that I think its ok, but I'm not 100% convinced. Can we add a work item to try and make a test that convinces us?

@333fred
Copy link
Member Author

333fred commented Jul 7, 2021

    }

This is a success case, not a failure case.


In reply to: 875936424


Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs:10293 in ae6c341. [](commit_id = ae6c341, deletion_comment = False)

Copy link
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

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

LGTM Thanks (iteration 11). Remaining test questions/suggestions can be tracked for later.

@jcouv
Copy link
Member

jcouv commented Jul 7, 2021

    }

Doh. Thanks :-)


In reply to: 875939910


Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs:10293 in 73be92a. [](commit_id = 73be92a, deletion_comment = False)

{
var builder = ArrayBuilder<IInterpolatedStringContentOperation>.GetInstance(parts.Length);
foreach (var part in parts)
return data is { PositionInfo: var positionInfo } ? createHandlerInterpolatedStringContent(positionInfo) : createNonHandlerInterpolatedStringContent();
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: personally I find these a or b methods with a pair of local functions harder to follow logically. Also the extra method call could be inefficient. (Purely personal, but just something to consider)

Copy link
Member Author

Choose a reason for hiding this comment

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

Also the extra method call could be inefficient.

It's small enough that the JIT will likely just inline the containing call :).

@@ -1105,7 +1105,10 @@ public override void VisitInterpolatedString(IInterpolatedStringOperation operat
public override void VisitInterpolatedStringText(IInterpolatedStringTextOperation operation)
{
Assert.Equal(OperationKind.InterpolatedStringText, operation.Kind);
Assert.Equal(OperationKind.Literal, operation.Text.Kind);
if (operation.Text.Kind != OperationKind.Literal)
Copy link
Contributor

Choose a reason for hiding this comment

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

Stupid question: why do we know its not a literal? because it could be dynamic?

Copy link
Member Author

Choose a reason for hiding this comment

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

We don't know it's not a literal. If it is a literal, everything is fine. If it's not a literal, it must be a conversion wrapping a literal.

@333fred 333fred merged commit 93b9822 into dotnet:features/interpolated-string Jul 8, 2021
@333fred 333fred deleted the cleanup branch July 8, 2021 04:38
@jcouv
Copy link
Member

jcouv commented Jul 22, 2021

nit: It looks like this PR was merged instead of squashed :-/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants