How to test `Int` vs `Int64` correctness on my 64 bit development machine

Does anyone have any advice on how to test whether I’m using Int vs Int64 correctly?

On 64-bit platforms like my laptop, Int === Int64 so it won’t error out when I’m using Int64 where I should use Int or vice-versa. I’m only testing 32 bit on my appveyor CI builds, and I’d like to be able to test correctness locally as well.

Concretely, I ran into issues with StatProfilerHTML using some of Profile's data structures. I ended up with reading the source code, trial and error (which is slow on CI), and replacing with <: Unsigned where possible. I’m sure there’s a better way?

It is not clear what you mean here.

Do you want to check that you are on a 64-bit platform?

Or unit test your code for 32-bit platforms using CI running on 64-bit ones?

This one is just Int === Int64 no?

If I understand you correctly, this is the one I mean. Given the availability of an M-bit platform, I want to test whether my code will work on N bit platforms for (possibly) N \neq M.

In practice, when M = 64, this mostly comes down to a correct usage of ::Int vs ::Int64 in method signatures, or ::Vector{Int} vs ::Vector{Int64}. That’s where I got the title of this topic.

In many cases, ::Integer or Vector{<:Integer} is more correct anyway, but not all. In particular, I don’t always control the method signatures I’m using. For example, Profile uses Vector{UInt} and Vector{UInt64} interchangeably. It probably shouldn’t (and that’s a bug I will report), but in the mean time I’ll have to work around it. I’d like to test locally CI to reflect whether those workarounds are successful.

Does that make sense?

edit: I mentioned CI where I should have said “locally”. That caused confusion.

I am not sure why you would expect it not to work in most cases. 32-bit platforms also have Int64.

The only thing I can think of is defining some methods too restrictively, eg with Int64 where Int would be the correct one. You can test some of these by calling them with Int32 inputs, but some will come from native methods (array indexes etc) so this could be tricky.

For a comprehensive solution, I would just run CI in both 32- and 64-bit environments.

For a quick check, you can grep the code for Int64.

Thanks for trying to help, but it looks like I’m a few steps ahead here. I’m applying all those steps and indeed I’m running CI in 32 and 64 bit scenarios.

Now the problem is that things that are only tested in CI have a very slow feedback loop, and that’s what I’m targeting for improvement in this topic. Apologies if I wasn’t clear about that from the start.

edit: I wasn’t clear about that, and edited one of the posts accordingly.

Downloading the 32 bit build but running on your 64 bit machine should do the trick? Then you should have Int === Int32.

4 Likes

I believe that you can just build a 32-bit binary on a 64-bit platform if you want to run tests locally. See eg https://github.com/JuliaLang/julia/blob/master/doc/build/linux.md#architecture-customization or similar sections for other platforms.

2 Likes

Thanks @Chris_Foster and @Tamas_Papp! That’s what I was looking for. Will mark Chris’ post as the solution because I unfortunately have to choose one.