question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The following code prevents the compiler from terminating

See original GitHub issue

I reported this to fsharp and it was suggested I should report it here as well.

Description: The idea was to make a function format that can return any function which’s type passes a static check. The functions that are valid take parameters (arbitrarily many) of type string or int and produce either a unit or an int. Including the checker function in another function would make sure that the type parameter is a valid function type, which would then be constructed unsafely via reflection or similar and then finally casted to the appropriate target type.

Unfortunately, this code causes the compiler to hang indefinitely (or as far as my patience extended). This might not be a bug if it’s a design decision to allow non-termination, but I’d find that strange considering my code consists only of valid language constructs.

Repro Steps: Compile this code

type Switcher = Switcher

let inline checker< ^s, ^r when (^s or ^r) : (static member pass : ^r -> unit)> (s : ^s) (r : ^r) = ()

let inline format () : ^r =
    checker Switcher Unchecked.defaultof< ^r>
    () :> obj :?> ^r

type Switcher with
    static member inline pass(_ : string -> ^r) =
        checker Switcher Unchecked.defaultof< ^r>
    static member inline pass(_ : int -> ^r) =
        checker Switcher Unchecked.defaultof< ^r>
    static member inline pass(_ : unit) = ()
    static member inline pass(_ : int) = ()

[<EntryPoint>]
let main argv = 
    let res : unit = format () "text" 5 "more text" ()
    printfn "%A" res
    Console.ReadKey()
    0 // return an integer exit code

Severity: It’s pretty bad that the compiler fails to terminate, but it’s a fairly obscure use case.

Version: Visual Studio 2015 Preview, my project targets .NET Framework 4.5.3 and the runtime is F# 4.0 (FSharp.Core, 4.4.0.0)

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
forkicommented, Sep 19, 2016

@gmpl one thing is for sure: giving a error message immediately is better than compiler going into quasi infinite loop. So from my point of view your pr is a win for this case here.

0reactions
gustycommented, Sep 19, 2016

After analyzing and working with the Constraint Solver I’m not surprised that some samples (like this) never ends. But after the fix I’m proposing they should. Now, whether they end successfully or with an error is a different thing. I need to study more this repro, but in principle I would say that if the code in the repro makes sense it should compile and if it don’t compile then we’re facing another compiler bug, similar to the ones I reported and they should be fixed in a separated pull request.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Preventing console window from closing on Visual Studio ...
Here's a solution that (1) doesn't require any code changes or breakpoints, and (2) pauses after program termination so that you can see ......
Read more >
VBCSCompiler.exe process stays runing after exiting ...
VBCSCompiler.exe process stays runing after exiting Visual Studio 2017Closed - Not ... Yes, this prevents the directory from being deleted.
Read more >
Is there anyway to stop running to code without closing ...
Is there anyway to stop running to code without closing vscode everytime? ... ctrl+c in terminal, shift+f5 if debugging, should work.
Read more >
The target process exited with code 'code' while evaluating ...
Solution #1: Prevent the debugger from calling the getter property or ToString method. The error message will tell you the name of the...
Read more >
Security Technologies: Stack Smashing Protection ...
During function return the canary value is checked and if the value has changed the program is terminated. Thus reducing code execution to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found