Merge: phases: do not reanalyze amodules in run_phase
authorJean Privat <jean@pryen.org>
Mon, 8 Sep 2014 20:30:20 +0000 (16:30 -0400)
committerJean Privat <jean@pryen.org>
Mon, 8 Sep 2014 20:30:20 +0000 (16:30 -0400)
Multiple `run_phase` invocation should not analyze a amodule twice.

This is a workaround, the whole phase API should be improved to make late
module loading less error-prone and more simple.

Close #726

Pull-Request: #729
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>

1  2 
src/phase.nit

diff --combined src/phase.nit
@@@ -71,6 -71,9 +71,9 @@@ redef class ToolContex
                return phases
        end
  
+       # Set of already analyzed modules.
+       private var phased_modules = new HashSet[AModule]
        # Run all registered phases on a set of modules
        fun run_phases(nmodules: Collection[AModule])
        do
@@@ -85,6 -88,9 +88,9 @@@
                end
  
                for nmodule in nmodules do
+                       if phased_modules.has(nmodule) then continue
+                       phased_modules.add nmodule
                        self.info("Semantic analysis module {nmodule.location.file.filename}", 2)
  
                        var vannot = new AnnotationPhaseVisitor
                                        phase.process_nclassdef(nclassdef)
                                        for npropdef in nclassdef.n_propdefs do
                                                assert phase.toolcontext == self
 -                                              phase.process_npropdef(npropdef)
 +                                              phase_process_npropdef(phase, npropdef)
                                        end
                                end
                                if errcount != self.error_count then
                var time1 = get_time
                self.info("*** END SEMANTIC ANALYSIS: {time1-time0} ***", 2)
        end
 +
 +      fun phase_process_npropdef(phase: Phase, npropdef: APropdef)
 +      do
 +              phase.process_npropdef(npropdef)
 +      end
  end
  
  # Collect all annotation