-
Notifications
You must be signed in to change notification settings - Fork 14
feat: traits for transforming Types/TypeArgs/etc. #1991
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
937cd14
Add TypeTransformer and (Sum/Function)Type(Arg/Row)::transform
acl-cqc 815536b
trait Transformable to common up all the 'let mut any_change = false'…
acl-cqc cc1e8f2
Transformable v2: implement for [E], works without iter_mut/etc. in a…
acl-cqc 4888184
first test, fix CustomType bound caching
acl-cqc 7002e4d
Second test, fix SumType caching
acl-cqc 6cc7cea
Make clippy happy
acl-cqc bf6a9a4
Test panics on unexpected argument - simpler, better
acl-cqc 5ecd9e6
test functiontype
acl-cqc d9a6d29
clippy that new test
acl-cqc 83e798e
Merge remote-tracking branch 'origin/main' into acl/type_transform
acl-cqc 044ff32
Test variable, boundednat; use list_type
acl-cqc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,10 @@ use std::num::NonZeroU64; | |
use thiserror::Error; | ||
|
||
use super::row_var::MaybeRV; | ||
use super::{check_typevar_decl, NoRV, RowVariable, Substitution, Type, TypeBase, TypeBound}; | ||
use super::{ | ||
check_typevar_decl, NoRV, RowVariable, Substitution, Transformable, Type, TypeBase, TypeBound, | ||
TypeTransformer, | ||
}; | ||
use crate::extension::ExtensionSet; | ||
use crate::extension::SignatureError; | ||
|
||
|
@@ -369,6 +372,19 @@ impl TypeArg { | |
} | ||
} | ||
|
||
impl Transformable for TypeArg { | ||
fn transform<T: TypeTransformer>(&mut self, tr: &T) -> Result<bool, T::Err> { | ||
match self { | ||
TypeArg::Type { ty } => ty.transform(tr), | ||
TypeArg::Sequence { elems } => elems.transform(tr), | ||
TypeArg::BoundedNat { .. } | ||
| TypeArg::String { .. } | ||
| TypeArg::Extensions { .. } | ||
| TypeArg::Variable { .. } => Ok(false), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This case should be tested |
||
} | ||
} | ||
} | ||
|
||
impl TypeArgVariable { | ||
/// Return the index. | ||
pub fn index(&self) -> usize { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
I haven't looked at the other callsites of get_type_def, but I don't like it. I would prefer to inline it here, and just "pub(crate)"-icise
get_extension
. If you disagree I'm fine with this.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.
I'd look at it the other way - how about removing
get_extension
by inlining intoget_type_def
and "pub(crate)"-icise onlyget_type_def
?Uh oh!
There was an error while loading. Please reload this page.
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.
There are three callers of
get_type_def
and they all callget_extension
first with only a slight change in how they handle errors fromget_extension
(i.e. one caller panics....on errors from either, so that's fine to combine both errors)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.
I agree that makes sense, but I do think
get_extension
is a perfectly reasonable thing to want to do. Up to you.Uh oh!
There was an error while loading. Please reload this page.
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.
OIC. The thing is that the caller has to hang onto the result Arc from
get_extension
for the lifetime of the&TypeDef
. Ugh. I guess ifExtension::get_type
returned anOption<Arc<TypeDef>>
rather than anOption<&TypeDef>
then this would go away but otherwise we're a bit stuck.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.
Ok, I don't think the implementation of
get_type_def
is great either, but it seems mad to make the caller do that work (looking up the CustomType's type-id in the extension). Could change it to an Option rather than Result if that's preferable but the SignatureError is appropriate in at least a couple of cases, so I'm inclined to leave it.#2001 covers what I think is the way forward but no need to do that in this PR.