Skip to content

Bind(C) prif_coarray_handle#3

Closed
bonachea wants to merge 16 commits into
mainfrom
bind-c-handle
Closed

Bind(C) prif_coarray_handle#3
bonachea wants to merge 16 commits into
mainfrom
bind-c-handle

Conversation

@bonachea
Copy link
Copy Markdown
Owner

Implements https://github.com/BerkeleyLab/prif/issues/157 , proposals 2, 2.1. 2.2, 2.3

@bonachea bonachea force-pushed the bind-c-handle branch 2 times, most recently from 9920535 to 6fddf2d Compare March 20, 2026 23:49
@bonachea bonachea changed the base branch from main to veggies-patch March 20, 2026 23:54
@bonachea bonachea changed the base branch from veggies-patch to main March 20, 2026 23:54
@bonachea bonachea force-pushed the bind-c-handle branch 2 times, most recently from d0d9cdd to 219b15c Compare April 13, 2026 17:07
@bonachea
Copy link
Copy Markdown
Owner Author

@certik This branch contains some new development in Caffeine for a forthcoming feature.

The latest commit (028cfd7) currently appears to be ICE'ing LFortran 0.62 and LFortran:recent on Linux, despite passing on all supported versions of gfortran and flang.

How can we narrow this down further?

@certik
Copy link
Copy Markdown

certik commented Apr 20, 2026

@bonachea Let me have a look to isolate an MRE, then we can fix it. I think this is unrelated to lfortran/lfortran#11175 ?

I can reproduce the failure. I am creating an MRE.

Here is the MRE:

program mre
  implicit none
  type :: t
    integer :: x
  end type
  type(t), pointer :: src, dest
  allocate(src)
  src%x = 1
  allocate(dest, source=src)
  if (dest%x /= 1) error stop "FAIL"
  print *, "PASS"
  deallocate(src)
  deallocate(dest)
end program

Which gives:

~/repos/caffeine(build4-mre)$ lfortran mre_allocate_source_ptr.f90
LCOMPILERS_ASSERT failed: /Users/ondrej/repos/lfortran/src/libasr/codegen/llvm_utils.cpp
function create_gep2(), line number 1774 at
ds_pointee_type == t
ERROR MESSAGE:
Type mismatch in create_gep2: GEP target type does not match pointer's pointee type. This would cause crashes in LLVM <= 8 constant folder. Target type: %mre.t = type { i32 }, Pointer pointee type: %mre.t*
Traceback (most recent call last):
...

I am fixing it.

@certik
Copy link
Copy Markdown

certik commented Apr 20, 2026

There were a few more bugs, so I fixed them all. With this PR lfortran/lfortran#11179 the bind-c-handle branch builds and passes all tests:

_____ 78 of 80 tests passed. 2 tests were skipped _____

I also tested the old main (b8dd1f9) and that also works with the PR:

_____ 78 of 80 tests passed. 2 tests were skipped _____

I also tested the latest main with your main, and that also failed, so I think we didn't have enough integration tests to keep it running. I'll see if I can set it up at our CI to test Caffeine with every commit.

@certik
Copy link
Copy Markdown

certik commented Apr 20, 2026

@bonachea ok, so lfortran/lfortran#11181 is in, the latest main in LFortran now works.

I have some more fixes / cleanup on top, but that shouldn't be a blocker for you.

You can also remove 028cfd7 which now works.

@bonachea
Copy link
Copy Markdown
Owner Author

@bonachea ok, so lfortran/lfortran#11181 is in, the latest main in LFortran now works.

I have some more fixes / cleanup on top, but that shouldn't be a blocker for you.

Thanks for the amazingly quick turnaround on these fixes @certik !!

I've re-run the CI for this PR against lfortran:latest and confirm that it's working!

This PR will ideally merge to caffeine:main in the next few weeks, and since LFortran 0.62 is no longer sufficient I'd prefer to simultaneously update our CI from LFortran 0.62 to a new stable release tag. What's your timeframe for the next LFortran release?

@certik
Copy link
Copy Markdown

certik commented Apr 20, 2026

I can release it any time you want. I am trying to get caffeine tested at our CI: lfortran/lfortran#11190, to ensure it is reproducible (but since it already works for you, I think we have it) and to prevent future breakages. Then we can make a release.

@bonachea bonachea force-pushed the bind-c-handle branch 3 times, most recently from 04c6a3d to 338b73c Compare April 24, 2026 04:38
bonachea added 13 commits May 1, 2026 20:17
* Replace info field with type(c_ptr)
* Add helper functions to convert between prif_coarray_handle and descriptor pointer (dp)
* Adjust all internal manipulation of prif_coarray_handle
* Make some minor unrelated improvements to affected code while rewriting
* Convert prif_coarray_handle argument from pointer to value
* Convert errmsg argument to kind=c_char
* Update tests
As the redesigned final_func is now supported by all supported compilers
Convert `prif_allocate_coarray(final_func)` argument to:
  `procedure(prif_coarray_cleanup_interface), pointer`

Adjust test code accordingly
Also, add gfortran bug workarounds:

1. Use caf_c_funloc_deref helper to workaround broken c_funloc
2. Use final_func_usher for !HAVE_PROCEDURE_ACTUAL_FOR_POINTER_DUMMY
bonachea added 3 commits May 1, 2026 20:18
As resolved in the 2026-04-16 PRIF Committee meeting

Adjust tests, removing keyword args to work with either version of PRIF
@bonachea
Copy link
Copy Markdown
Owner Author

bonachea commented May 5, 2026

Superseded by BerkeleyLab#320

@bonachea bonachea closed this May 5, 2026
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.

2 participants