-
Notifications
You must be signed in to change notification settings - Fork 800
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unique names for generated "test.fs" files #18308
base: main
Are you sure you want to change the base?
Conversation
✅ No release notes required |
I don't really like the approach in this PR. fsharp/src/Compiler/Utilities/range.fs Lines 189 to 195 in 5d0812f
And if it would help? |
What are you trying to solve? |
There's a problem with
It seems it is fundamentally non thread safe :( |
You mean the compiler caches based on just filename rather than the path? |
Yes, so it seems. |
Well, that is a compiler bug then. |
Yes, exactly! Working around it doesn't seems right to me. |
For IL verify, because the module name appears in the output I try to use rather than rely on generated names. Someone should add a bug and repro for the FileIndex issue. I wonder what it means for deterministic builds though. |
Aren't these two different problems?
|
Yes, right. I have to take a deeper look again. |
This reverts commit 45abdfb.
//static do testFileName.Value <- "test" | ||
static member internal MakeTestFileNameUniqueForThisTestCase() = | ||
testFileName.Value <- $"{Interlocked.Increment &counter}{Path.PathSeparator}test" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess you didn't want to use Path.PathSeparator
, which is "A platform-specific separator character used to separate path strings in environment variables."
@Martin521 I'll try to redo it with more limited approach, only touching the places where the checker is used directly. (i.e. ParseAndCheckFileInProject). Other code paths using checker.Compile actually do commit the files to a unique temp directory first, so they should be good. |
Ok, so I just made the names of synthetic sources (that never got written to disk) unique. |
Well, if it is done in parallel, one test might use the (intermediate) FileIndex-based results of another one. In "my" case, one might skip a warning because the other one had a "#nowarn". This is a rare race condition, but it is happening. It is at least my explanation for runs like this one that show errors that did not appear before or after. I would love to test your code in my PR. |
Ok, then it seems my approach is wrong again. Probably we should just give a unique ProjectId or Stamp: fsharp/tests/FSharp.Test.Utilities/CompilerAssert.fs Lines 410 to 420 in 5d0812f
each time we generate a test project. |
How would that help? Does it change the file name? |
It instructs the service that we have different project. I think it shoud create separate incremental builders for each, or in case of Transparent Compiler, cache the intermediate results correctly, because project snapshots are different. |
But as long as it runs in the same process, we have the same global FileIndex table, no? (Which means also that my remark above about "the same checker instance" does not make sense. It is about the same process, I think.) |
Yes! I'm not familiar with that stuff, but I think parsing and lexing operates on a lower level that is oblivious of the checker, and uses global state that is somehow not fully threadsafe. If it comes out that having a file with same name in two different projects leads to errors in parallel checking, this is really a compiler bug. |
It would be great to have a small clean repro. |
In all production scenarios it is not a problem, because a file with the same path is the same file. The problem appears only in testing. |
Let me try to create that |
It seems when this is called, there is no requirement for fsharp/src/Compiler/SyntaxTree/LexHelpers.fs Line 121 in 5d0812f
I wonder if it is sufficient to have two different files with same name in two different projects for this to break. |
WIP, just to see how many things break.
See: #18049 (comment)
Main problem is that the hardcoded "test.fs" makes it into expected IL as implicit module name (?) in many VerifyIL tests.