Skip to content
This repository has been archived by the owner on Sep 12, 2018. It is now read-only.

Commit

Permalink
Rename or delete things so that there is only one type named Entid (#768
Browse files Browse the repository at this point in the history
)

* Delete the (apparently unused) EntId

* Rename edn's Entid to EntidOrIdent to avoid confusion with the Entid that's actually an i64

* Fix travis beta bustage (This is actually unrelated to entids, but is a trivial fix nonetheless)
  • Loading branch information
thomcc committed Jun 26, 2018
1 parent f335253 commit 72a9b30
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 70 deletions.
20 changes: 10 additions & 10 deletions db/src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use mentat_core::{
ValueType,
};
use edn::entities::{
Entid,
EntidOrIdent,
};
use schema::{
SchemaBuilding,
Expand All @@ -43,8 +43,8 @@ use types::Schema;
#[derive(Clone,Debug,Eq,Hash,Ord,PartialOrd,PartialEq)]
pub(crate) struct Datom {
// TODO: generalize this.
e: Entid,
a: Entid,
e: EntidOrIdent,
a: EntidOrIdent,
v: edn::Value,
tx: i64,
added: Option<bool>,
Expand All @@ -70,10 +70,10 @@ pub(crate) struct FulltextValues(pub Vec<(i64, String)>);

impl Datom {
pub(crate) fn into_edn(&self) -> edn::Value {
let f = |entid: &Entid| -> edn::Value {
let f = |entid: &EntidOrIdent| -> edn::Value {
match *entid {
Entid::Entid(ref y) => edn::Value::Integer(y.clone()),
Entid::Ident(ref y) => edn::Value::Keyword(y.clone()),
EntidOrIdent::Entid(ref y) => edn::Value::Integer(y.clone()),
EntidOrIdent::Ident(ref y) => edn::Value::Keyword(y.clone()),
}
};

Expand Down Expand Up @@ -121,8 +121,8 @@ impl ToIdent for TypedValue {
}

/// Convert a numeric entid to an ident `Entid` if possible, otherwise a numeric `Entid`.
fn to_entid(schema: &Schema, entid: i64) -> Entid {
schema.get_ident(entid).map_or(Entid::Entid(entid), |ident| Entid::Ident(ident.clone()))
fn to_entid(schema: &Schema, entid: i64) -> EntidOrIdent {
schema.get_ident(entid).map_or(EntidOrIdent::Entid(entid), |ident| EntidOrIdent::Ident(ident.clone()))
}

/// Return the set of datoms in the store, ordered by (e, a, v, tx), but not including any datoms of
Expand Down Expand Up @@ -160,7 +160,7 @@ pub(crate) fn datoms_after<S: Borrow<Schema>>(conn: &rusqlite::Connection, schem
let tx: i64 = row.get_checked(4)?;

Ok(Some(Datom {
e: Entid::Entid(e),
e: EntidOrIdent::Entid(e),
a: to_entid(borrowed_schema, a),
v: value,
tx: tx,
Expand Down Expand Up @@ -197,7 +197,7 @@ pub(crate) fn transactions_after<S: Borrow<Schema>>(conn: &rusqlite::Connection,
let added: bool = row.get_checked(5)?;

Ok(Datom {
e: Entid::Entid(e),
e: EntidOrIdent::Entid(e),
a: to_entid(borrowed_schema, a),
v: value,
tx: tx,
Expand Down
8 changes: 4 additions & 4 deletions db/src/internal_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ impl TransactableValue for ValueAndSpan {
fn into_entity_place(self) -> Result<EntityPlace<Self>> {
use self::SpannedValue::*;
match self.inner {
Integer(v) => Ok(EntityPlace::Entid(entities::Entid::Entid(v))),
Integer(v) => Ok(EntityPlace::Entid(entities::EntidOrIdent::Entid(v))),
Keyword(v) => {
if v.is_namespaced() {
Ok(EntityPlace::Entid(entities::Entid::Ident(v)))
Ok(EntityPlace::Entid(entities::EntidOrIdent::Ident(v)))
} else {
// We only allow namespaced idents.
bail!(DbError::InputError(errors::InputError::BadEntityPlace))
Expand Down Expand Up @@ -121,8 +121,8 @@ impl TransactableValue for TypedValue {

fn into_entity_place(self) -> Result<EntityPlace<Self>> {
match self {
TypedValue::Ref(x) => Ok(EntityPlace::Entid(entities::Entid::Entid(x))),
TypedValue::Keyword(x) => Ok(EntityPlace::Entid(entities::Entid::Ident((*x).clone()))),
TypedValue::Ref(x) => Ok(EntityPlace::Entid(entities::EntidOrIdent::Entid(x))),
TypedValue::Keyword(x) => Ok(EntityPlace::Entid(entities::EntidOrIdent::Ident((*x).clone()))),
TypedValue::String(x) => Ok(EntityPlace::TempId(TempId::External((*x).clone()))),
TypedValue::Boolean(_) |
TypedValue::Long(_) |
Expand Down
22 changes: 11 additions & 11 deletions db/src/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ pub struct Tx<'conn, 'a, W> where W: TransactWatcher {
/// something suitable for the entity position rather than something suitable for a value position.
pub fn remove_db_id<V: TransactableValue>(map: &mut entmod::MapNotation<V>) -> Result<Option<entmod::EntityPlace<V>>> {
// TODO: extract lazy defined constant.
let db_id_key = entmod::Entid::Ident(Keyword::namespaced("db", "id"));
let db_id_key = entmod::EntidOrIdent::Ident(Keyword::namespaced("db", "id"));

let db_id: Option<entmod::EntityPlace<V>> = if let Some(id) = map.remove(&db_id_key) {
match id {
Expand Down Expand Up @@ -291,8 +291,8 @@ impl<'conn, 'a, W> Tx<'conn, 'a, W> where W: TransactWatcher {

fn intern_lookup_ref<W: TransactableValue>(&mut self, lookup_ref: &entmod::LookupRef<W>) -> Result<LookupRef> {
let lr_a: i64 = match lookup_ref.a {
AttributePlace::Entid(entmod::Entid::Entid(ref a)) => *a,
AttributePlace::Entid(entmod::Entid::Ident(ref a)) => self.schema.require_entid(&a)?.into(),
AttributePlace::Entid(entmod::EntidOrIdent::Entid(ref a)) => *a,
AttributePlace::Entid(entmod::EntidOrIdent::Ident(ref a)) => self.schema.require_entid(&a)?.into(),
};
let lr_attribute: &Attribute = self.schema.require_attribute_for_entid(lr_a)?;

Expand All @@ -319,8 +319,8 @@ impl<'conn, 'a, W> Tx<'conn, 'a, W> where W: TransactWatcher {
match x {
entmod::EntityPlace::Entid(e) => {
let e = match e {
entmod::Entid::Entid(ref e) => self.ensure_entid_exists(*e)?,
entmod::Entid::Ident(ref e) => self.ensure_ident_exists(&e)?,
entmod::EntidOrIdent::Entid(ref e) => self.ensure_entid_exists(*e)?,
entmod::EntidOrIdent::Ident(ref e) => self.ensure_ident_exists(&e)?,
};
Ok(Either::Left(e))
},
Expand All @@ -342,10 +342,10 @@ impl<'conn, 'a, W> Tx<'conn, 'a, W> where W: TransactWatcher {
}
}

fn entity_a_into_term_a(&mut self, x: entmod::Entid) -> Result<Entid> {
fn entity_a_into_term_a(&mut self, x: entmod::EntidOrIdent) -> Result<Entid> {
let a = match x {
entmod::Entid::Entid(ref a) => *a,
entmod::Entid::Ident(ref a) => self.schema.require_entid(&a)?.into(),
entmod::EntidOrIdent::Entid(ref a) => *a,
entmod::EntidOrIdent::Ident(ref a) => self.schema.require_entid(&a)?.into(),
};
Ok(a)
}
Expand All @@ -354,7 +354,7 @@ impl<'conn, 'a, W> Tx<'conn, 'a, W> where W: TransactWatcher {
self.entity_e_into_term_e(x).map(|r| r.map_left(|ke| TypedValue::Ref(ke.0)))
}

fn entity_v_into_term_e<W: TransactableValue>(&mut self, x: entmod::ValuePlace<W>, backward_a: &entmod::Entid) -> Result<KnownEntidOr<LookupRefOrTempId>> {
fn entity_v_into_term_e<W: TransactableValue>(&mut self, x: entmod::ValuePlace<W>, backward_a: &entmod::EntidOrIdent) -> Result<KnownEntidOr<LookupRefOrTempId>> {
match backward_a.unreversed() {
None => {
bail!(DbError::NotYetImplemented(format!("Cannot explode map notation value in :attr/_reversed notation for forward attribute")));
Expand Down Expand Up @@ -510,7 +510,7 @@ impl<'conn, 'a, W> Tx<'conn, 'a, W> where W: TransactWatcher {
deque.push_front(Entity::AddOrRetract {
op: op.clone(),
e: e.clone(),
a: AttributePlace::Entid(entmod::Entid::Entid(a)),
a: AttributePlace::Entid(entmod::EntidOrIdent::Entid(a)),
v: vv,
});
}
Expand Down Expand Up @@ -573,7 +573,7 @@ impl<'conn, 'a, W> Tx<'conn, 'a, W> where W: TransactWatcher {
deque.push_front(Entity::AddOrRetract {
op: OpType::Add,
e: db_id.clone(),
a: AttributePlace::Entid(entmod::Entid::Entid(inner_a)),
a: AttributePlace::Entid(entmod::EntidOrIdent::Entid(inner_a)),
v: inner_v,
});
}
Expand Down
18 changes: 9 additions & 9 deletions edn/src/edn.rustpeg
Original file line number Diff line number Diff line change
Expand Up @@ -238,18 +238,18 @@ raw_forward_namespaced_keyword -> Keyword
raw_backward_namespaced_keyword -> Keyword
= v:raw_namespaced_keyword {? if v.is_backward() { Ok(v) } else { Err("expected namespaced :backward/_keyword") } }

entid -> Entid
= v:( raw_basedinteger / raw_hexinteger / raw_octalinteger / raw_integer ) { Entid::Entid(v) }
/ v:raw_namespaced_keyword { Entid::Ident(v) }
entid -> EntidOrIdent
= v:( raw_basedinteger / raw_hexinteger / raw_octalinteger / raw_integer ) { EntidOrIdent::Entid(v) }
/ v:raw_namespaced_keyword { EntidOrIdent::Ident(v) }
/ #expected("entid")

forward_entid -> Entid
= v:( raw_basedinteger / raw_hexinteger / raw_octalinteger / raw_integer ) { Entid::Entid(v) }
/ v:raw_forward_namespaced_keyword { Entid::Ident(v) }
forward_entid -> EntidOrIdent
= v:( raw_basedinteger / raw_hexinteger / raw_octalinteger / raw_integer ) { EntidOrIdent::Entid(v) }
/ v:raw_forward_namespaced_keyword { EntidOrIdent::Ident(v) }
/ #expected("forward entid")

backward_entid -> Entid
= v:raw_backward_namespaced_keyword { Entid::Ident(v.to_reversed()) }
backward_entid -> EntidOrIdent
= v:raw_backward_namespaced_keyword { EntidOrIdent::Ident(v.to_reversed()) }
/ #expected("backward entid")

lookup_ref -> LookupRef<ValueAndSpan>
Expand All @@ -265,7 +265,7 @@ entity_place -> EntityPlace<ValueAndSpan>
/ v:lookup_ref { EntityPlace::LookupRef(v) }
/ v:tx_function { EntityPlace::TxFunction(v) }

value_place_pair -> (Entid, ValuePlace<ValueAndSpan>)
value_place_pair -> (EntidOrIdent, ValuePlace<ValueAndSpan>)
= k:(entid) __ v:(value_place) { (k, v) }

map_notation -> MapNotation<ValueAndSpan>
Expand Down
18 changes: 9 additions & 9 deletions edn/src/entities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ impl fmt::Display for TempId {
}

#[derive(Clone, Debug, Eq, Hash, Ord, PartialOrd, PartialEq)]
pub enum Entid {
pub enum EntidOrIdent {
Entid(i64),
Ident(Keyword),
}

impl Entid {
pub fn unreversed(&self) -> Option<Entid> {
impl EntidOrIdent {
pub fn unreversed(&self) -> Option<EntidOrIdent> {
match self {
&Entid::Entid(_) => None,
&Entid::Ident(ref a) => a.unreversed().map(Entid::Ident),
&EntidOrIdent::Entid(_) => None,
&EntidOrIdent::Ident(ref a) => a.unreversed().map(EntidOrIdent::Ident),
}
}
}
Expand Down Expand Up @@ -84,13 +84,13 @@ pub struct TxFunction {
pub op: PlainSymbol,
}

pub type MapNotation<V> = BTreeMap<Entid, ValuePlace<V>>;
pub type MapNotation<V> = BTreeMap<EntidOrIdent, ValuePlace<V>>;

#[derive(Clone, Debug, Eq, Hash, Ord, PartialOrd, PartialEq)]
pub enum ValuePlace<V> {
// We never know at parse-time whether an integer or ident is really an entid, but we will often
// know when building entities programmatically.
Entid(Entid),
Entid(EntidOrIdent),
// We never know at parse-time whether a string is really a tempid, but we will often know when
// building entities programmatically.
TempId(TempId),
Expand All @@ -103,15 +103,15 @@ pub enum ValuePlace<V> {

#[derive(Clone, Debug, Eq, Hash, Ord, PartialOrd, PartialEq)]
pub enum EntityPlace<V> {
Entid(Entid),
Entid(EntidOrIdent),
TempId(TempId),
LookupRef(LookupRef<V>),
TxFunction(TxFunction),
}

#[derive(Clone, Debug, Eq, Hash, Ord, PartialOrd, PartialEq)]
pub enum AttributePlace {
Entid(Entid),
Entid(EntidOrIdent),
}

#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialOrd, PartialEq)]
Expand Down
2 changes: 1 addition & 1 deletion edn/src/pretty_print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl Value {
Value::NamespacedSymbol(ref v) => pp.text(v.namespace()).append("/").append(v.name()),
Value::PlainSymbol(ref v) => pp.text(v.to_string()),
Value::Keyword(ref v) => pp.text(v.to_string()),
Value::Text(ref v) => pp.text("\"").append(v.as_ref()).append("\""),
Value::Text(ref v) => pp.text("\"").append(v.as_str()).append("\""),
Value::Uuid(ref u) => pp.text("#uuid \"").append(u.hyphenated().to_string()).append("\""),
Value::Instant(ref v) => pp.text("#inst \"").append(v.to_rfc3339_opts(SecondsFormat::AutoSi, true)).append("\""),
_ => pp.text(self.to_string())
Expand Down
25 changes: 0 additions & 25 deletions src/ident.rs

This file was deleted.

1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ macro_rules! kw {
pub mod errors;
pub mod conn;
pub mod entity_builder;
pub mod ident;
pub mod query;
pub mod query_builder;
pub mod store;
Expand Down

0 comments on commit 72a9b30

Please sign in to comment.