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

Implement definite assignment analysis for tuples #13107

Merged
merged 4 commits into from
Aug 17, 2016

Conversation

VSadov
Copy link
Member

@VSadov VSadov commented Aug 11, 2016

When recording assignments of tuple fields, associate tracking slots with underlying field symbols. This way the element assignment to a tuple field and to a corresponding "ItemX" field would be tracked equivalently.

When checking whether a tuple is definitely assigned, only look at nonvirtual fields - fields that map directly to the actual fields in the top level ValueTuple.

Fixes C# portion of #13046

@VSadov
Copy link
Member Author

VSadov commented Aug 11, 2016

@dotnet/roslyn-compiler - please review

@gafter
Copy link
Member

gafter commented Aug 11, 2016

                var actualFiledType = field.Type;

Could you please correct the spelling here while you're in the neighborhood?


Refers to: src/Compilers/CSharp/Portable/FlowAnalysis/EmptyStructTypeCache.cs:121 in 56f7010. [](commit_id = 56f7010, deletion_comment = False)

// Do not report virtual tuple fields.
// They are additional aliases to the fields of the underlying struct or nested extensions.
// and as such are already accounted for via the nonvirtual fields.
if (field is TupleVirtualElementFieldSymbol)
Copy link
Member

Choose a reason for hiding this comment

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

field is TupleVirtualElementFieldSymbol [](start = 28, length = 39)

I think this test would be better placed inside ShouldIgnoreStructField

Copy link
Member

Choose a reason for hiding this comment

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

Can you please make this the test a new internal virtual boolean property (FieldSymbol.IsVirtualTupleElement) rather than testing for particular implementation types? The latter makes the code more fragile as we refactor inheritance hierarchies, while the virtual property would make the dependency explicit.


In reply to: 74524647 [](ancestors = 74524647)

Copy link
Member Author

Choose a reason for hiding this comment

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

ShouldIgnoreStructField is a method emulating old compiler behavior for not other reasosn than compat and only if _dev12CompilerCompatibility is set.

Ignoring virtual tuple fields has a different reason and is not conditional on a flag. I think we should not mix these.


In reply to: 74525116 [](ancestors = 74525116,74524647)

Copy link
Member Author

Choose a reason for hiding this comment

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

Added a virtual property for the virtual field check.


In reply to: 74851677 [](ancestors = 74851677,74525116,74524647)

@gafter
Copy link
Member

gafter commented Aug 12, 2016

Other than the comment about the type test and virtual property, looks good.


In reply to: 239323243 [](ancestors = 239323243)

@gafter gafter removed their assignment Aug 12, 2016
containingSlot = GetOrCreateSlot(restField, containingSlot);
containingType = restField.Type.TupleUnderlyingTypeOrSelf();
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Would it be worth extracting a helper method for use here and in VariableSlot above: int GetTupleFieldSlot(TupleFieldSymbol field, int containingSlot, bool createIfMissing)?

Copy link
Member Author

Choose a reason for hiding this comment

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

extracted as
int DescendThroughTupleRestFields(ref Symbol symbol, int containingSlot, bool forceContainingSlotsToExist)


In reply to: 74526518 [](ancestors = 74526518)

@VSadov
Copy link
Member Author

VSadov commented Aug 15, 2016

                var actualFiledType = field.Type;

fixed


In reply to: 239328019 [](ancestors = 239328019)


Refers to: src/Compilers/CSharp/Portable/FlowAnalysis/EmptyStructTypeCache.cs:121 in 56f7010. [](commit_id = 56f7010, deletion_comment = False)

{
TypeSymbol containingType = ((TupleTypeSymbol)symbol.ContainingType).UnderlyingNamedType;

// for tuple fields the varible indentifier represents the underlying field
Copy link
Member

Choose a reason for hiding this comment

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

Typo: variable

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

@cston
Copy link
Member

cston commented Aug 16, 2016

LGTM

@@ -700,6 +705,52 @@ protected int GetOrCreateSlot(Symbol symbol, int containingSlot = 0)
return slot;
}

// Descends through Rest fields of a tuple is "symbol" is an extended field
Copy link
Member

Choose a reason for hiding this comment

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

First "is" on this line should be an "if".

@jcouv
Copy link
Member

jcouv commented Aug 16, 2016

LGTM Thanks

private int DescendThroughTupleRestFields(ref Symbol symbol, int containingSlot, bool forceContainingSlotsToExist)
{
var fieldSymbol = symbol as TupleFieldSymbol;
if ((object)fieldSymbol != null)
{
TypeSymbol containingType = ((TupleTypeSymbol)symbol.ContainingType).UnderlyingNamedType;

// for tuple fields the varible indentifier represents the underlying field
// for tuple fields the variable indentifier represents the underlying field
Copy link
Member

Choose a reason for hiding this comment

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

Typo: identifier

@cston
Copy link
Member

cston commented Aug 17, 2016

LGTM

@VSadov
Copy link
Member Author

VSadov commented Aug 17, 2016

Test this please

1 similar comment
@VSadov
Copy link
Member Author

VSadov commented Aug 17, 2016

Test this please

@VSadov
Copy link
Member Author

VSadov commented Aug 17, 2016

@dotnet-bot test windows_debug_unit64_prtest please

@VSadov
Copy link
Member Author

VSadov commented Aug 17, 2016

@dotnet-bot test windows_debug_unit32_prtest please

…bols

Fixed some typos.
Made virtual tuple elements to have right element IDs (needed since we no longer want to rely on symbol types)
Made virtual tuple field equality be sensitive to names. (needed since we no longer can rely on only default elements having IDs)
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.

5 participants