Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix rebuilding types with circular references (#5623). #5637

Merged
merged 1 commit into from
Apr 9, 2024

Conversation

dnovillo
Copy link
Contributor

@dnovillo dnovillo commented Apr 8, 2024

This fixes the problem reported in #5623 using the observation that if we are re-building a type that already exists in the type pool, we should just return that type.

This makes type rebuilding more efficient, and it also prevents the type builder from getting itself into infinite recursion (as reported in this issue).

In fixing this, I found a couple of other bugs in the type builder:

  • When rebuilding an Array type, we were not re-building the element type. This caused stale type references in the rebuilt type.

  • This bug had not been caught by the test, because the test itself had a bug in it: the test was rebuilding types on top of the same ID (the ID counter was never incremented).

Initially, the bug in the test caused a failure with the new logic in the builder because we now return types from the pool directly, which causes a failure when two incompatible types are registered under the same ID.

Fixing that issue in the test exposed another bug in the rebuilder: we were not re-building the element type for Array types. This was causing a stale type reference inside Array types which was later caught by the type removal logic in the test.

This fixes the problem reported in KhronosGroup#5623 using the observation that if
we are re-building a type that already exists in the type pool, we
should just return that type.

This makes type rebuilding more efficient, and it also prevents the
type builder from getting itself into infinite recursion (as reported in
this issue).

In fixing this, I found a couple of other bugs in the type builder:

- When rebuilding an Array type, we were not re-building the element
  type. This caused stale type references in the rebuilt type.

- This bug had not been caught by the test, because the test itself had
  a bug in it: the test was rebuilding types on top of the same ID (the
  ID counter was never incremented).

Initially, the bug in the test caused a failure with the new logic in
the builder because we now return types from the pool directly, which
causes a failure when two incompatible types are registered under the
same ID.

Fixing that issue in the test exposed another bug in the rebuilder: we
were not re-building the element type for Array types. This was causing
a stale type reference inside Array types which was later caught by the
type removal logic in the test.
@dnovillo dnovillo requested a review from alan-baker April 8, 2024 20:36
@dnovillo dnovillo merged commit 3983d15 into KhronosGroup:main Apr 9, 2024
24 checks passed
for (auto& t : types) {
context->get_type_mgr()->RegisterType(id, *t);
context->get_type_mgr()->RegisterType(++id, *t);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wow. Nice catch!

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