-
Notifications
You must be signed in to change notification settings - Fork 20
Add FnDef
#713
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
base: main
Are you sure you want to change the base?
Add FnDef
#713
Conversation
charon/src/transform/monomorphize.rs
Outdated
TyKind::FnDef(id, gargs) => { | ||
self.found_use_fn(id, gargs); | ||
} |
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.
Why did you remove 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.
it would monomorphize for<'a> foo<'a>
, which is not the actual use of the fn :)
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.
If you don't want to deal with the binder, it's fine to erase regions during mono (there's RegionBinder::erase
for you)
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.
it would monomorphize
for<'a> foo<'a>
, which is not the actual use of the fn :)
why not?
fn foo<'a, T>(_: &'a T) {}
fn takes_closure(_: impl for<'a> Fn(&'a u32)) {}
fn main() {
takes_closure(foo);
}
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.
it was monomorphising the fn twice, e.g. for this code:
fn foo<'a, T>(x: &'a T) {}
fn bar() {
let fooint1: fn(&u8) = foo;
fooint1(&11);
}
it was generating this:
fn test_crate::foo::<'_0_0, u8>(@1: &missing('_0_0) (u8))
{
let @0: (); // return
let x@1: &'_ (u8); // arg #1
@0 := ()
@0 := ()
return
}
fn test_crate::foo::<'_, u8>(@1: &'_ (u8))
{
let @0: (); // return
let x@1: &'_ (u8); // arg #1
@0 := ()
@0 := ()
return
}
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.
That does look good, I guess I'm surprised why this works at all. Where does it find a reference to the function item if not through FnDef
? Also, if you erase()
the binder I think that would get rid of the duplication you mentioned.
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.
through the parameter ! it has a ConstantExpr, which itself has a FnPtr
with the right parameters!
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.
basically a fn is used either via a ConstantExpr, which contains a FnPtr, or a call, that also has one, so it works out nicely
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 interesting. We still need to monomorphize all types though. I'm ok with RegionBinder::new_empty(fix_args(binder.erase())
for now.
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.
done, let me know if that's what you had in mind, and if there's anything else to do for this PR :p
Co-authored-by: Nadrieril <Nadrieril@users.noreply.github.com>
92f2f62
to
c2f8860
Compare
Add
FnDef
as a type -- this represents a constant function, and is a ZST, unlikeArrow
which is a function pointer.Companion PR to cryspen/hax#1487.