def testSwitchableBecomesResolved(self): with scopedVat(testingVat()): p, r = makePromise() self.assertFalse(isResolved(p)) r.resolve(IntObject(42)) self.assertTrue(isResolved(p))
def testSwitchableChains(self): with scopedVat(testingVat()): p, r = makePromise() p2, r2 = makePromise() r.resolve(p2) self.assertFalse(isResolved(p)) r2.resolve(IntObject(42)) self.assertTrue(isResolved(p))
def resolveKey(key): from typhon.objects.refs import Promise, isResolved if isinstance(key, Promise): key = key.resolution() if not isResolved(key): raise userError(u"Unresolved promises cannot be used as map keys") return key
def checkSlot(self): if self.committed: return True self.resolutionBox = resolution(self.resolutionBox) if isResolved(self.resolutionBox): self.commit() return True return False
def resolveKey(key): from typhon.objects.refs import Promise, isResolved if isinstance(key, Promise): key = key.resolution() # Do the resolution check again. if not isResolved(key): raise userError(u"Unresolved promises cannot be used as map keys") # If the original key wasn't a promise, then no checks are needed. return key
def samenessFringe(original, path, fringe, sofar=None): """ Walk an object graph, building up the fringe. Returns whether the graph is settled. """ # Resolve the object. o = resolution(original) # Handle primitive cases first. if o in (NullObject, TrueObject, FalseObject): return True if (isinstance(o, CharObject) or isinstance(o, DoubleObject) or isinstance(o, IntObject) or isinstance(o, BigInt) or isinstance(o, StrObject) or isinstance(o, BytesObject) or isinstance(o, TraversalKey)): return True if isinstance(o, ConstMap) and o.empty(): return True if sofar is None: sofar = {} elif o in sofar: return True if isinstance(o, ConstList): sofar[o] = None return listFringe(o, fringe, path, sofar) if selfless in o.auditorStamps(): if transparentStamp in o.auditorStamps(): sofar[o] = None return samenessFringe(o.call(u"_uncall", []), path, fringe, sofar) if semitransparentStamp in o.auditorStamps(): sofar[o] = None p = o.call(u"_uncall", []) if not isinstance(p, SealedPortrayal): userError( u'Semitransparent portrayal was not a SealedPortrayal!') return samenessFringe(p, path, fringe, sofar) if isResolved(o): return True # Welp, it's unsettled. if fringe is not None: fringe.append(FringeNode(o, path)) return False
def samenessFringe(original, path, fringe, sofar=None): """ Walk an object graph, building up the fringe. Returns whether the graph is settled. """ # Resolve the object. o = resolution(original) # Handle primitive cases first. if o in (NullObject, TrueObject, FalseObject): return True if (isinstance(o, CharObject) or isinstance(o, DoubleObject) or isinstance(o, IntObject) or isinstance(o, BigInt) or isinstance(o, StrObject) or isinstance(o, BytesObject) or isinstance(o, TraversalKey)): return True if isinstance(o, ConstMap) and o.empty(): return True if sofar is None: sofar = {} elif o in sofar: return True if isinstance(o, ConstList): sofar[o] = None return listFringe(o, fringe, path, sofar) if selfless in o.auditorStamps(): if transparentStamp in o.auditorStamps(): sofar[o] = None return samenessFringe(o.call(u"_uncall", []), path, fringe, sofar) if semitransparentStamp in o.auditorStamps(): sofar[o] = None p = o.call(u"_uncall", []) if not isinstance(p, SealedPortrayal): userError(u'Semitransparent portrayal was not a SealedPortrayal!') return samenessFringe(p, path, fringe, sofar) if isResolved(o): return True # Welp, it's unsettled. if fringe is not None: fringe.append(FringeNode(o, path)) return False
def samenessFringe(original, path, fringe, sofar=None): """ Walk an object graph, building up the fringe. Returns whether the graph is settled. """ # Resolve the object. o = resolution(original) # Handle primitive cases first. if o is NullObject: return True if ( isinstance(o, BoolObject) or isinstance(o, CharObject) or isinstance(o, DoubleObject) or isinstance(o, IntObject) or isinstance(o, BigInt) or isinstance(o, StrObject) or isinstance(o, TraversalKey) ): return True if isinstance(o, ConstMap) and len(o.objectMap) == 0: return True if sofar is None: sofar = {} elif o in sofar: return True if isinstance(o, ConstList): sofar[o] = None return listFringe(o, fringe, path, sofar) if selfless in o.auditorStamps(): if transparentStamp in o.auditorStamps(): return samenessFringe(o.call(u"_uncall", []), path, fringe, sofar) # XXX Semitransparent support goes here if isResolved(o): return True # Welp, it's unsettled. if fringe is not None: fringe.append(FringeNode(o, path)) return False
def samenessFringe(original, path, fringe, sofar=None): """ Walk an object graph, building up the fringe. Returns whether the graph is settled. """ # Resolve the object. o = resolution(original) # Handle primitive cases first. if o is NullObject: return True if (isinstance(o, BoolObject) or isinstance(o, CharObject) or isinstance(o, DoubleObject) or isinstance(o, IntObject) or isinstance(o, BigInt) or isinstance(o, StrObject) or isinstance(o, TraversalKey)): return True if isinstance(o, ConstMap) and len(o.objectMap) == 0: return True if sofar is None: sofar = {} elif o in sofar: return True if isinstance(o, ConstList): sofar[o] = None return listFringe(o, fringe, path, sofar) if selfless in o.auditorStamps(): if transparentStamp in o.auditorStamps(): sofar[o] = None return samenessFringe(o.call(u"_uncall", []), path, fringe, sofar) # XXX Semitransparent support goes here if isResolved(o): return True # Welp, it's unsettled. if fringe is not None: fringe.append(FringeNode(o, path)) return False
def samenessHash(obj, depth, fringe, path=None): """ Generate a hash code for an object that may not be completely settled. If two objects are the same, then they will have identical hashes. The generated hash is valid until settledness of a component changes. """ if depth <= 0: # not gonna look any further for the purposes of hash computation, but # we do have to know about unsettled refs if samenessFringe(obj, path, fringe): # obj is settled. return -1 elif fringe is None: raise userError(u"Must be settled") else: # not settled. return -1 o = resolution(obj) # The constants have their own special hash values. if o is NullObject: return 0 if o is TrueObject: return 1 if o is FalseObject: return 2 # Objects that do their own hashing. if (isinstance(o, CharObject) or isinstance(o, DoubleObject) or isinstance(o, IntObject) or isinstance(o, BigInt) or isinstance(o, StrObject) or isinstance(o, BytesObject) or isinstance(o, TraversalKey)): return o.computeHash(depth) # Lists. if isinstance(o, ConstList): oList = unwrapList(o) result = len(oList) for i, x in enumerate(oList): if fringe is None: fr = None else: fr = FringePath(i, path) result ^= i ^ samenessHash(x, depth - 1, fringe, path=fr) return result # The empty map. (Uncalls contain maps, thus this base case.) if isinstance(o, ConstMap) and o.empty(): return 127 from typhon.objects.proxy import FarRef, DisconnectedRef if isinstance(o, FarRef) or isinstance(o, DisconnectedRef): return samenessHash(o.handler, depth, fringe, path=path) # Other objects compared by structure. if selfless in o.auditorStamps(): if transparentStamp in o.auditorStamps(): return samenessHash(o.call(u"_uncall", []), depth, fringe, path=path) if semitransparentStamp in o.auditorStamps(): p = o.call(u"_uncall", []) if not isinstance(p, SealedPortrayal): userError(u'Semitransparent portrayal was not a SealedPortrayal!') return samenessHash(p.portrayal, depth, fringe, path=path) # Objects compared by identity. if isResolved(o): return compute_identity_hash(o) elif fringe is None: raise userError(u"Must be settled") # Unresolved refs. fringe.append(FringeNode(o, path)) return -1
def isResolved(self): if self.checkSlot(): return isResolved(self.resolutionBox.get()) return False
def samenessHash(obj, depth, path, fringe): """ Generate a hash code for an object that may not be completely settled. Equality of hash code implies sameness of objects. The generated hash is valid until settledness of a component changes. """ if depth <= 0: # not gonna look any further for the purposes of hash computation, but # we do have to know about unsettled refs if samenessFringe(obj, path, fringe): # obj is settled. return -1 elif fringe is None: raise userError(u"Must be settled") else: # not settled. return -1 o = resolution(obj) if o is NullObject: return 0 # Objects that do their own hashing. if ( isinstance(o, BoolObject) or isinstance(o, CharObject) or isinstance(o, DoubleObject) or isinstance(o, IntObject) or isinstance(o, BigInt) or isinstance(o, StrObject) or isinstance(o, BytesObject) or isinstance(o, TraversalKey) ): return o.hash() # Lists. if isinstance(o, ConstList): oList = unwrapList(o) result = len(oList) for i, x in enumerate(oList): if fringe is None: fr = None else: fr = FringePath(i, path) result ^= i ^ samenessHash(x, depth - 1, fr, fringe) return result # The empty map. (Uncalls contain maps, thus this base case.) if isinstance(o, ConstMap) and len(o.objectMap) == 0: return 127 from typhon.objects.proxy import FarRef, DisconnectedRef if isinstance(o, FarRef) or isinstance(o, DisconnectedRef): return samenessHash(o.handler, depth, path, fringe) # Other objects compared by structure. if selfless in o.auditorStamps(): if transparentStamp in o.auditorStamps(): return samenessHash(o.call(u"_uncall", []), depth, path, fringe) # XXX Semitransparent support goes here # Objects compared by identity. if isResolved(o): return compute_identity_hash(o) elif fringe is None: raise userError(u"Must be settled") # Unresolved refs. fringe.append(FringeNode(o, path)) return -1
def samenessHash(obj, depth, fringe, path=None): """ Generate a hash code for an object that may not be completely settled. If two objects are the same, then they will have identical hashes. The generated hash is valid until settledness of a component changes. """ if depth <= 0: # not gonna look any further for the purposes of hash computation, but # we do have to know about unsettled refs if samenessFringe(obj, path, fringe): # obj is settled. return -1 elif fringe is None: raise userError(u"Must be settled") else: # not settled. return -1 o = resolution(obj) # The constants have their own special hash values. if o is NullObject: return 0 if o is TrueObject: return 1 if o is FalseObject: return 2 # Objects that do their own hashing. if (isinstance(o, CharObject) or isinstance(o, DoubleObject) or isinstance(o, IntObject) or isinstance(o, BigInt) or isinstance(o, StrObject) or isinstance(o, BytesObject) or isinstance(o, TraversalKey)): return o.computeHash(depth) # Lists. if isinstance(o, ConstList): oList = unwrapList(o) result = len(oList) for i, x in enumerate(oList): if fringe is None: fr = None else: fr = FringePath(i, path) result ^= i ^ samenessHash(x, depth - 1, fringe, path=fr) return result # The empty map. (Uncalls contain maps, thus this base case.) if isinstance(o, ConstMap) and o.empty(): return 127 from typhon.objects.proxy import FarRef, DisconnectedRef if isinstance(o, FarRef) or isinstance(o, DisconnectedRef): return samenessHash(o.handler, depth, fringe, path=path) # Other objects compared by structure. if selfless in o.auditorStamps(): if transparentStamp in o.auditorStamps(): return samenessHash(o.call(u"_uncall", []), depth, fringe, path=path) if semitransparentStamp in o.auditorStamps(): p = o.call(u"_uncall", []) if not isinstance(p, SealedPortrayal): userError( u'Semitransparent portrayal was not a SealedPortrayal!') return samenessHash(p.portrayal, depth, fringe, path=path) # Objects compared by identity. if isResolved(o): return compute_identity_hash(o) elif fringe is None: raise userError(u"Must be settled") # Unresolved refs. fringe.append(FringeNode(o, path)) return -1
def testNearIsResolved(self): self.assertTrue(isResolved(IntObject(42)))
def samenessHash(obj, depth, path, fringe): """ Generate a hash code for an object that may not be completely settled. Equality of hash code implies sameness of objects. The generated hash is valid until settledness of a component changes. """ if depth <= 0: # not gonna look any further for the purposes of hash computation, but # we do have to know about unsettled refs if samenessFringe(obj, path, fringe): # obj is settled. return -1 elif fringe is None: raise userError(u"Must be settled") else: # not settled. return -1 o = resolution(obj) if o is NullObject: return 0 # Objects that do their own hashing. if (isinstance(o, BoolObject) or isinstance(o, CharObject) or isinstance(o, DoubleObject) or isinstance(o, IntObject) or isinstance(o, BigInt) or isinstance(o, StrObject) or isinstance(o, BytesObject) or isinstance(o, TraversalKey)): return o.hash() # Lists. if isinstance(o, ConstList): oList = unwrapList(o) result = len(oList) for i, x in enumerate(oList): if fringe is None: fr = None else: fr = FringePath(i, path) result ^= i ^ samenessHash(x, depth - 1, fr, fringe) return result # The empty map. (Uncalls contain maps, thus this base case.) if isinstance(o, ConstMap) and len(o.objectMap) == 0: return 127 from typhon.objects.proxy import FarRef, DisconnectedRef if isinstance(o, FarRef) or isinstance(o, DisconnectedRef): return samenessHash(o.handler, depth, path, fringe) # Other objects compared by structure. if selfless in o.auditorStamps(): if transparentStamp in o.auditorStamps(): return samenessHash(o.call(u"_uncall", []), depth, path, fringe) # XXX Semitransparent support goes here # Objects compared by identity. if isResolved(o): return compute_identity_hash(o) elif fringe is None: raise userError(u"Must be settled") # Unresolved refs. fringe.append(FringeNode(o, path)) return -1