Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

C# Compiler Request for 5.4 build

Discussion in 'Experimental Scripting Previews' started by Hyp-X, Jul 25, 2016.

  1. Hyp-X

    Hyp-X

    Joined:
    Jun 24, 2015
    Posts:
    421
    Please release a test build for the 5.4 branch if possible.
    There are developers who already switched to 5.4 and therefore cannot try the 5.3 test build

    Thanks
     
    Can-Baycay and S_Darkwell like this.
  2. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,775
    Thanks for the suggestion. How many others are interested in a 5.4 version of Unity with the new C# compiler? Releasing this is certainly possible, although it is non-trivial, so I want to gauge interest before we spend the time to work on it.
     
  3. orb

    orb

    Joined:
    Nov 24, 2010
    Posts:
    3,033
    Sign me up.
     
    zyzyx likes this.
  4. Lszt

    Lszt

    Joined:
    Sep 28, 2015
    Posts:
    38
    same here !
     
  5. JJJohan

    JJJohan

    Joined:
    Mar 18, 2016
    Posts:
    214
    I'd certainly be interested as well.
     
  6. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,685
    With all the features and stabilisation added to 5.4, this would help greatly to keeping it current
     
  7. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,775
    Thanks for the votes on this issue! If we do make the new compiler available in a 5.4 version, it won't be for a few weeks at least, I think. The public 5.4 release is not available yet, so we want to wait until then. But it seems to me there is enough interest here.

    I'm curious about why there is interest in this for 5.4 though. Is anyone planning to ship with this new compiler? Or do you have project working on 5.4 only already?
     
  8. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,685
    I don't have a project currently, but I suspect most who are trying to use the new features and planning to ship in 5.4 timelines will want to bear the pain of upgrade now while they are in 5.4 beta (or shortly after) rather than ship and then wait.
    Certainly for consoles, you want to irk out as much as possible.
     
  9. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,775
    Ok, that does make sense. Let me clear about our intent for the compiler upgrade though. At the moment, we're only planning to ship and support the new compiler in Unity 5.5. The purpose of this 5.3-based build with the new compiler is to get feedback and try to find any cases we have missed during our testing, as we want to be completely sure the new C# compiler is rock solid before it is released to everyone.

    We're not planning to ship the new C# compiler in the 5.3 or 5.4 series.

    But, that could change. If the new C# compiler is stable (I mean, really stable), and the few breaking changes (listed in the initial post http://forum.unity3d.com/threads/upgraded-c-compiler-on-5-3-5p8.417363/) are not a problem, then we could ship this new compiler for 5.3 and 5.4. Recently we've renewed our focus in general on stability, so we've been pretty conservative with things as low-level as the C# compiler.

    Let me ask the question in this thread a different way:
    1. Who is interested in trying an unsupported, alpha version of Unity with the new C# compiler in 5.4?
    2. Who wants to use a supported version of Unity with the new C# compiler in 5.3 and/or 5.4?
    I get the sense that must people will fall into group 2, but let me know.
     
    S_Darkwell likes this.
  10. Vanamerax

    Vanamerax

    Joined:
    Jan 12, 2012
    Posts:
    937
    I myself would really like to try the (un)supported compiler in 5.4 when that is publicly released (I guess this release is really close considering the roadmap?)

    I've got no idea how hard this will be to implement, but would it be possible to add the new compiler to the unity build where we can choose in a dropdown menu in the settings which compiler to use, in the same way that we can currently choose between the mono/IL2CPP runtime for some platforms? Again, I have no idea how hard this is to implement or how easy it is to switch the compilers used live, but this is just a wild idea I got. If it is feasable, you could mark it as experimental during the 5.4 cycle, like you guys are doing for other features currently and have done for the IL2CPP rollout. This approach would be preferable over a whole seperate build of unity since it is easier to switch back to the old compiler might we encounter a specific problem

    As for the rest, I personally wouldn't mind if you guys skipped a supported compiler for the 5.3 version, assuming that the 5.4 build will be at least as stable as 5.3 and considering how close the 5.4 release is. If I want to be on the bleeding edge of Unity's development, I will probably upgrade to 5.4 anyway.
     
  11. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,775
    @wasstraat65

    Thanks for the feedback. It is possible, from a technical perspective, to provide a toggle option for the C# compiler. We seriously considered doing things just as you described, but instead decided against a user-settable option for a few reasons.
    • This is the C# compiler, so it should just work. If we're going to ship it, we should only ship it when we are very confident that it won't cause any problems.
    • Each option in the GUI is something that we need to test internally, since the C# compiler requires that we run literally all of the internal tests have for Unity (it touches everything), we could not afford to run the tests both with an without the new compiler for a single version of Unity.
    • Since we are not enabling new C# language features, using the new C# compiler should not have any behavior differences from the old compiler, so the option might be confusing to many users. It would change something, but not have a difference anyone could perceive (except for bugs).
    So really we just need enough confidence to ship this without an option. After doing a lot of internal testing, then going to a closed alpha group, then finally going to the forums here, I think that we will get enough feedback to be confident.
     
    Vanamerax likes this.
  12. Vanamerax

    Vanamerax

    Joined:
    Jan 12, 2012
    Posts:
    937
    Thanks for your explanation, you mention some good points that I had not considered yet and I understand your reasoning. It is nice to hear that you guys have at least considered the option.


    While a little bit off topic, does this mean that there will be an experimental option provided in a similar way in the feature, when the new language features and/or the new GC are being rolled out?
     
  13. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,775
    We're hoping to use this forum to get feedback on the other parts of the Mono upgrade: The Mono runtime upgrade, .NET profile upgrade, C# language upgrade, new GC, etc. Our plan is to continue doing custom builds against stable versions of Unity with the new features enabled. Most of these other features cannot be enabled or disabled via a runtime option.
     
    Vanamerax likes this.
  14. Vanamerax

    Vanamerax

    Joined:
    Jan 12, 2012
    Posts:
    937
    I see. As long as the custom builds are periodically updated to new minor releases, that should be completely fine. I like the direction that you guys are taking for the experimental features, so thumbs up for that!
     
  15. -chris

    -chris

    Joined:
    Mar 1, 2012
    Posts:
    99
    I've been using 5.4 for a few months now for a sequel I'm developing.

    Would be happy to test the new C# compiler for 5.4 if available.

    Happy to wait 'til 5.5 too.
     
  16. codestage

    codestage

    Joined:
    Jul 27, 2012
    Posts:
    1,909
    Hey, Josh and everyone else in this thread!

    I'm really glad to see all these changes towards compiler upgrade, we all waited for this for so long!
    Thanks for letting us try it before official release!
    I'm already using 5.3.5p8 with new compiler to test my assets and tried it for one huge project - but unfortunately that huge project won't compile because in new compiler some bugs were fixed which we are exploiting haha =D
    E.g. DllImport for generic methods:
    Code (CSharp):
    1.             [DllImport(c_CrtDll, EntryPoint = c_Memcpy, CallingConvention = c_CallingConvention)]
    2.             static extern IntPtr memcpy(ref T dest, byte [] src, UIntPtr count);
    Though we'll fix it in future and will try new compiler for our huge project once again.

    Anyways, it would be really awesome to be able to test new compiler on 5.4 branch.
     
  17. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,775

    @Dmitriy-Yukhanov,

    Interesting, I was not aware of this issue. So the old compiler would allow this code? Thanks for noting this, we'll be sure to include it in our list of known breaking changes.
     
  18. codestage

    codestage

    Joined:
    Jul 27, 2012
    Posts:
    1,909
    Yeah, old compiler eats this and it works %)
    Thanks for picking this one up to your list of known breaking changes ^^

    Fun fact: when I run debug via VSTU it fails to compile it at VS, but still allows to run "last successful build" and debugging works fine.
     
  19. Player7

    Player7

    Joined:
    Oct 21, 2015
    Posts:
    1,533
    Add it on 5.4 and I'll try it out. I won't be switching any project back down to 5.3 just to try a new compiler. That's if 5.5builds with it are not going to be out for a while then even more reason.
     
  20. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,685
    My preference (if possible) is to simply add it as a new "preview" drop down option for the compiler to use in 5.4.
    Then let people use / not use it as they so wish, with the added benefit of not having to run / install multiple versions on machines (especially where disk space is a premium).

    This was done with WebGL to great effect for a fair few builds.

    So if it's possible to have it as an Option in the main build, that would be Nirvana :D
     
    orb likes this.
  21. Vanamerax

    Vanamerax

    Joined:
    Jan 12, 2012
    Posts:
    937
    I suggested this a few post above but the one of the Unity employees mentioned some problems with that. The reasons I like the idea however seem to be the same as yours
     
  22. Tuni

    Tuni

    Joined:
    May 24, 2013
    Posts:
    74
    +1 for a 5.4 version of the new compiler. We have a quite big and nearly finished project to test with.
     
  23. Jonny-Roy

    Jonny-Roy

    Joined:
    May 29, 2013
    Posts:
    666
    Agreed 5.4 version would be awesome/
     
  24. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,775
    Thanks again for the responses. Now that 5.4 is released, we'll look at the possibility of making a 5.4 build with the new compiler. I'm not sure how difficult it will be, so I can't promise anything yet.

    There certainly seems to be interest though, so we'll make a decision in the next week or so and let everyone know.
     
    fantastisch_, MrEsquire, Lszt and 5 others like this.
  25. strich

    strich

    Joined:
    Aug 14, 2012
    Posts:
    346
    Hey @JoshPeterson - I would also like to add our voice for having an option to use the new compiler with v5.4.

    I also wanted to let you know that we shipped a patch to our 150k+ userbase in War for the Overworld compiled with v5.3.5p8-compiler-upgrade yesterday. Everything looks solid so far.
     
  26. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,775
    @strich

    I'm glad to hear that things are working!

    Please note that this Unity build is experimental, and is not supported. We *think* everything will work properly, but exercise caution when shipping with this version.
     
  27. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,775
    We've decided to ship an updated preview of the new compiler against 5.4. We have one minor bug that needs to be corrected prior to shipping the next preview here, but look for it sometime in the next week or so.
     
    orb likes this.
  28. strich

    strich

    Joined:
    Aug 14, 2012
    Posts:
    346
    Fully understood. :)
     
  29. Hyp-X

    Hyp-X

    Joined:
    Jun 24, 2015
    Posts:
    421
    I'm certainly interested in (1). We are currently doing optimization work in our project - including memory allocation optimization. This would make it much simpler by not having to care about replacing each foreach.
    At the shipping title we can solve the issue other ways, but during development it would be much easier this way.

    As for (2) it would be good for 5.4 depending on when 5.5 comes out. If it will take as long as the 5.4 version then it will be too late for out project.
     
  30. orb

    orb

    Joined:
    Nov 24, 2010
    Posts:
    3,033
    If the 5.4 compiler alpha roughly follows the latest patch release, it'll be pretty much the same as usual for me. It could even lag a week and be released less often, because I wouldn't be updating as frequently as I currently do ;)
     
  31. strich

    strich

    Joined:
    Aug 14, 2012
    Posts:
    346
    Hey @JoshPeterson just wondering where the v5.4 updated preview is at? We could really make use of it shortly. :)
     
  32. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,775
    @strich

    We've had a few delays in synchronizing things with a 5.4 build, sorry about that. We're in the final stages now, and should have something this week.
     
  33. strich

    strich

    Joined:
    Aug 14, 2012
    Posts:
    346
    Actually I realized soon after that the v5.5 beta patch notes shows that this updated compiler is in there, so we've upgraded to the beta. So all good.
     
  34. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,775
    @strich

    Excellent, thanks. We're still planning on a 5.4 preview build soon for others who need to stay on 5.4 versions.
     
  35. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,775
    We're going to delay the 5.4 new compiler preview build for another day, sorry. We were planning ship it today with a known bug related to the debugger. The good news is that we corrected that bug yesterday, and decided to ship the preview with that bug fixed. The bad news is that we'll need to spin a new Unity build today though.
     
  36. Vanamerax

    Vanamerax

    Joined:
    Jan 12, 2012
    Posts:
    937
    I suppose that's both good and bad news at the same time. Glad you guys are working on it though, appreciated!
     
  37. orb

    orb

    Joined:
    Nov 24, 2010
    Posts:
    3,033
    I think delaying for known and fixed bugs is good.
     
    -chris likes this.
  38. MrEsquire

    MrEsquire

    Joined:
    Nov 5, 2013
    Posts:
    2,712
    So maybe then build 5.4.1 that just came out?
     
  39. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,775
    @MrEsquire

    No, the 5.4.1 official build does not have the new C# compiler. That will be shipped in a supported build in 5.5 (so the 5.5. betas have it). We will be shipping an experimental, unsupported version of 5.4 here with the new compiler for people to try.

    We're looking for feedback on problems with existing projects and the new compiler, so shipping a 5.4 version will hopefully help more people have the chance to try it on their current project.
     
  40. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,614
    Yeah, we are definitely not going to make a change as big as switching to a whole new compiler in a patch or point release :)
     
  41. joncham

    joncham

    Unity Technologies

    Joined:
    Dec 1, 2011
    Posts:
    276
  42. JJJohan

    JJJohan

    Joined:
    Mar 18, 2016
    Posts:
    214
    I've started to use the new 5.4 compiler build, although I'm experiencing some issues with the Visual Studio Tools for Unity.

    While I can step over breakpoints fine, I seem to be unable to view any values. Both the 'Local' and 'Auto' tabs are also blank.

    This seems like strange behaviour since I can't see how an updated compiler would affect the runtime debug information, unless it's just not generating the symbol files properly.

    I'll see if I can do anything to consistently replicate it but otherwise feel free to treat this is a one-off artifact.
     
  43. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,775
    @JJJohan

    Please keep us up to date if you continue to see this. It is in fact possible for the new compiler to impact the debugger. Specifically, we've seen the new compiler be more aggressive about adding sequence points (places where the debugger is allowed to check for break points), which exposed at least one existing bug in the runtime that we had not noticed before.

    When we shipped this build, we have no known issues with the debugger, but problems like this can be very specific to the source code involved, so sometimes are difficult for us to track down.

    In general though, watch windows should be working with this build.
     
  44. 00christian00

    00christian00

    Joined:
    Jul 22, 2012
    Posts:
    1,033
    Don't know if you have already seen this, but have a look at the changes this guy made to make roslyin compatible with visual studio, maybe some are in common.
    https://github.com/SaladLab/Unity3D...r/core/RoslynCompilerFix/CSharpCompilerFix.cs
    https://github.com/SaladLab/Unity3D.IncrementalCompiler/blob/master/docs/UnderTheHood.md

    Anyway, for me so far the new mono 4.4 compiler seem to work well.
     
  45. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,775
    @00christian00

    I'm glad to hear that you are able to access this build and it is working well. Thanks for trying it!
     
  46. AndyGainey

    AndyGainey

    Joined:
    Dec 2, 2015
    Posts:
    216
    Decided to give this a go with the RNG library I've been working on. I've tuned the library fairly aggressively for performance, so I have a convenient measurement system I can use to carefully observe speed.

    For the most part, I didn't see any substantial difference between the two compilers, nor did I expect any (aside from a wee bit of optimistic hope for small speed increases). Things continued to function precisely as they had. Certainly no crashes or other bugs* that I noticed, and all my unit tests continued to pass.

    The one thing that stood out was that my functions for generating random floats experience around 25% loss of performance on the new compiler compared to the official Unity 5.4 compiler. My float functions were already slightly slower than the nearly identical functions dealing with doubles, but I had let that slide previously; figured it was just due to operating on 32-bit data on a 64-bit processor. But the new compiler seems to dislike floats compared to doubles even more strongly, which is a tad worrisome given how heavily Unity makes use of floats instead of doubles.

    All the same, these are artificially tight and isolated loops that I'm measuring, and I'm doing some StructLayout/union trickery that's bound to make the compiler work harder, so perhaps a lot of it will just disappear in the pipelining and general noisiness of more complex code paths.

    *One final note, the compiler did trip up on code flow analysis in the presence of gotos. I consider it more of a Mono issue than a Unity responsibility anyway, and I worked around it with some code rearrangement, but for the sake of sharing, the following simplified code causes the new compiler to complain that "error CS0177: The out parameter `x' must be assigned to before control leaves the current method", while the current compiler accepts the code without error.

    Code (CSharp):
    1. static void Test(bool cond, out int x)
    2. {
    3.     if (cond)
    4.         goto Label;
    5.     Label:
    6.     x = 0;
    7. }
     
  47. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,775
    @AndyGainey

    Thanks for the details analysis, I appreciate it!

    Is it possible for you to share the generated assemblies from both compilers? I'd like to have a look at how the IL code differs to better understand why you are seeing a runtime performance degradation. If you would like to share these privately, please ping me via a conversation.

    As for the compiler bug, can you submit a bug report via the Unity editor? We can work with the Mono team to try to get this bug corrected. Then you will be notified via the Unity bug report when it is shipping with a version of Unity.
     
  48. AndyGainey

    AndyGainey

    Joined:
    Dec 2, 2015
    Posts:
    216
    Done (via private conversation) and done (Case 834753)!
     
  49. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,775
    @AndyGainey

    Excellent, thanks!
     
  50. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,775