Пример #1
0
        public static void Transform(LinearTypeChecker linearTypeChecker, MoverTypeChecker moverTypeChecker)
        {
            // The order in which originalDecls are computed and then *.AddCheckers are called is
            // apparently important.  The MyDuplicator code currently does not duplicate Attributes.
            // Consequently, all the yield attributes are eliminated by the AddCheckers code.

            List <Declaration> originalDecls = new List <Declaration>();
            Program            program       = linearTypeChecker.program;

            foreach (var decl in program.TopLevelDeclarations)
            {
                Procedure proc = decl as Procedure;
                if (proc != null && QKeyValue.FindBoolAttribute(proc.Attributes, "yields"))
                {
                    originalDecls.Add(proc);
                    continue;
                }
                Implementation impl = decl as Implementation;
                if (impl != null && QKeyValue.FindBoolAttribute(impl.Proc.Attributes, "yields"))
                {
                    originalDecls.Add(impl);
                }
            }

            List <Declaration> decls = new List <Declaration>();

            OwickiGries.AddCheckers(linearTypeChecker, moverTypeChecker, decls);
            MoverCheck.AddCheckers(linearTypeChecker, moverTypeChecker, decls);
            RefinementCheck.AddCheckers(linearTypeChecker, moverTypeChecker, decls);

            program.TopLevelDeclarations.RemoveAll(x => originalDecls.Contains(x));
            program.TopLevelDeclarations.AddRange(decls);
        }
Пример #2
0
        public static void Transform(LinearTypeChecker linearTypeChecker, MoverTypeChecker moverTypeChecker)
        {
            List <Declaration> originalDecls = new List <Declaration>();
            Program            program       = linearTypeChecker.program;

            foreach (var decl in program.TopLevelDeclarations)
            {
                Procedure proc = decl as Procedure;
                if (proc != null && moverTypeChecker.procToActionInfo.ContainsKey(proc))
                {
                    originalDecls.Add(proc);
                    continue;
                }
                Implementation impl = decl as Implementation;
                if (impl != null && moverTypeChecker.procToActionInfo.ContainsKey(impl.Proc))
                {
                    originalDecls.Add(impl);
                }
            }

            List <Declaration> decls = new List <Declaration>();

            if (!CommandLineOptions.Clo.TrustAtomicityTypes)
            {
                MoverCheck.AddCheckers(linearTypeChecker, moverTypeChecker, decls);
            }
            OwickiGries.AddCheckers(linearTypeChecker, moverTypeChecker, decls);
            foreach (Declaration decl in decls)
            {
                decl.Attributes = OwickiGries.RemoveYieldsAttribute(decl.Attributes);
            }
            program.RemoveTopLevelDeclarations(x => originalDecls.Contains(x));
            program.AddTopLevelDeclarations(decls);
        }
Пример #3
0
        public static void Transform(LinearTypeChecker linearTypeChecker, CivlTypeChecker civlTypeChecker)
        {
            Program program = linearTypeChecker.program;

            // Store the original declarations of yielding procedures, which will be removed after desugaring below.
            var origProc = program.TopLevelDeclarations.OfType <Procedure>().Where(p => civlTypeChecker.procToYieldingProc.ContainsKey(p));
            var origImpl = program.TopLevelDeclarations.OfType <Implementation>().Where(i => civlTypeChecker.procToYieldingProc.ContainsKey(i.Proc));
            List <Declaration> originalDecls = Enumerable.Union <Declaration>(origProc, origImpl).ToList();

            // Commutativity checks
            List <Declaration> decls = new List <Declaration>();

            if (!CommandLineOptions.Clo.TrustAtomicityTypes)
            {
                MoverCheck.AddCheckers(linearTypeChecker, civlTypeChecker, decls);
            }

            // Desugaring of yielding procedures
            YieldingProcChecker.AddCheckers(linearTypeChecker, civlTypeChecker, decls);

            // Linear type checks
            LinearTypeChecker.AddCheckers(linearTypeChecker, civlTypeChecker, decls);

            // Remove original declarations and add new checkers generated above
            program.RemoveTopLevelDeclarations(x => originalDecls.Contains(x));
            program.AddTopLevelDeclarations(decls);

            civlTypeChecker.SubstituteBackwardAssignments();

            foreach (AtomicAction atomicAction in civlTypeChecker.procToAtomicAction.Values)
            {
                program.RemoveTopLevelDeclaration(atomicAction.proc);
                program.RemoveTopLevelDeclaration(atomicAction.impl);
            }
        }
