Few cleanups to type simplification, plus enable it in various jobs (#3018)

This commit is contained in:
Aaron Boodman
2017-01-04 14:15:26 -08:00
committed by GitHub
parent b0689cb2a4
commit 8777321dd2
9 changed files with 16 additions and 4 deletions

View File

@@ -35,8 +35,6 @@ import (
// Anytime any of the above cases generates a union as output, the same process
// is applied to that union recursively.
func makeSimplifiedUnion(in ...*Type) *Type {
d.Chk.True(len(in) > 0)
ts := make(typeset, len(in))
for _, t := range in {
// De-cycle so that we handle cycles explicitly below. Otherwise, we would implicitly crawl
@@ -135,6 +133,8 @@ func makeSimplifiedUnionImpl(in typeset) *Type {
return out[0]
}
staticTypeCache.Lock()
defer staticTypeCache.Unlock()
return staticTypeCache.makeUnionType(out...)
}

View File

@@ -148,6 +148,9 @@ func TestMakeSimplifiedUnion(t *testing.T) {
in []*Type
out *Type
}{
// {} -> <empty-union>
{[]*Type{},
MakeUnionType()},
// {bool} -> bool
{[]*Type{BoolType},
BoolType},

View File

@@ -539,11 +539,12 @@ func MakeStructType(name string, fieldNames []string, fieldTypes []*Type) *Type
}
func MakeUnionType(elemTypes ...*Type) *Type {
staticTypeCache.Lock()
defer staticTypeCache.Unlock()
if enableTypeSimplification {
return makeSimplifiedUnion(elemTypes...)
}
staticTypeCache.Lock()
defer staticTypeCache.Unlock()
return staticTypeCache.makeUnionType(elemTypes...)
}

View File

@@ -55,6 +55,7 @@ func download() (win bool) {
var cacheDsArg = flag.String("cache-ds", "", "name of photo-cache dataset")
var concurrencyArg = flag.Uint("concurrency", 4, "number of concurrent HTTP calls to retrieve remote resources")
verbose.RegisterVerboseFlags(flag.CommandLine)
types.RegisterTypeSimplificationFlags(flag.CommandLine)
flag.Usage = usage
flag.Parse(false)

View File

@@ -37,6 +37,7 @@ func mergeFaces() {
var dbStr = flag.String("db", "", "input database spec")
var outDSStr = flag.String("out-ds", "", "output dataset to write to")
verbose.RegisterVerboseFlags(flag.CommandLine)
types.RegisterTypeSimplificationFlags(flag.CommandLine)
flag.Usage = usage
flag.Parse(false)

View File

@@ -57,6 +57,7 @@ func index() (win bool) {
var outDSStr = flag.String("out-ds", "", "output dataset to write to - if empty, defaults to input dataset")
var thresh = flag.Int("threshold", 5000, "Number of milliseconds within which to consider photos duplicates")
verbose.RegisterVerboseFlags(flag.CommandLine)
types.RegisterTypeSimplificationFlags(flag.CommandLine)
flag.Usage = usage
flag.Parse(true)

View File

@@ -12,6 +12,7 @@ import (
"github.com/attic-labs/noms/go/config"
"github.com/attic-labs/noms/go/datas"
"github.com/attic-labs/noms/go/spec"
"github.com/attic-labs/noms/go/types"
"github.com/attic-labs/noms/go/util/exit"
"github.com/attic-labs/noms/go/util/verbose"
"github.com/attic-labs/noms/samples/go/photo-dedup/job"
@@ -34,6 +35,7 @@ func main() {
var outDSStr = flag.String("out-ds", "", "output dataset to write to")
var threshold = flag.Int("threshold", 10, "photo's whose dhash distance is < threshold are grouped together")
verbose.RegisterVerboseFlags(flag.CommandLine)
types.RegisterTypeSimplificationFlags(flag.CommandLine)
flag.Usage = usage
flag.Parse(false)

View File

@@ -12,6 +12,7 @@ import (
"github.com/attic-labs/noms/go/config"
"github.com/attic-labs/noms/go/datas"
"github.com/attic-labs/noms/go/spec"
"github.com/attic-labs/noms/go/types"
"github.com/attic-labs/noms/go/util/exit"
"github.com/attic-labs/noms/go/util/verbose"
"github.com/attic-labs/noms/samples/go/photo-dedup/job"
@@ -34,6 +35,7 @@ func main() {
var dbStr = flag.String("db", "", "input database spec")
var outDSStr = flag.String("out-ds", "", "output dataset to write to")
verbose.RegisterVerboseFlags(flag.CommandLine)
types.RegisterTypeSimplificationFlags(flag.CommandLine)
flag.Usage = usage
flag.Parse(false)

View File

@@ -64,6 +64,7 @@ func index() (win bool) {
var outDSStr = flag.String("out-ds", "", "output dataset to write to - if empty, defaults to input dataset")
var indexCovers = flag.Bool("index-covers", false, "the resulting index will contain only the cover Photo, not the entire PhotoGroup")
verbose.RegisterVerboseFlags(flag.CommandLine)
types.RegisterTypeSimplificationFlags(flag.CommandLine)
flag.Usage = usage
flag.Parse(false)