Subject: Re: Relative includes in R7RS define-library seem broken

From: Amirouche <[email-masked]>
Date: Sat, 11 Nov 2023 11:58:49 +0000

If I am not mistaken, the patch is not backward compatible.

The problem with the current patch is that it force the included file 
to be next to the including file, there is no fallback  mechanism. 
The algorithm should be dynamic using an ordered list a priority to
the favorite behavior. 

The most relevant hunk is:

--- a/module/ice-9/psyntax.scm
+++ b/module/ice-9/psyntax.scm
@@ -3260,15 +3260,20 @@
   (let ((syntax-dirname (lambda (stx)
                           (define src (syntax-source stx))
                           (define filename (and src (assq-ref src 'filename)))
-                          (and (string? filename)
-                               (dirname filename)))))
+                          (define source-file-name
+                            (fluid-ref compilation-source-file-name))
+                          (or (and source-file-name
+                                   (dirname source-file-name))
+                              (and (string? filename)
+                                   (dirname filename))))))

Here the code says: the included file must be in (syntax-dirname). 
It is preferable to have fallbacks, to be backward compatible.

`syntax-dirname' must be `syntax-dirnames' to return candidate directories 
sorted list with biggest priority coming first where to find included 
files.

Also, mind the use of the fluid and how it interact with parallel compilation.

BR

ref: https://github.com/justinethier/cyclone/issues/494#issuecomment-1328958946
ref: https://github.com/justinethier/cyclone/commit/ab25e360a9d7b67c2e5eda086001ca0761a3f34f#diff-b9136575f3ccbf09887d1da9fb4b6e136e4e32a839c10cf855696ec1cf6add4bR54-R58