Пример #4
0
        public static void Transform(LinearTypeChecker linearTypeChecker, CivlTypeChecker civlTypeChecker)
        {
            Program program = linearTypeChecker.program;

            // Store the original declarations of yielding procedures, which will be removed after desugaring below.
            var origProc = program.TopLevelDeclarations.OfType <Procedure>().Where(p => civlTypeChecker.procToYieldingProc.ContainsKey(p));
            var origImpl = program.TopLevelDeclarations.OfType <Implementation>().Where(i => civlTypeChecker.procToYieldingProc.ContainsKey(i.Proc));
            List <Declaration> originalDecls = Enumerable.Union <Declaration>(origProc, origImpl).ToList();

            // Commutativity checks
            List <Declaration> decls = new List <Declaration>();

            if (!CommandLineOptions.Clo.TrustAtomicityTypes)
            {
                MoverCheck.AddCheckers(linearTypeChecker, civlTypeChecker, decls);
            }

            // Desugaring of yielding procedures
            CivlRefinement.AddCheckers(linearTypeChecker, civlTypeChecker, decls);

            // Trigger functions for existential vairables in transition relations
            decls.AddRange(civlTypeChecker.procToAtomicAction.Values.SelectMany(a => a.layerToActionCopy.Values.SelectMany(ac => ac.triggerFuns.Values)));

            // Remove original declarations and add new checkers generated above
            program.RemoveTopLevelDeclarations(x => originalDecls.Contains(x));
            program.AddTopLevelDeclarations(decls);

            foreach (AtomicAction atomicAction in civlTypeChecker.procToAtomicAction.Values)
            {
                program.RemoveTopLevelDeclaration(atomicAction.proc);
                program.RemoveTopLevelDeclaration(atomicAction.impl);
            }
        }
Пример #5
0
        public static void AddCheckers(LinearTypeChecker linearTypeChecker, CivlTypeChecker civlTypeChecker,
                                       List <Declaration> decls)
        {
            MoverCheck moverChecking = new MoverCheck(linearTypeChecker, civlTypeChecker, decls);

            // TODO: make enumeration of mover checks more efficient / elegant

            var regularMoverChecks =
                from first in civlTypeChecker.procToAtomicAction.Values
                from second in civlTypeChecker.procToAtomicAction.Values
                where first.layerRange.OverlapsWith(second.layerRange)
                where first.IsRightMover || second.IsLeftMover
                select new { first, second };

            foreach (var moverCheck in regularMoverChecks)
            {
                if (moverCheck.first.IsRightMover)
                {
                    moverChecking.CreateRightMoverCheckers(moverCheck.first, moverCheck.second);
                }
                if (moverCheck.second.IsLeftMover)
                {
                    moverChecking.CreateLeftMoverCheckers(moverCheck.first, moverCheck.second);
                }
            }

            var inductiveSequentializationMoverChecks =
                from IS in civlTypeChecker.inductiveSequentializations
                from leftMover in IS.elim.Values
                from action in civlTypeChecker.procToAtomicAction.Values
                where action.layerRange.Contains(IS.inputAction.layerRange.upperLayerNum)
                select new { action, leftMover };

            foreach (var moverCheck in inductiveSequentializationMoverChecks)
            {
                moverChecking.CreateLeftMoverCheckers(moverCheck.action, moverCheck.leftMover);
            }

            // Here we include IS abstractions
            foreach (var atomicAction in civlTypeChecker.AllAtomicActions.Where(a => a.IsLeftMover))
            {
                moverChecking.CreateNonBlockingChecker(atomicAction);
            }

            // IS abstractions are marked left movers, so here we select regular atomic actions
            // that are not marked left mover but used as abstraction in IS.
            foreach (var atomicAction in civlTypeChecker.inductiveSequentializations.SelectMany(IS => IS.elim.Values)
                     .Where(a => !a.IsLeftMover).Distinct())
            {
                moverChecking.CreateNonBlockingChecker(atomicAction);
            }

            foreach (var introductionAction in civlTypeChecker.procToIntroductionAction.Values)
            {
                moverChecking.CreateNonBlockingChecker(introductionAction);
            }
        }
