os-rust/compiler
bors 785c83015c Auto merge of #129458 - EnzymeAD:enzyme-frontend, r=jieyouxu
Autodiff Upstreaming - enzyme frontend

This is an upstream PR for the `autodiff` rustc_builtin_macro that is part of the autodiff feature.

For the full implementation, see: https://github.com/rust-lang/rust/pull/129175

**Content:**
It contains a new `#[autodiff(<args>)]` rustc_builtin_macro, as well as a `#[rustc_autodiff]` builtin attribute.
The autodiff macro is applied on function `f` and will expand to a second function `df` (name given by user).
It will add a dummy body to `df` to make sure it type-checks. The body will later be replaced by enzyme on llvm-ir level,
we therefore don't really care about the content. Most of the changes (700 from 1.2k) are in `compiler/rustc_builtin_macros/src/autodiff.rs`, which expand the macro. Nothing except expansion is implemented for now.
I have a fallback implementation for relevant functions in case that rustc should be build without autodiff support. The default for now will be off, although we want to flip it later (once everything landed) to on for nightly. For the sake of CI, I have flipped the defaults, I'll revert this before merging.

**Dummy function Body:**
The first line is an `inline_asm` nop to make inlining less likely (I have additional checks to prevent this in the middle end of rustc. If `f` gets inlined too early, we can't pass it to enzyme and thus can't differentiate it.
If `df` gets inlined too early, the call site will just compute this dummy code instead of the derivatives, a correctness issue. The following black_box lines make sure that none of the input arguments is getting optimized away before we replace the body.

**Motivation:**
The user facing autodiff macro can verify the user input. Then I write it as args to the rustc_attribute, so from here on I can know that these values should be sensible. A rustc_attribute also turned out to be quite nice to attach this information to the corresponding function and carry it till the backend.
This is also just an experiment, I expect to adjust the user facing autodiff macro based on user feedback, to improve usability.

As a simple example of what this will do, we can see this expansion:
From:
```
#[autodiff(df, Reverse, Duplicated, Const, Active)]
pub fn f1(x: &[f64], y: f64) -> f64 {
    unimplemented!()
}
```
to
```
#[rustc_autodiff]
#[inline(never)]
pub fn f1(x: &[f64], y: f64) -> f64 {
    ::core::panicking::panic("not implemented")
}
#[rustc_autodiff(Reverse, Duplicated, Const, Active,)]
#[inline(never)]
pub fn df(x: &[f64], dx: &mut [f64], y: f64, dret: f64) -> f64 {
    unsafe { asm!("NOP"); };
    ::core::hint::black_box(f1(x, y));
    ::core::hint::black_box((dx, dret));
    ::core::hint::black_box(f1(x, y))
}
```
I will add a few more tests once I figured out why rustc rebuilds every time I touch a test.

Tracking:

- https://github.com/rust-lang/rust/issues/124509

try-job: dist-x86_64-msvc
2024-10-15 01:30:01 +00:00
..
rustc disable size asserts in the compiler when randomizing layouts 2024-08-31 23:56:45 +02:00
rustc_abi compiler: Wire {TyAnd,}Layout into rustc_abi 2024-10-11 17:41:52 -07:00
rustc_arena Remove unnecessary lifetimes from Arena. 2024-09-13 15:33:19 +10:00
rustc_ast Auto merge of #129458 - EnzymeAD:enzyme-frontend, r=jieyouxu 2024-10-15 01:30:01 +00:00
rustc_ast_ir Add warn(unreachable_pub) to several crates. 2024-08-16 08:46:13 +10:00
rustc_ast_lowering Remove const trait bound modifier hack 2024-10-13 09:48:01 -04:00
rustc_ast_passes Rollup merge of #131550 - compiler-errors:extern-diags, r=spastorino 2024-10-14 17:06:38 +02:00
rustc_ast_pretty Auto merge of #131045 - compiler-errors:remove-unnamed_fields, r=wesleywiser 2024-10-11 13:11:13 +00:00
rustc_attr Rename NestedMetaItem to MetaItemInner 2024-10-06 23:28:30 +09:00
rustc_baked_icu_data Don't add warn(unreachable_pub) to rustc_baked_icu. 2024-08-16 08:46:52 +10:00
rustc_borrowck Rollup merge of #131626 - matthiaskrgr:dont_string, r=lqd 2024-10-12 21:38:38 -05:00
rustc_builtin_macros Auto merge of #129458 - EnzymeAD:enzyme-frontend, r=jieyouxu 2024-10-15 01:30:01 +00:00
rustc_codegen_cranelift intrinsics.fmuladdf{16,32,64,128}: expose llvm.fmuladd.* semantics 2024-10-11 15:32:56 -06:00
rustc_codegen_gcc intrinsics.fmuladdf{16,32,64,128}: expose llvm.fmuladd.* semantics 2024-10-11 15:32:56 -06:00
rustc_codegen_llvm Fix AArch64InlineAsmReg::emit 2024-10-14 06:04:07 +09:00
rustc_codegen_ssa Rollup merge of #129079 - Zoxc:thinlto_imp_symbols, r=wesleywiser 2024-10-11 15:36:51 +02:00
rustc_const_eval miri: avoid cloning AllocExtra 2024-10-12 12:14:28 +02:00
rustc_data_structures Rollup merge of #131277 - ismailarilik:handle-potential-query-instability-lint-for-clippy, r=xFrednet 2024-10-12 23:00:57 +02:00
rustc_driver Use tidy to sort crate attributes for all compiler crates. 2024-06-12 15:49:10 +10:00
rustc_driver_impl Rollup merge of #130899 - bjorn3:wasi_bootstrap_fixes, r=davidtwco 2024-10-07 11:10:53 -07:00
rustc_error_codes Fix typo in E0793 2024-10-09 10:28:16 -07:00
rustc_error_messages Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
rustc_errors Rollup merge of #131344 - nnethercote:ref-Lrc, r=compiler-errors 2024-10-07 12:23:54 +02:00
rustc_expand Single commit implementing the enzyme/autodiff frontend 2024-10-11 19:13:31 +02:00
rustc_feature Auto merge of #129458 - EnzymeAD:enzyme-frontend, r=jieyouxu 2024-10-15 01:30:01 +00:00
rustc_fluent_macro Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
rustc_fs_util Couple of changes to make it easier to compile rustc for wasm 2024-09-26 19:51:14 +00:00
rustc_graphviz Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
rustc_hir Rollup merge of #130625 - heiseish:issue-124028-fix, r=jieyouxu 2024-10-10 12:49:18 +02:00
rustc_hir_analysis Rollup merge of #131239 - VulnBandit:trait-vulnerability, r=lcnr 2024-10-12 23:00:56 +02:00
rustc_hir_pretty rm ItemKind::OpaqueTy 2024-10-04 23:28:22 +00:00
rustc_hir_typeck Auto merge of #131045 - compiler-errors:remove-unnamed_fields, r=wesleywiser 2024-10-11 13:11:13 +00:00
rustc_incremental Rename NestedMetaItem to MetaItemInner 2024-10-06 23:28:30 +09:00
rustc_index Rollup merge of #130625 - heiseish:issue-124028-fix, r=jieyouxu 2024-10-10 12:49:18 +02:00
rustc_index_macros Remove usage of specialization from newtype_index! 2024-06-30 16:42:53 +00:00
rustc_infer Make super combine into fns 2024-10-10 06:07:52 -04:00
rustc_interface Handle rustc_interface cases of rustc::potential_query_instability lint 2024-10-05 10:01:27 +03:00
rustc_lexer Reserve guarded string literals (RFC 3593) 2024-10-08 18:21:16 -06:00
rustc_lint Also use outermost const-anon for impl items in non_local_defs lint 2024-10-13 18:14:29 +02:00
rustc_lint_defs Rollup merge of #128784 - tdittr:check-abi-on-fn-ptr, r=compiler-errors 2024-10-12 23:00:55 +02:00
rustc_llvm Rollup merge of #131552 - durin42:llvm-20-getOrInsertDeclaration, r=cuviper 2024-10-11 16:53:50 -05:00
rustc_log Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
rustc_macros Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
rustc_metadata Auto merge of #131045 - compiler-errors:remove-unnamed_fields, r=wesleywiser 2024-10-11 13:11:13 +00:00
rustc_middle Rollup merge of #131473 - workingjubilee:move-that-abi-up, r=saethlin 2024-10-14 06:04:28 +02:00
rustc_mir_build Auto merge of #131045 - compiler-errors:remove-unnamed_fields, r=wesleywiser 2024-10-11 13:11:13 +00:00
rustc_mir_dataflow Auto merge of #131235 - codemountains:rename-nestedmetaitem-to-metaitemlnner, r=nnethercote 2024-10-07 08:59:55 +00:00
rustc_mir_transform coverage. Warn about too many test vectors 2024-10-08 11:15:26 +08:00
rustc_monomorphize Use wide pointers consistenly across the compiler 2024-10-04 14:06:48 +02:00
rustc_next_trait_solver Shallowly match opaque key in storage 2024-10-12 09:10:07 -04:00
rustc_parse Update unicode-width to 0.2.0 2024-10-12 21:57:50 +00:00
rustc_parse_format Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
rustc_passes Auto merge of #129458 - EnzymeAD:enzyme-frontend, r=jieyouxu 2024-10-15 01:30:01 +00:00
rustc_pattern_analysis cleanup: don't clone types that are Copy 2024-09-29 13:31:30 +02:00
rustc_privacy Visit opaques for visibilities. 2024-10-04 23:31:55 +00:00
rustc_query_impl Handle rustc_query_impl cases of rustc::potential_query_instability lint 2024-10-03 12:47:08 +03:00
rustc_query_system add unstable support for outputting file checksums for use in cargo 2024-10-01 21:23:20 -06:00
rustc_resolve Auto merge of #131045 - compiler-errors:remove-unnamed_fields, r=wesleywiser 2024-10-11 13:11:13 +00:00
rustc_sanitizers Fix some pub(crate) that were undetected bc of instrument 2024-10-04 14:02:09 -04:00
rustc_serialize Stabilize const_option 2024-10-12 17:07:13 -04:00
rustc_session Rollup merge of #131626 - matthiaskrgr:dont_string, r=lqd 2024-10-12 21:38:38 -05:00
rustc_smir various fixes for naked_asm! implementation 2024-10-06 19:00:09 +02:00
rustc_span Auto merge of #129458 - EnzymeAD:enzyme-frontend, r=jieyouxu 2024-10-15 01:30:01 +00:00
rustc_symbol_mangling Rollup merge of #130344 - Jaic1:fix-116306, r=BoxyUwU 2024-09-23 06:45:33 +02:00
rustc_target Rollup merge of #131667 - taiki-e:aarch64-inline-asm-reg-emit, r=Amanieu 2024-10-14 17:06:38 +02:00
rustc_trait_selection remove outdated FIXMEs 2024-10-11 10:41:10 +00:00
rustc_traits Compiler: Rename "object safe" to "dyn compatible" 2024-09-25 13:26:48 +02:00
rustc_transmute Fix some pub(crate) that were undetected bc of instrument 2024-10-04 14:02:09 -04:00
rustc_ty_utils compiler: Factor rustc_target::abi::* out of ty_utils 2024-10-08 18:24:38 -07:00
rustc_type_ir Add variances to RPITITs 2024-10-10 11:46:48 -07:00
rustc_type_ir_macros Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
stable_mir clarify semantics of ConstantIndex MIR projection 2024-10-05 12:19:14 +02:00