Skip to content

Enable support for top level generic objects - #51

Merged
hazelwiss merged 8 commits into
mainfrom
better-generic-support
Oct 15, 2025
Merged

Enable support for top level generic objects#51
hazelwiss merged 8 commits into
mainfrom
better-generic-support

Conversation

@hazelwiss

Copy link
Copy Markdown
Contributor

Previously in Bauble, it was not possible to have generic top level objects. Example:

let foo: Foo<Bar> = Foo(Bar(0));

Was syntactically unsupported.

Bauble does generate distinct types for Foo<Bar>, and so in order to support this it was simply necessary to allow Bauble to both parse explicit generic types and to resolve generic types with use. This PR does both of these.

@Imberflur Imberflur self-assigned this Sep 29, 2025
Comment thread bauble/src/types/path.rs
return false;
}

// Assume inner argument to type are valid.

@Imberflur Imberflur Sep 29, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why do we assume this? and not recursively invoke is_writeable?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not all generic arguments can be writable. For example HashMap<[u8; 4], f32>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So we want this to return true for HashMap<[u8; 4], f32> even though it isn't writable? Why is that?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I had issues not doing this. And I am still not completely certain what is_writable actually means anyway. Like. What even is it? Initially I had assumed it meant it was referencing an acceptable top level type for an object to be explicitly written out, but I now think it just means whether a path can or cannot be written in bauble entirely? If the former case, my logic here makes sense. If the latter, it does not.

I did initially validate the inner argument, but it did cause issues with the Bauble tests as I mentioned before. I think if you can clarify what you believe is_writable is exactly meant to indicate about a path and if it is the case it just means whether it can be written in bauble source, then yeah this code must validate the inner generic indeed!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think if you can clarify what you believe is_writable is exactly meant to indicate about a path and if it is the case it just means whether it can be written in bauble source, then yeah this code must validate the inner generic indeed!

I'm not exactly sure either, I was somewhat hoping your response would clarify this for me! I've seen is_writeable used a lot for determining whether something is a sub-object or not (so not related to type paths), but there are a few other places where it is used that I don't fully understand. My assumption so far is that it both is meant to indicate whether a path can be written in bauble source and for whether a object path is a subobject.

It would be nice to pin down what is_writeable means so that we don't introduce bugs here.

Comment thread bauble/src/types/path.rs
let mut generic_ending = false;
!self.is_empty()
&& self.iter().all(|part| {
if generic_ending {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does making generics writeable have any interaction with the built-in Ref<T> type?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I am not sure honestly, I was unaware of this type. Can you elaborate?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Whenever you have something referencing another object with the $path syntax bauble assigns it the type Ref<T> where T is the type of the referenced object. I think part of the is_writeable is meant to skip writing this type out when writing back to bauble source but I'm not fully sure.

E.g.

        test = integration::Test { x: -5, y: 5 } // type integration::Test
        test_ref = $test // type Ref<integration::Test>

Concrete instances of the generic Ref<T> are created in get_or_register_asset_ref (called from ctx.register_asset())

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah, I was not aware of this. I am not sure why it would be an issue tbh, if Ref is registered in the context and given a path, why is it a problem if it is explicitly written out?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe it would be fine, although this depends on if it is registered before anything looking at the explicit path tries to look it up.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I will look into this

Comment thread bauble/src/value/symbols.rs Outdated
Comment thread bauble/src/value/error.rs Outdated
Comment thread bauble/src/value/symbols.rs Outdated
Comment thread bauble/src/value/symbols.rs
@hazelwiss hazelwiss added blocked A PR is blocked on some discussion or other PR question Further information is requested labels Oct 13, 2025
@hazelwiss
hazelwiss merged commit a3f8338 into main Oct 15, 2025
1 check passed
@hazelwiss
hazelwiss deleted the better-generic-support branch October 15, 2025 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

blocked A PR is blocked on some discussion or other PR question Further information is requested

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants