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

Fix for #3402. Allows spawning an actor via expression. #3667

Merged
merged 3 commits into from
Dec 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/core/Akka.FSharp.Tests/Akka.FSharp.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="FSharp.Core" Version="4.2.3" />
<PackageReference Include="FSharp.Core" Version="4.5.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(TestSdkVersion)" />
<PackageReference Include="xunit" Version="$(XunitVersion)" />
<PackageReference Include="xunit.runner.visualstudio" Version="$(XunitVersion)" />
Expand Down
16 changes: 16 additions & 0 deletions src/core/Akka.FSharp.Tests/ApiTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,22 @@ let ``actor that accepts _ will receive string message`` () =
response
|> equals "SomethingToReturn"



type TestActor() =
inherit UntypedActor()

override x.OnReceive msg = ()

[<Fact>]
let ``can spawn actor from expression`` () =

let system = Configuration.load() |> System.create "test"
let actor = spawnObj system "test-actor" <@ fun () -> TestActor() @>

()


//[<Fact>]
// FAILS
let ``actor that accepts unit will receive unit message`` () =
Expand Down
4 changes: 2 additions & 2 deletions src/core/Akka.FSharp/Akka.FSharp.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="FSharp.Quotations.Evaluator" Version="1.1.2" />
<PackageReference Include="FSharp.Quotations.Evaluator" Version="1.1.3" />
<PackageReference Include="FsPickler" Version="5.2.0" />
<PackageReference Include="FSharp.Core" Version="4.2.3" />
<PackageReference Include="FSharp.Core" Version="4.5.0" />
</ItemGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
Expand Down
7 changes: 4 additions & 3 deletions src/core/Akka.FSharp/FsApi.fs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module Serialization =
type ExprSerializer(system) =
inherit Serializer(system)
let fsp = FsPickler.CreateBinarySerializer()
override __.Identifier = 9
override __.Identifier = 99
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call

override __.IncludeManifest = true
override __.ToBinary(o) = serializeToBinary fsp o
override __.FromBinary(bytes, _) = deserializeFromBinary fsp bytes
Expand Down Expand Up @@ -374,14 +374,15 @@ module Linq =

let toExpression<'Actor>(f : System.Linq.Expressions.Expression) =
match f with
| Lambda(_, Invoke(Call(null, Method "ToFSharpFunc", Ar [| Lambda(_, p) |])))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch, so this looks like this is what was causing the trouble @chrisjhoare ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think the previous signature of this got changed/removed in the move to netstandard and added back in some form from F# 4.5 onwards - but to be honest its a little beyond me. But this does appear to allow the actor to be spawned now.

| Lambda(_, (Call(null, Method "ToFSharpFunc", Ar [| Lambda(_, p) |])))
| Call(null, Method "ToFSharpFunc", Ar [| Lambda(_, p) |]) ->
Expression.Lambda(p, [||]) :?> System.Linq.Expressions.Expression<System.Func<'Actor>>
| _ -> failwith "Doesn't match"

type Expression =
static member ToExpression(f : System.Linq.Expressions.Expression<System.Func<FunActor<'Message, 'v>>>) = f
static member ToExpression<'Actor>(f : Quotations.Expr<(unit -> 'Actor)>) = toExpression<'Actor> (QuotationEvaluator.ToLinqExpression f)
static member ToExpression<'Actor>(f : Quotations.Expr<(unit -> 'Actor)>) =
toExpression<'Actor> (QuotationEvaluator.ToLinqExpression f)

[<RequireQualifiedAccess>]
module Configuration =
Expand Down