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

Fix MemberNames API for records #49138

Merged
merged 2 commits into from
Nov 6, 2020
Merged

Fix MemberNames API for records #49138

merged 2 commits into from
Nov 6, 2020

Conversation

jcouv
Copy link
Member

@jcouv jcouv commented Nov 2, 2020

Fixes #48947

@@ -1080,7 +1080,7 @@ public override IEnumerable<string> MemberNames
{
get
{
return IsTupleType ? GetMembers().Select(m => m.Name).Distinct() : this.declaration.MemberNames;
return (IsTupleType || IsRecord) ? GetMembers().Select(m => m.Name).Distinct() : this.declaration.MemberNames;
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'm debating whether we should add caching of MemberNames in SourceMemberContainerSymbol at this point... Thoughts?

Copy link
Member

Choose a reason for hiding this comment

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

I'm debating whether we should add caching of MemberNames in SourceMemberContainerSymbol at this point... Thoughts?

I would prefer that... but it's not necessarily a huge deal if you don't (unlesss people have tons of records).

The purpose of these collectoins is to allow the IDE to search for names very efficiently (i.e. in a non-allocating fashion). So it is important that the vast majority of source types not allocate here. And, as long as that holds we'll be ok.

But it would be a bit nicer to cache IMO in case you had someone with, say, 1k generated records, and we kept generaitng this over and over again.

Note: You don't need to do Distinct. MemberNames is explicitly doc'ed as returning dupes. exactly because we don't want to do the CPU/memory work to find and remove duplicates for htese sensitive scenarios.

Copy link
Member Author

@jcouv jcouv Nov 5, 2020

Choose a reason for hiding this comment

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

MemberNames is explicitly doc'ed as returning dupes

Where do you see that?
The implementations I looked at (such as source named type symbols) seem to explicitly de-dupe.

Copy link
Member

Choose a reason for hiding this comment

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

        public ICollection<string> MemberNames
        {
            get
            {
                if (_lazyMemberNames == null)
                {
                    var names = UnionCollection<string>.Create(this.Declarations, d => d.MemberNames);
                    Interlocked.CompareExchange(ref _lazyMemberNames, names, null);
                }

                return _lazyMemberNames;
            }
        }

The merged decl for named types (i.e. for partials) just literally 'combines' (i.e. concatenates) all the names of all the individual parts. SourceMemberContainer just does this:

        public override IEnumerable<string> MemberNames
        {
            get
            {
                return IsTupleType ? GetMembers().Select(m => m.Name).Distinct() : this.declaration.MemberNames;
            }
        }

So this will return dupes. We do not do any sort of 'distinct' as we want this not to cost anything in terms of memory/CPU. This was very intentional from teh impl. Source: i wrote it :)

Copy link
Member Author

Choose a reason for hiding this comment

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

@CyrusNajmabadi Thanks! Removed the .Distinct :-)

@jcouv jcouv marked this pull request as ready for review November 2, 2020 21:39
@jcouv jcouv requested a review from a team as a code owner November 2, 2020 21:39
Copy link
Contributor

@AlekseyTs AlekseyTs left a comment

Choose a reason for hiding this comment

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

LGTM (iteration 1)

@jcouv
Copy link
Member Author

jcouv commented Nov 4, 2020

@dotnet/roslyn-compiler for a second review. Thanks

"<Clone>$",
"Deconstruct"
};
AssertEx.Equal(expectedMemberNames, comp.GetMember<NamedTypeSymbol>("C").GetPublicSymbol().MemberNames);
Copy link
Member

Choose a reason for hiding this comment

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

is order guaranteed here? should this test sort, just to be sfe against that?

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 probably could relax the order checking if we feel the need.

@jcouv jcouv requested a review from a team November 5, 2020 17:14
@RikkiGibson RikkiGibson self-assigned this Nov 5, 2020
@jcouv jcouv merged commit 0effc24 into dotnet:master Nov 6, 2020
@ghost ghost added this to the Next milestone Nov 6, 2020
@jcouv jcouv deleted the member-names branch November 6, 2020 19:41
333fred added a commit to 333fred/roslyn that referenced this pull request Nov 9, 2020
* upstream/master: (519 commits)
  Remove workaround in PEMethodSymbol.ExplicitInterfaceImplementations (dotnet#49246)
  Enable LSP pull model diagnostic for XAML. (dotnet#49145)
  Update dependencies from https://github.com/dotnet/roslyn build 20201109.8 (dotnet#49240)
  Add test for with expression in F1 help service (dotnet#49236)
  Cache RegexPatternDetector per compilation
  Fix RazorRemoteHostClient to maintain binary back-compat
  Further tweak inline hints
  Fix MemberNames API for records (dotnet#49138)
  Minor cleanups (dotnet#49204)
  Report warning for assignment or explicit cast of possibly null value of unconstrained type parameter type (dotnet#48803)
  Clean up of EditorFeatures.Cocoa.Snippets (dotnet#49188)
  Fix OK button state handling. Make relation between viewmodels more tightly coupled
  Extend make type abstract to include records (dotnet#48227)
  Remove duplicated implementations of C# event hookup
  Add select all/deselect all buttons
  Consolidate conditional compilation (dotnet#49150)
  Implement IEquatable on Microsoft.Cci.DefinitionWithLocation structure (dotnet#49162)
  Add new document extensions file
  Unify implementations
  Only disable structure tagger provider in LSP scenario
  ...
@allisonchou allisonchou modified the milestones: Next, 16.9.P2 Nov 24, 2020
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.

Ensure that all user-accessible synthesized record members are reflected in MemberNames and the like APIs
5 participants