Пример #6
0
        public static void AddCheckers(LinearTypeChecker linearTypeChecker, MoverTypeChecker moverTypeChecker, List <Declaration> decls)
        {
            if (moverTypeChecker.procToActionInfo.Count == 0)
            {
                return;
            }

            Dictionary <int, HashSet <ActionInfo> > pools = new Dictionary <int, HashSet <ActionInfo> >();

            foreach (ActionInfo action in moverTypeChecker.procToActionInfo.Values)
            {
                foreach (int phaseNum in action.callerPhaseNums)
                {
                    if (!pools.ContainsKey(phaseNum))
                    {
                        pools[phaseNum] = new HashSet <ActionInfo>();
                    }
                    pools[phaseNum].Add(action);
                }
            }

            Program    program       = moverTypeChecker.program;
            MoverCheck moverChecking = new MoverCheck(linearTypeChecker, moverTypeChecker, decls);

            foreach (int phaseNum in pools.Keys)
            {
                foreach (ActionInfo first in pools[phaseNum])
                {
                    Debug.Assert(first.moverType != MoverType.Top);
                    if (first.moverType == MoverType.Atomic)
                    {
                        continue;
                    }
                    foreach (ActionInfo second in pools[phaseNum])
                    {
                        if (first.IsRightMover)
                        {
                            moverChecking.CreateCommutativityChecker(program, first, second);
                            moverChecking.CreateGatePreservationChecker(program, second, first);
                        }
                        if (first.IsLeftMover)
                        {
                            moverChecking.CreateCommutativityChecker(program, second, first);
                            moverChecking.CreateGatePreservationChecker(program, first, second);
                            moverChecking.CreateFailurePreservationChecker(program, second, first);
                        }
                    }
                }
            }
        }
Пример #7
0
        public static void Transform(CivlTypeChecker civlTypeChecker)
        {
            var     linearTypeChecker = civlTypeChecker.linearTypeChecker;
            Program program           = linearTypeChecker.program;

            // Store the original declarations of yielding procedures, which will be removed after desugaring below.
            var origProc = program.TopLevelDeclarations.OfType <Procedure>()
                           .Where(p => civlTypeChecker.procToYieldingProc.ContainsKey(p));
            var origImpl = program.TopLevelDeclarations.OfType <Implementation>()
                           .Where(i => civlTypeChecker.procToYieldingProc.ContainsKey(i.Proc));
            List <Declaration> originalDecls = Enumerable.Union <Declaration>(origProc, origImpl).ToList();

            // Commutativity checks
            List <Declaration> decls = new List <Declaration>();

            if (!CommandLineOptions.Clo.TrustMoverTypes)
            {
                MoverCheck.AddCheckers(civlTypeChecker, decls);
            }

            // Desugaring of yielding procedures
            YieldingProcChecker.AddCheckers(civlTypeChecker, decls);

            // Linear type checks
            LinearTypeChecker.AddCheckers(civlTypeChecker, decls);

            if (!CommandLineOptions.Clo.TrustInductiveSequentialization)
            {
                InductiveSequentializationChecker.AddCheckers(civlTypeChecker);
            }

            PendingAsyncChecker.AddCheckers(civlTypeChecker);

            foreach (AtomicAction action in civlTypeChecker.procToAtomicAction.Values.Union(civlTypeChecker
                                                                                            .procToIsAbstraction.Values))
            {
                action.AddTriggerAssumes(program);
            }

            // Remove original declarations and add new checkers generated above
            program.RemoveTopLevelDeclarations(x => originalDecls.Contains(x));
            program.AddTopLevelDeclarations(decls);

            BackwardAssignmentSubstituter.SubstituteBackwardAssignments(civlTypeChecker.procToAtomicAction.Values);

            linearTypeChecker.EraseLinearAnnotations();
        }
Пример #8
0
        public static void AddCheckers(LinearTypeChecker linearTypeChecker, MoverTypeChecker moverTypeChecker, List<Declaration> decls)
        {
            if (moverTypeChecker.procToActionInfo.Count == 0)
                return;

            Dictionary<int, HashSet<ActionInfo>> pools = new Dictionary<int, HashSet<ActionInfo>>();
            foreach (ActionInfo action in moverTypeChecker.procToActionInfo.Values)
            {
                foreach (int phaseNum in action.callerPhaseNums)
                {
                    if (!pools.ContainsKey(phaseNum))
                    {
                        pools[phaseNum] = new HashSet<ActionInfo>();
                    }
                    pools[phaseNum].Add(action);
                }
            }

            Program program = moverTypeChecker.program;
            MoverCheck moverChecking = new MoverCheck(linearTypeChecker, moverTypeChecker, decls);
            foreach (int phaseNum in pools.Keys)
            {
                foreach (ActionInfo first in pools[phaseNum])
                {
                    Debug.Assert(first.moverType != MoverType.Top);
                    if (first.moverType == MoverType.Atomic)
                        continue;
                    foreach (ActionInfo second in pools[phaseNum])
                    {
                        if (first.IsRightMover)
                        {
                            moverChecking.CreateCommutativityChecker(program, first, second);
                            moverChecking.CreateGatePreservationChecker(program, second, first);
                        }
                        if (first.IsLeftMover)
                        {
                            moverChecking.CreateCommutativityChecker(program, second, first);
                            moverChecking.CreateGatePreservationChecker(program, first, second);
                            moverChecking.CreateFailurePreservationChecker(program, second, first);
                        }
                    }
                }
            }
        }
Пример #9
0
        public static void AddCheckers(LinearTypeChecker linearTypeChecker, CivlTypeChecker civlTypeChecker, List <Declaration> decls)
        {
            if (civlTypeChecker.procToAtomicAction.Count == 0)
            {
                return;
            }

            MoverCheck moverChecking = new MoverCheck(linearTypeChecker, civlTypeChecker, decls);

            foreach (int layer in civlTypeChecker.allAtomicActionLayers)
            {
                var pool = civlTypeChecker.procToAtomicAction.Values.Where(a => a.layerRange.Contains(layer));

                var moverChecks =
                    from first in pool
                    from second in pool
                    where first.moverType != MoverType.Atomic
                    select new { First = first, Second = second };

                foreach (var moverCheck in moverChecks)
                {
                    var first  = moverCheck.First.layerToActionCopy[layer];
                    var second = moverCheck.Second.layerToActionCopy[layer];

                    if (moverCheck.First.IsRightMover)
                    {
                        moverChecking.CreateCommutativityChecker(first, second);
                        moverChecking.CreateGatePreservationChecker(second, first);
                    }
                    if (moverCheck.First.IsLeftMover)
                    {
                        moverChecking.CreateCommutativityChecker(second, first);
                        moverChecking.CreateGatePreservationChecker(first, second);
                        moverChecking.CreateFailurePreservationChecker(second, first);
                    }
                }
                foreach (AtomicAction atomicAction in pool.Where(a => a.IsLeftMover))
                {
                    moverChecking.CreateNonBlockingChecker(atomicAction.layerToActionCopy[layer]);
                }
            }
        }
