ASC 2.0A few minutes ago we just posted a preview on Adobe Labs of the new ActionScript Compiler (ASC 2.0) as part of the AIR 3.4/FP 11.4 SDK. You can find the complete release notes here. To fully utilize this new AIR 3.4 preview SDK, make sure you use Flash Builder 4.7 Preview also available here, which includes all this, plus things like Concurrency (ActionScript Workers) support for debugging and more.

Here are below the main improvements added to the ActionScript compiler:

  • Flash Builder 4.7 and the ASC 2.0 command-line compiler now share the same code model. This avoids duplicate representations of a program and means the IDE has an accurate representation of the language - matching the compiler.
  • A new multi-threaded architecture allows multiple files to be compiled at once, improving compilation time.
  • Better constant-folding and constant-propagation results in better performing code at runtime.
  • Reduces function overhead by removing unnecessary activation records.
  • Contains some demonstration byte-code optimizations for in-lining and dead code elimination.
  • Non-linear control flow added to AS3 through a new 'goto' keyword.
  • SWF 13 with LZMA compression is now supported.
  • A new symbol management system means Flash Builder 4.7 ActionScript workspaces that mix Flash and AIR projects should incrementally compile much faster.
  • ASC 2.0 based versions of fontswf, optimizer, swfdump and swcdepends command-line tools are available.
  • Legacy versions of asdoc and fdb command-line tools are also still included.
  • Font transcoding has been removed from [Embed] syntax. Fonts should be pre-transcoded and embedded as a SWF, which can be performed using a tool like fontswf or Flash Professional CS6.
  • Relative paths in source code ([Embed] assets, includes, etc...) resolve relatively from the including file. To specify a path relative from a source root, prefix your path with a forward slash '/'.
  • US English compiler error messages have been translated into French, Japanese, and Simplified Chinese. The locale is determined by the JVM and can be overridden using the -tools-locale configuration option.

We also added support for inlining. When the inlining feature is enabled, the compiler will attempt to inline getters, setters and any functions which are decorated with [Inline] metadata. Make sure you also add the -inline compiler argument.

A function can be inlined when the following constraints are met:

  • The function is final, static or the containing scope is file or package
  • The function does not contain any activations
  • The function does not contain any try or with statements
  • The function does not contain any function closures
  • The function body contains less than 50 expressions

Below are some basic examples of functions which the compiler will and won't be able to inline.

package
{
    public interface IA
    {
        function get m():int;
        function f0(p:int):int
    }

    public class A implements IA
    {
        private var _m:int = 0;
        private static var _s:int = 0;

        // inlineable as final getter
        [Inline]
        final public function get m():int
        {
            return _m;
        }

        // inlineable as final setter
        [Inline]
        final public function set m(m:int):void
        {
            if (m > 0)
                _m = m;
            else
                _m = 0;
        }

        // inlineable as static getter
        [Inline]
        static public function get s():int
        {
            return _s;
        }

        // inlineable as static setter
        [Inline]
        static public function set s(s:int):void
        {
            _s = s;
        }

        // inlineable as decorated with inline metadata and final
        [Inline]
        final public function f0(p:int):int
        {
            var v:int = p + _m;
            return v;
        }

        // not inlineable as decorated with inline metadata and final, but
        // contains try stmt
        final public function f1(p:int):int
        {
            try
            {
                return p + _m;
            }
            finally
            {
                return 0;
            }
        }
    }
}

var a:A = new A();
a.m = 5; //inlined
A.s = 7; //inlined
a.f0(0); //inlined
a.f1(0); // not-inlined, as f1 contains a try stmt

var ia:IA = a;
ia.f0(0); // not-inlined as f0 access through an interface

If you want to know more about the backward compatibility for ASC 2.0, check the following link.

Please test ASC 2.0 and provide your feedback on performance or any potential bugs you may find. Thanks guys!