From 264838b2ecc5bb96c0e4aa05887fd2d3a6126f9d Mon Sep 17 00:00:00 2001 From: Cat's Eye Technologies Date: Fri, 11 Apr 2014 12:50:41 +0100 Subject: [PATCH] Use weaker version of updateRoutCtx in merge. All tests pass. --- src/SixtyPical/Analyzer.hs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/SixtyPical/Analyzer.hs b/src/SixtyPical/Analyzer.hs index 0b86055..ef0f2c8 100644 --- a/src/SixtyPical/Analyzer.hs +++ b/src/SixtyPical/Analyzer.hs @@ -127,11 +127,12 @@ mergeRoutCtxs nm routCtx calledRoutCtx calledRout@(Routine name outputs _) = -- Take 2 routine contexts -- one from each branch of an `if` -- and merge -- them to create a new context for the remainder of the routine. -- --- TODO: this merge is "too sensitive" in a way that needs to be better --- understood and documented. It is that it is using updateRoutCtx to --- make the merged resultant context, but that routine raises an error --- if the new usage is replacing a poisoned entry. It should be "more OK" --- with replacing a poisoned entry, here. +-- We use a weaker version of updateRoutCtx to build the merged context. +-- We do this because accessing a poisoned storage location from either +-- of the branch contexts is not an error at the merge point -- we simply +-- make the storage location poisoned in the resulting context. (If the +-- poisoned location is accessed subsequently to the merge point, that is +-- of course still an error.) -- mergeAlternateRoutCtxs nm routCtx1 routCtx2 = let @@ -154,3 +155,14 @@ mergeAlternateRoutCtxs nm routCtx1 routCtx2 = updateRoutCtx nm location newUsage routCtxAccum in Map.foldrWithKey (poison) routCtx1 routCtx2 + where + -- a weaker version of updateRoutCtx, which does not error if + -- we access a poisoned source + updateRoutCtx nm dst (UpdatedWith src) routCtx = + let + s = untypedLocation src + d = untypedLocation dst + in + Map.insert d (UpdatedWith s) routCtx + updateRoutCtx nm dst (PoisonedWith src) routCtx = + Map.insert (untypedLocation dst) (PoisonedWith $ untypedLocation src) routCtx