From 7fa5adb305615613f182a5fc4e9191df38f07103 Mon Sep 17 00:00:00 2001 From: Don Syme Date: Mon, 21 Nov 2016 18:54:44 +0000 Subject: [PATCH 1/4] fix 1775 --- src/FSharpSource.targets | 2 +- src/scripts/fssrgen.targets | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/FSharpSource.targets b/src/FSharpSource.targets index c4710121cce..562cf0fadf3 100644 --- a/src/FSharpSource.targets +++ b/src/FSharpSource.targets @@ -446,7 +446,7 @@ Name="CopyAndSubstituteTextFiles" Inputs="@(CopyAndSubstituteText)" Outputs="@(CopyAndSubstituteText->'$(OutDir)%(TargetFilename)')" > - + diff --git a/src/scripts/fssrgen.targets b/src/scripts/fssrgen.targets index 9c89f648046..d193bd489cf 100644 --- a/src/scripts/fssrgen.targets +++ b/src/scripts/fssrgen.targets @@ -24,7 +24,7 @@ Copyright (C) Microsoft Corporation. Apache 2.0 License. - + From ba636916f9dc6673dd5c3e5ae922212b183db4cb Mon Sep 17 00:00:00 2001 From: Don Syme Date: Mon, 21 Nov 2016 20:40:10 +0000 Subject: [PATCH 2/4] Fix 1749 --- src/fsharp/IlxGen.fs | 15 --------------- src/fsharp/MethodCalls.fs | 3 ++- src/fsharp/TastOps.fs | 15 +++++++++++++++ src/fsharp/TastOps.fsi | 2 ++ .../InferenceProcedures/TypeInference/env.lst | 3 ++- 5 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/fsharp/IlxGen.fs b/src/fsharp/IlxGen.fs index 99949f9d608..1ecf681e70d 100644 --- a/src/fsharp/IlxGen.fs +++ b/src/fsharp/IlxGen.fs @@ -132,20 +132,6 @@ let CountMethodDef = NewCounter "IL method defintitions corresponding to values" let CountStaticFieldDef = NewCounter "IL field defintitions corresponding to values" let CountCallFuncInstructions = NewCounter "callfunc instructions (indirect calls)" -//------------------------------------------------------------------------- -// Part of the last-minute tranformation performed by this file -// is to eliminate variables of static type "unit". These are -// utility functions related to this. -//------------------------------------------------------------------------- - -let BindUnitVars g (mvs:Val list, paramInfos, body) = - match mvs,paramInfos with - | [v],[] -> - assert isUnitTy g v.Type - [], mkLet NoSequencePointAtInvisibleBinding v.Range v (mkUnit g v.Range) body - | _ -> mvs,body - - /// Non-local information related to internals of code generation within an assembly type IlxGenIntraAssemblyInfo = { /// A table recording the generated name of the static backing fields for each mutable top level value where @@ -155,7 +141,6 @@ type IlxGenIntraAssemblyInfo = /// that come from both the signature and the implementation. StaticFieldInfo : Dictionary } -//-------------------------------------------------------------------------- //-------------------------------------------------------------------------- /// Indicates how the generated IL code is ultimately emitted diff --git a/src/fsharp/MethodCalls.fs b/src/fsharp/MethodCalls.fs index 30b2f12f0f2..d1b53529d14 100644 --- a/src/fsharp/MethodCalls.fs +++ b/src/fsharp/MethodCalls.fs @@ -802,7 +802,8 @@ let BuildNewDelegateExpr (eventInfoOpt:EventInfo option, g, amap, delegateTy, in | Some _ -> let _,_,_,vsl,body,_ = IteratedAdjustArityOfLambda g amap topValInfo f - List.concat vsl, body + let vsl, body = BindUnitVars g (List.concat vsl, List.concat topValInfo.ArgInfos, body) + vsl, body let meth = TObjExprMethod(slotsig, [], [], [delArgVals], expr, m) mkObjExpr(delegateTy,None,BuildObjCtorCall g m,[meth],[],m) diff --git a/src/fsharp/TastOps.fs b/src/fsharp/TastOps.fs index 348e98185f6..3ae3051c9d9 100644 --- a/src/fsharp/TastOps.fs +++ b/src/fsharp/TastOps.fs @@ -7993,3 +7993,18 @@ let DetectAndOptimizeForExpression g option expr = // Used to remove Expr.Link for inner expressions in pattern matches let (|InnerExprPat|) expr = stripExpr expr + +//------------------------------------------------------------------------- +// One of the tranformations performed by the compiler +// is to eliminate variables of static type "unit". These are +// utility functions related to this. +//------------------------------------------------------------------------- + +let BindUnitVars g (mvs:Val list, paramInfos:ArgReprInfo list, body) = + match mvs,paramInfos with + | [v],[] -> + assert isUnitTy g v.Type + [], mkLet NoSequencePointAtInvisibleBinding v.Range v (mkUnit g v.Range) body + | _ -> mvs,body + + diff --git a/src/fsharp/TastOps.fsi b/src/fsharp/TastOps.fsi index ed924b26921..de400762b59 100755 --- a/src/fsharp/TastOps.fsi +++ b/src/fsharp/TastOps.fsi @@ -1432,3 +1432,5 @@ val mkCoerceIfNeeded : TcGlobals -> tgtTy: TType -> srcTy: TType -> Expr -> Expr val (|InnerExprPat|) : Expr -> Expr val allValsOfModDef : ModuleOrNamespaceExpr -> seq + +val BindUnitVars : TcGlobals -> (Val list * ArgReprInfo list * Expr) -> Val list * Expr diff --git a/tests/fsharpqa/Source/Conformance/InferenceProcedures/TypeInference/env.lst b/tests/fsharpqa/Source/Conformance/InferenceProcedures/TypeInference/env.lst index b302840e317..710b50ca1be 100644 --- a/tests/fsharpqa/Source/Conformance/InferenceProcedures/TypeInference/env.lst +++ b/tests/fsharpqa/Source/Conformance/InferenceProcedures/TypeInference/env.lst @@ -38,4 +38,5 @@ SOURCE=E_PrettifyForall.fs SCFLAGS="--test:ErrorRanges --flaterrors" # E_PrettifyForall.fs - SOURCE=IgnoreUnitParameters.fs # IgnoreUnitParameters.fs \ No newline at end of file + SOURCE=IgnoreUnitParameters.fs # IgnoreUnitParameters.fs + SOURCE=IgnoreUnitParameters.fs SCFLAGS="--optimize- -g" # IgnoreUnitParameters2.fs \ No newline at end of file From b68f1fad008d5f7341e2873da5ebb1138437a596 Mon Sep 17 00:00:00 2001 From: Don Syme Date: Mon, 21 Nov 2016 21:05:34 +0000 Subject: [PATCH 3/4] adjustment to fix --- src/fsharp/MethodCalls.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fsharp/MethodCalls.fs b/src/fsharp/MethodCalls.fs index d1b53529d14..274d9c1d235 100644 --- a/src/fsharp/MethodCalls.fs +++ b/src/fsharp/MethodCalls.fs @@ -802,7 +802,7 @@ let BuildNewDelegateExpr (eventInfoOpt:EventInfo option, g, amap, delegateTy, in | Some _ -> let _,_,_,vsl,body,_ = IteratedAdjustArityOfLambda g amap topValInfo f - let vsl, body = BindUnitVars g (List.concat vsl, List.concat topValInfo.ArgInfos, body) + let vsl, body = BindUnitVars g (List.concat vsl, List.replicate delArgTys.Length ValReprInfo.unnamedTopArg1, body) vsl, body let meth = TObjExprMethod(slotsig, [], [], [delArgVals], expr, m) From e6a6bcc0433195c44d300f000e45b2d784a3944f Mon Sep 17 00:00:00 2001 From: Don Syme Date: Mon, 21 Nov 2016 23:22:06 +0000 Subject: [PATCH 4/4] fix test --- src/fsharp/IlxGen.fs | 1 + src/fsharp/MethodCalls.fs | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fsharp/IlxGen.fs b/src/fsharp/IlxGen.fs index 1ecf681e70d..a26d3b4a296 100644 --- a/src/fsharp/IlxGen.fs +++ b/src/fsharp/IlxGen.fs @@ -4078,6 +4078,7 @@ and GenDelegateExpr cenv cgbuf eenvouter expr (TObjExprMethod((TSlotSig(_,delega let ilDelegeeParams,ilDelegeeRet = GenActualSlotsig m cenv envForDelegeeUnderTypars slotsig methTyparsOfOverridingMethod let numthis = 1 + let tmvs, body = BindUnitVars cenv.g (tmvs, List.replicate (List.concat slotsig.FormalParams).Length ValReprInfo.unnamedTopArg1, body) let envForDelegeeMeth = AddStorageForLocalVals cenv.g (List.mapi (fun i v -> (v,Arg (i+numthis))) tmvs) envForDelegeeUnderTypars let ilMethodBody = CodeGenMethodForExpr cenv cgbuf.mgbuf (SPAlways,[],delegeeMethName,envForDelegeeMeth,1,0,body,(if slotSigHasVoidReturnTy slotsig then discardAndReturnVoid else Return)) let delegeeInvokeMeth = diff --git a/src/fsharp/MethodCalls.fs b/src/fsharp/MethodCalls.fs index 274d9c1d235..30b2f12f0f2 100644 --- a/src/fsharp/MethodCalls.fs +++ b/src/fsharp/MethodCalls.fs @@ -802,8 +802,7 @@ let BuildNewDelegateExpr (eventInfoOpt:EventInfo option, g, amap, delegateTy, in | Some _ -> let _,_,_,vsl,body,_ = IteratedAdjustArityOfLambda g amap topValInfo f - let vsl, body = BindUnitVars g (List.concat vsl, List.replicate delArgTys.Length ValReprInfo.unnamedTopArg1, body) - vsl, body + List.concat vsl, body let meth = TObjExprMethod(slotsig, [], [], [delArgVals], expr, m) mkObjExpr(delegateTy,None,BuildObjCtorCall g m,[meth],[],m)