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

remove needless initobj for default values and local arising from out args #5110

Merged
merged 6 commits into from
Sep 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions TESTGUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ To run tests, use variations such as the following, depending on which test suit
build.cmd vs test
build.cmd all test

You can also submit pull requests to http://github.com/Microsoft/visualfsharp and run the tests via continuoous integration. Most people do wholesale testing that way.

## Prerequisites

It is recommended that you run tests from an elevated command prompt, as there are a couple of test cases which require administrative privileges.
Expand All @@ -35,12 +37,12 @@ The F# tests are split as follows:

This is compiled using [tests\fsharp\FSharp.Tests.FSharpSuite.fsproj](tests/fsharp/FSharp.Tests.FSharpSuite.fsproj) to a unit test DLL which acts as a driver script. Each individual test is an NUnit test case, and so you can run it like any other NUnit test.

.\build.cmd net40 test-net40-fsharp

Tests are grouped in folders per area. Each test compiles and executes a `test.fsx|fs` file in its folder using some combination of compiler or FSI flags specified in the FSharpSuite test project.
If the compilation and execution encounter no errors, the test is considered to have passed.

There are also negative tests checking code expected to fail compilation.

See note about baseline under "Other Tips" bellow for tests checking expectations against "baseline" files.
There are also negative tests checking code expected to fail compilation. See note about baseline under "Other Tips" bellow for tests checking expectations against "baseline" files.

### FSharpQA Suite

Expand Down Expand Up @@ -75,7 +77,6 @@ Note that for compatibility reasons, the IDE unit tests should be run in a 32-bi
using the `--x86` flag to `nunit3-console.exe`



### Logs and output