Пример #10
0
        public static void Transform(LinearTypeChecker linearTypeChecker, CivlTypeChecker civlTypeChecker)
        {
            List <Declaration> originalDecls = new List <Declaration>();
            Program            program       = linearTypeChecker.program;

            foreach (var decl in program.TopLevelDeclarations)
            {
                Procedure proc = decl as Procedure;
                if (proc != null && civlTypeChecker.procToActionInfo.ContainsKey(proc))
                {
                    originalDecls.Add(proc);
                    continue;
                }
                Implementation impl = decl as Implementation;
                if (impl != null && civlTypeChecker.procToActionInfo.ContainsKey(impl.Proc))
                {
                    originalDecls.Add(impl);
                }
            }

            List <Declaration> decls = new List <Declaration>();

            if (!CommandLineOptions.Clo.TrustAtomicityTypes)
            {
                MoverCheck.AddCheckers(linearTypeChecker, civlTypeChecker, decls);
            }
            CivlRefinement.AddCheckers(linearTypeChecker, civlTypeChecker, decls);
            foreach (AtomicActionInfo info in civlTypeChecker.procToActionInfo.Values.Where(x => x is AtomicActionInfo))
            {
                decls.AddRange(info.triggerFuns.Values);
            }
            foreach (Declaration decl in decls)
            {
                CivlAttributes.RemoveYieldsAttribute(decl);
            }
            program.RemoveTopLevelDeclarations(x => originalDecls.Contains(x));
            program.AddTopLevelDeclarations(decls);
        }
Пример #11
0
        public void TypeCheck()
        {
            foreach (Declaration decl in program.TopLevelDeclarations)
            {
                Procedure proc = decl as Procedure;
                if (proc == null)
                {
                    continue;
                }
                foreach (Ensures e in proc.Ensures)
                {
                    int       phaseNum;
                    MoverType moverType = MoverCheck.GetMoverType(e, out phaseNum);
                    if (moverType == MoverType.Top)
                    {
                        continue;
                    }
                    CodeExpr codeExpr = e.Condition as CodeExpr;
                    if (codeExpr == null)
                    {
                        Error(e, "An atomic action must be a CodeExpr");
                        continue;
                    }
                    if (procToActionInfo.ContainsKey(proc))
                    {
                        Error(proc, "A procedure can have at most one atomic action");
                        continue;
                    }
                    procToActionInfo[proc] = new ActionInfo(proc, codeExpr, moverType, phaseNum);
                }
            }
            this.VisitProgram(program);
#if QED
            YieldTypeChecker.PerformYieldTypeChecking(this);
#endif
        }
