Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Remove most use of "Bogus" from Microsoft.CSharp and fix remaining#22537

Merged
VSadov merged 10 commits into
dotnet:masterfrom
JonHanna:ms_cs_remove_bogus
Jul 27, 2017
Merged

Remove most use of "Bogus" from Microsoft.CSharp and fix remaining#22537
VSadov merged 10 commits into
dotnet:masterfrom
JonHanna:ms_cs_remove_bogus

Conversation

@JonHanna
Copy link
Copy Markdown
Contributor

  • Remove concept of bogus from types and most symbols.

Since bogus types can't get as far as the dynamic binder, the only case where bogus can be true is when a non-indexer parametrized property, defined in a language where that is allowed, is encountered.

In other cases computing bogosity involves recursive checks that always hit false.

Give PropertySymbol a separate Bogus property to use where it could be set, and remove all other uses of GetBogus and similar.

Entails removal of ERR_BogusType, contributes to #22470

  • Identify indexer properties correctly in AddPropertyToSymbolTable

AddPropertyToSymbolTable assumes any property with parameters is an indexer, which makes the subsequent check that only indexers can have parameters tautologous.

Check DefaultMemberAttribute instead.

  • Remove useMethInstead from property symbols and consider always true.

useMethInstead should be set in AddPropertyToSymbolTable when bogus is set, but is not.

However, the only time it is looked for the only possible value is true as that is the only condition under which a symbol can be bogus, so remove it, and the path for it being false.

This now means that ErrorCode.ERR_BindToBogusProp1 or ErrorCode.ERR_BindToBogusProp2 will be used when appropriate (contributes to #22470).

Fixes #22534

  • Tests for accessing non-indexer parameter properties

  • Remove bogus check within PredefinedMembers

Predefined properties cannot be bogus.

{
Name name;
bool isIndexer = property.GetIndexParameters() != null && property.GetIndexParameters().Length != 0;
bool isIndexer = property.GetIndexParameters().Length != 0
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please use Any()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Any reason to use predicateless-Any() on an array? The perf difference isn't much, but it's there, and Length != 0 is common with arrays elsewhere in corefx.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think Length is ok when we know it is an array. "Any" is often faster with various kind of collections/enumerables, but for array we know the "Length != 0" is the simplest way to check for emptiness.


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

Name name;
bool isIndexer = property.GetIndexParameters() != null && property.GetIndexParameters().Length != 0;
bool isIndexer = property.GetIndexParameters().Length != 0
&& (property.DeclaringType?.GetCustomAttribute(typeof(DefaultMemberAttribute)) as DefaultMemberAttribute)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

DefaultMemberAttribute [](start = 83, length = 22)

GetCustomAttribute()?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I don't understand this comment.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh. TIL about the generic GetCustomAttribute<>() extension!

@@ -288,46 +288,7 @@ typeThru is NullableType ||

public bool CheckBogus(Symbol sym)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please use this everywhere this functionality is needed. Example: GroupToArgsBinder.LookForCandidates()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done. Have also made it static as it requires no state.

return (IndexerSymbol)this;
}

public bool Bogus { get; set; }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I suggest keeping with other fields, or converting all fields to properties.
I know there is a bigger effort of refactoring these things, but we shouldn't special case this here now.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

isIndexer and AsIndexerSymbol should ideally have been changed when getting rid of the similar methods defined elsewhere, anyway.

Copy link
Copy Markdown
Contributor

@OmarTawfik OmarTawfik left a comment

Choose a reason for hiding this comment

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

Left comments.

}

[Fact]
public void LiteralDoubleCast()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not sure how this relates to this PR. Maybe from #22533?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, something slipped while doing a bunch of rebases. Sorry.

JonHanna added 8 commits July 26, 2017 12:35
Since bogus types can't get as far as the dynamic binder, the only case
where bogus can be true is when a non-indexer parametrized property,
defined in a language where that is allowed, is encountered.

In other cases computing bogosity involves recursive checks that always
hit false.

Give PropertySymbol a separate Bogus property to use where it could be
set, and remove all other uses of GetBogus and similar.

Entails removal of ERR_BogusType, contributes to #22470
AddPropertyToSymbolTable assumes any property with parameters is an
indexer, which makes the subsequent check that only indexers can have
parameters tautologous.

Check DefaultMemberAttribute instead.
useMethInstead should be set in AddPropertyToSymbolTable when bogus is
set, but is not.

However, the only time it is looked for the only possible value is true
as that is the only condition under which a symbol can be bogus, so
remove it, and the path for it being false.

This now means that ErrorCode.ERR_BindToBogusProp1 or
ErrorCode.ERR_BindToBogusProp2 will be used when appropriate.

Fixes #22534
Predefined properties cannot be bogus.
@JonHanna JonHanna force-pushed the ms_cs_remove_bogus branch from ad797e1 to 680e0ff Compare July 26, 2017 12:16
public bool isOverride; // Overrides an inherited member. Only valid if isVirtual is set.
// false implies that a new vtable slot is required for this method.
public bool useMethInstead; // Only valid iff isBogus == TRUE && IsPropertySymbol().
// If this is true then tell the user to call the accessors directly.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This comment refers to the code that is now gone. Also the comment above looks like after the code it is referring to. Can that be fixed too?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point. Done.

Copy link
Copy Markdown
Member

@VSadov VSadov left a comment

Choose a reason for hiding this comment

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

LGTM

@VSadov VSadov merged commit a2b8a66 into dotnet:master Jul 27, 2017
@JonHanna JonHanna deleted the ms_cs_remove_bogus branch July 27, 2017 23:22
@karelz karelz modified the milestone: 2.1.0 Aug 14, 2017
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
…otnet/corefx#22537)

* Remove concept of bogus from types and most symbols.

Since bogus types can't get as far as the dynamic binder, the only case
where bogus can be true is when a non-indexer parametrized property,
defined in a language where that is allowed, is encountered.

In other cases computing bogosity involves recursive checks that always
hit false.

Give PropertySymbol a separate Bogus property to use where it could be
set, and remove all other uses of GetBogus and similar.

Entails removal of ERR_BogusType, contributes to dotnet/corefx#22470

* Identify indexer properties correctly in AddPropertyToSymbolTable

AddPropertyToSymbolTable assumes any property with parameters is an
indexer, which makes the subsequent check that only indexers can have
parameters tautologous.

Check DefaultMemberAttribute instead.

* Remove useMethInstead from property symbols and consider always true.

useMethInstead should be set in AddPropertyToSymbolTable when bogus is
set, but is not.

However, the only time it is looked for the only possible value is true
as that is the only condition under which a symbol can be bogus, so
remove it, and the path for it being false.

This now means that ErrorCode.ERR_BindToBogusProp1 or
ErrorCode.ERR_BindToBogusProp2 will be used when appropriate.

Fixes dotnet/corefx#22534

* Tests for accessing non-indexer parameter properties

* Remove bogus check within PredefinedMembers

Predefined properties cannot be bogus.

* Refactor CheckBogus to static and use consistently.

* Replace IsIndexer and AsIndexer with direct operations

* Make all fields in PropertySymbol auto properties.

* Use generic form of GetCustomAttribute in looking up default member.

* Remove confusing leftover remnant of comment.


Commit migrated from dotnet/corefx@a2b8a66
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants