module alloy/A_CacheDetail -- Shows the structure of a simplified Evidence Module -- with just a TC, local owned Attribute instances, and -- a cache for cross-referenced data owned by external EMs. -- Type A type, simplified a lot abstract sig Type {} -- Types for: -- primitive values (TPrim: Int, Text, Blob, Real), -- address values (Uid), and one sig TPrim, TRef extends Type {} -- Values abstract sig Val {} -- Two types: primitive values and entity/attribute addresses sig VPrim, Uid extends Val {} -- An Instance of a typed attribute sig IAttr { ityp: one Type, addr: one Uid } -- A Value assigned to an IAttr -- There may be zero or more values per attribute instance -- representing differing points of view on what the value is sig IAttrVal { vattr: one IAttr, v: one Val } -- A collection of self-consistent typed values -- meaning all IAttrVals define separate values -- for an IAttr within the same ValArena. -- This has to be the case because an IAttrVal -- has a single vattr relation to its parent abstract sig ValArena { insts: set IAttr, } sig CValArena, OValArena extends ValArena {} -- Evidence Module - top level container -- Has a set of types, one OValArena (ownvals) for its own instance values -- and a cache of externally owned values from other EvidMods (cachevals) -- In the real system, the typectxs are separate trees of definitions -- Here, the type of an IAttr is selected from a global set of -- types. This models the needs of the cacheing process well enough, -- Only require two value types, pointers and constant immediate values. sig EvidMod { typectx: set Type, ownvals: one OValArena, cachevals: one CValArena } one sig Reachable { raddrmap: set IAttr -> set Uid } fact distinctEvidMods { -- Every type of an owned instance must be defined in the -- EvidMod's type context (typectx) all e: EvidMod | e.ownvals.insts.ityp in e.typectx all disj e, e_: EvidMod | no (e.ownvals & e_.ownvals) -- Partition TRef addresses into local IAttr values -- and external IAttr addresses. The remote set goes -- into the cache. all em: EvidMod | let iasO = em.ownvals.insts { let addrO = targAddrs[iasO] - iasO.addr { em.cachevals.insts = IAttr <: addr.addrO } } } fact consistentValArenas { -- A ValArena is in one Em only all va: OValArena | one em: EvidMod | va in em.ownvals all va: CValArena | one em: EvidMod | va in em.cachevals -- Each IAttr has a unique Uid address all disj ia, ia_: IAttr | ! ( ia.addr = ia_.addr ) all ia: IAttr | one em: EvidMod | ia in em.ownvals.insts -- The value in an IAttrVal must agree with the type -- specified in its parent IAttr all iav: IAttrVal |(iav.v in typeChk[ iav.vattr.ityp]) and -- Every TRef value points to an instance IAttr (iav.vattr.ityp = TRef and iav.v in IAttr.addr) -- A TRef pointer value in an IAttrVal cannot point -- to the parent IAttr itself in this model -- It might make sense in the real system all iav: IAttrVal | iav.vattr.ityp = TRef implies !(iav.v = iav.vattr.addr) -- Every IAttr must have at least one instance value all ia: IAttr | some iav: IAttrVal | iav.vattr = ia one r: Reachable | { r.raddrmap = {ia: IAttr, u: Uid | ia in IAttr and u = targAddrs[ia]} } } -- Check that all TRef address pointers reference an existing IAttr.addr assert TRefValsInAddr { all iav: IAttrVal | (iav.vattr.ityp = TRef and iav.v in IAttr.addr) or (iav.vattr.ityp != TRef) } check TRefValsInAddr for 4 check TRefValsInAddr for 8 -- Generate an IAttr's Uid -> {Uid} mapping fun fullIAttrAddrMap[ia: IAttr]: Uid one -> set Uid { {u: Uid, tas: Uid | u = ia.addr and tas = targAddrs[ia]} } -- Find one-hop address references in an IAttr's set of values fun targAddrs [ia: IAttr ]: set Uid { let iavs = {iav: IAttrVal | iav.vattr = ia} { {u: Uid |iavs.vattr.ityp = TRef and u = iavs.v } } } -- Lookup the IAttr by address -- There's a 1-1 relationship between an IAttr and its address fun lookupIAttrByAddr [u: set Uid]: one IAttr { {iat: IAttr | iat.addr in u} } -- Specify the value types associated with data types fun typeChk: Type -> Val { Type <: TPrim -> VPrim + TRef -> Uid } pred show { some EvidMod all em: EvidMod | #em.cachevals.insts > 0 all ia: IAttr | #vattr.ia > 0 } run show for 6 but exactly 2 EvidMod