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

Add VerifyMethodBody helper as a replacement of VerifyIL #66536

Merged
merged 8 commits into from
Feb 6, 2023

Conversation

tmat
Copy link
Member

@tmat tmat commented Jan 25, 2023

VerifyMethodBody verifies both IL and sequence points without requiring to specify sequencePoints and source arguments like VerifyIL. Instead of looking up method in the PDB by its metadata name it uses method token. The tokens are made available via TestData by exposing MetadataWriter used for emit. The source is retrieved from the compilation using the document name stored in the PDB.

VerifyMethodBody verifies both IL and sequence points without requiring to specify sequencePoints and source arguments like VerifyIL.
Instead of looking up method in the PDB by its metadata name it uses method token. The tokens are made available via TestData by exposing MetadataWriter used for emit.
The source is retrieved from the compilation using the document name stored in the PDB.
@tmat tmat requested a review from a team as a code owner January 25, 2023 01:16
@jcouv jcouv self-assigned this Jan 25, 2023
return result;
}

public static Dictionary<int, string> GetSequencePointMarkers(XElement methodXml, Func<string, SourceText> getSource)
Copy link
Member

Choose a reason for hiding this comment

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

Feels like these two GetSequencePointMarkers methods are 90% identical. Can we factor them into a single implementation?

Copy link
Member Author

Choose a reason for hiding this comment

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

They are actually quite different. I don't see benefit of a single implementation, especially since the GetSequencePointMarkers is only there for existing tests and should ideally be removed at some point.

Copy link
Member

Choose a reason for hiding this comment

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

They are actually quite different

I'm not convinced. I did a diff between the two and the only two differences are the ordering of two if blocks and which strings we decide to print out (either fixed strings like "~" or strings with some source).
I'll let second reviewer chime in.

Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason why the two foreach blocks are swapped?

the GetSequencePointMarkers is only there for existing tests and should ideally be removed at some point

I'm not sure we will ever refactor all the tests to get rid of this method, so it makes sense to me to share the code if possible.

Copy link
Member Author

Choose a reason for hiding this comment

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

Is there a reason why the two foreach blocks are swapped?

I don't know, the logic was implemented in two separate code paths before my change. I just moved it to a separate method. I really don't think there is any value in trying to unify them.

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 not sure we will ever refactor all the tests to get rid of this method, so it makes sense to me to share the code if possible.

There is not that many of these tests.

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

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

@jcouv
Copy link
Member

jcouv commented Feb 1, 2023

@dotnet/roslyn-compiler for second review. Thanks

2 similar comments
@jcouv
Copy link
Member

jcouv commented Feb 2, 2023

@dotnet/roslyn-compiler for second review. Thanks

@jcouv
Copy link
Member

jcouv commented Feb 3, 2023

@dotnet/roslyn-compiler for second review. Thanks

@@ -22416,9 +22416,9 @@ struct B
// (10,9): error CS8374: Cannot ref-assign 'this' to 'F' because 'this' has a narrower escape scope than 'F'.
// r.F = ref this; // 1
Diagnostic(ErrorCode.ERR_RefAssignNarrower, "r.F = ref this").WithArguments("F", "this").WithLocation(10, 9),
// (15,6): warning CS0436: The type 'UnscopedRefAttribute' in '' conflicts with the imported type 'UnscopedRefAttribute' in 'System.Runtime, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Using the type defined in ''.
// (15,6): warning CS0436: The type 'UnscopedRefAttribute' in '1.cs' conflicts with the imported type 'UnscopedRefAttribute' in 'System.Runtime, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Using the type defined in ''.
Copy link
Member

Choose a reason for hiding this comment

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

I assume the error message has the file name in both places? (This applies also to SymbolErrorTests, although it's probably not necessary to fix the comments.)

Suggested change
// (15,6): warning CS0436: The type 'UnscopedRefAttribute' in '1.cs' conflicts with the imported type 'UnscopedRefAttribute' in 'System.Runtime, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Using the type defined in ''.
// (15,6): warning CS0436: The type 'UnscopedRefAttribute' in '1.cs' conflicts with the imported type 'UnscopedRefAttribute' in 'System.Runtime, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Using the type defined in '1.cs'.

@tmat tmat merged commit 1e2115d into dotnet:main Feb 6, 2023
@tmat tmat deleted the VerifyMethodBody branch February 6, 2023 18:18
@ghost ghost added this to the Next milestone Feb 6, 2023
333fred added a commit to 333fred/roslyn that referenced this pull request Feb 6, 2023
* upstream/main: (547 commits)
  Add VerifyMethodBody helper as a replacement of VerifyIL (dotnet#66536)
  don't offer rename for ctor snippet (dotnet#66704)
  Get `ConditionalAttribute` type only once per compilation
  Convert language-specific option types to records (dotnet#66633)
  Enable MSBuild COMM log (dotnet#66708)
  ⚡️Share AssemblyloadTestFixture on Framework (dotnet#66684)
  NRT
  Don't overwrite binary logs in CI (dotnet#66683)
  Fix 'Generate Enum Member' to work in a 'Color Color' case.
  Find bitwise operators accessed through logical operators in FAR
  Semantic snippets - `propg` and `propi` snippets (dotnet#65979)
  NRT
  Properly classify aliases in quick info
  Fix
  Add tests
  Add support for finding collection initialiers with FAR
  Do not suggest replacing lambda with method group if the invoked mehod has `Conditional` attribute
  Revert "Record added node output states as new (dotnet#61575)" (dotnet#66696)
  Record added node output states as new (dotnet#61575)
  Fix formatting issue with convert-to-full-prop
  ...
@RikkiGibson RikkiGibson modified the milestones: Next, 17.6 P2 Mar 2, 2023
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