]> Repositorios git - scryer-prolog.git/commitdiff
remove vestigial uses of constant_eq
authorMark Thom <[email protected]>
Fri, 12 Feb 2021 02:22:03 +0000 (19:22 -0700)
committerMark Thom <[email protected]>
Fri, 12 Feb 2021 02:22:03 +0000 (19:22 -0700)
crates/prolog_parser/src/ast.rs
src/machine/preprocessor.rs

index f6703d1016e5b575e9ff3dc1e077f729309d30f6..ac794e6e2fa5aa25007238390520e10e07b7b2eb 100644 (file)
@@ -529,39 +529,6 @@ impl fmt::Display for Constant {
     }
 }
 
-/*
- * By defining constant_eq as the PartialEq instance of Constant, we
- * sometimes hash constants it considers identical to the same value,
- * which can make the WAM fail erroneously. This can be avoided by
- * using the machine-generated PartialEq for hashing.
- */
-pub fn constant_eq(arg: &Constant, other: &Constant) -> bool {
-    match (arg, other) {
-        (&Constant::Atom(ref atom, _), &Constant::Char(c))
-            | (&Constant::Char(c), &Constant::Atom(ref atom, _)) => {
-                atom.is_char() && atom.as_str().starts_with(c)
-            }
-        (&Constant::Atom(ref a1, _), &Constant::Atom(ref a2, _)) => a1.as_str() == a2.as_str(),
-        (&Constant::Char(c1), &Constant::Char(c2)) => c1 == c2,
-        (&Constant::Fixnum(n1), &Constant::Fixnum(n2)) => n1 == n2,
-        (&Constant::Fixnum(n1), &Constant::Integer(ref n2))
-            | (&Constant::Integer(ref n2), &Constant::Fixnum(n1)) => {
-                if let Some(n2) = n2.to_isize() {
-                    n1 == n2
-                } else {
-                    false
-                }
-            }
-        (&Constant::Integer(ref n1), &Constant::Integer(ref n2)) => n1 == n2,
-        (&Constant::Rational(ref n1), &Constant::Rational(ref n2)) => n1 == n2,
-        (&Constant::Float(ref n1), &Constant::Float(ref n2)) => n1 == n2,
-        (&Constant::String(ref s1), &Constant::String(ref s2)) => s1 == s2,
-        (&Constant::EmptyList, &Constant::EmptyList) => true,
-        (&Constant::Usize(u1), &Constant::Usize(u2)) => u1 == u2,
-        _ => false,
-    }
-}
-
 impl Constant {
     pub fn to_atom(&self) -> Option<ClauseName> {
         match self {
index dc0205337a990cd19f8c160ab19bc75713b4da2d..bdb9d7fb7c4bfa2fe5a07ae44245bd4fe0b8ae8c 100644 (file)
@@ -174,10 +174,10 @@ pub(super) fn setup_module_export_list(
         export_list = *t2;
     }
 
-    if export_list.into_constant().map(|c| !constant_eq(&c, &Constant::EmptyList)).unwrap_or(true) {
-        Err(CompilationError::InvalidModuleDecl)
-    } else {
+    if let Term::Constant(_, Constant::EmptyList) = export_list {
         Ok(exports)
+    } else {
+        Err(CompilationError::InvalidModuleDecl)
     }
 }
 
@@ -273,10 +273,10 @@ fn setup_qualified_import(
         export_list = *t2;
     }
 
-    if export_list.into_constant().map(|c| !constant_eq(&c, &Constant::EmptyList)).unwrap_or(true) {
-        Err(CompilationError::InvalidModuleDecl)
-    } else {
+    if let Term::Constant(_, Constant::EmptyList) = export_list {
         Ok((module_src, exports))
+    } else {
+        Err(CompilationError::InvalidModuleDecl)
     }
 }