Skip to content

Add align_double and align_int64 to ocamlc -config - #12019

Merged
dra27 merged 1 commit into
ocaml:trunkfrom
toots:align-double-int64-config
Sep 22, 2024
Merged

dra27 merged 1 commit into
ocaml:trunkfrom
toots:align-double-int64-config

Conversation

@toots

@toots toots commented Feb 18, 2023

Copy link
Copy Markdown
Contributor

These two values, particularly the double one, can be very useful to make low-level optimization of C code handling e.g. floatarray.

@nojb

nojb commented Feb 19, 2023

Copy link
Copy Markdown
Contributor

These two values, particularly the double one, can be very useful to make low-level optimization of C code handling e.g. floatarray.

Just to confirm, this is only an issue in 32-bits, do you agree? In 64-bits everything is 64-bit aligned anyway, right?

@toots

toots commented Feb 19, 2023

Copy link
Copy Markdown
Contributor Author

These two values, particularly the double one, can be very useful to make low-level optimization of C code handling e.g. floatarray.

Just to confirm, this is only an issue in 32-bits, do you agree? In 64-bits everything is 64-bit aligned anyway, right?

Maybe? Looks like the configure test has at least 3 different branches. I think, from a user perspective, it makes sense to have a clear data point without having to dig into specifics of the underlying architecture.

@shindere

shindere commented Feb 20, 2023 via email

Copy link
Copy Markdown
Contributor

@xavierleroy

Copy link
Copy Markdown
Contributor

These two values, particularly the double one, can be very useful to make low-level optimization of C code handling e.g. floatarray.

Agreed. But they are already readily accessible from C code: just include <caml/m.h> and test for ARCH_ALIGN_DOUBLE and ARCH_ALIGN_INT64. Why do you also need this information in the output of ocamlc -config ?

@toots

toots commented Feb 20, 2023 •

Copy link
Copy Markdown
Contributor Author

These two values, particularly the double one, can be very useful to make low-level optimization of C code handling e.g. floatarray.

Agreed. But they are already readily accessible from C code: just include <caml/m.h> and test for ARCH_ALIGN_DOUBLE and ARCH_ALIGN_INT64. Why do you also need this information in the output of ocamlc -config ?

ocamlc -config is pretty convenient to use with the existing tooling such as dune to have conditional compilation at build system level.

ocamlc -config values are exported durectly as dune variables. (I would add a link but it looks like the dune doc is broken at the moment).

Otherwise, one has to write a test C program that does the include/printf dance and execute it to get its result.

Also, I was pretty surprised to see an unscoped global macro named like that. ARCH_ALIGN_DOUBLE does not seem OCaml specific and could potentially clash with other publicly defined macros. Not sure if it's a good idea to use it this way, it should also be renamed and named-spaced in my opinion.

@toots

toots commented Feb 20, 2023

Copy link
Copy Markdown
Contributor Author

Overall the code looks okay to me. I have one remark and one question. Question: can you confirm that the values in utils/config.fixed.ml really are what you defined, i.e. true? Remark: in the documentation strings in utils/config.mli, there are two occurrences of Wether the compiler and runtime needs to ... where needs should be need.

Thanks! It's carnival time here in New Orleans but I plan on addressing these comments as soon as reality is back to normal! 🎭

@xavierleroy

Copy link
Copy Markdown
Contributor

ocamlc -config is pretty convenient to use with the existing tooling such as dune to have conditional compilation at build system level.

Point well taken. I'm still curious why you need to know the alignment constraints of the target machine to conditionally select things at build system level. My experience so far is that you need to #ifdef on these constraints within C code, and nowhere else.

Also, I was pretty surprised to see an unscoped global macro named like that. ARCH_ALIGN_DOUBLE does not seem OCaml specific and could potentially clash with other publicly defined macros. Not sure if it's a good idea to use it this way, it should also be renamed and named-spaced in my opinion.