Пример #12
0
        public static void AddCheckers(LinearTypeChecker linearTypeChecker, CivlTypeChecker civlTypeChecker, List <Declaration> decls)
        {
            if (civlTypeChecker.procToActionInfo.Count == 0)
            {
                return;
            }

            List <ActionInfo> sortedByCreatedLayerNum = new List <ActionInfo>(civlTypeChecker.procToActionInfo.Values.Where(x => x is AtomicActionInfo && !x.isExtern));

            sortedByCreatedLayerNum.Sort((x, y) => { return((x.createdAtLayerNum == y.createdAtLayerNum) ? 0 : (x.createdAtLayerNum < y.createdAtLayerNum) ? -1 : 1); });
            List <ActionInfo> sortedByAvailableUptoLayerNum = new List <ActionInfo>(civlTypeChecker.procToActionInfo.Values.Where(x => x is AtomicActionInfo && !x.isExtern));

            sortedByAvailableUptoLayerNum.Sort((x, y) => { return((x.availableUptoLayerNum == y.availableUptoLayerNum) ? 0 : (x.availableUptoLayerNum < y.availableUptoLayerNum) ? -1 : 1); });

            Dictionary <int, HashSet <AtomicActionInfo> > pools = new Dictionary <int, HashSet <AtomicActionInfo> >();
            int indexIntoSortedByCreatedLayerNum       = 0;
            int indexIntoSortedByAvailableUptoLayerNum = 0;
            HashSet <AtomicActionInfo> currPool        = new HashSet <AtomicActionInfo>();

            while (indexIntoSortedByCreatedLayerNum < sortedByCreatedLayerNum.Count)
            {
                var currLayerNum = sortedByCreatedLayerNum[indexIntoSortedByCreatedLayerNum].createdAtLayerNum;
                pools[currLayerNum] = new HashSet <AtomicActionInfo>(currPool);
                while (indexIntoSortedByCreatedLayerNum < sortedByCreatedLayerNum.Count)
                {
                    var actionInfo = sortedByCreatedLayerNum[indexIntoSortedByCreatedLayerNum] as AtomicActionInfo;
                    if (actionInfo.createdAtLayerNum > currLayerNum)
                    {
                        break;
                    }
                    pools[currLayerNum].Add(actionInfo);
                    indexIntoSortedByCreatedLayerNum++;
                }
                while (indexIntoSortedByAvailableUptoLayerNum < sortedByAvailableUptoLayerNum.Count)
                {
                    var actionInfo = sortedByAvailableUptoLayerNum[indexIntoSortedByAvailableUptoLayerNum] as AtomicActionInfo;
                    if (actionInfo.availableUptoLayerNum > currLayerNum)
                    {
                        break;
                    }
                    pools[currLayerNum].Remove(actionInfo);
                    indexIntoSortedByAvailableUptoLayerNum++;
                }
                currPool = pools[currLayerNum];
            }

            // No atomic action has mover type Top
            Debug.Assert(pools.All(l => l.Value.All(a => a.moverType != MoverType.Top)));

            Program    program       = civlTypeChecker.program;
            MoverCheck moverChecking = new MoverCheck(linearTypeChecker, civlTypeChecker, decls);

            var moverChecks =
                from layer in pools.Keys
                from first in pools[layer]
                from second in pools[layer]
                where first.moverType != MoverType.Atomic
                select new { First = first, Second = second };

            foreach (var moverCheck in moverChecks)
            {
                var first  = moverCheck.First;
                var second = moverCheck.Second;

                if (first.IsRightMover)
                {
                    moverChecking.CreateCommutativityChecker(program, first, second);
                    moverChecking.CreateGatePreservationChecker(program, second, first);
                }
                if (first.IsLeftMover)
                {
                    moverChecking.CreateCommutativityChecker(program, second, first);
                    moverChecking.CreateGatePreservationChecker(program, first, second);
                    moverChecking.CreateFailurePreservationChecker(program, second, first);
                }
            }
            foreach (AtomicActionInfo atomicActionInfo in sortedByCreatedLayerNum)
            {
                if (atomicActionInfo.IsLeftMover && atomicActionInfo.hasAssumeCmd)
                {
                    moverChecking.CreateNonBlockingChecker(program, atomicActionInfo);
                }
            }
        }
Пример #13
0
        public static void AddCheckers(LinearTypeChecker linearTypeChecker, MoverTypeChecker moverTypeChecker, List <Declaration> decls)
        {
            if (moverTypeChecker.procToActionInfo.Count == 0)
            {
                return;
            }

            List <ActionInfo> sortedByCreatedLayerNum = new List <ActionInfo>(moverTypeChecker.procToActionInfo.Values.Where(x => x is AtomicActionInfo));

            sortedByCreatedLayerNum.Sort((x, y) => { return((x.createdAtLayerNum == y.createdAtLayerNum) ? 0 : (x.createdAtLayerNum < y.createdAtLayerNum) ? -1 : 1); });
            List <ActionInfo> sortedByAvailableUptoLayerNum = new List <ActionInfo>(moverTypeChecker.procToActionInfo.Values.Where(x => x is AtomicActionInfo));

            sortedByAvailableUptoLayerNum.Sort((x, y) => { return((x.availableUptoLayerNum == y.availableUptoLayerNum) ? 0 : (x.availableUptoLayerNum < y.availableUptoLayerNum) ? -1 : 1); });

            Dictionary <int, HashSet <AtomicActionInfo> > pools = new Dictionary <int, HashSet <AtomicActionInfo> >();
            int indexIntoSortedByCreatedLayerNum       = 0;
            int indexIntoSortedByAvailableUptoLayerNum = 0;
            HashSet <AtomicActionInfo> currPool        = new HashSet <AtomicActionInfo>();

            while (indexIntoSortedByCreatedLayerNum < sortedByCreatedLayerNum.Count)
            {
                var currLayerNum = sortedByCreatedLayerNum[indexIntoSortedByCreatedLayerNum].createdAtLayerNum;
                pools[currLayerNum] = new HashSet <AtomicActionInfo>(currPool);
                while (indexIntoSortedByCreatedLayerNum < sortedByCreatedLayerNum.Count)
                {
                    var actionInfo = sortedByCreatedLayerNum[indexIntoSortedByCreatedLayerNum] as AtomicActionInfo;
                    if (actionInfo.createdAtLayerNum > currLayerNum)
                    {
                        break;
                    }
                    pools[currLayerNum].Add(actionInfo);
                    indexIntoSortedByCreatedLayerNum++;
                }
                while (indexIntoSortedByAvailableUptoLayerNum < sortedByAvailableUptoLayerNum.Count)
                {
                    var actionInfo = sortedByAvailableUptoLayerNum[indexIntoSortedByAvailableUptoLayerNum] as AtomicActionInfo;
                    if (actionInfo.availableUptoLayerNum > currLayerNum)
                    {
                        break;
                    }
                    pools[currLayerNum].Remove(actionInfo);
                    indexIntoSortedByAvailableUptoLayerNum++;
                }
                currPool = pools[currLayerNum];
            }

            Program    program       = moverTypeChecker.program;
            MoverCheck moverChecking = new MoverCheck(linearTypeChecker, moverTypeChecker, decls);

            foreach (int layerNum in pools.Keys)
            {
                foreach (AtomicActionInfo first in pools[layerNum])
                {
                    Debug.Assert(first.moverType != MoverType.Top);
                    if (first.moverType == MoverType.Atomic)
                    {
                        continue;
                    }
                    foreach (AtomicActionInfo second in pools[layerNum])
                    {
                        if (first.IsRightMover)
                        {
                            moverChecking.CreateCommutativityChecker(program, first, second);
                            moverChecking.CreateGatePreservationChecker(program, second, first);
                        }
                        if (first.IsLeftMover)
                        {
                            moverChecking.CreateCommutativityChecker(program, second, first);
                            moverChecking.CreateGatePreservationChecker(program, first, second);
                            moverChecking.CreateFailurePreservationChecker(program, second, first);
                        }
                    }
                }
            }
            foreach (ActionInfo actionInfo in moverTypeChecker.procToActionInfo.Values)
            {
                AtomicActionInfo atomicActionInfo = actionInfo as AtomicActionInfo;
                if (atomicActionInfo != null && atomicActionInfo.IsLeftMover && atomicActionInfo.hasAssumeCmd)
                {
                    moverChecking.CreateNonBlockingChecker(program, atomicActionInfo);
                }
            }
        }
