Forums

Error threshold causes endless compilation

General discussion about Cobra. Releases and general news will also be posted here.
Feel free to ask questions or just say "Hello".

Error threshold causes endless compilation

Postby Chasm » Sat Jun 22, 2013 10:45 am

I have found a very specific case in which the compiler locks-up.

Operating System: Win 7 x86-64
Compiler Version: Cobra 0.9.4
IDE: Xamarin - latest

Code: Select all
@args -lib:"C:\Program Files (x86)\Microsoft XNA\XNA Game Studio\v4.0\References\Windows\x86"

@ref 'Microsoft.Xna.Framework.Graphics'

use Microsoft.Xna.Framework.Graphics

class Program

   var blendState as Microsoft.Xna.Framework.Graphics.BlendState

   def main

      .blendState = BlendState()
      .blendState.AlphaBlendFunction = BlendState.AlphaBlend.AlphaBlendFunction
      .blendState.AlphaDestinationBlend = BlendState.AlphaBlend.AlphaDestinationBlend
      .blendState.AlphaSourceBlend = BlendState.AlphaBlend.AlphaSourceBlend
      .blendState.BlendFactor = BlendState.AlphaBlend.BlendFactor
      .blendState.ColorBlendFunction = BlendState.AlphaBlend.ColorBlendFunction
      .blendState.ColorDestinationBlend = BlendState.AlphaBlend.ColorDestinationBlend
      .blendState.ColorSourceBlend = BlendState.AlphaBlend.ColorSourceBlend
      .blendState.ColorWriteChannels = BlendState.AlphaBlend.ColorWriteChannels
      #.blendState.ColorWriteChannels1 = BlendState.AlphaBlend.ColorWriteChannels1


Compilation of this incorrect code simply reports the errors. However, if the last line is uncommented, the compiler will completely lock up and the IDE then has to be closed (compilation cannot be cancelled).

To prove that this is not a case that involves only XNA, the following code will also cause a lock-up:

Code: Select all
class Program

   def main
      variable = 15
      variable = 'x'
      variable = 'x'
      variable = 'x'
      variable = 'x'
      variable = 'x'
      variable = 'x'
      variable = 'x'
      variable = 'x'
      variable = 'x'
      variable = 'x'
      variable = 'x'
      variable = 'x'
      variable = 'x'
      variable = 'x'
      variable = 'x'
      variable = 'x'
      variable = 'x'
      variable = 'x'
      variable = 'x'
      variable = 'x'
      variable = 'x'
      variable = 'x'
      variable = 'x'      
      variable = 'x'
      variable = 'x'
      variable = 'x'


The second code is obviously an extreme corner-case, but it proves that you can lock the compiler up with any code.
Chasm
 
Posts: 33

Re: Error threshold causes endless compilation

Postby nerdzero » Sat Jun 22, 2013 11:41 am

This appears to be the MonoDevelop/Xamarin Studio addin that is locking up as opposed to the compiler. If I compile that program from the command line it returns the errors correctly. But, yeah it locks up for me to from the IDE. Hmm...not sure what could be causing this yet...
nerdzero
 
Posts: 286
Location: Chicago, IL

Re: Error threshold causes endless compilation

Postby nerdzero » Sat Jun 22, 2013 12:11 pm

Thanks for reporting this, Chasm.

Okay, here's what I think is happening: The addin spawns the Cobra compiler in a separate process with redirected output and then waits for it to finish. I think the output/error buffers are getting full with so many error messages but there is still more output to write, so the compiler process blocks. Meanwhile the addin is still waiting for the process to finish. DEADLOCK!

I'll change the code to be asynchronous. Should fix this. Assuming that's what the problem is. Unfortunately, I won't have time to get it to it today and probably not tomorrow. If someone wants to play around with this in the meantime, here is the code that needs to be modified:

https://github.com/ramon-rocha/MonoDeve ... cobra#L295

https://github.com/ramon-rocha/MonoDeve ... cobra#L246

Do a CTRL+F on this page: http://msdn.microsoft.com/en-us/library ... utput.aspx and search for "deadlock" to get an idea of what needs to change to avoid the deadlock condition (basically read before we wait instead of waiting then reading).
nerdzero
 
Posts: 286
Location: Chicago, IL

Re: Error threshold causes endless compilation

Postby Charles » Sat Jun 22, 2013 12:22 pm

I think .runAndCaptureAllOutput avoids this problem. It's an extension method on Process that I wrote because this situation comes up repeatedly.

See http://cobra-language.com/trac/cobra/br ... cess.cobra

If you need the stdout and stderr separated we could consider a "result object" to capture those.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Error threshold causes endless compilation

Postby Chasm » Sat Jun 22, 2013 1:38 pm

Interesting. I always had a knack for breaking things, lol.
Chasm
 
Posts: 33

Re: Error threshold causes endless compilation

Postby Charles » Sat Jun 22, 2013 5:14 pm

We have a knack for fixing things, so this should work out well. 8-)
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Error threshold causes endless compilation

Postby nerdzero » Mon Jun 24, 2013 9:04 am

Charles wrote:...If you need the stdout and stderr separated we could consider a "result object" to capture those.

This would be nice. It would make it easier to just drop in .runAndCaptureAllOutput as a replacement to the current code.
nerdzero
 
Posts: 286
Location: Chicago, IL

Re: Error threshold causes endless compilation

Postby Charles » Mon Jun 24, 2013 4:11 pm

Done. http://cobra-language.com/trac/cobra/changeset/3006

The new methods have a slightly different name and the old methods are still available for backwards compatibility. The return result has three properties you can query.
output = process.runAndCaptureOutput
trace output.standardOutput, output.errorOutput, output.combinedOutput

If you have any problems or feedback, let me know.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Error threshold causes endless compilation

Postby nerdzero » Wed Jun 26, 2013 9:45 am

This is fixed now. Just download and install the addin again from the 'master' branch: https://github.com/ramon-rocha/MonoDeve ... master.zip

I'm only using runAndCaptureOutput in the 'cleanup' branch. I ended up doing an asynchronous read of stdOut in 'master' so as not to introduce a dependency on an svn version of Cobra.
nerdzero
 
Posts: 286
Location: Chicago, IL

Re: Error threshold causes endless compilation

Postby Chasm » Wed Jun 26, 2013 12:11 pm

Awesome, thank you
Chasm
 
Posts: 33


Return to Discussion

Who is online

Users browsing this forum: No registered users and 25 guests

cron