Merge branch 'use_more_callsite'
authorJean Privat <jean@pryen.org>
Mon, 24 Feb 2014 15:55:20 +0000 (10:55 -0500)
committerJean Privat <jean@pryen.org>
Mon, 24 Feb 2014 15:55:20 +0000 (10:55 -0500)
CallSite is a great data-class to store various information on a call
site.

This series generalizes its usage in some place, and remove a old
depreciated API.

This uniformization and cleanup will be useful in future work, like
call-site optimizations and the new constructors

src/abstract_compiler.nit
src/auto_super_init.nit
src/collect_super_sends.nit
src/naive_interpreter.nit
src/rapid_type_analysis.nit
src/typing.nit
tests/sav/nitmetrics_args1.res

index b02369f..76aaa19 100644 (file)
@@ -2402,13 +2402,13 @@ redef class ASuperExpr
                        args = v.frame.arguments
                end
 
-               var mproperty = self.mproperty
-               if mproperty != null then
-                       if mproperty.intro.msignature.arity == 0 then
+               var callsite = self.callsite
+               if callsite != null then
+                       if callsite.mproperty.intro.msignature.arity == 0 then
                                args = [recv]
                        end
                        # Super init call
-                       var res = v.send(mproperty, args)
+                       var res = v.compile_callsite(callsite, args)
                        return res
                end
 
index 316320a..89362a2 100644 (file)
@@ -124,7 +124,7 @@ end
 redef class ASendExpr
        redef fun accept_auto_super_init(v)
        do
-               var mproperty = self.mproperty
+               var mproperty = self.callsite.mproperty
                if mproperty == null then return
                if mproperty.is_init then
                        v.has_explicit_super_init = true
index 9e6f9b0..70822ce 100644 (file)
@@ -41,7 +41,7 @@ private class CollectSuperSends
                        return
                end
                n.visit_all(self)
-               if n isa ASuperExpr and n.mproperty == null then
+               if n isa ASuperExpr and n.callsite == null then
                        var mprop = mpropdef
                        assert mprop != null
                        res.add(mprop)
index 26149a4..b5139f1 100644 (file)
@@ -1103,7 +1103,7 @@ redef class AVarReassignExpr
                var vari = v.frame.map[self.variable.as(not null)]
                var value = v.expr(self.n_value)
                if value == null then return
-               var res = v.send(reassign_property.mproperty, [vari, value])
+               var res = v.send(reassign_callsite.mproperty, [vari, value])
                assert res != null
                v.frame.map[self.variable.as(not null)] = res
        end
@@ -1517,9 +1517,8 @@ redef class ASendExpr
                        if i == null then return null
                        args.add(i)
                end
-               var mproperty = self.mproperty.as(not null)
 
-               var res = v.send(mproperty, args)
+               var res = v.send(callsite.mproperty, args)
                return res
        end
 end
@@ -1538,16 +1537,15 @@ redef class ASendReassignFormExpr
                var value = v.expr(self.n_value)
                if value == null then return
 
-               var mproperty = self.mproperty.as(not null)
-               var read = v.send(mproperty, args)
+               var read = v.send(callsite.mproperty, args)
                assert read != null
 
-               var write = v.send(self.reassign_property.mproperty, [read, value])
+               var write = v.send(reassign_callsite.mproperty, [read, value])
                assert write != null
 
                args.add(write)
 
-               v.send(self.write_mproperty.as(not null), args)
+               v.send(write_callsite.mproperty, args)
        end
 end
 
@@ -1565,13 +1563,13 @@ redef class ASuperExpr
                        args = v.frame.arguments
                end
 
-               var mproperty = self.mproperty
-               if mproperty != null then
-                       if mproperty.intro.msignature.arity == 0 then
+               var callsite = self.callsite
+               if callsite != null then
+                       if callsite.mproperty.intro.msignature.arity == 0 then
                                args = [recv]
                        end
                        # Super init call
-                       var res = v.send(mproperty, args)
+                       var res = v.send(callsite.mproperty, args)
                        return res
                end
 
@@ -1596,8 +1594,7 @@ redef class ANewExpr
                        if i == null then return null
                        args.add(i)
                end
-               var mproperty = self.mproperty.as(not null)
-               var res2 = v.send(mproperty, args)
+               var res2 = v.send(callsite.mproperty, args)
                if res2 != null then
                        #self.debug("got {res2} from {mproperty}. drop {recv}")
                        return res2
@@ -1641,7 +1638,7 @@ redef class AAttrReassignExpr
                if value == null then return
                var mproperty = self.mproperty.as(not null)
                var attr = v.read_attribute(mproperty, recv)
-               var res = v.send(reassign_property.mproperty, [attr, value])
+               var res = v.send(reassign_callsite.mproperty, [attr, value])
                assert res != null
                assert recv isa MutableInstance
                recv.attributes[mproperty] = res
index 820819d..3ee7b28 100644 (file)
@@ -383,6 +383,8 @@ class RapidTypeVisitor
        fun add_send(mtype: MType, mproperty: MMethod) do analysis.add_send(mtype, mproperty)
 
        fun add_cast_type(mtype: MType) do analysis.add_cast(mtype)
