Skip to content

Conversation

@RyanGlScott
Copy link
Contributor

Due to an oversight, the SAW_IMPORT_PATH environment variable (or, equivalently, the -i/--import-path command-line options) were being blatantly ignored by SAW. This fixes that oversight by restricting the API in SAWScript.Import to a single exported function (findAndLoadFile), which always consults SAW_IMPORT_PATH before attempting to load a file.

Fixes #2756.

@RyanGlScott RyanGlScott self-assigned this Oct 30, 2025
@RyanGlScott RyanGlScott added the subsystem: saw-script Issues related to the SAWScript language and/or its interpretation and execution label Oct 30, 2025
@RyanGlScott
Copy link
Contributor Author

RyanGlScott commented Oct 30, 2025

16 tests now fail because of changes in error messages that look like this:

-    within "x" (unify009.saw:20:6-20:7)
+    within "x" (./unify009.saw:20:6-20:7)

This is because the default SAW_IMPORT_PATH is . (i.e., the current path), and the import paths get prepended to the overall file path when calling findAndLoadFile. I wonder if we should add a special case for . such that ./foo.saw is instead represented as foo.saw?

@brianhuffman
Copy link
Contributor

I wonder if we should add a special case for . such that ./foo.saw is instead represented as foo.saw?

Yes, I think we should drop the leading ./. It is longer, noisier, and provides no extra information; we're better off without it.

Copy link
Contributor

@brianhuffman brianhuffman left a comment

Choose a reason for hiding this comment

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

I think we should go ahead and fix the leading "./" thing; other than that everything looks good to me.

This old definition of `findFile` was only needed for ancient versions of GHC
that SAW no longer supports.
Due to an oversight, the `SAW_IMPORT_PATH` environment variable (or,
equivalently, the `-i`/`--import-path` command-line options) were being
blatantly ignored by SAW. This fixes that oversight by restricting the API in
`SAWScript.Import` to a single exported function (`findAndLoadFile`), which
always consults `SAW_IMPORT_PATH` before attempting to load a file.

Fixes #2756.
@RyanGlScott RyanGlScott force-pushed the T2756-fix-SAW_IMPORT_PATH branch from 8b1ad79 to b9881b5 Compare October 30, 2025 14:24
@RyanGlScott
Copy link
Contributor Author

I opted to fix this by using System.FilePath.normalise, which collapses ./foo.saw to foo.saw, among various other touchups. I think this should suffice to restore the original error messages' formatting of file paths, and it might also make the formatting a bit prettier in other obscure cases on Windows. Let's see what the CI says.

@RyanGlScott
Copy link
Contributor Author

Using normalise causes the CI to pass, but with one slight technicality: the Windows CI job that runs the integration tests now has more failing tests than it did before. This is because on Windows, normalise will normalize / path separators to \\, as seen in this failing test case:

  test2301:                            eval saw  -j 'D:\a\saw-script\saw-script\intTests\jars\bcprov-jdk16-145.jar;D:\a\saw-script\saw-script\intTests\jars\galois.jar;D:\a\saw-script\saw-script\intTests\jars\org.sat4j.core.jar' test0.saw

Unexpected test diffs.
If the new outputs are correct, update the reference outputs, but
please don't do so without thinking.

--- test0.log.good	2025-10-30 14:45:25.597637700 +0000
+++ test0.log	2025-10-30 14:49:15.594833800 +0000
@@ -1,2 +1,2 @@
- Loading file "test0.saw"
- Loading file "subdir/testsym.saw"
+ Loading file "test0.saw"
+ Loading file "subdir\\testsym.saw"

FAIL (0.71s)
    intTests\IntegrationTest.hs:185:
    expected: ExitSuccess
     but got: ExitFailure 1
    Use -p '/test2301/' to rerun this test only.

The Windows integration tests CI job is already allowed to fail, so this doesn't affect whether the overall CI passes or not. Still, it does mean that if we ever did want to make the integration tests all pass on Windows, this PR would give us more work to do. Would folks be OK with accepting this? I could foresee ways to make the test suite more robust to Windows-style path separators (e.g., by making the test-diff infrastructure less sensitive to path-separator differences), but it would take some work to implement this.

@sauclovian-g
Copy link
Contributor

Go ahead and merge and I'll take care of it. It should let me remove some annoying hacks I had to add in the last run. (The prior state of things was that some paths came out with / and some with \ and some with \\, arbitrarily.)

@RyanGlScott RyanGlScott merged commit bf09a34 into master Oct 30, 2025
37 checks passed
@RyanGlScott RyanGlScott deleted the T2756-fix-SAW_IMPORT_PATH branch October 30, 2025 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

subsystem: saw-script Issues related to the SAWScript language and/or its interpretation and execution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SAW ignores SAW_IMPORT_PATH/--import-path

4 participants