From b7c7424a5a2f13ef50a3dfe9b5bd3c1ef1031ead Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Fri, 7 Feb 2014 16:20:59 -0500 Subject: [PATCH] src: remove check_init_instance everywhere Signed-off-by: Jean Privat --- src/abstract_compiler.nit | 9 --------- src/debugger.nit | 1 - src/global_compiler.nit | 27 --------------------------- src/naive_interpreter.nit | 18 ------------------ src/separate_compiler.nit | 28 ---------------------------- src/separate_erasure_compiler.nit | 3 --- 6 files changed, 86 deletions(-) diff --git a/src/abstract_compiler.nit b/src/abstract_compiler.nit index 4705f08..e6f8aa6 100644 --- a/src/abstract_compiler.nit +++ b/src/abstract_compiler.nit @@ -494,9 +494,6 @@ abstract class AbstractCompiler # This is used to avoid adding an extern file more than once private var seen_extern = new ArraySet[String] - # Generate code that check if an instance is correctly initialized - fun generate_check_init_instance(mtype: MClassType) is abstract - # Generate code that initialize the attributes on a new instance fun generate_init_attr(v: VISITOR, recv: RuntimeVariable, mtype: MClassType) do @@ -804,9 +801,6 @@ abstract class AbstractCompilerVisitor end end - # Generate a check-init-instance - fun check_init_instance(recv: RuntimeVariable, mtype: MClassType) is abstract - # Names handling private var names: HashSet[String] = new HashSet[String] @@ -2235,7 +2229,6 @@ redef class ACrangeExpr var mtype = self.mtype.as(MClassType) var res = v.init_instance(mtype) var it = v.send(v.get_property("init", res.mtype), [res, i1, i2]) - v.check_init_instance(res, mtype) return res end end @@ -2248,7 +2241,6 @@ redef class AOrangeExpr var mtype = self.mtype.as(MClassType) var res = v.init_instance(mtype) var it = v.send(v.get_property("without_last", res.mtype), [res, i1, i2]) - v.check_init_instance(res, mtype) return res end end @@ -2405,7 +2397,6 @@ redef class ANewExpr #self.debug("got {res2} from {mproperty}. drop {recv}") return res2 end - v.check_init_instance(recv, mtype) return recv end end diff --git a/src/debugger.nit b/src/debugger.nit index 9aa622e..be9c26b 100644 --- a/src/debugger.nit +++ b/src/debugger.nit @@ -334,7 +334,6 @@ class Debugger if initprop != null then self.send(initprop, [mobj]) end - self.check_init_instance(mobj) var mainprop = mmod.try_get_primitive_method("main", sys_type.mclass) if mainprop != null then self.rt_send(mainprop, [mobj]) diff --git a/src/global_compiler.nit b/src/global_compiler.nit index 6dc5295..004c8a3 100644 --- a/src/global_compiler.nit +++ b/src/global_compiler.nit @@ -48,7 +48,6 @@ redef class ModelBuilder for t in runtime_type_analysis.live_types do if t.ctype == "val*" then compiler.generate_init_instance(t) - compiler.generate_check_init_instance(t) else compiler.generate_box_instance(t) end @@ -223,19 +222,6 @@ class GlobalCompiler v.add("\}") end - redef fun generate_check_init_instance(mtype) - do - if self.modelbuilder.toolcontext.opt_no_check_initialization.value then return - - var v = self.new_visitor - var res = new RuntimeVariable("self", mtype, mtype) - self.header.add_decl("void CHECK_NEW_{mtype.c_name}({mtype.ctype});") - v.add_decl("/* allocate {mtype} */") - v.add_decl("void CHECK_NEW_{mtype.c_name}({mtype.ctype} {res}) \{") - self.generate_check_attr(v, res, mtype) - v.add("\}") - end - fun generate_box_instance(mtype: MClassType) do assert self.runtime_type_analysis.live_types.has(mtype) @@ -826,18 +812,6 @@ class GlobalCompilerVisitor return res end - redef fun check_init_instance(recv, mtype) - do - if self.compiler.modelbuilder.toolcontext.opt_no_check_initialization.value then return - - mtype = self.anchor(mtype).as(MClassType) - if not self.compiler.runtime_type_analysis.live_types.has(mtype) then - debug "problem: {mtype} was detected dead" - end - - self.add("CHECK_NEW_{mtype.c_name}({recv});") - end - redef fun array_instance(array, elttype) do elttype = self.anchor(elttype) @@ -853,7 +827,6 @@ class GlobalCompilerVisitor end var length = self.int_instance(array.length) self.send(self.get_property("with_native", arraytype), [res, nat, length]) - self.check_init_instance(res, arraytype) self.add("\}") return res end diff --git a/src/naive_interpreter.nit b/src/naive_interpreter.nit index 74b22b3..ef2a5f3 100644 --- a/src/naive_interpreter.nit +++ b/src/naive_interpreter.nit @@ -62,7 +62,6 @@ redef class ModelBuilder if initprop != null then interpreter.send(initprop, [mainobj]) end - interpreter.check_init_instance(mainobj) var mainprop = mainmodule.try_get_primitive_method("main", sys_type.mclass) if mainprop != null then interpreter.send(mainprop, [mainobj]) @@ -243,7 +242,6 @@ private class NaiveInterpreter var res = new MutableInstance(mtype) self.init_instance(res) self.send(self.force_get_primitive_method("with_native", mtype), [res, nat, self.int_instance(values.length)]) - self.check_init_instance(res) return res end @@ -463,19 +461,6 @@ private class NaiveInterpreter end end - # Check that non nullable attributes of `recv` are correctly initialized. - # This function is used as the last instruction of a new - fun check_init_instance(recv: Instance) - do - if not recv isa MutableInstance then return - for npropdef in collect_attr_propdef(recv.mtype) do - if npropdef.n_expr == null then - # Force read to check the initialization - self.read_attribute(npropdef.mpropdef.mproperty, recv) - end - end - end - # This function determine the correct type according the reciever of the current definition (self). fun unanchor_type(mtype: MType): MType do @@ -1423,7 +1408,6 @@ redef class ACrangeExpr var res = new MutableInstance(mtype) v.init_instance(res) v.send(v.force_get_primitive_method("init", mtype), [res, e1, e2]) - v.check_init_instance(res) return res end end @@ -1439,7 +1423,6 @@ redef class AOrangeExpr var res = new MutableInstance(mtype) v.init_instance(res) v.send(v.force_get_primitive_method("without_last", mtype), [res, e1, e2]) - v.check_init_instance(res) return res end end @@ -1619,7 +1602,6 @@ redef class ANewExpr #self.debug("got {res2} from {mproperty}. drop {recv}") return res2 end - v.check_init_instance(recv) return recv end end diff --git a/src/separate_compiler.nit b/src/separate_compiler.nit index 629cdd4..3ba9452 100644 --- a/src/separate_compiler.nit +++ b/src/separate_compiler.nit @@ -814,8 +814,6 @@ class SeparateCompiler v.add("return {res};") end v.add("\}") - - generate_check_init_instance(mtype) end # Add a dynamic test to ensure that the type referenced by `t` is a live type @@ -831,24 +829,6 @@ class SeparateCompiler v.add("\}") end - redef fun generate_check_init_instance(mtype) - do - if self.modelbuilder.toolcontext.opt_no_check_initialization.value then return - - var v = self.new_visitor - var c_name = mtype.mclass.c_name - var res = new RuntimeVariable("self", mtype, mtype) - self.provide_declaration("CHECK_NEW_{c_name}", "void CHECK_NEW_{c_name}({mtype.ctype});") - v.add_decl("/* allocate {mtype} */") - v.add_decl("void CHECK_NEW_{c_name}({mtype.ctype} {res}) \{") - if runtime_type_analysis.live_classes.has(mtype.mclass) then - self.generate_check_attr(v, res, mtype) - else - v.add_abort("{mtype.mclass} is DEAD") - end - v.add("\}") - end - redef fun new_visitor do return new SeparateCompilerVisitor(self) # Stats @@ -1286,13 +1266,6 @@ class SeparateCompilerVisitor return self.new_expr("NEW_{mtype.mclass.c_name}(&type_{mtype.c_name})", mtype) end - redef fun check_init_instance(value, mtype) - do - if self.compiler.modelbuilder.toolcontext.opt_no_check_initialization.value then return - self.require_declaration("CHECK_NEW_{mtype.mclass.c_name}") - self.add("CHECK_NEW_{mtype.mclass.c_name}({value});") - end - redef fun type_test(value, mtype, tag) do self.add("/* {value.inspect} isa {mtype} */") @@ -1543,7 +1516,6 @@ class SeparateCompilerVisitor self.add("((struct instance_{nclass.c_name}*){nat})->values[{i}] = (val*) {r};") end self.send(self.get_property("with_native", arrayclass.intro.bound_mtype), [res, nat, length]) - self.check_init_instance(res, arraytype) self.add("\}") return res end diff --git a/src/separate_erasure_compiler.nit b/src/separate_erasure_compiler.nit index e4256ea..7657c5c 100644 --- a/src/separate_erasure_compiler.nit +++ b/src/separate_erasure_compiler.nit @@ -333,8 +333,6 @@ class SeparateErasureCompiler self.generate_init_attr(v, res, mtype) v.add("return {res};") v.add("\}") - - generate_check_init_instance(mtype) end private fun build_class_vts_table(mclass: MClass): Bool do @@ -604,7 +602,6 @@ class SeparateErasureCompilerVisitor end var length = self.int_instance(array.length) self.send(self.get_property("with_native", arraytype), [res, nat, length]) - self.check_init_instance(res, arraytype) self.add("\}") return res end -- 1.7.9.5