Merge: Do not compile dead modules
authorJean Privat <jean@pryen.org>
Thu, 18 Jun 2015 03:09:33 +0000 (23:09 -0400)
committerJean Privat <jean@pryen.org>
Thu, 18 Jun 2015 03:09:33 +0000 (23:09 -0400)
Separate compilation implies that a module is compiled independently of its clients.
This point ensure us that the recompilation of programs is fast since only modified modules need to be recompiled and that modules used by multiples clients need to be compiled only once.

Unfortunately, currently an already compiled module need to still to be fully compiled in C on each compilation (avoiding doing it is a very complex matter). Fortunately, most of the compilation time is spend by the C compiler (especially when #1498) and this time is safely decimated by ccache.

However, a thing that some modules are imported by programs (thus provide declarations, introductions, importations) but are only made of method definitions that will never be executed by the program. Such a module is called a *dead* module and our static analysis RTA can approximate them.
So, now, the generation of C code for such a module is skipped (and its associated C compilation, obviously)

This will benefit mostly small programs that imports standard and other libraries but only use a small portion of them. Eg: programs in `tests/` or in `examples/rossetacode`.

For numbers, lets try with `time ./tests.sh ../examples/rosettacode/*.nit` to test the 32 (currently) programs.

* before: 30s
* after: 21s

I hope that CI servers will like what we, human masters, do for them!

Pull-Request: #1509
Reviewed-by: Alexis Laferrière <alexis.laf@xymus.net>
Reviewed-by: Romain Chanoir <chanoir.romain@courrier.uqam.ca>

1  2 
src/rapid_type_analysis.nit

@@@ -82,6 -82,10 +82,10 @@@ class RapidTypeAnalysi
        # Live methods.
        var live_methods = new HashSet[MMethod]
  
+       # Live mmodules.
+       # Those with a live method definitions (see `live_methoddefs`)
+       var live_mmodules = new HashSet[MModule]
        # Live callsites.
        var live_callsites = new HashSet[CallSite]
  
        do
                if live_methoddefs.has(mpropdef) then return
                live_methoddefs.add(mpropdef)
+               live_mmodules.add(mpropdef.mclassdef.mmodule)
                todo.add(mpropdef)
  
                var mproperty = mpropdef.mproperty
@@@ -519,42 -524,31 +524,42 @@@ redef class ANod
        end
  end
  
 +redef class AExpr
 +      # Make the `mtype` of the expression live
 +      # Used by literals and instantiations
 +      fun allocate_mtype(v: RapidTypeVisitor)
 +      do
 +              var mtype = self.mtype
 +              if not mtype isa MClassType then return
 +              v.add_type(self.mtype.as(MClassType))
 +      end
 +end
 +
  redef class AIntExpr
        redef fun accept_rapid_type_visitor(v)
        do
 -              v.add_type(self.mtype.as(MClassType))
 +              allocate_mtype(v)
        end
  end
  
  redef class AByteExpr
        redef fun accept_rapid_type_visitor(v)
        do
 -              v.add_type(self.mtype.as(MClassType))
 +              allocate_mtype(v)
        end
  end
  
  redef class AFloatExpr
        redef fun accept_rapid_type_visitor(v)
        do
 -              v.add_type(self.mtype.as(MClassType))
 +              allocate_mtype(v)
        end
  end
  
  redef class ACharExpr
        redef fun accept_rapid_type_visitor(v)
        do
 -              v.add_type(self.mtype.as(MClassType))
 +              allocate_mtype(v)
        end
  end
  
@@@ -603,8 -597,7 +608,8 @@@ en
  redef class ACrangeExpr
        redef fun accept_rapid_type_visitor(v)
        do
 -              var mtype = self.mtype.as(MClassType)
 +              var mtype = self.mtype
 +              if not mtype isa MClassType then return
                v.add_type(mtype)
                v.add_callsite(init_callsite)
        end
@@@ -613,8 -606,7 +618,8 @@@ en
  redef class AOrangeExpr
        redef fun accept_rapid_type_visitor(v)
        do
 -              var mtype = self.mtype.as(MClassType)
 +              var mtype = self.mtype
 +              if not mtype isa MClassType then return
                v.add_type(mtype)
                v.add_callsite(init_callsite)
        end
@@@ -623,32 -615,28 +628,32 @@@ en
  redef class ATrueExpr
        redef fun accept_rapid_type_visitor(v)
        do
 -              v.add_type(self.mtype.as(MClassType))
 +              allocate_mtype(v)
        end
  end
  
  redef class AFalseExpr
        redef fun accept_rapid_type_visitor(v)
        do
 -              v.add_type(self.mtype.as(MClassType))
 +              allocate_mtype(v)
        end
  end
  
  redef class AIsaExpr
        redef fun accept_rapid_type_visitor(v)
        do
 -              v.add_cast_type(self.cast_type.as(not null))
 +              var cast_type = self.cast_type
 +              if cast_type == null then return
 +              v.add_cast_type(cast_type)
        end
  end
  
  redef class AAsCastExpr
        redef fun accept_rapid_type_visitor(v)
        do
 -              v.add_cast_type(self.mtype.as(not null))
 +              var mtype = self.mtype
 +              if mtype == null then return
 +              v.add_cast_type(mtype)
        end
  end