Пример #14
0
        public static void AddCheckers(LinearTypeChecker linearTypeChecker, CivlTypeChecker civlTypeChecker, List<Declaration> decls)
        {
            if (civlTypeChecker.procToActionInfo.Count == 0)
                return;

            List<ActionInfo> sortedByCreatedLayerNum = new List<ActionInfo>(civlTypeChecker.procToActionInfo.Values.Where(x => x is AtomicActionInfo && !x.isExtern));
            sortedByCreatedLayerNum.Sort((x, y) => { return (x.createdAtLayerNum == y.createdAtLayerNum) ? 0 : (x.createdAtLayerNum < y.createdAtLayerNum) ? -1 : 1; });
            List<ActionInfo> sortedByAvailableUptoLayerNum = new List<ActionInfo>(civlTypeChecker.procToActionInfo.Values.Where(x => x is AtomicActionInfo && !x.isExtern));
            sortedByAvailableUptoLayerNum.Sort((x, y) => { return (x.availableUptoLayerNum == y.availableUptoLayerNum) ? 0 : (x.availableUptoLayerNum < y.availableUptoLayerNum) ? -1 : 1; });

            Dictionary<int, HashSet<AtomicActionInfo>> pools = new Dictionary<int, HashSet<AtomicActionInfo>>();
            int indexIntoSortedByCreatedLayerNum = 0;
            int indexIntoSortedByAvailableUptoLayerNum = 0;
            HashSet<AtomicActionInfo> currPool = new HashSet<AtomicActionInfo>();
            while (indexIntoSortedByCreatedLayerNum < sortedByCreatedLayerNum.Count)
            {
                var currLayerNum = sortedByCreatedLayerNum[indexIntoSortedByCreatedLayerNum].createdAtLayerNum;
                pools[currLayerNum] = new HashSet<AtomicActionInfo>(currPool);
                while (indexIntoSortedByCreatedLayerNum < sortedByCreatedLayerNum.Count)
                {
                    var actionInfo = sortedByCreatedLayerNum[indexIntoSortedByCreatedLayerNum] as AtomicActionInfo;
                    if (actionInfo.createdAtLayerNum > currLayerNum) break;
                    pools[currLayerNum].Add(actionInfo);
                    indexIntoSortedByCreatedLayerNum++;
                }
                while (indexIntoSortedByAvailableUptoLayerNum < sortedByAvailableUptoLayerNum.Count)
                {
                    var actionInfo = sortedByAvailableUptoLayerNum[indexIntoSortedByAvailableUptoLayerNum] as AtomicActionInfo;
                    if (actionInfo.availableUptoLayerNum > currLayerNum) break;
                    pools[currLayerNum].Remove(actionInfo);
                    indexIntoSortedByAvailableUptoLayerNum++;
                }
                currPool = pools[currLayerNum];
            }

            // No atomic action has mover type Top
            Debug.Assert(pools.All(l => l.Value.All(a => a.moverType != MoverType.Top)));

            Program program = civlTypeChecker.program;
            MoverCheck moverChecking = new MoverCheck(linearTypeChecker, civlTypeChecker, decls);

            var moverChecks =
            from layer in pools.Keys
            from first in pools[layer]
            from second in pools[layer]
            where first.moverType != MoverType.Atomic
            select new { First = first, Second = second };

            foreach (var moverCheck in moverChecks)
            {
                var first = moverCheck.First;
                var second = moverCheck.Second;

                if (first.IsRightMover)
                {
                    moverChecking.CreateCommutativityChecker(program, first, second);
                    moverChecking.CreateGatePreservationChecker(program, second, first);
                }
                if (first.IsLeftMover)
                {
                    moverChecking.CreateCommutativityChecker(program, second, first);
                    moverChecking.CreateGatePreservationChecker(program, first, second);
                    moverChecking.CreateFailurePreservationChecker(program, second, first);
                }
            }
            foreach (AtomicActionInfo atomicActionInfo in sortedByCreatedLayerNum)
            {
                if (atomicActionInfo.IsLeftMover && atomicActionInfo.hasAssumeCmd)
                {
                    moverChecking.CreateNonBlockingChecker(program, atomicActionInfo);
                }
            }
        }