Skip to content

immutable named types and type any#6821

Merged
mccanne merged 1 commit intomainfrom
type-any
Apr 13, 2026
Merged

immutable named types and type any#6821
mccanne merged 1 commit intomainfrom
type-any

Conversation

@mccanne
Copy link
Copy Markdown
Collaborator

@mccanne mccanne commented Apr 10, 2026

This commit changes the semantics of named type definitions so they are now immutable and cannot be modified once encountered and/or entered into a type context. It was sensible in early versions of SuperDB to allow named types to change in the spirit of coping with dynamic data, but now that we have fusion types, we can encode named types as abstract types that need not change.

To do so, we introduce the concept of an any type, which is a fusion type whose super type is type "all" (added in this PR as the counterpart to type "none"). In a future PR, we will add a shorthand notation for the type "any" to be an abbreviation for "fusion(all)". The any type allows serializing native data structures with embedded super.Values or super.Types to an immutable named type, which can then be deserialized back into the correct native data type using reflection directed by the type name. This was needed by SuperDB's storage of various types of metadata (in CSUP and in commit logs) so that type names would continue to work for these data structures while now being immutable.

In the future, the runtime will have complete transparency to the fusion and any types, but for now, we had to update many tests to manually call defuse on any values. A future version of SuperDB will (by default) automatically defuse output to SUP, etc. and the runtime will automatically defuse values that are operated upon.

We also ran into a problem where the order.Which type was persisted into a type context from serialized super data and also from marshaled Go structs. This caused a now-illegal type redefinition. To avoid this, we changed order.Which from a bool to string and removed the custom marshalers.

Finally, we disabled tests related to "db manage" and "create vectors" as the latter will go away when databases become CSUP native and the manage command likely depends on some script logic that is tripping over any types. (This problem will go away by itself when the runtime handles fusion types everywhere.)

@mccanne mccanne force-pushed the type-any branch 2 times, most recently from ade95b4 to 095e2bb Compare April 11, 2026 11:55
done
super db manage -q
super db -s -c 'from test@main:objects | drop id'
super db -s -c 'from test@main:objects | drop id | min:=defuse(min),max:=defuse(max)'
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe don't bother doing this change if we're just going to skip this test

seq 1 10 | super -c '{ts:this}' - | super db load -q -
super db manage -log.level=warn -q -vectors
super db -s -c 'from test1@main:vectors | drop id'
super db -s -c 'from test1@main:vectors | drop id | min:=defuse(min),max:=defuse(max)'
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider just not have the defuse here since this test is skipped anyways.

csup/scode.go Outdated
}
if p.max == nil || p.cmp(val, *p.max) > 0 {
p.max = val.Copy().Ptr()
if p.minmax || p.cmp(val, p.max) > 0 {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be not minmax

Suggested change
if p.minmax || p.cmp(val, p.max) > 0 {
if !p.minmax || p.cmp(val, p.max) > 0 {

context.go Outdated
c.named[name] = named
return named, nil
if _, ok := c.byID[id]; ok {
//XXX if it wasn't in the named table, it can't be in byID table
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this comment need the XXX which to me usually implies TODO ?

spq_test.go Outdated
if testing.Short() {
t.Skip("skipping boomerang in short mode")
}
t.Skip()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider putting a reason on the skip here?

Copy link
Copy Markdown
Collaborator Author

@mccanne mccanne Apr 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, I forgot I did that. It should not be skipped and boomerangs don't pass. I have more work to do on this branch!

}
it := val.Bytes().Iter()
bytes := it.Next()
//XXX
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this about?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is doing a DerefFusion so I'll replace.


func validate(strings []string) bool {
for _, s := range strings {
if !utf8.Valid([]byte(s)) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be faster.

Suggested change
if !utf8.Valid([]byte(s)) {
if !utf8.ValidString(s) {

Comment on lines +33 to +38
func (d Direction) Which() Which {
if d == Down {
return Desc
}
return Asc
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implicit conversion from Unknown to Asc feels like a potential rake. Maybe add a comment or a default parameter?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done on other PR!

This commit changes the semantics of named type definitions so they
are now immutable and cannot be modified once encountered and/or
entered into a type context. It was  sensible in early versions of
SuperDB to allow named types to change in the spirit of coping with
dynamic data, but now that we have fusion types, we can encode
 named types as abstract types that need not change.

To do so, we introduce the concept of an any type, which is a
fusion type whose super type is type "all" (added in this PR
as the counterpart to type "none").  In a future PR, we will
add a shorthand notation for the type "any" to be an abbreviation
for "fusion(all)".  The any type allows serializing native data structures
with embedded super.Values or super.Types to an immutablnamed type, which
can then be deserialized back into the correct native data type
using reflection directed by the type name.  This was needed by
SuperDB's storage of various types of metadata (in CSUP and
in commit logs) so that type names would continue to work for
these data structures while now being immutable.

In the future, the runtime will have complete transparency to
the fusion and any types, but for now, we had to update many tests
to manually call defuse on any values.  A future version of SuperDB
will (by default) automatically defuse output to SUP, etc. and the
runtime will automatically defuse values that are operated upon.

Finally, we disabled tests related to "db manage" and "create vectors"
as the latter will go away when databases become CSUP native and the
manage command likely depends on some script logic that is tripping
over any types.  (This problem will go away by itself when the runtime
handles fusion types everywhere.)

don't link check goes-around paper

address PR feedback (boomerangs broken and need to be fixed)

fix boomerangs

fix typo

address PR feedback
@mccanne mccanne merged commit af84fb5 into main Apr 13, 2026
4 checks passed
@mccanne mccanne deleted the type-any branch April 13, 2026 17:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants