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

Some type inference cleanups #227

Merged
merged 4 commits into from
Jul 1, 2024
Merged

Some type inference cleanups #227

merged 4 commits into from
Jul 1, 2024

Conversation

apoelstra
Copy link
Collaborator

Over the weekend I largely rewrote the type inference API to allocate bounds using a slab allocator so that we don't leak memory when we construct reference cycles. These changes seemed independently useful and could be PR'd on their own.

The arrow module has a ton of `for_*` methods which duplicate the
methods in the Constructible traits. Most of these are purely redundant
and can be deleted. A couple provide some code reuse, and are demoted to
be non-`pub`.

Smoe variable names changed in the redundant code, so this will likely
not appear as a code-move in the diff, even though it is one. You can
just skim this commit.
This eliminates an `unwrap`, cleans up a bit of code in named_node.rs,
and moves every instance of `Type::from` into types/mod.rs, where it
will be easy to modify or remove in a later commit.

Also removes From<Arc<Final>> for Type, a somewhat-weird From impl which
was introduced in #218. It is now superceded by Type::complete.

In general I would like to remove From impls from Type because they have
an inflexible API and because they have somewhat nonobvious behavior.
The type_name conversion methods use a private TypeConstructible trait
which winds up taking more code to use than it saves by reducing reuse.
(Though arguably the reuse makes the code more obviously internally
consistent.)

In future we won't be able to use this trait anyway because the Type
constructor will need a type-inference context while the other
constructors will not. So delete it now.
@@ -227,12 +226,6 @@ impl Final {
}
}

impl From<Arc<Final>> for Type {
Copy link
Collaborator

Choose a reason for hiding this comment

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

12a1885: Out of curiosity, what is the nonobvious behavior of From that you referenced in the commit message?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually this one is pretty straightforward -- it is the From impls from Bound to Type that are weird. It takes a bound, creates a new union-bound object (which users do not see at all, but which have crazy nonlocal behavior) and constructs a type which initially has that bound and no others.

In a later PR I may actually make the Bound type private and not user-visible. It's not actually used outside of the types module (including types/arrow.rs which actually implements the type inference rules) and it's not obvious what it's suppose to mean for users.

Copy link
Collaborator

@uncomputable uncomputable left a comment

Choose a reason for hiding this comment

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

ACK dc83206

@uncomputable uncomputable merged commit b55b8e7 into master Jul 1, 2024
27 checks passed
@apoelstra apoelstra deleted the 2024-06--types-1 branch July 1, 2024 17:44
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.

2 participants