Skip to content

Change name of record Clone method to unspeakable#44852

Merged
agocke merged 1 commit intodotnet:features/recordsfrom
agocke:clone-name
Jun 6, 2020
Merged

Change name of record Clone method to unspeakable#44852
agocke merged 1 commit intodotnet:features/recordsfrom
agocke:clone-name

Conversation

@agocke
Copy link
Member

@agocke agocke commented Jun 4, 2020

The compiler now uses a reserved name for the clone method which only
records will generate. Some existing tests are interesting if we ever
allow user-generation of the clone method but cannot be run in the
current state. I've left them in, but marked them skipped with the
text "unspeakable clone."

Copy link
Member

Choose a reason for hiding this comment

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

It looks like there is also a PROTOTYPE comment on line 53, do we still consider it to be relevant or is overriding/hiding Clone an unsupported scenario?

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 think it's half-relevant in that I haven't thought about hiding. But it should handle overriding -- at least, my understanding of LookupMembersInType is that it will stop looking through base types when it finds a candidate in a derived type.

@agocke agocke force-pushed the clone-name branch 4 times, most recently from f656c76 to 26adbca Compare June 5, 2020 02:57
@agocke agocke marked this pull request as ready for review June 5, 2020 03:01
@agocke agocke requested a review from a team as a code owner June 5, 2020 03:01
Copy link
Member

Choose a reason for hiding this comment

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

For other unspeakable names, don't we use a key letter (such as "k" for backing fields)?

        internal static string MakeBackingFieldName(string propertyName)
        {
            Debug.Assert((char)GeneratedNameKind.AutoPropertyBackingField == 'k');
            return "<" + propertyName + ">k__BackingField";
        }

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, but those examples are generated names where there's a user-dependent component. This is always the same name, so I didn't think it was particularly hard to reverse engineer if we needed to.

@jcouv
Copy link
Member

jcouv commented Jun 5, 2020

    public void WithExpr19()

I couldn't find a test like this (attempting with expression on a regular class) where there is no void Clone() method on that type. Can we add, if we don't have one?


Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/RecordTests.cs:1000 in 26adbca. [](commit_id = 26adbca7ce47f559e611b2e30f1dc93dabee7dec, 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 1)

Copy link
Contributor

@AlekseyTs AlekseyTs Jun 5, 2020

Choose a reason for hiding this comment

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

diagnostics.Add(ErrorCode.ERR_BadRecordBase, baseLocation); [](start = 16, length = 59)

I think this is going to break some tests added in #44876 #Closed

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is going to break some tests added in #44876

I'll try to preemptively fix this


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

Copy link
Contributor

@AlekseyTs AlekseyTs Jun 5, 2020

Choose a reason for hiding this comment

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

if (!field.IsStatic) [](start = 16, length = 20)

I opened a #44879 for this bug. #Closed

@agocke
Copy link
Member Author

agocke commented Jun 5, 2020

@jcouv I didn't understand your comment about WithExpr19

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 2)

@jcouv jcouv self-assigned this Jun 5, 2020
@agocke
Copy link
Member Author

agocke commented Jun 5, 2020

@RikkiGibson Do you have a chance to take a look at this?

@RikkiGibson
Copy link
Member

Taking a look.

Copy link
Member

Choose a reason for hiding this comment

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

nit: these diagnostic comments seem out of date, which makes interpreting the test a bit confusing.

Copy link
Member Author

Choose a reason for hiding this comment

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

Which one are you thinking of?

// (5,12): error CS0527: Type 'C' in interface list is not an interface
// struct F : C { }

this looks right, structs can only have interfaces in the base list.

Copy link
Member

@RikkiGibson RikkiGibson Jun 5, 2020

Choose a reason for hiding this comment

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

for example, E is a record type in the source, but the diagnostic comments make mention of an interface E. Just deleting the expected diagnostics and pasting the baselines back in would fix it.

Copy link
Contributor

Choose a reason for hiding this comment

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

useSiteDiagnostics [](start = 20, length = 18)

Could use-site diagnostics be the source of the error here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Convert [](start = 37, length = 7)

Did we check that the conversion exist? Are user-defined conversions going to be handled here? I think we should probably include conversion information into IOperation node and apply conversion in CFG rewrite when necessary. We don't have to do all this for the preview, but should capture things to follow up on.

Copy link
Contributor

@AlekseyTs AlekseyTs Jun 6, 2020

Choose a reason for hiding this comment

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

IsVirtual => true; [](start = 29, length = 18)

IsOverride and IsVirtual cannot be both true. #Closed

Copy link
Contributor

Choose a reason for hiding this comment

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

return method; [](start = 24, length = 14)

Post preview we should probably deal with ambiguity cases. Two or more methods match

Copy link
Contributor

@AlekseyTs AlekseyTs Jun 6, 2020

Choose a reason for hiding this comment

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

IsVirtual: true, [](start = 24, length = 16)

This is not going to be true for an override. #Closed

Copy link
Contributor

@AlekseyTs AlekseyTs Jun 6, 2020

Choose a reason for hiding this comment

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

IsOverride [](start = 29, length = 10)

It looks like the Clone method is now always called virtually, we should reflect that in CFG. If any additional fix-ups will be necessary for this PR, consider adjusting this #44712 (review) #Closed

@AlekseyTs
Copy link
Contributor

Done with review pass (iteration 1). I think there is a feedback actionable for the preview. Doesn't have to be addressed in this PR though, but shouldn't be lost.

@agocke
Copy link
Member Author

agocke commented Jun 6, 2020

These seemed important enough to address now and there are merge conflicts to resolve anyway.

The compiler now uses a reserved name for the clone method which only
records will generate. Some existing tests are interesting if we ever
allow user-generation of the clone method but cannot be run in the
current state. I've left them in, but marked them skipped.
@agocke agocke merged commit 089d7bd into dotnet:features/records Jun 6, 2020
@agocke agocke deleted the clone-name branch June 6, 2020 08:44
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.

4 participants