Beispiel #1
0
        public InductiveSequentialization(AtomicAction inputAction, AtomicAction outputAction,
                                          AtomicAction invariantAction, Dictionary <AtomicAction, AtomicAction> elim)
        {
            this.inputAction     = inputAction;
            this.outputAction    = outputAction;
            this.invariantAction = invariantAction;
            this.elim            = elim;

            // TODO: check frame computation
            // We could compute a tighter frame per check. For example, base/conclusion checkers
            // don't have to take the eliminated actions into account.
            var frameVars = new List <AtomicAction> {
                invariantAction, outputAction, inputAction
            }
            .Union(elim.Select(kv => kv.Value))
            .SelectMany(a => a.gateUsedGlobalVars.Union(a.modifiedGlobalVars)).Distinct();

            this.frame    = new HashSet <Variable>(frameVars);
            this.modifies = frame.Select(Expr.Ident).ToList();

            newPAs = Expr.Ident(VarHelper.LocalVariable("newPAs", PendingAsyncMultisetType));
            if (HasChoice)
            {
                choice = Expr.Ident(invariantAction.impl.OutParams.Last());
            }
            else
            {
                choice = Expr.Ident(VarHelper.LocalVariable("choice", PendingAsyncType));
            }
        }
            private void AddBoundVariablesForRemainingVars()
            {
                var remainingVars = NotEliminatedVars.Except(IntermediateFrameWithWitnesses);

                existsVarMap = remainingVars.ToDictionary(v => (Variable)VarHelper.BoundVariable(v.Name, v.TypedIdent.Type));
                pathExprs    = SubstitutionHelper.Apply(existsVarMap, pathExprs).ToList();
            }
Beispiel #3
0
        public static void AddCheckers(CivlTypeChecker ctc)
        {
            foreach (var action in ctc.AllAtomicActions.Where(a => a.HasPendingAsyncs))
            {
                var requires = action.gate.Select(g => new Requires(false, g.Expr)).ToList();
                var cmds     = new List <Cmd>
                {
                    CmdHelper.CallCmd(
                        action.proc,
                        action.impl.InParams.Select(Expr.Ident).ToList <Expr>(),
                        action.impl.OutParams.Select(Expr.Ident).ToList())
                };
                var blocks = new List <Block>()
                {
                    new Block(Token.NoToken, "init", cmds, CmdHelper.ReturnCmd)
                };

                var PAs     = Expr.Ident(action.impl.OutParams.Last(p => p.TypedIdent.Type.Equals(ctc.pendingAsyncMultisetType)));
                var paBound = VarHelper.BoundVariable("pa", ctc.pendingAsyncType);
                var pa      = Expr.Ident(paBound);

                var nonnegativeExpr =
                    new ForallExpr(Token.NoToken, new List <Variable> {
                    paBound
                },
                                   Expr.Ge(Expr.Select(PAs, pa), Expr.Literal(0)));
                var correctTypeExpr = new ForallExpr(Token.NoToken, new List <Variable> {
                    paBound
                },
                                                     Expr.Imp(
                                                         Expr.Gt(Expr.Select(PAs, pa), Expr.Literal(0)),
                                                         Expr.Or(action.pendingAsyncs.Select(a => ExprHelper.FunctionCall(a.pendingAsyncCtor.membership, pa)))));
                var ensures = new List <Ensures>
                {
                    new Ensures(false, nonnegativeExpr)
                    {
                        ErrorData = $"Action {action.proc.Name} might create negative pending asyncs"
                    },
                    new Ensures(false, correctTypeExpr)
                    {
                        ErrorData = $"Action {action.proc.Name} might create undeclared pending asyncs"
                    },
                };

                CivlUtil.ResolveAndTypecheck(ensures);

                var proc = new Procedure(Token.NoToken, $"PendingAsyncChecker_{action.proc.Name}", new List <TypeVariable>(),
                                         action.impl.InParams, action.impl.OutParams,
                                         requires, action.proc.Modifies, ensures);
                var impl = new Implementation(Token.NoToken, proc.Name, proc.TypeParameters,
                                              proc.InParams, proc.OutParams, new List <Variable>(), blocks)
                {
                    Proc = proc
                };

                ctc.program.AddTopLevelDeclaration(proc);
                ctc.program.AddTopLevelDeclaration(impl);
            }
        }
            private void MakeNewCopy(Variable v)
            {
                int id      = varCopies[v].Count;
                var copyVar = VarHelper.LocalVariable(string.Format(copierFormat, v.Name, id), v.TypedIdent.Type);

                varCopies[v].Add(copyVar);
                copyToOriginalVar[copyVar] = v;
            }
Beispiel #5
0
            private void AddBoundVariablesForRemainingVars()
            {
                var remainingVars = NotEliminatedVars.Except(IntermediateFrameWithWitnesses);

                existsVarMap = remainingVars.ToDictionary(v => v, v => (Variable)VarHelper.BoundVariable(v.Name, v.TypedIdent.Type));
                var substMap = remainingVars.ToDictionary(v => copyToOriginalVar[v], v => existsVarMap[v]);

                existsVarMap.Iter(kv => kv.Value.Attributes = CloneAttributes(copyToOriginalVar[kv.Key].Attributes, substMap));
                pathExprs = SubstitutionHelper.Apply(existsVarMap, pathExprs).ToList();
            }
 private void DeclareTriggerFunctions()
 {
     triggerFunctions = new Dictionary <Variable, Function>();
     foreach (var v in impl.LocVars)
     {
         List <Variable> args = new List <Variable> {
             VarHelper.Formal(v.Name, v.TypedIdent.Type, true)
         };
         Variable result = VarHelper.Formal("r", Type.Bool, false);
         triggerFunctions[v] = new Function(Token.NoToken, $"Trigger_{impl.Name}_{v.Name}", args, result);
     }
     for (int i = 0; i < impl.LocVars.Count; i++)
     {
         triggerFunctions[firstImpl.LocVars[i]]  = triggerFunctions[impl.LocVars[i]];
         triggerFunctions[secondImpl.LocVars[i]] = triggerFunctions[impl.LocVars[i]];
     }
 }
Beispiel #7
0
 private static LocalVariable CopyLocal(Variable v)
 {
     return(VarHelper.LocalVariable(v.Name, v.TypedIdent.Type));
 }