model: remove `new_msignature` and special call as the new signature is the method...
authorJean Privat <jean@pryen.org>
Fri, 26 Feb 2016 19:33:23 +0000 (14:33 -0500)
committerJean Privat <jean@pryen.org>
Fri, 26 Feb 2016 19:33:23 +0000 (14:33 -0500)
Signed-off-by: Jean Privat <jean@pryen.org>

src/compiler/abstract_compiler.nit
src/compiler/java_compiler.nit
src/doc/console_templates/console_model.nit
src/interpreter/naive_interpreter.nit
src/model/model.nit
src/modelize/modelize_property.nit
src/rapid_type_analysis.nit
src/semantize/auto_super_init.nit
src/semantize/typing.nit
src/web/model_html.nit

index 2375940..b8681bc 100644 (file)
@@ -1162,29 +1162,6 @@ abstract class AbstractCompilerVisitor
        fun compile_callsite(callsite: CallSite, arguments: Array[RuntimeVariable]): nullable RuntimeVariable
        do
                if callsite.is_broken then return null
-               var initializers = callsite.mpropdef.initializers
-               if not initializers.is_empty then
-                       var recv = arguments.first
-
-                       var i = 1
-                       for p in initializers do
-                               if p isa MMethod then
-                                       var args = [recv]
-                                       for x in p.intro.msignature.mparameters do
-                                               args.add arguments[i]
-                                               i += 1
-                                       end
-                                       self.send(p, args)
-                               else if p isa MAttribute then
-                                       self.write_attribute(p, recv, arguments[i])
-                                       i += 1
-                               else abort
-                       end
-                       assert i == arguments.length
-
-                       return self.send(callsite.mproperty, [recv])
-               end
-
                return self.send(callsite.mproperty, arguments)
        end
 
@@ -1207,7 +1184,7 @@ abstract class AbstractCompilerVisitor
        # of runtime variables to use in the call.
        fun varargize(mpropdef: MMethodDef, map: nullable SignatureMap, recv: RuntimeVariable, args: SequenceRead[AExpr]): Array[RuntimeVariable]
        do
-               var msignature = mpropdef.new_msignature or else mpropdef.msignature.as(not null)
+               var msignature = mpropdef.msignature.as(not null)
                var res = new Array[RuntimeVariable]
                res.add(recv)
 
index ec759a2..66115be 100644 (file)
@@ -497,7 +497,7 @@ class JavaCompilerVisitor
        # This method is used to manage varargs in signatures and returns the real array
        # of runtime variables to use in the call.
        fun varargize(mpropdef: MMethodDef, map: nullable SignatureMap, recv: RuntimeVariable, args: SequenceRead[AExpr]): Array[RuntimeVariable] do
-               var msignature = mpropdef.new_msignature or else mpropdef.msignature.as(not null)
+               var msignature = mpropdef.msignature.as(not null)
                var res = new Array[RuntimeVariable]
                res.add(recv)
 
index 96b1a40..7e9487f 100644 (file)
@@ -484,16 +484,10 @@ redef class MMethodDef
        end
 
        redef fun cs_short_signature do
-               if mproperty.is_root_init then
-                       return new_msignature.cs_short_signature
-               end
                return msignature.cs_short_signature
        end
 
        redef fun cs_signature do
-               if mproperty.is_root_init then
-                       return new_msignature.cs_signature
-               end
                return msignature.cs_signature
        end
 
index 545d89d..6d25e7c 100644 (file)
@@ -437,7 +437,7 @@ class NaiveInterpreter
        # Return `null` if one of the evaluation of the arguments return null.
        fun varargize(mpropdef: MMethodDef, map: nullable SignatureMap, recv: Instance, args: SequenceRead[AExpr]): nullable Array[Instance]
        do
-               var msignature = mpropdef.new_msignature or else mpropdef.msignature.as(not null)
+               var msignature = mpropdef.msignature.as(not null)
                var res = new Array[Instance]
                res.add(recv)
 
@@ -569,28 +569,6 @@ class NaiveInterpreter
        fun callsite(callsite: nullable CallSite, arguments: Array[Instance]): nullable Instance
        do
                if callsite == null then return null
-               var initializers = callsite.mpropdef.initializers
-               if not initializers.is_empty then
-                       var recv = arguments.first
-                       var i = 1
-                       for p in initializers do
-                               if p isa MMethod then
-                                       var args = [recv]
-                                       for x in p.intro.msignature.mparameters do
-                                               args.add arguments[i]
-                                               i += 1
-                                       end
-                                       self.send(p, args)
-                               else if p isa MAttribute then
-                                       assert recv isa MutableInstance
-                                       write_attribute(p, recv, arguments[i])
-                                       i += 1
-                               else abort
-                       end
-                       assert i == arguments.length
-
-                       return send(callsite.mproperty, [recv])
-               end
                return send(callsite.mproperty, arguments)
        end
 