First, you're changing the topic. Second, I don't agree with your other suggestion. Like most C libraries, OCaml tries to make function names and global variable names unique by prefixing them with caml_. That's a necessity because all those names are visible at link-time.

But like most C libraries, OCaml doesn't need to make and macro names unique, because they are visible only if you #include the corresponding header, and in the rare case you get a conflict with another header, you can always #undef the problematic names.

For example, <X11/Xlib.h> proudly defines macros Bool, True and False, and while it did break some of my code in the past, it is considered acceptable. OCaml's header files don't get anywhere this amount of annoyance :-)

@toots
toots force-pushed the align-double-int64-config branch from 7b388b2 to a6355fa Compare March 1, 2023 16:51
@toots

toots commented Mar 1, 2023

Copy link
Copy Markdown
Contributor Author

Overall the code looks okay to me. I have one remark and one question. Question: can you confirm that the values in utils/config.fixed.ml really are what you defined, i.e. true?

Good call, thanks. boot/ocamlc has been updated in the PR and now:

% ./boot/ocamlrun ./boot/ocamlc -config
...
flat_float_array: true
align_double: true
align_int64: true

Remark: in the documentation strings in utils/config.mli, there are two occurrences of Wether the compiler and runtime needs to ... where needs should be need.

Fixed too, thanks for pointing out!

@toots

toots commented Mar 1, 2023

Copy link
Copy Markdown
Contributor Author

ocamlc -config is pretty convenient to use with the existing tooling such as dune to have conditional compilation at build system level.

Point well taken. I'm still curious why you need to know the alignment constraints of the target machine to conditionally select things at build system level. My experience so far is that you need to #ifdef on these constraints within C code, and nowhere else.

Also, I was pretty surprised to see an unscoped global macro named like that. ARCH_ALIGN_DOUBLE does not seem OCaml specific and could potentially clash with other publicly defined macros. Not sure if it's a good idea to use it this way, it should also be renamed and named-spaced in my opinion.

First, you're changing the topic. Second, I don't agree with your other suggestion. Like most C libraries, OCaml tries to make function names and global variable names unique by prefixing them with caml_. That's a necessity because all those names are visible at link-time.

But like most C libraries, OCaml doesn't need to make and macro names unique, because they are visible only if you #include the corresponding header, and in the rare case you get a conflict with another header, you can always #undef the problematic names.

For example, <X11/Xlib.h> proudly defines macros Bool, True and False, and while it did break some of my code in the past, it is considered acceptable. OCaml's header files don't get anywhere this amount of annoyance :-)

Fair enough! As a developer I don't really feel confortable using a macro with a generic name but, as you pointed out, this is done some other places.

If I have this value explicitly available through dune/ocamlc -config, I would personally use it to generate a custom C macro and be happy forever after 🙂

@shindere

shindere commented Mar 1, 2023 via email

Copy link
Copy Markdown
Contributor

@toots

toots commented Mar 1, 2023 •

Copy link
Copy Markdown
Contributor Author

Thanks a lot. I am notsure that the PR itself does need to update boot/ocamlc\? Can we perhaps wait the next bootstrap, or do we have to have correct values immediately? Actually my question was unclear, sorry about that. What I was asking was whether the values for hte fixed configuration were really intended to be true, I wanted to make sure you had asked yourself about that. I was not trying to ensure that you deed a bootstrap to update the boot compiler and I don't actually knowwhether this really needs to happen in this PR.

Ha I see. I'm not sure what the values should be in fact, the doc says:

(* Configuration for the boot compiler. The compiler should refuse to bootstrap
if configured with values which would contradict the configuration below.
The values below are picked to trigger errors if accidentally used in the
compiler (e.g. for the C compiler). *)

In this case, the values could be true or false depending on the architecture/build configuration. Seems like this file has to match the general configuration module but that the effective parts to catch errors are with the values for c_compiler, native_pack_linker etc., in which case the default values added in this PR and set in this file would not matter much correct?

@shindere