All test execution logs and result files will be dropped into the `tests\TestResults` folder, and have file names matching
Expand All @@ -86,6 +87,20 @@ All test execution logs and result files will be dropped into the `tests\TestRes
net40-coreunit-suite-*.*
vs-ideunit-suite-*.*

### Baselines

FSharp Test Suite works with couples of .bsl (or .bslpp) files considered "expected" and called baseline, those are matched against the actual output which resides under .err or .vserr files of same name at the during test execution.
When doing so keep in mind to carefully review the diff before comitting updated baseline files.
.bslpp (baseline pre-process) files are specially designed to enable substitution of certain tokens to generate the .bsl file. You can look further about the pre-processing logic under [tests/fsharp/TypeProviderTests.fs](tests/fsharp/TypeProviderTests.fs), this is used only for type provider tests for now.

To update baselines use this:

fsi tests\scripts\update-baselines.fsx

Use `-n` to dry-run:

fsi tests\scripts\update-baselines.fsx -n

### Other Tips

#### Run as Administrator
Expand All @@ -98,12 +113,3 @@ Do this, or a handful of tests will fail.
* The FSharp and FSharpQA suites will run test cases in parallel by default. You can comment out the relevant line (look for `PARALLEL_ARG`) to disable this.
* By default, tests from the FSharpQA suite are run using a persistent, hosted version of the compiler. This speeds up test execution, as there is no need for the `fsc.exe` process to spin up repeatedly. To disable this, uncomment the relevant line (look for `HOSTED_COMPILER`).

#### Test outcome against baseline

FSharp Test Suite works with couples of .bsl (or .bslpp) files considered "expected" and called baseline, those are matched against the actual output which resides under .err or .vserr files of same name at the during test execution.

When working on changes generating conflicts with the baseline, you can use the helper script [tests/fsharp/update.base.line.with.actuals.fsx](tests/fsharp/update.base.line.with.actuals.fsx) to update all .bsl based on the matching .err file.

When doing so keep in mind to carefully review the diff before comitting updated baseline files.

.bslpp (baseline pre-process) files are specially designed to enable substitution of certain tokens to generate the .bsl file. You can look further about the pre-processing logic under [tests/fsharp/TypeProviderTests.fs](tests/fsharp/TypeProviderTests.fs), this is used only for type provider tests for now.
137 changes: 76 additions & 61 deletions src/fsharp/IlxGen.fs

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions src/fsharp/Optimizer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2210,8 +2210,11 @@ and TryOptimizeValInfo cenv env m vinfo =
//-------------------------------------------------------------------------

and AddValEqualityInfo g m (v:ValRef) info =
if v.IsMutable then
/// the env assumes known-values do not change
// ValValue is information that v = v2, where v2 does not change
// So we can't record this information for mutable values. An exception can be made
// for "outArg" values arising from method calls since they are only temporarily mutable
// when their address is passed to the method call.
if v.IsMutable && not (v.IsCompilerGenerated && v.DisplayName.StartsWith(PrettyNaming.outArgCompilerGeneratedName)) then
info
else
{info with Info= MakeValueInfoForValue g m v info.Info}
Expand Down
2 changes: 2 additions & 0 deletions src/fsharp/PrettyNaming.fs
Original file line number Diff line number Diff line change
Expand Up @@ -694,3 +694,5 @@ module public Microsoft.FSharp.Compiler.PrettyNaming
| Some v when v = actualArgValue -> None
| _ -> Some (defaultArgName, actualArgValue))
mangleProvidedTypeName (nm, nonDefaultArgs)

let outArgCompilerGeneratedName = "outArg"
2 changes: 1 addition & 1 deletion src/fsharp/TypeChecker.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10004,7 +10004,7 @@ and TcMethodApplication
finalUnnamedCalledOutArgs |> List.map (fun calledArg ->
let calledArgTy = calledArg.CalledArgumentType
let outArgTy = destByrefTy cenv.g calledArgTy
let outv, outArgExpr = mkMutableCompGenLocal mMethExpr "outArg" outArgTy // mutable!
let outv, outArgExpr = mkMutableCompGenLocal mMethExpr PrettyNaming.outArgCompilerGeneratedName outArgTy // mutable!
let expr = mkDefault(mMethExpr, outArgTy)
let callerArg = CallerArg(calledArgTy, mMethExpr, false, mkValAddr mMethExpr false (mkLocalValRef outv))
let outArg = { NamedArgIdOpt=None;CalledArg=calledArg;CallerArg=callerArg }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
.assembly extern FSharp.Core
{
.publickeytoken = (B0 3F 5F 7F 11 D5 0A 3A ) // .?_....:
.ver 4:4:1:0
.ver 4:4:3:0
}
.assembly GenIter01
{
Expand All @@ -29,20 +29,20 @@
}
.mresource public FSharpSignatureData.GenIter01
{
// Offset: 0x00000000 Length: 0x000001F7
// Offset: 0x00000000 Length: 0x000001FF
}
.mresource public FSharpOptimizationData.GenIter01
{
// Offset: 0x00000200 Length: 0x0000007A
// Offset: 0x00000208 Length: 0x0000007A
}
.module GenIter01.exe
// MVID: {59B19213-F836-DC98-A745-03831392B159}
// MVID: {5B17FC4F-F836-DC98-A745-03834FFC175B}
.imagebase 0x00400000
.file alignment 0x00000200
.stackreserve 0x00100000
.subsystem 0x0003 // WINDOWS_CUI
.corflags 0x00000001 // ILONLY
// Image base: 0x00720000
// Image base: 0x02EB0000


// =============== CLASS MEMBERS DECLARATION ===================
Expand Down Expand Up @@ -200,121 +200,119 @@
.method public strict virtual instance void
Close() cil managed
{
// Code size 150 (0x96)
// Code size 148 (0x94)
.maxstack 6
.locals init ([0] class [mscorlib]System.Exception V_0,
[1] class [FSharp.Core]Microsoft.FSharp.Core.Unit V_1,
[2] class [mscorlib]System.Exception e)
.line 100001,100001 : 0,0 ''
IL_0000: ldnull
IL_0001: stloc.0
IL_0002: ldarg.0
IL_0003: ldfld int32 GenIter01/squaresOfOneToTen@5::pc
IL_0008: ldc.i4.3
IL_0009: sub
IL_000a: switch (
IL_0015)
IL_0013: br.s IL_001b
IL_0000: ldarg.0
IL_0001: ldfld int32 GenIter01/squaresOfOneToTen@5::pc
IL_0006: ldc.i4.3
IL_0007: sub
IL_0008: switch (
IL_0013)
IL_0011: br.s IL_0019

.line 100001,100001 : 0,0 ''
IL_0015: nop
IL_0016: br IL_0089
IL_0013: nop
IL_0014: br IL_0087

.line 100001,100001 : 0,0 ''
IL_001b: nop
IL_0019: nop
.try
{
IL_001c: ldarg.0
IL_001d: ldfld int32 GenIter01/squaresOfOneToTen@5::pc
IL_0022: switch (
IL_001a: ldarg.0
IL_001b: ldfld int32 GenIter01/squaresOfOneToTen@5::pc
IL_0020: switch (
IL_0037,
IL_0039,
IL_003b,
IL_003d,
IL_003f)
IL_0037: br.s IL_004d
IL_003d)
IL_0035: br.s IL_004b

IL_0039: br.s IL_0041
IL_0037: br.s IL_003f

IL_003b: br.s IL_0044
IL_0039: br.s IL_0042

IL_003d: br.s IL_0047
IL_003b: br.s IL_0045

IL_003f: br.s IL_004a
IL_003d: br.s IL_0048

.line 100001,100001 : 0,0 ''
IL_0041: nop
IL_0042: br.s IL_0063
IL_003f: nop
IL_0040: br.s IL_0061

.line 100001,100001 : 0,0 ''
IL_0044: nop
IL_0045: br.s IL_004f
IL_0042: nop
IL_0043: br.s IL_004d

.line 100001,100001 : 0,0 ''
IL_0047: nop
IL_0048: br.s IL_004e
IL_0045: nop
IL_0046: br.s IL_004c

.line 100001,100001 : 0,0 ''
IL_004a: nop
IL_004b: br.s IL_0063
IL_0048: nop
IL_0049: br.s IL_0061

.line 100001,100001 : 0,0 ''
IL_004d: nop
IL_004b: nop
.line 100001,100001 : 0,0 ''
IL_004e: nop
IL_004f: ldarg.0
IL_0050: ldc.i4.3
IL_0051: stfld int32 GenIter01/squaresOfOneToTen@5::pc
IL_0056: ldarg.0
IL_0057: ldfld class [mscorlib]System.Collections.Generic.IEnumerator`1<int32> GenIter01/squaresOfOneToTen@5::'enum'
IL_005c: call void [FSharp.Core]Microsoft.FSharp.Core.LanguagePrimitives/IntrinsicFunctions::Dispose<class [mscorlib]System.Collections.Generic.IEnumerator`1<int32>>(!!0)
IL_0061: nop
IL_004c: nop
IL_004d: ldarg.0
IL_004e: ldc.i4.3
IL_004f: stfld int32 GenIter01/squaresOfOneToTen@5::pc
IL_0054: ldarg.0
IL_0055: ldfld class [mscorlib]System.Collections.Generic.IEnumerator`1<int32> GenIter01/squaresOfOneToTen@5::'enum'
IL_005a: call void [FSharp.Core]Microsoft.FSharp.Core.LanguagePrimitives/IntrinsicFunctions::Dispose<class [mscorlib]System.Collections.Generic.IEnumerator`1<int32>>(!!0)
IL_005f: nop
.line 100001,100001 : 0,0 ''
IL_0062: nop
IL_0063: ldarg.0
IL_0064: ldc.i4.3
IL_0065: stfld int32 GenIter01/squaresOfOneToTen@5::pc
IL_006a: ldarg.0
IL_006b: ldc.i4.0
IL_006c: stfld int32 GenIter01/squaresOfOneToTen@5::current
IL_0071: ldnull
IL_0072: stloc.1
IL_0073: leave.s IL_0081
IL_0060: nop
IL_0061: ldarg.0
IL_0062: ldc.i4.3
IL_0063: stfld int32 GenIter01/squaresOfOneToTen@5::pc
IL_0068: ldarg.0
IL_0069: ldc.i4.0
IL_006a: stfld int32 GenIter01/squaresOfOneToTen@5::current
IL_006f: ldnull
IL_0070: stloc.1
IL_0071: leave.s IL_007f

} // end .try
catch [mscorlib]System.Object
{
IL_0075: castclass [mscorlib]System.Exception
IL_007a: stloc.2
IL_0073: castclass [mscorlib]System.Exception
IL_0078: stloc.2
.line 5,6 : 7,23 ''
IL_007b: ldloc.2
IL_007c: stloc.0
IL_007d: ldnull
IL_007e: stloc.1
IL_007f: leave.s IL_0081
IL_0079: ldloc.2
IL_007a: stloc.0
IL_007b: ldnull
IL_007c: stloc.1
IL_007d: leave.s IL_007f

.line 100001,100001 : 0,0 ''
} // end handler
IL_0081: ldloc.1
IL_0082: pop
IL_007f: ldloc.1
IL_0080: pop
.line 100001,100001 : 0,0 ''
IL_0083: nop
IL_0084: br IL_0002
IL_0081: nop
IL_0082: br IL_0000

IL_0089: ldloc.0
IL_008a: ldnull
IL_008b: cgt.un
IL_008d: brfalse.s IL_0091
IL_0087: ldloc.0
IL_0088: ldnull
IL_0089: cgt.un
IL_008b: brfalse.s IL_008f

IL_008f: br.s IL_0093
IL_008d: br.s IL_0091

IL_0091: br.s IL_0095
IL_008f: br.s IL_0093

.line 100001,100001 : 0,0 ''
IL_0093: ldloc.0
IL_0094: throw
IL_0091: ldloc.0
IL_0092: throw

.line 100001,100001 : 0,0 ''
IL_0095: ret
IL_0093: ret
} // end of method squaresOfOneToTen@5::Close

.method public strict virtual instance bool
Expand Down
Loading