Some positive feedback :)

I continue to be pleasantly surprised at how well LLVM works. Working with it is certainly a treat.

As an example, tonight I implemented structure types (i.e. aggregate types that are passed as values, not references) in my front end, and I wrote up this little unit test:

    struct Vector {
      var x:int;
      var y:int;
      var z:int;
           def Vector(x:int, y:int, z:int) {
        self.x = x;
        self.y = y;
        self.z = z;
      }

      def Vector() {
        self.x = 0;
        self.y = 0;
        self.z = 0;
      }
    }

    [EntryPoint]
    def main(args:String) {
      var v0:Vector = Vector();
      assert(v0.x == 0);
      assert(v0.y == 0);
      assert(v0.z == 0);

      let v1 = Vector(2, 3, 4);
      assert(v1.x == 2);
      assert(v1.y == 3);
      assert(v1.z == 4);

      v0 = v1;
      assert(v0.x == 2);
      assert(v0.y == 3);
      assert(v0.z == 4);
    }

After making a few tweaks to my code generator, it passed all of the tests...which was surprising enough. But then I turned on optimization -- and lo and behold, it converted every one of those asserts to "assert(1)", and completely eliminated everything else! If it had been able to inline the asserts (which I am still working on), it would have eliminated the body of main entirely.

Now that's the kind of optimization I like to see :slight_smile:

-- Talin

Awesome!

-Chris

Chris Lattner wrote:

  

I continue to be pleasantly surprised at how well LLVM works. Working
with it is certainly a treat.
    
After making a few tweaks to my code generator, it passed all of the
tests...which was surprising enough. But then I turned on optimization
-- and lo and behold, it converted every one of those asserts to "assert(1)", and completely eliminated everything else! If it had been
able to inline the asserts (which I am still working on), it would have
eliminated the body of main entirely.

Now that's the kind of optimization I like to see :slight_smile:
    
Awesome!
  

Here's another code sample that boils down to "assert(true)" when optimization is turned on:

    struct CountIterator(Iterator<int>) {
      private var count:int;
      def CountIterator(count:int) { self.count = count; }
      def atEnd:bool { get { return count <= 0; } }
      def current:int { get { return count; } }
      def next() { --count; }
    }

    def testSimpleIterator() {
      var sum = 0;
      for i in CountIterator(5) {
        sum = sum + i;
      }
           assert(sum == 15);
    }

-- Talin