Why are some primitive types defined in Julia, and others in the C code?

The ones that are defined in C are the ones are used from the C code for Julia’s runtime. Since one needs to have a reference to these types from both C and Julia, there are two ways you can go about it:

  1. Define in Julia then make C bindings;
  2. Define in C then make Julia bindings.

For a while we did the former to try to make more things defined in Julia code, but it’s a bit awkward. You need to predeclare all these types in C without definitions, then get enough of the Julia runtime working to evaluate enough Julia code to define those types (without using any of them). Then you need to finish setting up the C runtime by grabbing references to the types you’ve created in Julia and initializing C references to them. Then you can go back to evaluating Julia code to bootstrap Base.

The second order is less annoying: you setup the C runtime including all the Julia types it needs in one go; then you make Julia references to those types and you’re ready for pure Julia bootstrapping. In particular, this avoids needing a phase where you can evaluate Julia code without being able to use any Julia types from the C runtime code.

Taking this one as an example: the Julia runtime uses the UInt8 type but doesn’t use Int8 anywhere, so Int8 can simply be defined in Julia code and no C reference to it needs to exist.

37 Likes