Skip to content

Commit a7eaed6

Browse files
committed
wip
1 parent 940982a commit a7eaed6

8 files changed

Lines changed: 17 additions & 16 deletions

File tree

runtime/sam/expr/function/downcast.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func (d *downcast) downcast(typ super.Type, bytes scode.Bytes, to super.Type) (s
4747
return d.downcast(fusionType.Type, superBytes, subtype)
4848
}
4949
}
50-
//typ, bytes = deunion(typ, bytes)
50+
typ, bytes = deunion(typ, bytes)
5151
switch to := to.(type) {
5252
case *super.TypeRecord:
5353
return d.toRecord(typ, bytes, to)
@@ -251,12 +251,16 @@ func (d *downcast) toNamed(typ super.Type, bytes scode.Bytes, to *super.TypeName
251251
// from the union options present. XXX devise a torture test that
252252
// reconstruct nested unions from the flattened named union...?
253253
for _, t := range unionType.Types {
254+
//fmt.Println("TO NAMED FROM UNION TRY", sup.String(t))
254255
if named, ok := t.(*super.TypeNamed); ok && named.Name == to.Name {
255-
val, errVal := d.downcast(typ, bytes, to.Type)
256-
if errVal != nil {
257-
return super.Value{}, errVal
258-
}
259-
return super.NewValue(to, val.Bytes()), nil
256+
//fmt.Println("TO NAMED FROM UNION MATCH", sup.String(t))
257+
typ, bytes = deunion(typ, bytes)
258+
return super.NewValue(to, bytes), nil
259+
// val, errVal := d.downcast(typ, bytes, to.Type)
260+
// if errVal != nil {
261+
// return super.Value{}, errVal
262+
// }
263+
// return super.NewValue(to, val.Bytes()), nil
260264
}
261265

262266
}

runtime/sam/expr/function/upcast.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ func (u *Upcast) toMap(b *scode.Builder, typ super.Type, bytes scode.Bytes, to *
174174
func (u *Upcast) toUnion(b *scode.Builder, typ super.Type, bytes scode.Bytes, to *super.TypeUnion) bool {
175175
// Take the value out of the union (if it is union), then look for it
176176
// in the target union.
177-
//typ, bytes = deunion(typ, bytes)
177+
typ, bytes = deunion(typ, bytes)
178178
//if to == typ {
179179
// b.Append(bytes)
180180
// return true

runtime/sam/op/fuse/fuse.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package fuse
22

33
import (
4-
"fmt"
54
"sync"
65

76
"github.com/brimdata/super"
@@ -184,7 +183,6 @@ func (v *valueFuser) Read() (*super.Value, error) {
184183
if !ok {
185184
return v.sctx.WrapError("cannot upcast to "+sup.FormatType(v.typ), *val).Ptr(), nil
186185
}
187-
fmt.Println("FUSE UPCAST", sup.String(*val), "TO", sup.String(v.typ), "IS", sup.String(sval))
188186
return sval.Ptr(), nil
189187
}
190188

runtime/ztests/expr/function/defuse.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ input: &input |
4040
|[|[1::=s1]|::=s2]|::=s3
4141
|{1::=m1:2::=m2}|::=m3
4242
"a"::(en1=enum(a,b))
43-
1::=u1::(u2=(u1|(u3=string)))
43+
1::=u1::(u2=u1|(u3=string))
4444
error(1::=er1)::=er2
4545

4646
output: *input

runtime/ztests/expr/function/downcast.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ input: |
5151
5252
output: |
5353
[1,"foo"]::[int64|bool|string]
54-
error({message:"downcast: invalid subtype {x:int64}|{y:string}",on:{x:1::(int64|string)}::({x:int64|string}|{y:int64|string})})
55-
54+
error({message:"downcast: invalid subtype {x:int64}|{y:string}",on:{x:1::(int64|string)}})
5655
---
5756

5857
# This should seemingly fail because int64|bool|string is not subtype of

runtime/ztests/expr/function/upcast.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ input: |
1313
[|{1::=n1:2::=n2}|::=n3,<n4=|{n5=int64:n6=int64}|>]
1414
[1::=n1::(n2=n1|(n3=string)),<n4=(n5=int64)|(n6=string)>]
1515
["a"::n1=enum(a,b),<n2=enum(a,b)>]
16-
[1::=n1,<fusion(int64|string)>]
16+
[1::=n1,<fusion((n1=int64)|string)>]
1717
1818
output: |
1919
error({message:"upcast: value not a subtype of [int8|string]",on:[1,"a"]})
@@ -25,7 +25,7 @@ output: |
2525
|{1::=n5:2::=n6}|::=n4
2626
1::=n5::(n4=n5|(n6=string))
2727
"a"::(n2=enum(a,b))
28-
fusion(1::(int64|string),<n1=int64>)
28+
fusion(1::((n1=int64)|string),<n1=int64>)
2929
3030
---
3131

runtime/ztests/expr/fuser.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ spq: fuse | defuse(this)
1212
input: &input |
1313
"foo"::(int64|string)
1414
"foo"::=named
15-
"foo"::(named=int64|string)
15+
"foo"::(named2=int64|string)
1616

1717
output: *input

runtime/ztests/op/blend.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,6 @@ output: |
141141
[1::=a1]::=a2::((p1=int64)|(r2={a:r1=int64})|a2|(s2=|[s1=int64]|)|(m3=|{m1=int64:m2=int64}|)|(u2=(u1=int64)|(u3=string))|(en1=enum(a,b))|(er2=error(er1=int64)))
142142
|[1::=s1]|::=s2::((p1=int64)|(r2={a:r1=int64})|(a2=[a1=int64])|s2|(m3=|{m1=int64:m2=int64}|)|(u2=(u1=int64)|(u3=string))|(en1=enum(a,b))|(er2=error(er1=int64)))
143143
|{1::=m1:2::=m2}|::=m3::((p1=int64)|(r2={a:r1=int64})|(a2=[a1=int64])|(s2=|[s1=int64]|)|m3|(u2=(u1=int64)|(u3=string))|(en1=enum(a,b))|(er2=error(er1=int64)))
144-
1::=p1::(p1|(r2={a:r1=int64})|(a2=[a1=int64])|(s2=|[s1=int64]|)|(m3=|{m1=int64:m2=int64}|)|(u2=(u1=int64)|(u3=string))|(en1=enum(a,b))|(er2=error(er1=int64)))
144+
1::=u1::(u2=u1|(u3=string))::((p1=int64)|(r2={a:r1=int64})|(a2=[a1=int64])|(s2=|[s1=int64]|)|(m3=|{m1=int64:m2=int64}|)|u2|(en1=enum(a,b))|(er2=error(er1=int64)))
145145
"a"::(en1=enum(a,b))::((p1=int64)|(r2={a:r1=int64})|(a2=[a1=int64])|(s2=|[s1=int64]|)|(m3=|{m1=int64:m2=int64}|)|(u2=(u1=int64)|(u3=string))|en1|(er2=error(er1=int64)))
146146
error(1::=er1)::=er2::((p1=int64)|(r2={a:r1=int64})|(a2=[a1=int64])|(s2=|[s1=int64]|)|(m3=|{m1=int64:m2=int64}|)|(u2=(u1=int64)|(u3=string))|(en1=enum(a,b))|er2)

0 commit comments

Comments
 (0)