Skip to content

Make boot/ocamlc read directly byterun/primitives#324

Closed
bobot wants to merge 2 commits intoocaml:trunkfrom
bobot:use_prims_for_boot
Closed

Make boot/ocamlc read directly byterun/primitives#324
bobot wants to merge 2 commits intoocaml:trunkfrom
bobot:use_prims_for_boot

Conversation

@bobot
Copy link
Copy Markdown
Contributor

@bobot bobot commented Dec 1, 2015

boot/* are often responsible for merge conflict in github or rebase conflict during development, because they are binaries. People needs to modifies boot/ocamlc each time the set of primitives in the default runtime is modified.

This merge request proposes to use for boot/ocamlc the option -use-prims byterun/primitives. It allows to add new primitive and use it in the standard library without bootstrapping. Compilation with ./ocamlc,./ocamlopt are not modified.

For example you can compile with the following patch without the errors:

File "_none_", line 1:
Error: Error while linking boot/stdlib.cma(Weak):
The external function `caml_test_add_prim' is not available
diff --git a/byterun/weak.c b/byterun/weak.c
index 3614d11..29e1845 100644
--- a/byterun/weak.c
+++ b/byterun/weak.c
@@ -190,3 +190,8 @@ CAMLprim value caml_weak_blit (value ars, value ofs,
   }
   return Val_unit;
 }
+
+CAMLprim value caml_test_add_prim (value ar, value n)
+{
+  return ar;
+}
diff --git a/stdlib/weak.ml b/stdlib/weak.ml
index 71385c9..5dc37b4 100644
--- a/stdlib/weak.ml
+++ b/stdlib/weak.ml
@@ -303,3 +303,7 @@ module Make (H : Hashtbl.HashedType) : (S with type data = H.t) = struct
   ;;

 end;;
+
+external test_add_prim: int -> int -> int = "caml_test_add_prim"
+
+let _ = test_add_prim 1 2

I think that work also for removing some primitives but I don't know which exactly.

This could wait after 4.03 since it only simplifies compiler development.

bobot added 2 commits December 1, 2015 14:52
   Adding primitives doesn't require to bootstrap anymore
@gasche
Copy link
Copy Markdown
Member

gasche commented Dec 1, 2015

I don't know enough of the compiler build machinery to understand if that is correct, but I warmly welcome the change. Indeed bootstrapping on primitive changes is a pain and makes some sorts of contributions much more delicate. (It also generates conflicts that makes handling out-of-tree branches painful, etc.)

Thanks for this very productive work.

@damiendoligez
Copy link
Copy Markdown
Member

@gerdstolpmann should look at this, as it's getting close to cross-compilation territory.

Anyway, let's wait for 4.04, there's a lot going on now and I don't want to risk breaking the makefiles at this time.

@gerdstolpmann
Copy link
Copy Markdown

Basically, we have primitives that are hard-coded in the compiler (e.g. look at the beginnning of Translcore, it assumes caml_equal and others), and primitives that are used in the standard library. The -use-prims option is correct for the latter. My thinking is that there should also be a list of hard-coded primitives that is merged with the loaded list.

But anyway, given that there are rarely new hard-coded primitives the new approach is better than the old one. I don't see any problems with cross-compilation. On the contrary, host and target compilers could now even deviate with respect to the primitives.

@damiendoligez damiendoligez added this to the 4.04-or-later milestone Dec 17, 2015
@bobot bobot mentioned this pull request Dec 24, 2015
@alainfrisch
Copy link
Copy Markdown
Contributor

Thanks! Merged (manually -- somehow Git got overly confused while trying to merge, apparently by Windows EOL in .nt files).

@damiendoligez damiendoligez mentioned this pull request Oct 19, 2017
poechsel pushed a commit to poechsel/ocaml that referenced this pull request Mar 1, 2021
poechsel pushed a commit to poechsel/ocaml that referenced this pull request Mar 1, 2021
poechsel pushed a commit to poechsel/ocaml that referenced this pull request Mar 1, 2021
chambart pushed a commit to chambart/ocaml-1 that referenced this pull request Jan 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants