def test_virtuals_with_equal_fields(self): info1 = VirtualStateInfo(ConstInt(42), [1, 2]) value = OptValue(self.nodebox) classbox = self.cpu.ts.cls_of_box(self.nodebox) value.make_constant_class(classbox, -1) knownclass_info = NotVirtualStateInfo(value) info1.fieldstate = [knownclass_info, knownclass_info] vstate1 = VirtualState([info1]) assert vstate1.generalization_of(vstate1) info2 = VirtualStateInfo(ConstInt(42), [1, 2]) unknown_info1 = NotVirtualStateInfo(OptValue(self.nodebox)) info2.fieldstate = [unknown_info1, unknown_info1] vstate2 = VirtualState([info2]) assert vstate2.generalization_of(vstate2) assert not vstate1.generalization_of(vstate2) assert vstate2.generalization_of(vstate1) info3 = VirtualStateInfo(ConstInt(42), [1, 2]) unknown_info1 = NotVirtualStateInfo(OptValue(self.nodebox)) unknown_info2 = NotVirtualStateInfo(OptValue(self.nodebox)) info3.fieldstate = [unknown_info1, unknown_info2] vstate3 = VirtualState([info3]) assert vstate3.generalization_of(vstate2) assert vstate3.generalization_of(vstate1) assert not vstate2.generalization_of(vstate3) assert not vstate1.generalization_of(vstate3)
def test_nonvirtual_is_not_array(self): info1 = VArrayStateInfo(42) value = OptValue(self.nodebox) classbox = self.cpu.ts.cls_of_box(self.nodebox) value.make_constant_class(classbox, -1) knownclass_info = NotVirtualStateInfo(value) info1.fieldstate = [knownclass_info, knownclass_info] vstate1 = VirtualState([info1]) assert vstate1.generalization_of(vstate1) info2 = NotVirtualStateInfo(value) vstate2 = VirtualState([info2]) assert vstate2.generalization_of(vstate2) assert not vstate2.generalization_of(vstate1) assert not vstate1.generalization_of(vstate2)
def test_virtuals_with_nonmatching_classes(self): info1 = VirtualStateInfo(ConstInt(42), [1, 2]) value = OptValue(self.nodebox) classbox = self.cpu.ts.cls_of_box(self.nodebox) value.make_constant_class(classbox, -1) knownclass_info = NotVirtualStateInfo(value) info1.fieldstate = [knownclass_info, knownclass_info] vstate1 = VirtualState([info1]) assert vstate1.generalization_of(vstate1) info2 = VirtualStateInfo(ConstInt(7), [1, 2]) value = OptValue(self.nodebox2) classbox = self.cpu.ts.cls_of_box(self.nodebox2) value.make_constant_class(classbox, -1) knownclass_info = NotVirtualStateInfo(value) info2.fieldstate = [knownclass_info, knownclass_info] vstate2 = VirtualState([info2]) assert vstate2.generalization_of(vstate2) assert not vstate2.generalization_of(vstate1) assert not vstate1.generalization_of(vstate2)
def test_equal_inputargs(self): value = OptValue(self.nodebox) classbox = self.cpu.ts.cls_of_box(self.nodebox) value.make_constant_class(classbox, -1) knownclass_info = NotVirtualStateInfo(value) vstate1 = VirtualState([knownclass_info, knownclass_info]) assert vstate1.generalization_of(vstate1) unknown_info1 = NotVirtualStateInfo(OptValue(self.nodebox)) vstate2 = VirtualState([unknown_info1, unknown_info1]) assert vstate2.generalization_of(vstate2) assert not vstate1.generalization_of(vstate2) assert vstate2.generalization_of(vstate1) unknown_info1 = NotVirtualStateInfo(OptValue(self.nodebox)) unknown_info2 = NotVirtualStateInfo(OptValue(self.nodebox)) vstate3 = VirtualState([unknown_info1, unknown_info2]) assert vstate3.generalization_of(vstate2) assert vstate3.generalization_of(vstate1) assert not vstate2.generalization_of(vstate3) assert not vstate1.generalization_of(vstate3) expected = """ [p0] guard_nonnull(p0) [] guard_class(p0, ConstClass(node_vtable)) [] """ guards = [] vstate1.generate_guards(vstate2, [self.nodebox, self.nodebox], self.cpu, guards) self.compare(guards, expected, [self.nodebox]) with py.test.raises(InvalidLoop): guards = [] vstate1.generate_guards(vstate3, [self.nodebox, self.nodebox], self.cpu, guards) with py.test.raises(InvalidLoop): guards = [] vstate2.generate_guards(vstate3, [self.nodebox, self.nodebox], self.cpu, guards)