Skip to content

Commit 4868cb5

Browse files
authored
Merge pull request #2757 from GaloisInc/bh/issue2749
Avoid applying Nat recursor to bvToNat.
2 parents 213f9ed + f5e2ed3 commit 4868cb5

File tree

5 files changed

+29
-2
lines changed

5 files changed

+29
-2
lines changed

intTests/test2749/test.saw

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// test.saw
2+
enable_experimental;
3+
4+
let
5+
{{
6+
inc : [1024][8] -> [64] -> [1024][8]
7+
inc arr idx = update arr idx (arr @ idx + 10)
8+
}};
9+
10+
prove_print
11+
do {
12+
print_goal;
13+
goal_normalize [];
14+
z3;
15+
}
16+
{{ \arr_val -> inc arr_val 0 == update arr_val 0 (arr_val @ 0 + 10) }};

intTests/test2749/test.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/sh
2+
$SAW test.saw

saw-central/src/SAWCentral/Builtins.hs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import qualified Data.ByteString.Lazy as BS
2525
import qualified Data.IntMap as IntMap
2626
import Data.List (isPrefixOf, isInfixOf, sort, intersperse)
2727
import qualified Data.Map as Map
28+
import Data.Maybe (catMaybes)
2829
import Data.Parameterized.Classes (KnownRepr(..))
2930
import Data.Set (Set)
3031
import qualified Data.Set as Set
@@ -63,9 +64,10 @@ import SAWCore.ExternalFormat
6364
import SAWCore.FiniteValue
6465
( FiniteType(..), readFiniteValue
6566
)
66-
import SAWCore.Name (ModuleName, VarName(..), mkModuleName)
67+
import SAWCore.Name (ModuleName, VarName(..), mkModuleName, moduleIdentToURI)
6768
import SAWCore.SATQuery
6869
import SAWCore.SCTypeCheck
70+
import SAWCore.Simulator.Concrete (constMap)
6971
import SAWCore.Recognizer
7072
import SAWCore.Prelude (scEq)
7173
import SAWCore.SharedTerm
@@ -571,7 +573,10 @@ goal_normalize opaque =
571573
execTactic $ tacticChange $ \goal ->
572574
do sc <- getSharedContext
573575
idxs <- mconcat <$> mapM (resolveName sc) opaque
574-
let opaqueSet = Set.fromList idxs
576+
-- Also exclude defined SAWCore constants that are implemented as primitives
577+
let primURIs = map moduleIdentToURI (Map.keys constMap)
578+
primIdxs <- io $ traverse (scResolveNameByURI sc) primURIs
579+
let opaqueSet = Set.fromList (catMaybes primIdxs ++ idxs)
575580
sqt' <- io $ traverseSequentWithFocus (normalizeProp sc opaqueSet) (goalSequent goal)
576581
return (sqt', NormalizePropEvidence opaqueSet)
577582

saw-core/src/SAWCore/Simulator.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,9 @@ evalTermF cfg lam recEval tf env =
251251
VCtorMux _ps branches ->
252252
do alts <- traverse (evalCtorMuxBranch vrec) (IntMap.elems branches)
253253
combineAlts alts
254+
VBVToNat{} ->
255+
panic "evalTerF / evalRecursor"
256+
["Unsupported symbolic recursor argument of type Nat"]
254257
_ ->
255258
panic "evalTermF / evalRecursor"
256259
["Expected constructor for datatype: " <> toAbsoluteName (nameInfo d)]

saw-core/src/SAWCore/Simulator/Concrete.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module SAWCore.Simulator.Concrete
1717
, toBool
1818
, toWord
1919
, runIdentity
20+
, constMap
2021
) where
2122

2223
import Control.Monad.Identity

0 commit comments

Comments
 (0)