-
Notifications
You must be signed in to change notification settings - Fork 123
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
Fix ProjectFileNames order when getting project options from script #594
Conversation
Shouldn't this be addressed inside FSharp.Compiler.Service? I think the |
I thought this already happened? How would scripts ever have worked? |
Seems I didn't make a good job to explain the problem. I'll try to fix that:
In super-simplified and imperative (because that is what we love 😉) code this would become: type LoadDirective = { file: File }
and File = { path: string; loadDirectives: LoadDirective list }
let rec getProjectSourceFiles (sourceFiles: ResizeArray<string>) (file: File) =
for loadDirective in file.loadDirectives do
sourceFiles.Add(loadDirective.file.path)
getProjectSourceFiles sourceFiles loadDirective.file
let sourceFiles = ResizeArray<string>()
getProjectSourceFiles sourceFiles mainFile So my naive thinking it's the problem can be solved by swapping the lines within the for loop in the above code (so the dependencies of a file are added to the sourceFiles list before the file itself). Is that correct? I hope it's a bit clearer now and I didn't mess things further. If you want me to create a repo with the sample files I'm talking about, just tell me. |
This is the fix for #587, correct? |
It clearly looks like someone was doing "distinct" on the reverted list. |
Yeah, it seems to be related to #587, I didn't notice that. Thanks for pointing it out! |
@alfonsogarciacaro Do you know if this bug manifests in the Visual F# Tools (fsi.exe and its language service)? Should we be making a corresponding fix there? |
@dsyme 1.fsx #load "2.fsx"
#load "3.fsx"
printfn "HELLO FROM 1" 2.fsx #load "4.fsx"
printfn "HELLO FROM 2" 3.fsx #load "4.fsx"
printfn "HELLO FROM 3" 4.fsx printfn "HELLO FROM 4"
(I run fake.exe, but it uses FSharp.Compiler.Service internally) FSI executes script 4 twice, while FSharp.Compiler.Service executes each script exactly once, but in the wrong order. |
I'm on OSX/Mono and I'm getting similar results, MyLib.fs let add2 x = x + 2 MyLib1.fsx #load "MyLib.fs"
let add3 = MyLib.add2 >> ((+) 1) MyLib2.fsx #load "MyLib.fs"
let add4 = MyLib.add2 >> ((+) 2) Main.fsx #load "MyLib1.fsx"
#load "MyLib2.fsx"
MyLib1.add3 5 |> printfn "%i"
MyLib2.add4 5 |> printfn "%i" $ fsharpi Main.fsx
8
9
$ fsharpc Main.fsx
F# Compiler for F# 4.0 (Open Source Edition)
Freely distributed under the Apache 2.0 Open Source License
/temp/MyLib1.fsx(4,6): error FS0039: The namespace or module 'MyLib' is not defined
/temp/MyLib1.fsx(7,12): error FS0039: The value or constructor 'add2' is not defined |
There are two similar options here. The first one is called by fsc |
As @matthid pointed out, the problem seems to be with grouping in this line: I undid changes in the previous commit and just used closure's |
I've changed the name of the PR. Please let me know if it can be accepted just as a patch for |
@alfonsogarciacaro Could you add a test case please? That would clarify the impact of the change for me. Thanks |
@alfonsogarciacaro We've now integrated all the changes from visualfsharp. Could you merge with master and update the PR please? Thanks |
2dfa90a
to
c7d8333
Compare
Closing and reopening to trigger CI |
c7d8333
to
c213aea
Compare
Hi Don, I've rebased with latest master and added the test. Checking the test I realised that my second "fix" was actually wrong (replacing In any case, I'd appreciate if you can have a look. This is working now for my use case but I haven't managed to run the other tests, so I don't know if I'm breaking something else. |
c213aea
to
913962e
Compare
@dsyme, with the latest commit, only the tests that are also failing on |
I realized my previous fix wasn't working in all situations so I've added more tests and improved it. What confused me was the |
b263858
to
c55cd55
Compare
bd64dcc
to
b787099
Compare
b787099
to
d06a424
Compare
@dsyme, I rebased the PR against the latest changes in master and now build checks are passing 🎉 Also, I published a Fable version with a custom build including this fix and there have not been errors reported so far. If the PR is merged, how should this fix be propagated to the F# compiler? Should I send another PR to the fsharp or visualfsharp repo? Cheers! |
I've confirmed that the broken behaviour reported above also repros on F# 4.0 on Windows. It also repros when So yes, we wiwll also need to propagate this fix to the visualfsharp repository. I'll just cherry-pick it and send a PR there since it's quite important to fix |
Fix in visualfsharp is here: dotnet/fsharp#1363 |
@alfonsogarciacaro We have failing tests in visualfsharp after this change, see dotnet/fsharp#1363 We'd better get those sorted out |
@dsyme, thanks for that! I'll try to move the tests to FCS and fix them here 👍 |
@alfonsogarciacaro I think the errors are all of this form below. This is for
from
We get the same error whether
in
|
That's very valuable info! We may fix it by passing and initial value to the observed sources (the sources that were passed on the command line). I'll give it a try. |
@alfonsogarciacaro Updated the information above - the bug appears with
in the script |
@alfonsogarciacaro The bug in
The order test2.fs and test.fs is reversed from the command line arguments:
|
@alfonsogarciacaro Finally, the
which contains
The test is running
from
|
Removing the List.rev from this line looks promising:
|
@alfonsogarciacaro I pushed two fixes to the visualfsharp PR that should I think address these problems |
Let's get it green there then cherry-pick the fix-on-fix back here |
I checked most of the failing tests by hand and they seem to now be ok. |
Wow, you're fast! Ok, if everything is green in visualfsharp I can do the cherry-picking and send a new PR here if you want. Thanks a lot for your help! |
Previous failing tests now pass but there's a new failure 😞 I'm not sure how serious it is.
|
@dsyme, I tried rebuilding FCS applying your latest fix and unfortunately |
Yeah, I know. I've made a better set of changes in dotnet/fsharp#1363, I think things are healthier now. |
Cherry picked the fix here. When both FCS and visualfsharp are green then we are in good shape |
This is more of an issue/question than a PR but I wanted to include the code to better illustrate my point.
I would like to make it possible just to use F# scripts instead of a
fsproj
file. However, compilation of scripts quickly fails when the file structure complicates a bit. Consider we have the following four files:BaseLib.fs
Lib1.fsx
(loadsBaseLib.fs
)Lib2.fsx
(loadsBaseLib.fs
)Main.fsx
(loadsLib1.fsx
,Lib2.fsx
)When I call
FSharpChecker.GetProjectOptionsFromScript
onMain.fsx
I get the following file ordering, which makes compilation fail:Of course this is fixed if I load
BaseLib.fs
before anything inMain.fsx
but, given thatGetProjectOptionsFromScript
actually findsBaseLib.fs
, I wonder if it would be possible to fix the ordering soMain.fsx
doesn't need to knowLib1.fsx
dependencies in advance.The fix in this PR does actually this, however I got it by trial-and-error and I didn't test with other file structures so probably there's a much better solution. My question, would something along these lines be possible (so it's worth working on it) or is there any reason it's bound to fail in certain situations?
Thanks!