-
Notifications
You must be signed in to change notification settings - Fork 12
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
Conversation
7d05d67
to
dd3e6aa
Compare
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.
Refactor only.
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.
dd3e6aa
to
dc83206
Compare
@@ -227,12 +226,6 @@ impl Final { | |||
} | |||
} | |||
|
|||
impl From<Arc<Final>> for Type { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK dc83206
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.