Skip to content

Commit 3b97534

Browse files
committed
More witness fixes
1 parent e74b105 commit 3b97534

2 files changed

Lines changed: 59 additions & 1 deletion

File tree

src/Compiler/Optimize/Optimizer.fs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3457,8 +3457,11 @@ and TryInlineApplication cenv env finfo (valExpr: Expr) (tyargs: TType list, arg
34573457
let allTyargsAreConcrete =
34583458
tyargs |> List.forall (fun t -> (freeInType CollectTyparsNoCaching t).FreeTypars.IsEmpty)
34593459

3460+
let allTyargsAreGeneric =
3461+
tyargs |> List.forall (fun t -> not (freeInType CollectTyparsNoCaching t).FreeTypars.IsEmpty)
3462+
34603463
let canCallDirectly =
3461-
hasNoTraits || (not allTyargsAreConcrete && vref.ValReprInfo.IsSome)
3464+
hasNoTraits || (allTyargsAreGeneric && vref.ValReprInfo.IsSome)
34623465

34633466
if canCallDirectly then
34643467
Some(mkApps g ((exprForValRef m vref, vref.Type), [tyargs], argsR, m), info)

tests/FSharp.Compiler.ComponentTests/EmittedIL/DebugInlineAsCall.fs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,61 @@ let main _ =
484484
|> shouldSucceed
485485

486486

487+
[<Fact>]
488+
let ``SRTP 12 - Witness - Struct with partially resolved type args`` () =
489+
FSharp """
490+
[<Struct>]
491+
type S =
492+
member _.M() = ()
493+
494+
type T() =
495+
member _.N() = ()
496+
497+
let inline f (a: ^A when ^A: (member M: unit -> unit)) (_b: ^B when ^B: (member N: unit -> unit)) =
498+
(^A: (member M: unit -> unit) a)
499+
500+
let inline g b = f (S()) b
501+
502+
[<EntryPoint>]
503+
let main _ =
504+
g (T())
505+
0
506+
"""
507+
|> withDebug
508+
|> withNoOptimize
509+
|> asExe
510+
|> compileAndRun
511+
|> shouldSucceed
512+
513+
[<Fact>]
514+
let ``SRTP 13 - Witness - Struct with ResumableCode and partially resolved type args`` () =
515+
FSharp """
516+
open Microsoft.FSharp.Core.CompilerServices
517+
518+
[<Struct>]
519+
type S = member this.Foo() = ()
520+
521+
type D = member _.Bar() = true
522+
523+
let inline f (x: ^A) =
524+
ResumableCode< ^B, _>(fun sm ->
525+
(^A: (member Foo: unit -> unit) x)
526+
(^B: (member Bar: unit -> bool) sm.Data)
527+
)
528+
529+
let inline g () = f (S())
530+
531+
[<EntryPoint>]
532+
let main _ =
533+
let _ : ResumableCode<D, _> = g ()
534+
0
535+
"""
536+
|> withDebug
537+
|> withNoOptimize
538+
|> asExe
539+
|> compileAndRun
540+
|> shouldSucceed
541+
487542
[<Fact>]
488543
let ``Member 01 - Non-generic`` () =
489544
FSharp """

0 commit comments

Comments
 (0)