mirage-lambda icon indicating copy to clipboard operation
mirage-lambda copied to clipboard

Width of `int` type.

Open aherrmann opened this issue 6 years ago • 3 comments

The width of the type int differs between evaluation and protobufs encoding. The protobufs encoding uses int32, the evaluator uses a wider type.

E.g. the following program (int_max + 1)

2147483647 + 1

Produces the following log on the server (no overflow):

2018-07-13 15:23:11 +00:00: INF [application] Process and eval: (fun (in[s: Cstruct.t list)
                                      -> (fun (outs: Cstruct.t list)
                                           -> (2147483647 + 1))) => 2147483648.

But returns the value -2147483648 (overflow).

These should probably agree to avoid subtle bugs when interacting with the server.

aherrmann avatar Jul 13 '18 15:07 aherrmann

Your computer is in 32-bits architecture?

dinosaure avatar Jul 23 '18 13:07 dinosaure

Your computer is in 32-bits architecture?

No, 64 bit. ~Could it be due to the build in the Docker container?~

Sorry, replied too quickly. The protobufs encoding specifies to use int32 for Int values. The mirage server has 64-bit wide int values, so when encoding int64 to int32 there's potential for overflow.

aherrmann avatar Jul 23 '18 14:07 aherrmann

Hmmhmm, I don't know what we can do about that when the problem seems to come from protobuf. Do you want a specific behavior from the unikernel about that? Note than in OCaml (in 64 bits architecture), the integer has 63 bits available - so if you want a 64 bits integer, it's better to use int64 (however, this value is boxed at the runtime).

dinosaure avatar Jul 25 '18 11:07 dinosaure