YaccConstructor / Brahma.FSharp

F# quotation to OpenCL translator and respective runtime to utilize GPGPUs in F# applications.
http://yaccconstructor.github.io/Brahma.FSharp
Eclipse Public License 1.0
74 stars 17 forks source link

Assigning value to the mutable variable causes an exception #146

Open kirillgarbar opened 1 year ago

kirillgarbar commented 1 year ago

Describe the bug Assigning value to the mutable variable using quotation injected method causes an exception in some cases. Looks like exception occures only then there are match statement in the method. Also, if variable is not mutable it works fine

To Reproduce

let op1 =
    <@ fun (x: bool option) ->
        let mutable res = None
        match x with
        | Some _ -> res <- Some true
        | None -> ()
        res
         @>

let op2 =
    <@ fun (x: bool option) ->
        x
         @>

let kernelEx =
    <@ fun (ndRange: Range1D) ->
        let mutable sum: bool option = None
        sum <- (%op1) (Some true) @>

let kernelOK1 =
    <@ fun (ndRange: Range1D) ->
        let mutable sum: bool option = None
        sum <- (%op2) (Some true) @>

let kernelOK2 =
    <@ fun (ndRange: Range1D) ->
        let mutable sum: bool option = None
        let newSum = (%op1) (Some true)
        sum <- newSum @>

context.Compile kernelOK1
context.Compile kernelOK2
context.Compile kernelEx

Expected behavior All kernels should compile

Actual behavior Only last 2 kernels compile. First kernel causes System.InvalidCastException: Unable to cast object of type 'Brahma.FSharp.OpenCL.AST.StatementBlock1[Brahma.FSharp.OpenCL.AST.Lang]' to type 'Brahma.FSharp.OpenCL.AST.Expression1[Brahma.FSharp.OpenCL.AST.Lang]'.