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); }
public MyDuplicator(MoverTypeChecker moverTypeChecker, int phaseNum) { this.moverTypeChecker = moverTypeChecker; this.phaseNum = phaseNum; this.procMap = new Dictionary<Procedure, Procedure>(); this.absyMap = new Dictionary<Absy, Absy>(); }
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); }
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); }
/* * PerformYieldTypeChecking : * 3.1 Input parameters : * 3.1.1 MoverTypeChecker moverTypeChecker : * 3.2 Action : This function is called in TypeCheck.cs. This is the only function that is externalized. This function traverses the program declarations and performs */ public static void PerformYieldTypeChecking(MoverTypeChecker moverTypeChecker) { Program yieldTypeCheckedProgram = moverTypeChecker.program; YieldTypeChecker regExprToAuto = new YieldTypeChecker(); foreach (var decl in yieldTypeCheckedProgram.TopLevelDeclarations) { Implementation impl = decl as Implementation; if (impl == null) { continue; } int phaseNumSpecImpl = moverTypeChecker.FindPhaseNumber(impl.Proc); YieldTypeCheckerCore yieldTypeCheckerPerImpl = new YieldTypeCheckerCore(moverTypeChecker); List <Tuple <int, int> > phaseIntervals = ComputePhaseIntervals(impl, phaseNumSpecImpl, moverTypeChecker); // Compute intervals for (int i = 0; i < phaseIntervals.Count; i++) // take current phase check num from each interval { int yTypeCheckCurrentPhaseNum = phaseIntervals[i].Item1; Automaton <BvSet> yieldTypeCheckAutoPerPhase = yieldTypeCheckerPerImpl.YieldTypeCheckAutomaton(impl, phaseNumSpecImpl, yTypeCheckCurrentPhaseNum); if (!IsYieldTypeSafe(yieldTypeCheckAutoPerPhase, impl, moverTypeChecker, i)) { moverTypeChecker.Error(impl, "\n Body of " + impl.Proc.Name + " is not yield type safe " + "\n"); } } } }
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); }
private MoverCheck(LinearTypeChecker linearTypeChecker, MoverTypeChecker moverTypeChecker, List <Declaration> decls) { this.linearTypeChecker = linearTypeChecker; this.moverTypeChecker = moverTypeChecker; this.decls = decls; this.commutativityCheckerCache = new HashSet <Tuple <AtomicActionInfo, AtomicActionInfo> >(); this.gatePreservationCheckerCache = new HashSet <Tuple <AtomicActionInfo, AtomicActionInfo> >(); this.failurePreservationCheckerCache = new HashSet <Tuple <AtomicActionInfo, AtomicActionInfo> >(); }
private MoverCheck(LinearTypeChecker linearTypeChecker, MoverTypeChecker moverTypeChecker, List<Declaration> decls) { this.linearTypeChecker = linearTypeChecker; this.moverTypeChecker = moverTypeChecker; this.decls = decls; this.commutativityCheckerCache = new HashSet<Tuple<ActionInfo, ActionInfo>>(); this.gatePreservationCheckerCache = new HashSet<Tuple<ActionInfo, ActionInfo>>(); this.failurePreservationCheckerCache = new HashSet<Tuple<ActionInfo, ActionInfo>>(); }
public MyDuplicator(MoverTypeChecker moverTypeChecker, int layerNum) { this.moverTypeChecker = moverTypeChecker; this.layerNum = layerNum; this.enclosingProc = null; this.enclosingImpl = null; this.procMap = new Dictionary<Procedure, Procedure>(); this.absyMap = new Dictionary<Absy, Absy>(); this.implMap = new Dictionary<Implementation, Implementation>(); this.yieldingProcs = new HashSet<Procedure>(); this.impls = new List<Implementation>(); }
private YieldTypeChecker(MoverTypeChecker moverTypeChecker, Implementation impl, int currLayerNum, IEnumerable <Block> loopHeaders) { this.moverTypeChecker = moverTypeChecker; this.impl = impl; this.currLayerNum = currLayerNum; this.loopHeaders = loopHeaders; this.stateCounter = 0; this.absyToNode = new Dictionary <Absy, int>(); this.initialState = 0; this.finalStates = new HashSet <int>(); this.edgeLabels = new Dictionary <Tuple <int, int>, int>(); foreach (Block block in impl.Blocks) { absyToNode[block] = stateCounter; stateCounter++; foreach (Cmd cmd in block.Cmds) { absyToNode[cmd] = stateCounter; stateCounter++; } absyToNode[block.TransferCmd] = stateCounter; stateCounter++; if (block.TransferCmd is ReturnCmd) { finalStates.Add(absyToNode[block.TransferCmd]); } } foreach (Block block in impl.Blocks) { Absy blockEntry = block.Cmds.Count == 0 ? (Absy)block.TransferCmd : (Absy)block.Cmds[0]; edgeLabels[new Tuple <int, int>(absyToNode[block], absyToNode[blockEntry])] = 'P'; GotoCmd gotoCmd = block.TransferCmd as GotoCmd; if (gotoCmd == null) { continue; } foreach (Block successor in gotoCmd.labelTargets) { edgeLabels[new Tuple <int, int>(absyToNode[gotoCmd], absyToNode[successor])] = 'P'; } } this.nodeToAbsy = new Dictionary <int, Absy>(); foreach (KeyValuePair <Absy, int> state in absyToNode) { this.nodeToAbsy[state.Value] = state.Key; } ComputeGraph(); IsYieldTypeSafe(); }
/* ComputePhaseIntervals : 1.1 Input parameters : 1.1.1 Implementation impl : Implementation whose body is being YTS checked. 1.1.2 int specPhaseNumImpl : Phase number in which procedure of implementation, impl, reaches its specification,{A,R,L,B} 1.1.3 MoverTypeChecker moverTypeChecker : moverTypeChecker is the integration point of YieldTypeChecker to OG class. moverTypeChecker has functions enables YieldTypeChecker to find phaseNum and spec of procedures. 1.2 Return value : is a list of tuples(phase interval start,phase interval end). Every tuple in this list is representing an interval formed by callCmds' phase numbers inside impl. 1.3 Action : This function first traverses the blocks inside impl, collects all CallCmds inside it into a HashSet ,callCmdsInImpl. * Then it puts all these callCmds' phase numbers into a HashSet,callCmdPhaseNumSet. * After adding all callCmds' phase numbers' it adds phase number of procedure of impl into the set. * It sorts all numbers in this set and creates [-inf...n-1] [n...k-1] [k PhaseNumProcOfImpl] disjoint intervals. */ private static List<Tuple<int, int>> ComputePhaseIntervals(Implementation impl, int specPhaseNumImpl, MoverTypeChecker moverTypeChecker) { HashSet<CallCmd> callCmdsInImpl = new HashSet<CallCmd>(); // callCmdsInImpl[Implementation] ==> Set = { call1, call2, call3 ... } List<Tuple<int, int>> phaseIntervals = new List<Tuple<int, int>>(); // [MinValue ph0 ] [ph0 ph1] [ph1 ph2] ..... [phk phk+1] intervals // Compute CallCmds inside impl foreach (Block b in impl.Blocks) { for (int i = 0; i < b.Cmds.Count; i++) { CallCmd callCmd = b.Cmds[i] as CallCmd; if (callCmd == null) continue; callCmdsInImpl.Add(callCmd); } } //Collect phase numbers of CallCmds inside impl HashSet<int> callCmdPhaseNumSet = new HashSet<int>(); foreach (CallCmd callCmd in callCmdsInImpl) { int tmpPhaseNum = moverTypeChecker.FindPhaseNumber(callCmd.Proc); callCmdPhaseNumSet.Add(tmpPhaseNum); } callCmdPhaseNumSet.Add(specPhaseNumImpl); List<int> callCmdPhaseNumList = callCmdPhaseNumSet.ToList(); callCmdPhaseNumList.Sort(); //Create Phase Intervals for (int i = 0; i < callCmdPhaseNumList.Count; i++) { //create the initial phase (-inf leastPhaseNum] if (i == 0) { Tuple<int, int> initTuple = new Tuple<int, int>(int.MinValue, callCmdPhaseNumList[i]); phaseIntervals.Add(initTuple); } else // create other phase intervals { Tuple<int, int> intervalToInsert = new Tuple<int, int>(callCmdPhaseNumList[i - 1] + 1, callCmdPhaseNumList[i]); phaseIntervals.Add(intervalToInsert); } } #if (DEBUG && !DEBUG_DETAIL) Console.Write("\n Number of phases is " + phaseIntervals.Count.ToString()); for (int i = 0;i<phaseIntervals.Count ; i++) { Console.Write("\n Phase " + i.ToString() + "[" + phaseIntervals[i].Item1.ToString() + "," + phaseIntervals[i].Item2.ToString() + "]" + "\n"); } #endif return phaseIntervals; }
private YieldTypeChecker(MoverTypeChecker moverTypeChecker, Implementation impl, int currLayerNum, IEnumerable<Block> loopHeaders) { this.moverTypeChecker = moverTypeChecker; this.impl = impl; this.currLayerNum = currLayerNum; this.loopHeaders = loopHeaders; this.stateCounter = 0; this.absyToNode = new Dictionary<Absy, int>(); this.initialState = 0; this.finalStates = new HashSet<int>(); this.edgeLabels = new Dictionary<Tuple<int, int>, int>(); foreach (Block block in impl.Blocks) { absyToNode[block] = stateCounter; stateCounter++; foreach (Cmd cmd in block.Cmds) { absyToNode[cmd] = stateCounter; stateCounter++; } absyToNode[block.TransferCmd] = stateCounter; stateCounter++; if (block.TransferCmd is ReturnCmd) { finalStates.Add(absyToNode[block.TransferCmd]); } } foreach (Block block in impl.Blocks) { Absy blockEntry = block.Cmds.Count == 0 ? (Absy)block.TransferCmd : (Absy)block.Cmds[0]; edgeLabels[new Tuple<int, int>(absyToNode[block], absyToNode[blockEntry])] = 'P'; GotoCmd gotoCmd = block.TransferCmd as GotoCmd; if (gotoCmd == null) continue; foreach (Block successor in gotoCmd.labelTargets) { edgeLabels[new Tuple<int, int>(absyToNode[gotoCmd], absyToNode[successor])] = 'P'; } } this.nodeToAbsy = new Dictionary<int, Absy>(); foreach (KeyValuePair<Absy, int> state in absyToNode) { this.nodeToAbsy[state.Value] = state.Key; } ComputeGraph(); IsYieldTypeSafe(); }
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); } } } } }
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); } } } } }
public static void PerformYieldSafeCheck(MoverTypeChecker moverTypeChecker) { foreach (var impl in moverTypeChecker.program.Implementations) { if (!moverTypeChecker.procToActionInfo.ContainsKey(impl.Proc)) { continue; } impl.PruneUnreachableBlocks(); Graph <Block> implGraph = Program.GraphFromImpl(impl); implGraph.ComputeLoops(); int specLayerNum = moverTypeChecker.procToActionInfo[impl.Proc].createdAtLayerNum; foreach (int layerNum in moverTypeChecker.AllCreatedLayerNums.Except(new int[] { moverTypeChecker.leastUnimplementedLayerNum })) { if (layerNum > specLayerNum) { continue; } YieldTypeChecker executor = new YieldTypeChecker(moverTypeChecker, impl, layerNum, implGraph.Headers); } } }
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); } } }
public static void PerformYieldSafeCheck(MoverTypeChecker moverTypeChecker) { foreach (var impl in moverTypeChecker.program.Implementations) { if (!moverTypeChecker.procToActionInfo.ContainsKey(impl.Proc)) continue; impl.PruneUnreachableBlocks(); Graph<Block> implGraph = Program.GraphFromImpl(impl); implGraph.ComputeLoops(); int specLayerNum = moverTypeChecker.procToActionInfo[impl.Proc].createdAtLayerNum; foreach (int layerNum in moverTypeChecker.AllCreatedLayerNums.Except(new int[] { moverTypeChecker.leastUnimplementedLayerNum })) { if (layerNum > specLayerNum) continue; YieldTypeChecker executor = new YieldTypeChecker(moverTypeChecker, impl, layerNum, implGraph.Headers); } } }
public OwickiGries(LinearTypeChecker linearTypeChecker, MoverTypeChecker moverTypeChecker, MyDuplicator duplicator) { this.linearTypeChecker = linearTypeChecker; this.moverTypeChecker = moverTypeChecker; this.absyMap = duplicator.absyMap; this.layerNum = duplicator.layerNum; this.implMap = duplicator.implMap; this.yieldingProcs = duplicator.yieldingProcs; Program program = linearTypeChecker.program; globalMods = new List<IdentifierExpr>(); foreach (Variable g in moverTypeChecker.SharedVariables) { globalMods.Add(Expr.Ident(g)); } asyncAndParallelCallDesugarings = new Dictionary<string, Procedure>(); yieldCheckerProcs = new List<Procedure>(); yieldCheckerImpls = new List<Implementation>(); yieldProc = null; }
public static void AddCheckers(LinearTypeChecker linearTypeChecker, MoverTypeChecker moverTypeChecker, List<Declaration> decls) { Program program = linearTypeChecker.program; foreach (int layerNum in moverTypeChecker.AllCreatedLayerNums.Except(new int[] { moverTypeChecker.leastUnimplementedLayerNum })) { if (CommandLineOptions.Clo.TrustLayersDownto <= layerNum || layerNum <= CommandLineOptions.Clo.TrustLayersUpto) continue; MyDuplicator duplicator = new MyDuplicator(moverTypeChecker, layerNum); foreach (var proc in program.Procedures) { if (!moverTypeChecker.procToActionInfo.ContainsKey(proc)) continue; Procedure duplicateProc = duplicator.VisitProcedure(proc); decls.Add(duplicateProc); } decls.AddRange(duplicator.impls); OwickiGries ogTransform = new OwickiGries(linearTypeChecker, moverTypeChecker, duplicator); foreach (var impl in program.Implementations) { if (!moverTypeChecker.procToActionInfo.ContainsKey(impl.Proc) || moverTypeChecker.procToActionInfo[impl.Proc].createdAtLayerNum < layerNum) continue; Implementation duplicateImpl = duplicator.VisitImplementation(impl); ogTransform.TransformImpl(duplicateImpl); decls.Add(duplicateImpl); } decls.AddRange(ogTransform.Collect()); } }
/* * ComputePhaseIntervals : * 1.1 Input parameters : * 1.1.1 Implementation impl : Implementation whose body is being YTS checked. * 1.1.2 int specPhaseNumImpl : Phase number in which procedure of implementation, impl, reaches its specification,{A,R,L,B} * 1.1.3 MoverTypeChecker moverTypeChecker : moverTypeChecker is the integration point of YieldTypeChecker to OG class. moverTypeChecker has functions enables YieldTypeChecker to find phaseNum and spec of procedures. * * 1.2 Return value : is a list of tuples(phase interval start,phase interval end). Every tuple in this list is representing an interval formed by callCmds' phase numbers inside impl. * 1.3 Action : This function first traverses the blocks inside impl, collects all CallCmds inside it into a HashSet ,callCmdsInImpl. * Then it puts all these callCmds' phase numbers into a HashSet,callCmdPhaseNumSet. * After adding all callCmds' phase numbers' it adds phase number of procedure of impl into the set. * It sorts all numbers in this set and creates [-inf...n-1] [n...k-1] [k PhaseNumProcOfImpl] disjoint intervals. */ private static List <Tuple <int, int> > ComputePhaseIntervals(Implementation impl, int specPhaseNumImpl, MoverTypeChecker moverTypeChecker) { HashSet <CallCmd> callCmdsInImpl = new HashSet <CallCmd>(); // callCmdsInImpl[Implementation] ==> Set = { call1, call2, call3 ... } List <Tuple <int, int> > phaseIntervals = new List <Tuple <int, int> >(); // [MinValue ph0 ] [ph0 ph1] [ph1 ph2] ..... [phk phk+1] intervals // Compute CallCmds inside impl foreach (Block b in impl.Blocks) { for (int i = 0; i < b.Cmds.Count; i++) { CallCmd callCmd = b.Cmds[i] as CallCmd; if (callCmd == null) { continue; } callCmdsInImpl.Add(callCmd); } } //Collect phase numbers of CallCmds inside impl HashSet <int> callCmdPhaseNumSet = new HashSet <int>(); foreach (CallCmd callCmd in callCmdsInImpl) { int tmpPhaseNum = moverTypeChecker.FindPhaseNumber(callCmd.Proc); callCmdPhaseNumSet.Add(tmpPhaseNum); } callCmdPhaseNumSet.Add(specPhaseNumImpl); List <int> callCmdPhaseNumList = callCmdPhaseNumSet.ToList(); callCmdPhaseNumList.Sort(); //Create Phase Intervals for (int i = 0; i < callCmdPhaseNumList.Count; i++) { //create the initial phase (-inf leastPhaseNum] if (i == 0) { Tuple <int, int> initTuple = new Tuple <int, int>(int.MinValue, callCmdPhaseNumList[i]); phaseIntervals.Add(initTuple); } else // create other phase intervals { Tuple <int, int> intervalToInsert = new Tuple <int, int>(callCmdPhaseNumList[i - 1] + 1, callCmdPhaseNumList[i]); phaseIntervals.Add(intervalToInsert); } } #if (DEBUG && !DEBUG_DETAIL) Console.Write("\n Number of phases is " + phaseIntervals.Count.ToString()); for (int i = 0; i < phaseIntervals.Count; i++) { Console.Write("\n Phase " + i.ToString() + "[" + phaseIntervals[i].Item1.ToString() + "," + phaseIntervals[i].Item2.ToString() + "]" + "\n"); } #endif return(phaseIntervals); }
public YieldTypeCheckerCore(MoverTypeChecker moverTypeChecker) { this.moverTypeChecker = moverTypeChecker; }
/* PerformYieldTypeChecking : 3.1 Input parameters : 3.1.1 MoverTypeChecker moverTypeChecker : 3.2 Action : This function is called in TypeCheck.cs. This is the only function that is externalized. This function traverses the program declarations and performs */ public static void PerformYieldTypeChecking(MoverTypeChecker moverTypeChecker) { Program yieldTypeCheckedProgram = moverTypeChecker.program; YieldTypeChecker regExprToAuto = new YieldTypeChecker(); foreach (var decl in yieldTypeCheckedProgram.TopLevelDeclarations) { Implementation impl = decl as Implementation; if (impl == null) continue; int phaseNumSpecImpl = moverTypeChecker.FindPhaseNumber(impl.Proc); YieldTypeCheckerCore yieldTypeCheckerPerImpl = new YieldTypeCheckerCore(moverTypeChecker); List<Tuple<int, int>> phaseIntervals = ComputePhaseIntervals(impl, phaseNumSpecImpl, moverTypeChecker); // Compute intervals for (int i = 0; i < phaseIntervals.Count; i++) // take current phase check num from each interval { int yTypeCheckCurrentPhaseNum = phaseIntervals[i].Item1; Automaton<BvSet> yieldTypeCheckAutoPerPhase = yieldTypeCheckerPerImpl.YieldTypeCheckAutomaton(impl, phaseNumSpecImpl, yTypeCheckCurrentPhaseNum); if (!IsYieldTypeSafe(yieldTypeCheckAutoPerPhase, impl, moverTypeChecker, i)) { moverTypeChecker.Error(impl, "\n Body of " + impl.Proc.Name + " is not yield type safe " + "\n"); } } } }
/* * IsYieldTypeSafe : * 2.1 Input parameters : * 2.1.1 Automaton<BvSet> implTypeCheckAutomaton : This input Automaton is generated for a phase of YTS checking of an impl. * 2.2 Return value : returns true if input automaton is subset of YTS property autoamaton. * 2.3 Action : Subset checking for a phase of an implementation. f L(YTSI) is subset of L(YTSP) {TRUE} else {FALSE} */ public static bool IsYieldTypeSafe(Automaton <BvSet> implTypeCheckAutomaton, Implementation impl, MoverTypeChecker moverTypeChecker, int phaseNum) { List <BvSet> witnessSet; var isNonEmpty = Automaton <BvSet> .CheckDifference( implTypeCheckAutomaton, yieldTypeCheckerAutomaton, 0, yieldTypeCheckerAutomatonSolver, out witnessSet); #if DEBUG && !DEBUG_DETAIL var diffAutomaton = implTypeCheckAutomaton.Minus(yieldTypeCheckerAutomaton, yieldTypeCheckerAutomatonSolver); string diffAutomatonGraphName = "diffAutomaton" + impl.Proc.Name + phaseNum.ToString(); yieldTypeCheckerAutomatonSolver.ShowGraph(diffAutomaton, diffAutomatonGraphName + ".dgml"); #endif #if DEBUG && !DEBUG_DETAIL string s = yieldTypeCheckerAutomatonSolver.GenerateMember(implTypeCheckAutomaton); Console.WriteLine("\n member " + s + " \n"); if (!yieldTypeCheckerAutomatonSolver.Accepts(yieldTypeCheckerAutomaton, s)) { Console.WriteLine("Property Automaton accepts a random member of impl_automaton " + s); } else { Console.WriteLine("Property Automaton does not accept a random member of impl_automaton " + s); } #endif if (isNonEmpty) { var witness = new String(Array.ConvertAll(witnessSet.ToArray(), bvset => (char)yieldTypeCheckerAutomatonSolver.Choose(bvset))); moverTypeChecker.Error(impl, "\n Body of " + impl.Proc.Name + " has invalid trace of actions " + witness + "\n"); return(false); } return(true); }
public static void AddCheckers(LinearTypeChecker linearTypeChecker, MoverTypeChecker moverTypeChecker, List<Declaration> decls) { }
/// <summary> /// Resolves and type checks the given Boogie program. Any errors are reported to the /// console. Returns: /// - Done if no errors occurred, and command line specified no resolution or no type checking. /// - ResolutionError if a resolution error occurred /// - TypeCheckingError if a type checking error occurred /// - ResolvedAndTypeChecked if both resolution and type checking succeeded /// </summary> public static PipelineOutcome ResolveAndTypecheck(Program program, string bplFileName, out LinearTypeChecker linearTypeChecker, out MoverTypeChecker moverTypeChecker) { Contract.Requires(program != null); Contract.Requires(bplFileName != null); linearTypeChecker = null; moverTypeChecker = null; // ---------- Resolve ------------------------------------------------------------ if (CommandLineOptions.Clo.NoResolve) { return PipelineOutcome.Done; } int errorCount = program.Resolve(); if (errorCount != 0) { Console.WriteLine("{0} name resolution errors detected in {1}", errorCount, GetFileNameForConsole(bplFileName)); return PipelineOutcome.ResolutionError; } // ---------- Type check ------------------------------------------------------------ if (CommandLineOptions.Clo.NoTypecheck) { return PipelineOutcome.Done; } errorCount = program.Typecheck(); if (errorCount != 0) { Console.WriteLine("{0} type checking errors detected in {1}", errorCount, GetFileNameForConsole(bplFileName)); return PipelineOutcome.TypeCheckingError; } if (PolymorphismChecker.IsMonomorphic(program)) { CommandLineOptions.Clo.TypeEncodingMethod = CommandLineOptions.TypeEncoding.Monomorphic; } CollectModSets(program); moverTypeChecker = new MoverTypeChecker(program); moverTypeChecker.TypeCheck(); if (moverTypeChecker.errorCount != 0) { Console.WriteLine("{0} type checking errors detected in {1}", moverTypeChecker.errorCount, GetFileNameForConsole(bplFileName)); return PipelineOutcome.TypeCheckingError; } linearTypeChecker = new LinearTypeChecker(program); linearTypeChecker.TypeCheck(); if (linearTypeChecker.errorCount == 0) { linearTypeChecker.Transform(); } else { Console.WriteLine("{0} type checking errors detected in {1}", linearTypeChecker.errorCount, GetFileNameForConsole(bplFileName)); return PipelineOutcome.TypeCheckingError; } if (CommandLineOptions.Clo.PrintFile != null && CommandLineOptions.Clo.PrintDesugarings) { // if PrintDesugaring option is engaged, print the file here, after resolution and type checking PrintBplFile(CommandLineOptions.Clo.PrintFile, program, true, true, CommandLineOptions.Clo.PrettyPrint); } return PipelineOutcome.ResolvedAndTypeChecked; }
public static void AddCheckers(LinearTypeChecker linearTypeChecker, MoverTypeChecker moverTypeChecker, List <Declaration> decls) { }
public YieldTypeCheckerCore(MoverTypeChecker moverTypeChecker) { this.moverTypeChecker = moverTypeChecker; }
/* IsYieldTypeSafe : 2.1 Input parameters : 2.1.1 Automaton<BvSet> implTypeCheckAutomaton : This input Automaton is generated for a phase of YTS checking of an impl. 2.2 Return value : returns true if input automaton is subset of YTS property autoamaton. 2.3 Action : Subset checking for a phase of an implementation. f L(YTSI) is subset of L(YTSP) {TRUE} else {FALSE} */ public static bool IsYieldTypeSafe(Automaton<BvSet> implTypeCheckAutomaton, Implementation impl, MoverTypeChecker moverTypeChecker, int phaseNum) { List<BvSet> witnessSet; var isNonEmpty = Automaton<BvSet>.CheckDifference( implTypeCheckAutomaton, yieldTypeCheckerAutomaton, 0, yieldTypeCheckerAutomatonSolver, out witnessSet); #if DEBUG && !DEBUG_DETAIL var diffAutomaton = implTypeCheckAutomaton.Minus(yieldTypeCheckerAutomaton, yieldTypeCheckerAutomatonSolver); string diffAutomatonGraphName = "diffAutomaton" + impl.Proc.Name + phaseNum.ToString(); yieldTypeCheckerAutomatonSolver.ShowGraph(diffAutomaton, diffAutomatonGraphName+".dgml"); #endif #if DEBUG && !DEBUG_DETAIL string s = yieldTypeCheckerAutomatonSolver.GenerateMember(implTypeCheckAutomaton); Console.WriteLine("\n member " + s+ " \n"); if(!yieldTypeCheckerAutomatonSolver.Accepts(yieldTypeCheckerAutomaton,s)){ Console.WriteLine("Property Automaton accepts a random member of impl_automaton " + s); }else{ Console.WriteLine("Property Automaton does not accept a random member of impl_automaton " + s); } #endif if (isNonEmpty) { var witness = new String(Array.ConvertAll(witnessSet.ToArray(), bvset => (char)yieldTypeCheckerAutomatonSolver.Choose(bvset))); moverTypeChecker.Error(impl, "\n Body of " + impl.Proc.Name + " has invalid trace of actions " + witness + "\n"); return false; } return true; }
public static void AddCheckers(LinearTypeChecker linearTypeChecker, MoverTypeChecker moverTypeChecker, List<Declaration> decls) { Program program = linearTypeChecker.program; foreach (int phaseNum in moverTypeChecker.assertionPhaseNums) { MyDuplicator duplicator = new MyDuplicator(moverTypeChecker, phaseNum); List<Implementation> impls = new List<Implementation>(); List<Procedure> procs = new List<Procedure>(); foreach (var decl in program.TopLevelDeclarations) { Procedure proc = decl as Procedure; if (proc == null || !QKeyValue.FindBoolAttribute(proc.Attributes, "yields")) continue; Procedure duplicateProc = duplicator.VisitProcedure(proc); procs.Add(duplicateProc); if (moverTypeChecker.procToActionInfo.ContainsKey(proc) && moverTypeChecker.procToActionInfo[proc].phaseNum < phaseNum) { duplicateProc.Attributes = OwickiGries.RemoveYieldsAttribute(duplicateProc.Attributes); program.GlobalVariables().Iter(x => duplicateProc.Modifies.Add(new IdentifierExpr(Token.NoToken, x))); CodeExpr action = (CodeExpr)duplicator.VisitCodeExpr(moverTypeChecker.procToActionInfo[proc].thisAction); Implementation impl = new Implementation(Token.NoToken, duplicateProc.Name, proc.TypeParameters, proc.InParams, proc.OutParams, new List<Variable>(), action.Blocks); impl.Proc = duplicateProc; impl.Proc.AddAttribute("inline", new LiteralExpr(Token.NoToken, Microsoft.Basetypes.BigNum.FromInt(1))); impl.AddAttribute("inline", new LiteralExpr(Token.NoToken, Microsoft.Basetypes.BigNum.FromInt(1))); impls.Add(impl); } } foreach (var decl in program.TopLevelDeclarations) { Implementation impl = decl as Implementation; if (impl == null || !QKeyValue.FindBoolAttribute(impl.Proc.Attributes, "yields") || (moverTypeChecker.procToActionInfo.ContainsKey(impl.Proc) && moverTypeChecker.procToActionInfo[impl.Proc].phaseNum < phaseNum)) continue; Implementation duplicateImpl = duplicator.VisitImplementation(impl); impls.Add(duplicateImpl); } Dictionary<Absy, Absy> reverseAbsyMap = new Dictionary<Absy, Absy>(); foreach (Absy key in duplicator.absyMap.Keys) { reverseAbsyMap[duplicator.absyMap[key]] = key; } OwickiGries ogTransform = new OwickiGries(linearTypeChecker, reverseAbsyMap, phaseNum, decls); ogTransform.Transform(impls, procs); } }