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

Moved CodeGen/EmittedIL/LiteralValue over to NUnit #7291

Merged
merged 2 commits into from
Aug 2, 2019

Conversation

sergey-tihon
Copy link
Contributor

part of #7075

let ``Literal Value``() =
CompilerAssert.CompileLibraryAndVerifyIL
"""
module LiteralValue
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@TIHan I have to add module line and rename arg to _ to make this test works.
It is OK that CompilerAssert.CompileLibraryAndVerifyIL require source code to compile without warnings?

@sergey-tihon sergey-tihon changed the title Moved CodeGen/EmittedIL/LiteralValue over to NUnit [WIP] Moved CodeGen/EmittedIL/LiteralValue over to NUnit Jul 29, 2019
@sergey-tihon sergey-tihon marked this pull request as ready for review July 29, 2019 20:03
.method public static int32 main(string[] _arg1) cil managed
{
.custom instance void [FSharp.Core]Microsoft.FSharp.Core.EntryPointAttribute::.ctor() = ( 01 00 00 00 )

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In general I do not like that we remove comments from emitted IL code

let textNoComments =
System.Text.RegularExpressions.Regex.Replace(text,
blockComments + "|" + lineComments + "|" + strings + "|" + verbatimStrings,
(fun me ->
if (me.Value.StartsWith("/*") || me.Value.StartsWith("//")) then
if me.Value.StartsWith("//") then Environment.NewLine else String.Empty
else
me.Value), System.Text.RegularExpressions.RegexOptions.Singleline)
|> filterSpecialComment

and do not do it for expectedIL samples.

In this test I have to remove all comments manually.
Can we apply the same transformation to emitted and expected IL? What do think @TIHan ?

Copy link
Contributor

Choose a reason for hiding this comment

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

This is necessary since some tools (ILDasm?) add comments such that you cannot verify IL emitted by the compiler. This was necessary for string concat optimization work I believe.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cartermp I got it, but I think that would be nice to allow copy generated IL from ILDasm and use it in test directly (without manual comments removal).

Then test framework (inside verifier.VerifyIL):

  1. compile code sample and generate IL using ILDASM
  2. remove comments from IL produced in step 1 (like it does now)
  3. remove comments from expected IL specified in using test, the same transformation that we do in step 2 (I propose)
  4. compare two set of IL instructions from 2 & 3

benefits: less manual work to cleanup expected IL (ability to use snippet from ILDasm).

@sergey-tihon
Copy link
Contributor Author

sergey-tihon commented Jul 29, 2019

This PR should be ready for review (if tests pass).
My questions/concerns:

  1. I have to update source code to compile without warnings to run test (I think that IL tests should not require this)
  2. I think that VerifyIL should remove comments from emitted and expected IL (apply same transformation for both IL samples)
  3. Would be nice to make the error message more readable. Maybe it is personal, but I think if it test fail then It is hard to understand where the difference is. Ok, in the console with reasonable expectedIL message is readable
  4. Please review expected IL, I've used only part of original file and slightly modified it. How much IL do you want to keep in expected IL? My understanding that .field public static literal int32 x = int32(0x00000007) would be enough for this case.

@sergey-tihon
Copy link
Contributor Author

sergey-tihon commented Jul 30, 2019

Because of these errors on corecrl I decided to minimize expected IL

==
Name: .class public abstract auto ansi sealed LiteralValue

Expected:	 extends [mscorlib]System.Object
Actual:		 extends [System.Runtime]System.Object
==

==
Name: .class public abstract auto ansi sealed LiteralValue

Expected:	 .custom instance void [mscorlib]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 )
Actual:		 .custom instance void [System.Diagnostics.Debug]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [System.Diagnostics.Debug]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 )
==

@sergey-tihon sergey-tihon changed the title [WIP] Moved CodeGen/EmittedIL/LiteralValue over to NUnit Moved CodeGen/EmittedIL/LiteralValue over to NUnit Jul 30, 2019
@KevinRansom KevinRansom merged commit 31388f7 into dotnet:master Aug 2, 2019
@sergey-tihon sergey-tihon deleted the codegen_literal branch August 2, 2019 13:01
nosami pushed a commit to xamarin/visualfsharp that referenced this pull request Feb 23, 2021
* Moved CodeGen/EmittedIL/LiteralValue over to NUnit

* Expected IL simplified to test one thing and to be runtime independent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants