-
Notifications
You must be signed in to change notification settings - Fork 353
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
Harden GenAPI #4585
Harden GenAPI #4585
Conversation
/fyi @pakrym @JunTaoLuo |
src/Microsoft.Cci.Extensions/Filters/ExcludeAttributesFilter.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Cci.Extensions/Filters/ExcludeCompilerGeneratedCciFilter.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Cci.Extensions/Filters/ExcludeCompilerGeneratedCciFilter.cs
Show resolved
Hide resolved
I'll take another full look. @dougbu can you make sure you test this package in dotnet/runtime repo before committing? We need to test 1) library build, 2) |
The impact of the change on reference assemblies looks good to me and lines up with what I'd expect in a reference assembly. I'm not very familiar with this project though hence I'm hesitant to "sign off" on the totality of the changes. |
Those assemblies would be good tests. Also, after those changes running APICompat on those projects if there are significant changes we need to take on those reference assemblies. When I did the nullable changes, I also had a dummy assembly with a lot of edge cases and ran it against that. |
src/Microsoft.Cci.Extensions/Filters/ExcludeCompilerGeneratedCciFilter.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Cci.Extensions/Filters/ExcludeCompilerGeneratedCciFilter.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Cci.Extensions/Filters/ExcludeAttributesFilter.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Cci.Extensions/Filters/InternalsAndPublicCciFilter.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Cci.Extensions/Filters/InternalsAndPublicCciFilter.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Cci.Extensions/Filters/InternalsAndPublicCciFilter.cs
Outdated
Show resolved
Hide resolved
if (!method.IsExplicitInterfaceMethod()) WriteVisibility(method.Visibility); | ||
if (method.IsMethodUnsafe()) | ||
{ | ||
WriteKeyword("unsafe"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks to me like WriteInterfaceMethodModifiers
is supposed to write modifiers that are common to both methods and interfaces methods. Can you instead just move unsafe check out of WriteMethodModifiers
and into WriteInterfaceMethodModifiers
? Granted this would change the ordering of the modifiers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, can't do this because WriteMethodModifiers(...)
is also called to generate the modifiers for events and properties. Both can be declared unsafe
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/Microsoft.Cci.Extensions/Writers/CSharp/CSDeclarationWriter.Methods.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Cci.Extensions/Filters/ExcludeAttributesFilter.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Cci.Extensions/Filters/ExcludeCompilerGeneratedCciFilter.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Cci.Extensions/Filters/InternalsAndPublicCciFilter.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Cci.Extensions/Filters/InternalsAndPublicCciFilter.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Cci.Extensions/Filters/InternalsAndPublicCciFilter.cs
Outdated
Show resolved
Hide resolved
FYI I'm nearly ready to update this PR to resolve the conflict, address review comments, and fix a couple of problems hit in dotnet/aspnetcore. That repo (with changes to use
This was a good idea but not something I did in this case. The dotnet/aspnetcore repo contains all of the edge cases I was trying to fix i.e. I wasn't adding support for new C# features. Of course, please let me know of any corner cases I should double-check; hopefully I can find them where I've already tested. |
Generating a
When testing with
The above occurs despite having built the libraries subcategory completely before starting. What am I missing? Separately from the above, I see some differences in the generation for - bool System.Collections.Generic.IDictionary<string, object?>.TryGetValue(string key, out object? value) { throw null; }
- System.Collections.Generic.IEnumerator<System.Collections.Generic.KeyValuePair<string, object?>> System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, object?>>.GetEnumerator() { throw null; }
+ bool System.Collections.Generic.IDictionary<string, object?>.TryGetValue(string key, out object value) { throw null; }
+ System.Collections.Generic.IEnumerator<System.Collections.Generic.KeyValuePair<string, object>> System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, object?>>.GetEnumerator() { throw null; } Unlike other cases where the nullability generation has changed, the above code was correct before I ran GenApi. Before I get deep into debugging the change, is this a known issue that you've been working around? |
faadc8a
to
38fdbce
Compare
🆙📅 to current state of my branch. My updated ref/ code for dotnet/runtime is visible at https://github.com/dotnet/runtime/compare/master...dougbu:dougbu/local.GenApi?expand=1 |
} | ||
|
||
public static bool IsConstructorVisible(this ITypeDefinition type) | ||
public static bool IsConstructorVisibleToFriendAssemblies(this ITypeDefinition type) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is new
return MemberHelper.IsVisibleOutsideAssembly(member); | ||
} | ||
|
||
public static bool IsVisibleToFriendAssemblies(this ITypeDefinitionMember member) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unlike most of this file (which was moved from TypeExtensions
), this method and the local IsExplicitImplementationVisible(...)
are new
@@ -339,7 +354,12 @@ private void WritePrivateConstructor(ITypeDefinition type) | |||
type.IsStatic) | |||
return; | |||
|
|||
WriteVisibility(TypeMemberVisibility.Assembly); | |||
WriteVisibility(TypeMemberVisibility.Private); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change needs to be optional in some fashion. See overall comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I replied. Can you please record the reasoning for the WritePrivateConstructor in a comment when making your change?
@@ -32,7 +32,7 @@ | |||
<ApiCompatBaseline Condition="!Exists('$(ApiCompatBaseline)')">$(MSBuildProjectDirectory)\ApiCompatBaseline.txt</ApiCompatBaseline> | |||
|
|||
<MatchingRefApiCompatBaseline Condition="!Exists('$(MatchingRefApiCompatBaseline)')">$(MSBuildProjectDirectory)\MatchingRefApiCompatBaseline.$(_apiCompatTargetSuffix).txt</MatchingRefApiCompatBaseline> | |||
<MatchingRefApiCompatBaseline Condition="'$(BaselineAllMatchingRefApiCompatError)' != 'true' and !Exists('$(MatchingRefApiCompatBaseline)')">$(MSBuildProjectDirectory)\MatchingRefApiCompatBaseline.txt</MatchingRefApiCompatBaseline> | |||
<MatchingRefApiCompatBaseline Condition="!Exists('$(MatchingRefApiCompatBaseline)')">$(MSBuildProjectDirectory)\MatchingRefApiCompatBaseline.txt</MatchingRefApiCompatBaseline> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned in commit comments, the previous Condition
meant baselines were read and written from different files by default
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect this was done to make the default behavior to write to TargetFramework-specific baseline files, though I am OK with this change.
@@ -68,8 +68,8 @@ | |||
<ApiCompatArgs Condition="'$(ApiCompatExcludeAttributeList)' != ''">$(ApiCompatArgs) --exclude-attributes "$(ApiCompatExcludeAttributeList)"</ApiCompatArgs> | |||
<ApiCompatArgs Condition="'$(ApiCompatEnforceOptionalRules)' == 'true'">$(ApiCompatArgs) --enforce-optional-rules</ApiCompatArgs> | |||
<ApiCompatArgs Condition="'$(BaselineAllAPICompatError)' != 'true' and Exists('$(ApiCompatBaseline)')">$(ApiCompatArgs) --baseline "$(ApiCompatBaseline)"</ApiCompatArgs> | |||
<!-- Must be last option. --> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was a lie
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably was true before c380971.
excludeNonBrowsable.HasValue(), remapFile.Value(), !skipGroupByAssembly.HasValue(), leftOperandValue, rightOperandValue, excludeAttributes.Value()); | ||
var includeInternals = respectInternals.HasValue() && | ||
contractAssemblies.Any(assembly => assembly.Attributes.HasAttributeOfType( | ||
"System.Runtime.CompilerServices.InternalsVisibleToAttribute")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No const
here because the string
is used only in this one place. Any objections?
I'm OK with this.
Do you see System.Private.CoreLib being passed in to GenAPI? If not, try adding
Yes, we're working around nullable annotations on explicit interface implementations. #4722 |
Could somebody please take a look at the related PR #4649? I think it's an easy but important fix. |
@dougbu let me know if you're waiting on anything here. I can take another look if you have specific places for me to check. I was under the impression you were going to make some changes. |
- split member-related methods into `MemberExtensions` - add `MemberExtensions.IsVisibleToFriendAssemblies(...)` - add `TypeExtensions.IsConstructorVisibleToFriendAssemblies(...)`
- remove parameter `null` checks - remove `ContainingTypeDefinition` visibility checks from `Include(ITypeDefinitionMember)`
nit: remove and sort `using`s
- correct `$(MatchingRefApiCompatBaseline)` setting; read and write same file nits: - correct spelling of `$(ImplementationAssemblyAsContract)` property - remove incorrect "must be last option" comments
- lack of comparer led to "X != X" messages due to varying `InternedKey` and similar properties
….) generates - choose `private` if internal constructurs are likely to be generated by default - flatten `IntersectionFilter.Filters` list to make `WritePrivateConstructor(...)` use reasonable - also improves overall efficiency
- aligns with generation exclusions in GenAPI (if enabled)
…RunMatchingRefApiCompat` target
- otherwise, `ValidateApiCompatForSrc` target succeeds while `RunMatchingRefApiCompat` fails in some cases - or visa versa
- remove redundant bits
3f3138c
to
24d6981
Compare
FYI the last update included only the |
- example failure in https://dev.azure.com/dnceng/internal/_build/results?buildId=601199 - undo a small part of #4585 (@1faec9a821cf767d349c7ff18c544876be28cf2d - unfortunately likely to be GC'd soon) - restore generation of `[StructLayout]` attributes on most value types
- example failure in https://dev.azure.com/dnceng/internal/_build/results?buildId=601199 - undo a small part of #4585) - restore generation of `[StructLayout]` attributes on most value types - original commit was 1faec9a
- example failure in https://dev.azure.com/dnceng/internal/_build/results?buildId=601199 - undo a small part of #4585) - restore generation of `[StructLayout]` attributes on most value types - original commit was 1faec9a
#nullable enable
gen--all
(probably easiest to review individual commits)