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

Assigning value to the mutable variable causes an exception #146

Open
kirillgarbar opened this issue Nov 12, 2022 · 0 comments
Open

Assigning value to the mutable variable causes an exception #146

kirillgarbar opened this issue Nov 12, 2022 · 0 comments

Comments

@kirillgarbar
Copy link
Member

kirillgarbar commented Nov 12, 2022

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]'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant