From 9a177a42cbb1cd5dcf2ae43a2b1bd9119c06e650 Mon Sep 17 00:00:00 2001 From: Libo Zeng Date: Thu, 9 Feb 2017 22:47:47 -0500 Subject: [PATCH 1/4] attempt to fix units of measure issue with structs and no optimizations --- src/fsharp/IlxGen.fs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/fsharp/IlxGen.fs b/src/fsharp/IlxGen.fs index 2f0286d1b7d..262b7c13138 100644 --- a/src/fsharp/IlxGen.fs +++ b/src/fsharp/IlxGen.fs @@ -5362,14 +5362,21 @@ and GenBindRhs cenv cgbuf eenv sp (vspec:Val) e = | Expr.TyLambda _ | Expr.Lambda _ -> let isLocalTypeFunc = IsNamedLocalTypeFuncVal cenv.g vspec e - match e, isLocalTypeFunc with - | Expr.TyLambda(_, tyargs, body, _, _), true when + match e with + | Expr.TyLambda(_, tyargs, body, _, ttype) when ( tyargs |> List.forall (fun tp -> tp.IsErased) && (match StorageForVal vspec.Range vspec eenv with Local _ -> true | _ -> false) ) -> - // type lambda with erased type arguments that is stored as local variable (not method or property)- inline body - GenExpr cenv cgbuf eenv sp body Continue + if isLocalTypeFunc || + (match ttype with + TType_var(typar) -> match typar.Solution with Some(TType_app(t,_))-> t.IsStructOrEnumTycon | _ -> false + | _ -> false) then + // type lambda with erased type arguments that is stored as local variable (not method or property)- inline body + GenExpr cenv cgbuf eenv sp body Continue + else + let selfv = if isLocalTypeFunc then None else Some (mkLocalValRef vspec) + GenLambda cenv cgbuf eenv isLocalTypeFunc selfv e Continue | _ -> let selfv = if isLocalTypeFunc then None else Some (mkLocalValRef vspec) GenLambda cenv cgbuf eenv isLocalTypeFunc selfv e Continue From 1e1f520966cd72d445b6334d5880d968d28e9e4c Mon Sep 17 00:00:00 2001 From: Libo Zeng Date: Sun, 12 Feb 2017 20:18:40 -0500 Subject: [PATCH 2/4] reducing code duplication --- src/fsharp/IlxGen.fs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/fsharp/IlxGen.fs b/src/fsharp/IlxGen.fs index 262b7c13138..831dd53151b 100644 --- a/src/fsharp/IlxGen.fs +++ b/src/fsharp/IlxGen.fs @@ -5366,17 +5366,13 @@ and GenBindRhs cenv cgbuf eenv sp (vspec:Val) e = | Expr.TyLambda(_, tyargs, body, _, ttype) when ( tyargs |> List.forall (fun tp -> tp.IsErased) && - (match StorageForVal vspec.Range vspec eenv with Local _ -> true | _ -> false) + (match StorageForVal vspec.Range vspec eenv with Local _ -> true | _ -> false) && + (isLocalTypeFunc || + (match ttype with + TType_var(typar) -> match typar.Solution with Some(TType_app(t,_))-> t.IsStructOrEnumTycon | _ -> false + | _ -> false)) ) -> - if isLocalTypeFunc || - (match ttype with - TType_var(typar) -> match typar.Solution with Some(TType_app(t,_))-> t.IsStructOrEnumTycon | _ -> false - | _ -> false) then - // type lambda with erased type arguments that is stored as local variable (not method or property)- inline body - GenExpr cenv cgbuf eenv sp body Continue - else - let selfv = if isLocalTypeFunc then None else Some (mkLocalValRef vspec) - GenLambda cenv cgbuf eenv isLocalTypeFunc selfv e Continue + GenExpr cenv cgbuf eenv sp body Continue | _ -> let selfv = if isLocalTypeFunc then None else Some (mkLocalValRef vspec) GenLambda cenv cgbuf eenv isLocalTypeFunc selfv e Continue From 191b896e6626ea30936ed6e7a6cdce882ac3dd80 Mon Sep 17 00:00:00 2001 From: Libo Zeng Date: Sun, 12 Feb 2017 20:19:47 -0500 Subject: [PATCH 3/4] keep the original comment --- src/fsharp/IlxGen.fs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/fsharp/IlxGen.fs b/src/fsharp/IlxGen.fs index 831dd53151b..b6e862a6090 100644 --- a/src/fsharp/IlxGen.fs +++ b/src/fsharp/IlxGen.fs @@ -5372,6 +5372,7 @@ and GenBindRhs cenv cgbuf eenv sp (vspec:Val) e = TType_var(typar) -> match typar.Solution with Some(TType_app(t,_))-> t.IsStructOrEnumTycon | _ -> false | _ -> false)) ) -> + // type lambda with erased type arguments that is stored as local variable (not method or property)- inline body GenExpr cenv cgbuf eenv sp body Continue | _ -> let selfv = if isLocalTypeFunc then None else Some (mkLocalValRef vspec) From 6e9f67cd209331437dfd4ede26fe2c7b8344e6d4 Mon Sep 17 00:00:00 2001 From: Libo Zeng Date: Mon, 13 Feb 2017 10:27:07 -0500 Subject: [PATCH 4/4] add test --- tests/fsharp/regression/struct-measure-bug-1/test.fs | 8 ++++++++ tests/fsharp/tests.fs | 8 ++++++++ 2 files changed, 16 insertions(+) create mode 100644 tests/fsharp/regression/struct-measure-bug-1/test.fs diff --git a/tests/fsharp/regression/struct-measure-bug-1/test.fs b/tests/fsharp/regression/struct-measure-bug-1/test.fs new file mode 100644 index 00000000000..b8f3629ef6c --- /dev/null +++ b/tests/fsharp/regression/struct-measure-bug-1/test.fs @@ -0,0 +1,8 @@ +type AStruct<[]'u> = + struct + end + +[] +let main argv = + let x = AStruct() // This doesn't work + 0 \ No newline at end of file diff --git a/tests/fsharp/tests.fs b/tests/fsharp/tests.fs index 0c1e0eeeb28..02341122a41 100644 --- a/tests/fsharp/tests.fs +++ b/tests/fsharp/tests.fs @@ -1439,6 +1439,14 @@ module RegressionTests = [] let ``struct-tuple-bug-1-FSI_BASIC`` () = singleTestBuildAndRun "regression/struct-tuple-bug-1" FSI_BASIC + [] + let ``struct-measure-bug-1`` () = + let cfg = testConfig "regression/struct-measure-bug-1" + + fsc cfg "%s --optimize- -o:test.exe -g" cfg.fsc_flags ["test.fs"] + + peverify cfg "test.exe" + #if !FSHARP_SUITE_DRIVES_CORECLR_TESTS module OptimizationTests =