I’m trying to understand the different types, but it isn’t completely clear.
As far as I understand, primitive types are those that contain one actual value. So are all concrete types, that aren’t containers, primitive types? Did I simplify it too much?
As for composite types, are they exclusively user defined? Or is there an existing type in Julia that qualifies as a composite type?
1 Like
almost all types are composite types. (and almost all types defined in Julia are “user” defined in the sense that they are defined in normal julia without any special compiler support).
The real difference between primitive and composite types is whether they are built out of a single region of pure bits or other types. An example of the former is Int64. it has no constituent parts, and the basic operations you can perform on it are described in the language as (essentially) specific LLVM code. However, most types are built out of other types (e.g. Rational) where operations on a Rational are written in terms of operations on the numerator and denominator.
3 Likes
To add:
The tremendous majority of Julia users (and developers) will never ever define a primitive type. There are only a handful of them in the Base language (Base.BitInteger, Base.IEEEFloat, Bool, Char, and probably something related to Ptr are the ones that come to mind) and I’ve never seen one defined in a package until I found Quadmath.jl researching this post (which adds Float128 as a primitive via library support).
If a computer doesn’t have hardware-native instructions (or, less commonly, software emulation libraries) that support the type, it probably isn’t a primitive. And Julia has already covered most of the common hardware types. The main reason I would imagine needing a new primitive type is if you were using non-IEEE-754 floats (like some of the nonstandard flavors of 16 bit floats or anything smaller) or longer IEEE floats. Or if you had some hardware or library that natively supported longer fixed-size integer types.
Another useful distinction you might be searching for is isbitstype.
2 Likes
The Quadmath case is actually quite interesting (and recent, this was only introduced ~2 months ago in cleanups by oscardssmith · Pull Request #92 · JuliaMath/Quadmath.jl · GitHub). It turns out that the Julia compiler is smart enough to pass primitive types that are AbstractFloats using floating point calling conventions rather than normal calling conventions (specifically using xmm registers on x86), so we were able to save a fair bit of complexity by just telling Julia to treat the Float128 as a bunch of bits.
3 Likes