Skip to content

Commit 481c618

Browse files
author
Brian Huffman
committed
Avoid concatenating Text values in termToPat.
Fixes #1263. We now use `identBaseName` instead of `identText` in the `termToPat` definition. While `identText` concatenates the module name and base name, `identBaseName` just returns the base name directly. Using only the base name means that there is a chance of name collisions between constants that differ only by module name. However, term nets are only used as an approximate filter prior to term matching; it is not a problem if a few extra hits are returned from time to time. Ultimately it might be better to replace the use of `Text` in the term net `Atom` constructor with a more specialized key type; for example with `ExtCns` names we could use the `VarIndex` for matching. However, this would require modifying the term net library.
1 parent 7b8c134 commit 481c618

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

saw-core/src/Verifier/SAW/Conversion.hs

+3-3
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ resolveArgs (Matcher p m) (defaultArgsMatcher -> args@(ArgsMatcher pl _)) =
205205

206206
-- | Match a global definition.
207207
asGlobalDef :: Ident -> Matcher ()
208-
asGlobalDef ident = Matcher (Net.Atom (identText ident)) f
208+
asGlobalDef ident = Matcher (Net.Atom (identBaseName ident)) f
209209
where f (R.asGlobalDef -> Just o) | ident == o = return ()
210210
f _ = Nothing
211211

@@ -262,15 +262,15 @@ asRecordSelector m = asVar $ \t -> _1 (runMatcher m) =<< R.asRecordSelector t
262262

263263
-- | Match a constructor
264264
asCtor :: ArgsMatchable v a => Ident -> v a -> Matcher a
265-
asCtor o = resolveArgs $ Matcher (Net.Atom (identText o)) match
265+
asCtor o = resolveArgs $ Matcher (Net.Atom (identBaseName o)) match
266266
where match t = do
267267
CtorApp c params l <- R.asFTermF t
268268
guard (c == o)
269269
return (params ++ l)
270270

271271
-- | Match a datatype.
272272
asDataType :: ArgsMatchable v a => Ident -> v a -> Matcher a
273-
asDataType o = resolveArgs $ Matcher (Net.Atom (identText o)) match
273+
asDataType o = resolveArgs $ Matcher (Net.Atom (identBaseName o)) match
274274
where match t = do
275275
DataTypeApp dt params l <- R.asFTermF t
276276
guard (dt == o)

saw-core/src/Verifier/SAW/Term/Functor.hs

+4-4
Original file line numberDiff line numberDiff line change
@@ -344,15 +344,15 @@ instance Net.Pattern Term where
344344
termToPat :: Term -> Net.Pat
345345
termToPat t =
346346
case unwrapTermF t of
347-
Constant ec _ -> Net.Atom (toAbsoluteName (ecName ec))
347+
Constant ec _ -> Net.Atom (toShortName (ecName ec))
348348
App t1 t2 -> Net.App (termToPat t1) (termToPat t2)
349-
FTermF (Primitive ec) -> Net.Atom (toAbsoluteName (ecName ec))
349+
FTermF (Primitive ec) -> Net.Atom (toShortName (ecName ec))
350350
FTermF (Sort s) -> Net.Atom (Text.pack ('*' : show s))
351351
FTermF (NatLit _) -> Net.Var
352352
FTermF (DataTypeApp c ps ts) ->
353-
foldl Net.App (Net.Atom (identText c)) (map termToPat (ps ++ ts))
353+
foldl Net.App (Net.Atom (identBaseName c)) (map termToPat (ps ++ ts))
354354
FTermF (CtorApp c ps ts) ->
355-
foldl Net.App (Net.Atom (identText c)) (map termToPat (ps ++ ts))
355+
foldl Net.App (Net.Atom (identBaseName c)) (map termToPat (ps ++ ts))
356356
_ -> Net.Var
357357

358358
unwrapTermF :: Term -> TermF Term

0 commit comments

Comments
 (0)