index 1560022..8207bf0 100644 (file)
@@ -2357,19 +2357,17 @@ class MMethodDef
        # The signature attached to the property definition
        var msignature: nullable MSignature = null is writable
 
-       # The signature attached to the `new` call on a root-init
-       # This is a concatenation of the signatures of the initializers
-       #
-       # REQUIRE `mproperty.is_root_init == (new_msignature != null)`
-       var new_msignature: nullable MSignature = null is writable
-
        # List of initialisers to call in root-inits
        #
        # They could be setters or attributes
-       #
-       # REQUIRE `mproperty.is_root_init == (new_msignature != null)`
        var initializers = new Array[MProperty]
 
+       # Does the method take the responsibility to call `init`?
+       #
+       # If the method is used as an initializer, then
+       # using this information prevents to call `init` twice.
+       var is_calling_init = false is writable
+
        # Is the method definition abstract?
        var is_abstract: Bool = false is writable
 
index fe755a5..abce092 100644 (file)
@@ -150,7 +150,6 @@ redef class ModelBuilder
                        var mparameters = new Array[MParameter]
                        var msignature = new MSignature(mparameters, null)
                        mpropdef.msignature = msignature
-                       mpropdef.new_msignature = msignature
                        mprop.is_init = true
                        self.toolcontext.info("{mclassdef} gets a free empty constructor {mpropdef}{msignature}", 3)
                        the_root_init_mmethod = mprop
@@ -335,7 +334,7 @@ redef class ModelBuilder
 
                                # Combine the inherited list to what is collected
                                if longest.initializers.length > 0 then
-                                       mparameters.prepend longest.new_msignature.mparameters
+                                       mparameters.prepend longest.msignature.mparameters
                                        initializers.prepend longest.initializers
                                end
                        end
@@ -885,7 +884,6 @@ redef class AMethPropdef
                        var root_init = mclassdef.mclass.root_init
                        if root_init != null then
                                # Inherit the initializers by refinement
-                               mpropdef.new_msignature = root_init.new_msignature
                                assert mpropdef.initializers.is_empty
                                mpropdef.initializers.add_all root_init.initializers
                        end
index 4f3651d..9624932 100644 (file)
@@ -245,7 +245,6 @@ class RapidTypeAnalysis
                                v.add_monomorphic_send(vararg, self.modelbuilder.force_get_primitive_method(node, "with_native", vararg.mclass, self.mainmodule))
                        end
 
-                       # TODO? new_msignature
                        var sig = msignature
                        var osig = mmeth.intro.msignature.as(not null)
                        for i in [0..sig.arity[ do
index 55263bd..454e9fb 100644 (file)
@@ -121,7 +121,7 @@ redef class AMethPropdef
                                return
                        end
 
-                       var msignature = candidatedef.new_msignature or else candidatedef.msignature
+                       var msignature = candidatedef.msignature
                        msignature = msignature.resolve_for(recvtype, anchor, mmodule, true)
 
                        if msignature.arity > 0 then
index ffabc08..4824cb4 100644 (file)
@@ -378,7 +378,7 @@ private class TypeVisitor
                end
 
 
-               var msignature = mpropdef.new_msignature or else mpropdef.msignature
+               var msignature = mpropdef.msignature
                if msignature == null then return null # skip error
                msignature = resolve_for(msignature, recvtype, recv_is_self).as(MSignature)
 
@@ -2008,7 +2008,7 @@ redef class ASuperExpr
                        return
                end
 
-               var msignature = superprop.new_msignature or else superprop.msignature.as(not null)
+               var msignature = superprop.msignature.as(not null)
                msignature = v.resolve_for(msignature, recvtype, true).as(MSignature)
 
                var callsite = new CallSite(hot_location, recvtype, v.mmodule, v.anchor, true, superprop.mproperty, superprop, msignature, false)
index 2b49b9e..2d47728 100644 (file)
@@ -500,18 +500,10 @@ redef class MMethodDef
        end
 
        redef fun html_short_signature do
-               var new_msignature = self.new_msignature
-               if mproperty.is_root_init and new_msignature != null then
-                       return new_msignature.html_short_signature
-               end
                return msignature.as(not null).html_short_signature
        end
 
        redef fun html_signature do
-               var new_msignature = self.new_msignature
-               if mproperty.is_root_init and new_msignature != null then
-                       return new_msignature.html_signature
-               end
                return msignature.as(not null).html_signature
        end
 end