shindere commented Mar 1, 2023 via email

Copy link
Copy Markdown
Contributor

@dra27 dra27 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, apart from a couple of tweaks to the .mli file. The update to config.fixed.ml is indeed correct - the alignment requirements won't affect any of the outputs of the compiler, and therefore you just pick a value in the bootstrap.

Comment thread utils/config.mli Resolved
@toots

toots commented Mar 5, 2023

Copy link
Copy Markdown
Contributor Author

LGTM, apart from a couple of tweaks to the .mli file. The update to config.fixed.ml is indeed correct - the alignment requirements won't affect any of the outputs of the compiler, and therefore you just pick a value in the bootstrap.

Done, thanks!

@toots
toots force-pushed the align-double-int64-config branch from 5fa51e5 to cb37932 Compare September 21, 2024 20:03
@toots

toots commented Sep 21, 2024

Copy link
Copy Markdown
Contributor Author

Looks like I totally forgot to merge this. Just fixed the conflicts. Planning on merging unless someone is opposed to it.

@gasche

gasche commented Sep 21, 2024

Copy link
Copy Markdown
Member

There is a change to boot/ocamlc in your PR, you need to redo this step now to not put back an older compiler version. Did you already redo the bootstrap?

@toots

toots commented Sep 21, 2024

Copy link
Copy Markdown
Contributor Author

There is a change to boot/ocamlc in your PR, you need to redo this step now to not put back an older compiler version. Did you already redo the bootstrap?

Yes I did!

% ./boot/ocamlrun ./boot/ocamlc -config                                                                                                                  15:05:27
version: 5.4.0+dev0-2024-08-25
...

@dra27 dra27 removed the merge-me label Sep 22, 2024
@dra27

dra27 commented Sep 22, 2024

Copy link
Copy Markdown
Member

Bootstrap doesn't appear to be correct (just noting not to merge yet)

@dra27
dra27 marked this pull request as draft September 22, 2024 09:25
@dra27

dra27 commented Sep 22, 2024

Copy link
Copy Markdown
Member

I can't repeat the bootstrap in cb37932 (boot/ocamllex differs) or 12ddfed (both boot artefacts differ)

@dra27
dra27 force-pushed the align-double-int64-config branch from 12ddfed to 8e81698 Compare September 22, 2024 09:36
@dra27
dra27 marked this pull request as ready for review September 22, 2024 09:36
@dra27

dra27 commented Sep 22, 2024

Copy link
Copy Markdown
Member

Rebased to clean out the edits in merge commits - this shouldn't require a bootstrap. Should be good to go now, thanks!

@dra27 dra27 added the merge-me label Sep 22, 2024
@dra27
dra27 merged commit 13a7fa9 into ocaml:trunk Sep 22, 2024
@toots

toots commented Sep 22, 2024

Copy link
Copy Markdown
Contributor Author

Thanks so much for the help!

@toots
toots deleted the align-double-int64-config branch September 22, 2024 14:20
@Octachron

Copy link
Copy Markdown
Member

It seems that the lack of handling for 32bit architecture is making the compiler fails due to a syntax error on 32 bits architecture.

@dra27

dra27 commented Sep 25, 2024

Copy link
Copy Markdown
Member

Is there a pointer to where the problem is, @Octachron? Apart from the fact the i386 test here was fine, I'm struggling to see by inspection how any path could lead to a syntax error here?

@Octachron

Copy link
Copy Markdown
Member

Sorry, this is indeed ARM32 specific, for which the generated config.generated.ml file ends up containing:

let align_double = true,
let align_int64 = true,

@shindere

shindere commented Sep 26, 2024 via email

Copy link
Copy Markdown
Contributor

@shindere shindere mentioned this pull request Sep 26, 2024
@dra27

dra27 commented Sep 26, 2024 •

Copy link
Copy Markdown
Member

Thanks! @mtelvers had spotted it on our arm32 builds as well and we were about to open a PR with the same fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants