Skip to content
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 problem with loop optimization (#742) #756

Closed
wants to merge 2 commits into from
Closed

Conversation

dsyme
Copy link
Contributor

@dsyme dsyme commented Dec 3, 2015

Provides a modified and reviewed fix for the problem reported here: #742

I've made the code cleaner and added additional constraints to ensure the optimization only applies to the compiled forms of for ... in ... do ... loops

@dsyme dsyme changed the title fix problem with loop optimization fix problem with loop optimization (#742) Dec 3, 2015
@robertpi
Copy link
Contributor

robertpi commented Dec 3, 2015

Cool. Looks good. I did wonder if checking the value in the enumerator and previous let binding was possible, but thought what I had was good enough. Would never have thought to make the change in the type checker either.

@@ -487,6 +487,31 @@ check "hfhdfsjkfur34"
Failure "ss!!!" -> results := "caught"::!results
!results)
["caught";"ssDispose";"eDispose"]

// Check https://github.com/Microsoft/visualfsharp/pull/742

Choose a reason for hiding this comment

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

In lieu of GitHub not lasting forever, one line of context would be helpful

@KevinRansom
Copy link
Member

Thanks for fixing this merged.

@dsyme
Copy link
Contributor Author

dsyme commented Dec 5, 2015

A not-so-pretty workaround for this issue is here: #759 (comment). (note however it requires changes to user code)

enumeratorVar.IsCompilerGenerated &&
let fvs = (freeInExpr CollectLocals bodyExpr)
not (Zset.contains enumerableVar fvs.FreeLocals) &&
not (Zset.contains enumeratorVar fvs.FreeLocals) ->
Copy link
Member

Choose a reason for hiding this comment

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

Don is this right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I think so - is there something I've missed? The "bodyExpr" is the body of the while loop, but it shouldn't directly refer to either enumerableVar (the variable holding the enumerable collection, which is consumed in GetEnumeratorCall) or enumeratorVar (the variable holding the enumerator for the collection, which is consumed in the binding for the elemVar "let").

@KevinRansom
Copy link
Member

On the internal build this fails with:

D:\fsharp_D14\src\fsharp\projects\Prototype.FSharp.Compiler\FSharp.Compiler.fsproj" (BuildLinked target) (43:63) ->
CoreCompile target) ->
 D:\fsharp_D14\src\fsharp\devdiv\src\fsharp\tastops.fs(7768,23): error FS0010: Unexpected identifier in expression. Expecte
 'in' or other token. [D:\fsharp_D14\src\fsharp\projects\Prototype.FSharp.Compiler\FSharp.Compiler.fsproj]
 D:\fsharp_D14\src\fsharp\devdiv\src\fsharp\tastops.fs(7769,23): error FS0058: Possible incorrect indentation: this token i
 offside of context started at position (7767:23). Try indenting this token further or using standard formatting convention
. [D:\fsharp_D14\src\fsharp\projects\Prototype.FSharp.Compiler\FSharp.Compiler.fsproj]
 D:\fsharp_D14\src\fsharp\devdiv\src\fsharp\tastops.fs(7769,23): error FS0058: Possible incorrect indentation: this token i
 offside of context started at position (7767:23). Try indenting this token further or using standard formatting convention
. [D:\fsharp_D14\src\fsharp\projects\Prototype.FSharp.Compiler\FSharp.Compiler.fsproj]
 D:\fsharp_D14\src\fsharp\devdiv\src\fsharp\tastops.fs(7772,9): error FS0058: Possible incorrect indentation: this token is
offside of context started at position (7767:23). Try indenting this token further or using standard formatting conventions
 [D:\fsharp_D14\src\fsharp\projects\Prototype.FSharp.Compiler\FSharp.Compiler.fsproj]
 D:\fsharp_D14\src\fsharp\devdiv\src\fsharp\tastops.fs(7773,9): error FS0058: Possible incorrect indentation: this token is
offside of context started at position (7772:9). Try indenting this token further or using standard formatting conventions.
[D:\fsharp_D14\src\fsharp\projects\Prototype.FSharp.Compiler\FSharp.Compiler.fsproj]
 D:\fsharp_D14\src\fsharp\devdiv\src\fsharp\tastops.fs(7775,9): error FS0058: Possible incorrect indentation: this token is
offside of context started at position (7773:9). Try indenting this token further or using standard formatting conventions.
[D:\fsharp_D14\src\fsharp\projects\Prototype.FSharp.Compiler\FSharp.Compiler.fsproj]
 D:\fsharp_D14\src\fsharp\devdiv\src\fsharp\tastops.fs(7776,9): error FS0058: Possible incorrect indentation: this token is
offside of context started at position (7775:9). Try indenting this token further or using standard formatting conventions.
[D:\fsharp_D14\src\fsharp\projects\Prototype.FSharp.Compiler\FSharp.Compiler.fsproj]
 D:\fsharp_D14\src\fsharp\devdiv\src\fsharp\tastops.fs(7777,9): error FS0058: Possible incorrect indentation: this token is
offside of context started at position (7776:9). Try indenting this token further or using standard formatting conventions.
[D:\fsharp_D14\src\fsharp\projects\Prototype.FSharp.Compiler\FSharp.Compiler.fsproj]
 D:\fsharp_D14\src\fsharp\devdiv\src\fsharp\tastops.fs(7783,1): error FS0058: Possible incorrect indentation: this token is
offside of context started at position (7777:9). Try indenting this token further or using standard formatting conventions.
[D:\fsharp_D14\src\fsharp\projects\Prototype.FSharp.Compiler\FSharp.Compiler.fsproj]
 D:\fsharp_D14\src\fsharp\devdiv\src\fsharp\tastops.fs(7791,1): error FS0058: Possible incorrect indentation: this token is
offside of context started at position (7783:1). Try indenting this token further or using standard formatting conventions.
[D:\fsharp_D14\src\fsharp\projects\Prototype.FSharp.Compiler\FSharp.Compiler.fsproj]
 D:\fsharp_D14\src\fsharp\devdiv\src\fsharp\tastops.fs(7793,1): error FS0058: Possible incorrect indentation: this token is
offside of context started at position (7783:1). Try indenting this token further or using standard formatting conventions.
[D:\fsharp_D14\src\fsharp\projects\Prototype.FSharp.Compiler\FSharp.Compiler.fsproj]
 D:\fsharp_D14\src\fsharp\devdiv\src\fsharp\tastops.fs(7800,5): error FS0010: Incomplete structured construct at or before
his point in definition. Expected incomplete structured construct at or before this point or other token. [D:\fsharp_D14\sr
\fsharp\projects\Prototype.FSharp.Compiler\FSharp.Compiler.fsproj]
 D:\fsharp_D14\src\fsharp\devdiv\src\fsharp\tastops.fs(7868,1): error FS0058: Possible incorrect indentation: this token is
offside of context started at position (7793:1). Try indenting this token further or using standard formatting conventions.
[D:\fsharp_D14\src\fsharp\projects\Prototype.FSharp.Compiler\FSharp.Compiler.fsproj]````
The OSS build succeeds though.

@mexx
Copy link
Contributor

mexx commented Dec 6, 2015

fails for me also in the wild ;) already on the FSharp.Compiler-proto.dll

mexx added a commit to mexx/visualfsharp that referenced this pull request Dec 6, 2015
@mexx mexx mentioned this pull request Dec 6, 2015
@enricosada
Copy link
Contributor

why this difference with appveyor build?

@mexx
Copy link
Contributor

mexx commented Dec 7, 2015

I think it's a matter of what fsc version is used to build the proto compiler, will check which version was used in my setup.

@mexx
Copy link
Contributor

mexx commented Dec 7, 2015

Here is the start of the failing call on my setup
..\..\..\lkg\FSharp-4.0.30319.1\bin\fsc.exe -o:obj\Proto\net40\FSharp.Build-proto.dll ...
on AppVeyor
C:\Program Files (x86)\Microsoft SDKs\F#\3.1\Framework\v4.0\fsc.exe -o:obj\Proto\net40\FSharp.Build-proto.dll

@KevinRansom
Copy link
Member

the appveyor build uses F# 3.1, that is the difference between build success and failure. It fails with the LKG.

@mexx
Copy link
Contributor

mexx commented Dec 8, 2015

What are the reasons why AppVeyor build doesn't use the LKG version, like the local ones?
Shouldn't the build take the same path as local ones?

KevinRansom pushed a commit that referenced this pull request Dec 8, 2015
KevinRansom pushed a commit that referenced this pull request Dec 8, 2015
@KevinRansom
Copy link
Member

It'seems a bug in the script, we are looking at fixing it.

@KevinRansom
Copy link
Member

pulled

@KevinRansom KevinRansom closed this Dec 9, 2015
dsyme added a commit to fsharp/fsharp-compiler-docs that referenced this pull request Dec 14, 2015
dsyme added a commit to fsharp/fsharp-compiler-docs that referenced this pull request Dec 14, 2015
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.

7 participants