Skip to content

Support for Generic Functions #4

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

Closed
ZuseZ4 opened this issue Jan 23, 2023 · 1 comment
Closed

Support for Generic Functions #4

ZuseZ4 opened this issue Jan 23, 2023 · 1 comment
Assignees

Comments

@ZuseZ4
Copy link
Collaborator

ZuseZ4 commented Jan 23, 2023

Overlaps with not using extern blocks anymore.
Design proposal as per our discussion:

fn foo<T: Add>(a: T) -> T {
    a * a
}

#[autodiff(foo, dfoo, Active, Duplicated)]
fn dfoo<T>(a: T, b: T) -> T;

fn main() {
    dbg!(dfoo<f32>(3.14, 1.0));
}

require ; after function declaration trough the autodiff macro.
Automatically replace ; with {unimplemented!();}

Required Checks:
dfoo<f32> checks if foo<f32> is a valid instanciation
input and output Activity must be valid for the given T (think of Output for Scalar types, Duplicated for ptr/ref/.. types.

Actions:
Instanciate foo in case that no other code is using foo<f32>.
Mark foo as used s.t. it won't be optimized away. Similar to our previous primary fncs.

Explanation:
Asking for the derivative dfoo<T> must differentiate the source code of foo<T>, so we must instanciate foo<T>.

@ZuseZ4
Copy link
Collaborator Author

ZuseZ4 commented Jan 23, 2023

issues: Not using extern "unadjusted" will bring back all the issues we had with abi modifications:
https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/rustc.2Fllvm.20changing.20fnc.20signature

We need to make sure that the same abi modifications will be applied to our Enzyme generated dfoo, to match the modified rustc abi for dfoo.

@ZuseZ4 ZuseZ4 closed this as completed Feb 6, 2023
bytesnake pushed a commit that referenced this issue May 27, 2023
…t, r=tmiasko

Encode def span for foreign return-position `impl Trait` in trait

Fixes rust-lang#111031, yet another def-span encoding issue :/

Includes a smaller repro than the issue, but I can confirm it ICEs:

```
query stack during panic:
#0 [def_span] looking up span for `rpitit::Foo::bar::{opaque#0}`
#1 [object_safety_violations] determining object safety of trait `rpitit::Foo`
#2 [check_is_object_safe] checking if trait `rpitit::Foo` is object safe
#3 [typeck] type-checking `main`
#4 [used_trait_imports] finding used_trait_imports `main`
#5 [analysis] running analysis passes on this crate
```

Luckily since this only affects nightly, this desn't need to be backported.
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

No branches or pull requests

2 participants