Skip to content

Conversation

@Noir01
Copy link
Collaborator

@Noir01 Noir01 commented Oct 28, 2025

fixes #308

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR improves Clang compiler compatibility for the Gibbon runtime system by adding compiler-agnostic macro wrappers and toolchain detection. The changes address issue #308 by ensuring the codebase can compile cleanly with both GCC and Clang.

Key changes:

  • Introduces cross-compiler pragma macros (GIB_PRAGMA_MESSAGE, GIB_PRAGMA_UNROLL) to handle compiler-specific syntax differences
  • Adds automatic detection of Clang compiler and selection of appropriate archiver tool (llvm-ar vs gcc-ar)
  • Replaces GCC-specific inline assembly syntax with portable __asm__ __volatile__ form

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
gibbon-rts/rts-c/gibbon_rts.h Adds pragma wrapper macros and updates inline assembly syntax for cross-compiler compatibility
gibbon-rts/rts-c/gibbon_rts.c Replaces direct pragma usage with new wrapper macros throughout the runtime
gibbon-rts/Makefile Adds -Werror flag and uthash include path configuration
gibbon-compiler/src/Gibbon/HaskellFrontend.hs Removes redundant CPP conditionals around import statement
gibbon-compiler/src/Gibbon/Compiler.hs Implements Clang detection and automatic archiver selection for build process

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Collaborator

@ulysses4ever ulysses4ever left a comment

Choose a reason for hiding this comment

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

It's be wise to set up a test that runs in CI.

@Noir01
Copy link
Collaborator Author

Noir01 commented Oct 29, 2025

It's be wise to set up a test that runs in CI.

What kind of tests should I add?

@vidsinghal
Copy link
Collaborator

It's be wise to set up a test that runs in CI.

What kind of tests should I add?

I believe all the tests run with gcc atm.
In gibbon-test-examples and the Benchrunner, you can add a gcc mode and a clang mode.
Run all tests with clang by changing the compile/run command and one with gcc.

@ulysses4ever
Copy link
Collaborator

ulysses4ever commented Oct 29, 2025

You can set up a smoke test separately from everything else (e. g. a separate ci workflow but maybe not, needs thinking). It could compile some simple program with clang.

What Vidush suggests is bonus points (but sounds great!).

@Noir01 Noir01 force-pushed the aniruddh-clang-support-fixing_indirections branch from 466991a to 90b43ad Compare October 30, 2025 17:38
@Noir01
Copy link
Collaborator Author

Noir01 commented Oct 30, 2025

I did what @vidsinghal suggested and now our tests run twice, once for gcc and once for clang. I also rebased my branch.

@Noir01 Noir01 force-pushed the aniruddh-clang-support-fixing_indirections branch from 90b43ad to 0d7e935 Compare October 30, 2025 18:15
@vidsinghal
Copy link
Collaborator

@Noir01 can you rebase this with fixing_indirections? Tests should pass now

Not exactly sure why it was conditionalized
but I kept running into an error and
'unconditionalizing' worked.
GIB_PRAGMA will emit build-time messages in the same manner as
before but safely across Clang and GCC.
I had Codex suggest this code, but I did my due diligence and
tested and looked into official docs to ensure the solution
works and actually makes sense.
Enable -Werror since we've fixed the errors in prev commits
Also explicitly bundle uthash
Add an opt-in --cc={compiler} which is threaded throughout
all compiler invocations.
@Noir01 Noir01 force-pushed the aniruddh-clang-support-fixing_indirections branch from 0d7e935 to e7eb02a Compare November 3, 2025 04:51
@vidsinghal
Copy link
Collaborator

builds failing

The only usage of foldl' seems to be with L.foldl' on line 1412
@vidsinghal
Copy link
Collaborator

@noir tests aren't setup properly?

    < [compiler] clang detected but llvm-ar not found; using '/usr/bin/ar' instead.
    ```

@Noir01
Copy link
Collaborator Author

Noir01 commented Nov 3, 2025

I just looked at the logs, and what I guess is happening is that I didn't add llvm-ar in the workflow image, so every time it runs the tests and compares the output, the warning we added for different major versions of clang and llvm-ar triggers which is tripping up the simple diff tests.

@vidsinghal
Copy link
Collaborator

I just looked at the logs, and what I guess is happening is that I didn't add llvm-ar in the workflow image, so every time it runs the tests and compares the output, the warning we added for different major versions of clang and llvm-ar triggers which is tripping up the simple diff tests.

we need to update the workflow image to include llvm-ar

This should prevent tests failing if llvm-ar and a fallback like
/usr/bin/ar is used instead.
@ulysses4ever
Copy link
Collaborator

Regarding hPutStrLn stderr: I thought Gibbon already had some messaging infrastructure so that we have control over how things get printed.

@Noir01
Copy link
Collaborator Author

Noir01 commented Nov 4, 2025

Regarding hPutStrLn stderr: I thought Gibbon already had some messaging infrastructure so that we have control over how things get printed.

Oh, I wasn't aware of that. How do I use the existing infrastructure?

@ulysses4ever
Copy link
Collaborator

I'm not sure there is. I might have mixed that up with err:

It's a good idea to grep for stderr to check.

@Noir01
Copy link
Collaborator Author

Noir01 commented Nov 4, 2025

I did rg "stderr" and on a cursory glance, it doesn't seem like any infrastructure exists yet.

Also, some of the tests are failing with segfaults for the clang workflows. I will try to debug them tonight/tomorrow morning.

@vidsinghal
Copy link
Collaborator

I did rg "stderr" and on a cursory glance, it doesn't seem like any infrastructure exists yet.

Also, some of the tests are failing with segfaults for the clang workflows. I will try to debug them tonight/tomorrow morning.

oh wow, this is interesting, i would be interested to know why, if you can't figure out lmk, i might try to investigate. Otherwise we will have to mark these failing for Clang.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants