Skip to content

Commit

Permalink
Use canonical format for output records.
Browse files Browse the repository at this point in the history
DDlog used two similar, but slightly different formats for output
values.  One of them includes record argument names, while
the other does not.  In addition, the former uses `_` as module path
separator, while the other uses `.`  We now consistently use the same
format that includes argument names and uses `.` as path separator.

Unfortunately this simple change required lots of adjustments throughout
the code base, as well as changes to almost all reference files; hence
the huge commit.

Resolves #537 and #539
  • Loading branch information
ryzhyk committed Mar 2, 2020
1 parent ff23ed7 commit 3103de6
Show file tree
Hide file tree
Showing 41 changed files with 466,754 additions and 466,736 deletions.
4 changes: 2 additions & 2 deletions java/test/SpanTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ protected SpanBase(DDlogRecord r) {

@Override
public String toString() {
return this.getClass().getSimpleName() + "{" +
this.entity.toString() + "," + this.tn.toString() + "}";
return this.getClass().getSimpleName() + "{.entity = " +
this.entity.toString() + ", .tn = " + this.tn.toString() + "}";
}
}
static class SpanComparator implements Comparator<SpanBase> {
Expand Down
6 changes: 3 additions & 3 deletions java/test1/RedistTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ protected SpanBase(int entity) {
@Override
public String toString() {
StringBuilder result = new StringBuilder();
result.append("Span{");
result.append("Span{.entity = ");
result.append(this.entity);
result.append(",[");
result.append(", .tns = [");
List<Integer> list = new ArrayList<Integer>();
for (int i : this.getTNs())
list.add(i);
Collections.sort(list);
boolean first = true;
for (int i : list) {
if (!first)
result.append(",");
result.append(", ");
else
first = false;
result.append(i);
Expand Down
20 changes: 10 additions & 10 deletions java/test_flatbuf1/Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,18 @@ private String printQI(QIReader v) {
private String printTI(TIReader v) {
std_Option__bit_32_Reader m = (std_Option__bit_32_Reader)(v).m();
if (m instanceof std_Option__bit_32_Reader.std_Some) {
return "TI{std_Some{" + ((std_Option__bit_32_Reader.std_Some)m).x() + "}}";
return "TI{std.Some{" + ((std_Option__bit_32_Reader.std_Some)m).x() + "}}";
} else {
return "TI{std_None{}}";
return "TI{std.None{}}";
}
}

private String printWI(WIReader v) {
std_Option__ManyReader m = (std_Option__ManyReader)(v).m();
if (m instanceof std_Option__ManyReader.std_Some) {
return "WI{std_Some{" + printMany(((std_Option__ManyReader.std_Some)m).x()) + "}}";
return "WI{std.Some{" + printMany(((std_Option__ManyReader.std_Some)m).x()) + "}}";
} else {
return "WI{std_None{}}";
return "WI{std.None{}}";
}
}

Expand All @@ -94,9 +94,9 @@ private String printYI(YIReader v) {
ArrayList<String> strings = new ArrayList<String>(val.size());
val.forEach((x) -> {
if (x instanceof std_Option___bool__bit_8___string_Reader.std_Some) {
strings.add("std_Some{" + printTuple(((std_Option___bool__bit_8___string_Reader.std_Some)x).x()) + "}");
strings.add("std.Some{" + printTuple(((std_Option___bool__bit_8___string_Reader.std_Some)x).x()) + "}");
} else {
strings.add("std_None{}");
strings.add("std.None{}");
}
});
return "YI{[" + String.join(", ", strings) + "]}";
Expand All @@ -110,9 +110,9 @@ private String printStrings(List<String> v) {

private String printOptString(Object v) {
if (v instanceof std_Option__stringReader.std_Some) {
return "std_Some{\"" + ((std_Option__stringReader.std_Some)v).x() + "\"}";
return "std.Some{\"" + ((std_Option__stringReader.std_Some)v).x() + "\"}";
} else {
return "std_None{}";
return "std.None{}";
}
}

Expand Down Expand Up @@ -493,7 +493,7 @@ void onFBCommit(DDlogCommand<Object> command) throws IOException {
}
case typesTestRelation.Omodule_ZI16: {
module_ZI16Reader r = (module_ZI16Reader)command.value();
fb_file.println("From " + relid + " " + command.kind() + " module_ZI16{\"" + r.x() + "\"}");
fb_file.println("From " + relid + " " + command.kind() + " module.ZI16{\"" + r.x() + "\"}");
break;
}
case typesTestRelation.Omodule_ZI17: {
Expand All @@ -503,7 +503,7 @@ void onFBCommit(DDlogCommand<Object> command) throws IOException {
}
case typesTestRelation.Omodule_ZI18: {
module_ZI18Reader b = (module_ZI18Reader)command.value();
fb_file.println("From " + relid + " " + command.kind() + " module_ZI18{" + printMTuple(b.t()) + "}");
fb_file.println("From " + relid + " " + command.kind() + " module.ZI18{" + printMTuple(b.t()) + "}");
break;
}
case typesTestRelation.Omodule_ZI19: {
Expand Down
18 changes: 9 additions & 9 deletions java/test_flatbuf1/fb.dump.expected
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ From 37 Insert PI5{[2, 3, 72057594037927935]}
From 38 Insert QI{{2=>"here", 3=>"there"}}
From 39 Insert RI{2}
From 40 Insert SI{C{"s"}}
From 41 Insert TI{std_None{}}
From 41 Insert TI{std_Some{10}}
From 41 Insert TI{std.None{}}
From 41 Insert TI{std.Some{10}}
From 42 Insert A{"a"}
From 42 Insert B{false}
From 42 Insert D{(false, 2, "zz")}
From 43 Insert VI{false,A{"aa"}}
From 43 Insert VI{false,D{(false, 2, "string")}}
From 43 Insert VI{true,B{false}}
From 44 Insert WI{std_None{}}
From 44 Insert WI{std_Some{B{true}}}
From 44 Insert WI{std.None{}}
From 44 Insert WI{std.Some{B{true}}}
From 45 Insert XI{[A{"aa"}, B{false}, D{(false, 2, "string")}]}
From 46 Insert YI{[std_Some{(false, 255, "")}, std_Some{(true, 254, "!")}, std_None{}]}
From 46 Insert YI{[std.Some{(false, 255, "")}, std.Some{(true, 254, "!")}, std.None{}]}
From 47 Insert ZI{1234566788901239813761283}
From 48 Insert "Hello, world!"
From 48 Insert "Привіт!"
Expand All @@ -61,13 +61,13 @@ From 59 Insert A{"It's all Greek to me: Α α, Β β, Γ γ, Δ δ, Ε ε, Ζ
From 60 Insert ["Foo
", " bar"]
From 61 Insert {"key1"=>B{false}, "key2"=>A{"val2"}}
From 62 Insert std_None{}
From 62 Insert std_Some{"ZI6"}
From 62 Insert std.None{}
From 62 Insert std.Some{"ZI6"}
From 63 Insert "ZI7"
From 63 Insert "♛"
From 64 Insert 100
From 65 Insert 100
From 66 Insert module_ZI16{"zi16"}
From 66 Insert module.ZI16{"zi16"}
From 67 Insert "zi17"
From 68 Insert module_ZI18{(4294967295, "ZZZ")}
From 68 Insert module.ZI18{(4294967295, "ZZZ")}
From 69 Insert (4294967293, "zi19")
36 changes: 18 additions & 18 deletions java/test_flatbuf1/query.dump.expected
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ SI{C{"s"}}
Query SI_by_x["s"]:
SI{C{"s"}}
Query TI_by_m[10]:
TI{std_Some{10}}
TI{std.Some{10}}
Query TI_by_some[10]:
TI{std_Some{10}}
TI{std.Some{10}}
Query TI_by_none[]:
TI{std_None{}}
TI{std.None{}}
Query UI_by_x["a"]:
A{"a"}
Query UI_by_b[false]:
Expand All @@ -112,11 +112,11 @@ Query WI_by_t[(false, 2, "string")]:
Query XI_by_m[A{"aa"}, B{false}, D{(false,2,"string")}]:
XI{[A{"aa"}, B{false}, D{(false, 2, "string")}]}
Query YI_by_v[...]:
YI{[std_Some{(false, 255, "")}, std_Some{(true, 254, "!")}, std_None{}]}
YI{[std.Some{(false, 255, "")}, std.Some{(true, 254, "!")}, std.None{}]}
Query YI_by_none[]:
YI{[std_Some{(false, 255, "")}, std_Some{(true, 254, "!")}, std_None{}]}
YI{[std.Some{(false, 255, "")}, std.Some{(true, 254, "!")}, std.None{}]}
Query YI_by_self[...]:
YI{[std_Some{(false, 255, "")}, std_Some{(true, 254, "!")}, std_None{}]}
YI{[std.Some{(false, 255, "")}, std.Some{(true, 254, "!")}, std.None{}]}
Query ZI_by_d[0]:
Query ZI0_by_self["Привіт!"]:
"Привіт!"
Expand All @@ -138,9 +138,9 @@ Query ZI4_by_self[...]:
Query ZI5_by_self[...]:
{"key1"=>B{false}, "key2"=>A{"val2"}}
Query ZI6_by_self["ZI6"]:
std_Some{"ZI6"}
std.Some{"ZI6"}
Query ZI6_by_none[]:
std_None{}
std.None{}
Query ZI7_by_self["♛"]:
"♛"
Query ZI7_by_val["ZI7"]:
Expand Down Expand Up @@ -290,12 +290,12 @@ SI{C{"s"}}
Dump SI_by_x:
SI{C{"s"}}
Dump TI_by_m:
TI{std_None{}}
TI{std_Some{10}}
TI{std.None{}}
TI{std.Some{10}}
Dump TI_by_some:
TI{std_Some{10}}
TI{std.Some{10}}
Dump TI_by_none:
TI{std_None{}}
TI{std.None{}}
Dump UI_by_x:
A{"a"}
Dump UI_by_b:
Expand All @@ -315,11 +315,11 @@ Dump WI_by_t:
Dump XI_by_m:
XI{[A{"aa"}, B{false}, D{(false, 2, "string")}]}
Dump YI_by_v:
YI{[std_Some{(false, 255, "")}, std_Some{(true, 254, "!")}, std_None{}]}
YI{[std.Some{(false, 255, "")}, std.Some{(true, 254, "!")}, std.None{}]}
Dump YI_by_none:
YI{[std_Some{(false, 255, "")}, std_Some{(true, 254, "!")}, std_None{}]}
YI{[std.Some{(false, 255, "")}, std.Some{(true, 254, "!")}, std.None{}]}
Dump YI_by_self:
YI{[std_Some{(false, 255, "")}, std_Some{(true, 254, "!")}, std_None{}]}
YI{[std.Some{(false, 255, "")}, std.Some{(true, 254, "!")}, std.None{}]}
Dump ZI_by_d:
HI{1234566788901239813761283}
Dump ZI0_by_self:
Expand All @@ -345,10 +345,10 @@ Dump ZI4_by_self:
Dump ZI5_by_self:
{"key1"=>B{false}, "key2"=>A{"val2"}}
Dump ZI6_by_self:
std_None{}
std_Some{"ZI6"}
std.None{}
std.Some{"ZI6"}
Dump ZI6_by_none:
std_None{}
std.None{}
Dump ZI7_by_self:
"ZI7"
"♛"
Expand Down
15 changes: 11 additions & 4 deletions rust/template/differential_datalog/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1409,6 +1409,13 @@ pub fn arg_find<'a>(args: &'a [(Name, Record)], argname: &str) -> Option<&'a Rec

#[macro_export]
macro_rules! decl_struct_into_record {
( $n:ident [ $nstr:expr ] <$( $targ:ident),*>, $( $arg:ident ),* ) => {
impl <$($targ: $crate::record::IntoRecord),*> $crate::record::IntoRecord for $n<$($targ),*> {
fn into_record(self) -> $crate::record::Record {
$crate::record::Record::NamedStruct(borrow::Cow::from($nstr),vec![$((borrow::Cow::from(stringify!($arg)), self.$arg.into_record())),*])
}
}
};
( $n:ident, <$( $targ:ident),*>, $( $arg:ident ),* ) => {
impl <$($targ: $crate::record::IntoRecord),*> $crate::record::IntoRecord for $n<$($targ),*> {
fn into_record(self) -> $crate::record::Record {
Expand Down Expand Up @@ -1484,20 +1491,20 @@ macro_rules! decl_record_mutator_enum {

#[macro_export]
macro_rules! decl_enum_into_record {
( $n:ident, <$( $targ:ident),*>, $($cons:ident {$($arg:ident),*} ),* ) => {
( $n:ident, <$( $targ:ident),*>, $($cons:ident [$consn:expr] {$($arg:ident),*} ),* ) => {
impl <$($targ: $crate::record::IntoRecord),*> $crate::record::IntoRecord for $n<$($targ),*> {
fn into_record(self) -> $crate::record::Record {
match self {
$($n::$cons{$($arg),*} => $crate::record::Record::NamedStruct(borrow::Cow::from(stringify!($cons)), vec![$((borrow::Cow::from(stringify!($arg)), $arg.into_record())),*])),*
$($n::$cons{$($arg),*} => $crate::record::Record::NamedStruct(borrow::Cow::from($consn), vec![$((borrow::Cow::from(stringify!($arg)), $arg.into_record())),*])),*
}
}
}
};
( $n:ident, <$( $targ:ident),*>, $($cons:ident ($($arg:ident),*) ),* ) => {
( $n:ident, <$( $targ:ident),*>, $($cons:ident [$consn:expr] ($($arg:ident),*) ),* ) => {
impl <$($targ: $crate::record::IntoRecord),*> $crate::record::IntoRecord for $n<$($targ),*> {
fn into_record(self) -> $crate::record::Record {
match self {
$($n::$cons($($arg),*) => $crate::record::Record::NamedStruct(borrow::Cow::from(stringify!($cons)), vec![$((borrow::Cow::from(stringify!($arg)), $arg.into_record())),*])),*
$($n::$cons($($arg),*) => $crate::record::Record::NamedStruct(borrow::Cow::from($consn), vec![$((borrow::Cow::from(stringify!($arg)), $arg.into_record())),*])),*
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions rust/template/differential_datalog/test_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,13 +572,13 @@ pub struct NestedStruct<T> {
}
pub struct StructWithNoFields;

decl_struct_into_record!(Foo, <T>, f1);
decl_struct_into_record!(Foo ["Foo"] <T>, f1);
decl_record_mutator_struct!(Foo, <T>, f1: T);

decl_struct_into_record!(NestedStruct, <T>, x,y);
decl_struct_into_record!(NestedStruct ["Foo"] <T>, x,y);
decl_record_mutator_struct!(NestedStruct, <T>, x: bool, y: Foo<T>);

decl_struct_into_record!(StructWithNoFields, <>,);
decl_struct_into_record!(StructWithNoFields ["StructWithNoFields"] <>,);
decl_record_mutator_struct!(StructWithNoFields, <>, );

#[test]
Expand Down Expand Up @@ -664,7 +664,7 @@ impl<T: FromRecord + Default> FromRecord for DummyEnum<T> {
}
}

decl_enum_into_record!(DummyEnum,<T>,Constr1{f1,f2},Constr2{f1,f2,f3},Constr3{f1});
decl_enum_into_record!(DummyEnum,<T>,Constr1["Constr1"]{f1,f2},Constr2["Constr2"]{f1,f2,f3},Constr3["Constr3"]{f1});
decl_record_mutator_enum!(DummyEnum,<T>,Constr1{f1:Bbool ,f2: String},Constr2{f1: T, f2: BigInt, f3: Foo<T>},Constr3{f1: (bool, bool)});

#[test]
Expand Down
4 changes: 2 additions & 2 deletions rust/template/ovsdb/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ fn record_into_field(rec: Record) -> Result<Value, String> {
}
}
Record::NamedStruct(n, mut v) => {
if n.as_ref() == "std_Left" {
if n.as_ref() == "std.Left" {
match v.remove(0) {
(_, Record::Int(i)) => {
let uuid = uuid_from_int(&i)?;
Expand All @@ -383,7 +383,7 @@ fn record_into_field(rec: Record) -> Result<Value, String> {
}
_ => Err(format!("Unexpected uuid value: {:?}", v)),
}
} else if n.as_ref() == "std_Right" {
} else if n.as_ref() == "std.Right" {
match v.remove(0) {
(_, Record::String(s)) => Ok(Value::Array(vec![
Value::String("named-uuid".to_owned()),
Expand Down
9 changes: 4 additions & 5 deletions src/Language/DifferentialDatalog/Compile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ module Language.DifferentialDatalog.Compile (
mkConstructorName,
mkType,
mkValue,
tupleStruct,
rname
) where

Expand Down Expand Up @@ -742,7 +743,7 @@ mkFromRecord t@TypeDef{..} =

mkStructIntoRecord :: TypeDef -> Doc
mkStructIntoRecord t@TypeDef{..} =
"decl_struct_into_record!(" <> rname (name t) <> ", " <> targs <> "," <+> args <> ");"
"decl_struct_into_record!(" <> rname (name t) <> "[\"" <> pp (name t) <> "\"]" <> targs <> "," <+> args <> ");"
where
targs = "<" <> (hcat $ punctuate comma $ map pp tdefArgs) <> ">"
args = commaSep $ map (pp . name) $ consArgs $ head $ typeCons $ fromJust tdefType
Expand All @@ -759,7 +760,7 @@ mkEnumIntoRecord t@TypeDef{..} =
"decl_enum_into_record!(" <> rname (name t) <> "," <+> targs <> "," <+> cons <> ");"
where
targs = "<" <> (hcat $ punctuate comma $ map pp tdefArgs) <> ">"
cons = commaSep $ map (\c -> (rname $ name c) <> "{" <> (commaSep $ map (pp . name) $ consArgs c) <> "}")
cons = commaSep $ map (\c -> (rname $ name c) <> "[\"" <> pp (name c) <> "\"]" <> "{" <> (commaSep $ map (pp . name) $ consArgs c) <> "}")
$ typeCons $ fromJust tdefType

mkEnumMutator :: TypeDef -> Doc
Expand Down Expand Up @@ -1114,9 +1115,7 @@ mkValType d types =
"impl abomonation::Abomonation for" <+> tname <+> "{}" $$
"impl fmt::Display for" <+> tname <+> "{" $$
" fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {" $$
(nest' $ nest' $ if isString d t
then "record::format_ddlog_str(&self.0, f)"
else "fmt::Debug::fmt(&self.0, f)") $$
" self.clone().into_record().fmt(f)" $$
" }" $$
"}" $$
"impl record::IntoRecord for" <+> tname <+> "{" $$
Expand Down
1 change: 1 addition & 0 deletions src/Language/DifferentialDatalog/Compile.hs-boot
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ mkType :: (WithType a) => a -> Doc
rname :: String -> Doc

mkValue :: (?cfg::CompilerConfig) => DatalogProgram -> Doc -> Type -> Doc
tupleStruct :: [Doc] -> Doc
2 changes: 1 addition & 1 deletion src/Language/DifferentialDatalog/FlatBuffer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1616,7 +1616,7 @@ rustTypeFromFlatbuf t@TUser{..} =
rustTypeFromFlatbuf t@TTuple{..} =
"impl <'a> FromFlatBuffer<fb::" <> tname <> "<'a>> for" <+> rtype <+> "{" $$
" fn from_flatbuf(v: fb::" <> tname <> "<'a>) -> Response<Self> {" $$
" Ok((" <> commaSep from_args <> "))" $$
" Ok(" <> R.tupleStruct from_args <> ")" $$
" }" $$
"}" $$
"impl <'b> ToFlatBuffer<'b> for" <+> rtype <+> "{" $$
Expand Down
Loading

0 comments on commit 3103de6

Please sign in to comment.