+
+       fun add_callsite(callsite: nullable CallSite) do if callsite != null then analysis.add_send(callsite.recv, callsite.mproperty)
 end
 
 ###
@@ -501,9 +503,7 @@ end
 redef class ASendExpr
        redef fun accept_rapid_type_visitor(v)
        do
-               var mproperty = self.mproperty.as(not null)
-               var recvtype = self.n_expr.mtype.as(not null)
-               v.add_send(recvtype, mproperty)
+               v.add_callsite(callsite)
        end
 end
 
@@ -511,40 +511,32 @@ end
 redef class ASendReassignFormExpr
        redef fun accept_rapid_type_visitor(v)
        do
-               v.add_send(self.read_type.as(not null), self.reassign_property.mproperty)
-               var mproperty = self.mproperty.as(not null)
-               var write_mproperty = self.write_mproperty.as(not null)
-               if n_expr isa ASelfExpr then
-                       v.add_monomorphic_send(v.receiver, mproperty)
-                       v.add_monomorphic_send(v.receiver, write_mproperty)
-               else
-                       var recvtype = self.n_expr.mtype.as(not null)
-                       v.add_send(recvtype, mproperty)
-                       v.add_send(recvtype, write_mproperty)
-               end
+               v.add_callsite(callsite)
+               v.add_callsite(reassign_callsite)
+               v.add_callsite(write_callsite)
        end
 end
 
 redef class AVarReassignExpr
        redef fun accept_rapid_type_visitor(v)
        do
-               v.add_send(self.read_type.as(not null), self.reassign_property.mproperty)
+               v.add_callsite(reassign_callsite)
        end
 end
 
 redef class AAttrReassignExpr
        redef fun accept_rapid_type_visitor(v)
        do
-               v.add_send(self.read_type.as(not null), self.reassign_property.mproperty)
+               v.add_callsite(reassign_callsite)
        end
 end
 
 redef class ASuperExpr
        redef fun accept_rapid_type_visitor(v)
        do
-               var mproperty = self.mproperty
-               if mproperty != null then
-                       v.add_monomorphic_send(v.receiver, mproperty)
+               var callsite = self.callsite
+               if callsite != null then
+                       v.add_callsite(callsite)
                        return
                end
 
@@ -579,7 +571,6 @@ redef class ANewExpr
        do
                var mtype = self.mtype.as(MClassType)
                v.add_type(mtype)
-               var mproperty = self.mproperty.as(not null)
-               v.add_monomorphic_send(mtype, mproperty)
+               v.add_callsite(callsite)
        end
 end
index 2a1fa54..719fae2 100644 (file)
@@ -640,9 +640,6 @@ redef class AVarAssignExpr
 end
 
 redef class AReassignFormExpr
-       # @depreciated use `reassign_callsite`
-       fun reassign_property: nullable MMethodDef do return self.reassign_callsite.mpropdef
-
        # The method designed by the reassign operator.
        var reassign_callsite: nullable CallSite
 
@@ -1190,9 +1187,6 @@ end
 ## MESSAGE SENDING AND PROPERTY
 
 redef class ASendExpr
-       # @depreciated: use `callsite`
-       fun mproperty: nullable MMethod do return callsite.mproperty
-
        # The property invoked by the send.
        var callsite: nullable CallSite
 
@@ -1353,9 +1347,6 @@ redef class ABraAssignExpr
 end
 
 redef class ASendReassignFormExpr
-       # @depreciated use `write_callsite`
-       fun write_mproperty: nullable MMethod do return write_callsite.mproperty
-
        # The property invoked for the writing
        var write_callsite: nullable CallSite
 
@@ -1426,7 +1417,7 @@ end
 redef class ASuperExpr
        # The method to call if the super is in fact a 'super init call'
        # Note: if the super is a normal call-next-method, then this attribute is null
-       var mproperty: nullable MMethod
+       var callsite: nullable CallSite
 
        redef fun accept_typing(v)
        do
@@ -1490,12 +1481,14 @@ redef class ASuperExpr
                        v.error(self, "Error: No super method to call for {mproperty}.")
                        return
                end
-               self.mproperty = superprop.mproperty
 
-               var args = self.n_args.to_a
                var msignature = v.resolve_signature_for(superprop, recvtype, true)
+               var callsite = new CallSite(self, recvtype, true, superprop.mproperty, superprop, msignature, false)
+               self.callsite = callsite
+
+               var args = self.n_args.to_a
                if args.length > 0 then
-                       v.check_signature(self, args, mproperty.name, msignature)
+                       callsite.check_signature(v, args)
                else
                        # TODO: Check signature
                end
@@ -1507,9 +1500,6 @@ end
 ####
 
 redef class ANewExpr
-       # @depreciated use `callsite`
-       fun mproperty: nullable MMethod do return self.callsite.mproperty
-
        # The constructor invoked by the new.
        var callsite: nullable CallSite
 
index ebc4cab..adcfffd 100644 (file)
@@ -321,7 +321,7 @@ Number of live runtime classes: 6
        Sys Bool Int A B C
 Number of live runtime types (instantied resolved type): 6
        Sys Bool Int A B C
-Number of live methods: 11
+Number of live methods: 14
 Number of live method definitions: 14
 Number of live runtime cast types (ie used in as and isa): 0