Skip to content

autodiff: generate TypeTree metadata for extractvalue#158440

Draft
ZuseZ4 wants to merge 2 commits into
rust-lang:mainfrom
ZuseZ4:typetrees-for-enzyme4
Draft

autodiff: generate TypeTree metadata for extractvalue#158440
ZuseZ4 wants to merge 2 commits into
rust-lang:mainfrom
ZuseZ4:typetrees-for-enzyme4

Conversation

@ZuseZ4

@ZuseZ4 ZuseZ4 commented Jun 26, 2026

Copy link
Copy Markdown
Member

Further improvements after #158333

This is the first time that we actually generate enough typetree information to make autodiff succed in compiling a previously failing build.

@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. F-autodiff `#![feature(autodiff)]` S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 26, 2026
@rust-bors

This comment has been minimized.

@ZuseZ4 ZuseZ4 force-pushed the typetrees-for-enzyme4 branch from 1b673bf to d773c15 Compare June 27, 2026 07:33
@rust-log-analyzer

This comment has been minimized.

@ZuseZ4 ZuseZ4 force-pushed the typetrees-for-enzyme4 branch from d773c15 to e252e58 Compare June 29, 2026 02:13
@rustbot rustbot added the A-run-make Area: port run-make Makefiles to rmake.rs label Jun 29, 2026
@rust-log-analyzer

This comment has been minimized.

ZuseZ4 added 2 commits June 30, 2026 04:32
…r generation for memcpy.

This moves a TA failure in the testcase from memcpy to a later location.
@ZuseZ4 ZuseZ4 force-pushed the typetrees-for-enzyme4 branch from e252e58 to ab0cb6a Compare June 30, 2026 02:51
@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

The job tidy failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
[TIMING:end] tool::ToolBuild { build_compiler: Compiler { stage: 0, host: x86_64-unknown-linux-gnu, forced_compiler: false }, target: x86_64-unknown-linux-gnu, tool: "tidy", path: "src/tools/tidy", mode: ToolBootstrap, source_type: InTree, extra_features: [], allow_features: "", cargo_args: [], artifact_kind: Binary } -- 12.104
[TIMING:end] tool::Tidy { compiler: Compiler { stage: 0, host: x86_64-unknown-linux-gnu, forced_compiler: false }, target: x86_64-unknown-linux-gnu } -- 0.000
fmt check
Diff in /checkout/compiler/rustc_codegen_ssa/src/traits/builder.rs:568:
     fn va_arg(&mut self, list: Self::Value, ty: Self::Type) -> Self::Value;
     fn extract_element(&mut self, vec: Self::Value, idx: Self::Value) -> Self::Value;
     fn vector_splat(&mut self, num_elts: usize, elt: Self::Value) -> Self::Value;
-    fn extract_value(&mut self, agg_val: Self::Value, idx: u64, tt: Option<TypeTree>) -> Self::Value;
+    fn extract_value(
+        &mut self,
+        agg_val: Self::Value,
+        idx: u64,
+        tt: Option<TypeTree>,
+    ) -> Self::Value;
     fn insert_value(&mut self, agg_val: Self::Value, elt: Self::Value, idx: u64) -> Self::Value;
 
     fn set_personality_fn(&mut self, personality: Self::Function);
Diff in /checkout/compiler/rustc_codegen_ssa/src/mir/operand.rs:5:
 use rustc_abi::{
     Align, BackendRepr, FIRST_VARIANT, FieldIdx, Primitive, Size, TagEncoding, VariantIdx, Variants,
 };
+use rustc_ast::expand::typetree::TypeTree;
 use rustc_hir::LangItem;
 use rustc_middle::mir::interpret::{Pointer, Scalar, alloc_range};
 use rustc_middle::mir::{self, ConstValue};
Diff in /checkout/compiler/rustc_codegen_ssa/src/mir/operand.rs:11:
 use rustc_middle::ty::layout::{LayoutOf, TyAndLayout};
+use rustc_middle::ty::typetree::typetree_from_ty;
 use rustc_middle::ty::{self, Ty};
 use rustc_middle::{bug, span_bug};
 use rustc_session::config::{AnnotateMoves, DebugInfo, OptLevel};
Diff in /checkout/compiler/rustc_codegen_ssa/src/mir/operand.rs:15:
+use rustc_span::sym;
 use tracing::{debug, instrument};
 
 use super::place::{PlaceRef, PlaceValue};
Diff in /checkout/compiler/rustc_codegen_ssa/src/mir/operand.rs:18:
 use super::rvalue::transmute_scalar;
 use super::{FunctionCx, LocalRef};
-use crate::MemFlags;
 use crate::common::IntPredicate;
 use crate::traits::*;
+use crate::{MemFlags, TyCtxt};
 
-
-use rustc_ast::expand::typetree::TypeTree;
-use rustc_middle::ty::typetree::typetree_from_ty;
-use crate::TyCtxt;
-use rustc_span::sym;
-
-fn option_ptr_like_scalar_pair_tts<'tcx>(
-    tcx: TyCtxt<'tcx>,
-    ty: Ty<'tcx>,
-) -> Option<TypeTree> {
+fn option_ptr_like_scalar_pair_tts<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option<TypeTree> {
     let ty::Adt(def, args) = ty.kind() else {
         return None;
     };
Diff in /checkout/compiler/rustc_codegen_ssa/src/mir/operand.rs:395:
 
             // Deconstruct the immediate aggregate.
             let f1 = option_ptr_like_scalar_pair_tts(bx.tcx(), layout.ty);
-            let f2 = if f1.is_none() {
-                None
-            } else {
-                Some(TypeTree::int(8))
-            };
+            let f2 = if f1.is_none() { None } else { Some(TypeTree::int(8)) };
             let a_llval = bx.extract_value(llval, 0, f1);
             let b_llval = bx.extract_value(llval, 1, f2);
             OperandValue::Pair(a_llval, b_llval)
Diff in /checkout/compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs:68:
 
     pub(crate) safe fn LLVMRustIsCall(V: &Value) -> bool;
     pub(crate) safe fn LLVMRustSupportsEnzymeMD(V: &Value) -> bool;
-    pub(crate) fn LLVMRustSetEnzymeTypeMD(
-        v: &Value,
-        md: &Value,
-    );
+    pub(crate) fn LLVMRustSetEnzymeTypeMD(v: &Value, md: &Value);
 }
 
 unsafe extern "C" {
Diff in /checkout/compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs:120:
         unsafe extern "C" fn(CTypeTreeRef, *const i64, usize, CConcreteType, &Context);
     type EnzymeTypeTreeToStringFn = unsafe extern "C" fn(CTypeTreeRef) -> *const c_char;
     type EnzymeTypeTreeToStringFreeFn = unsafe extern "C" fn(*const c_char);
-    type EnzymeTypeTreeToMDFn = unsafe extern "C" fn(CTypeTreeRef, &Context) -> Option<& Value>;
+    type EnzymeTypeTreeToMDFn = unsafe extern "C" fn(CTypeTreeRef, &Context) -> Option<&Value>;
 
     #[allow(non_snake_case)]
     pub(crate) struct EnzymeWrapper {
Diff in /checkout/compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs:309:
             unsafe { (self.EnzymeTypeTreeToStringFree)(ch) }
         }
 
-        pub(crate) fn tree_to_md<'a>(&'a self, tree: *mut EnzymeTypeTree, ctx: &'a Context) -> Option<&'a Value> {
+        pub(crate) fn tree_to_md<'a>(
+            &'a self,
+            tree: *mut EnzymeTypeTree,
+            ctx: &'a Context,
+        ) -> Option<&'a Value> {
             unsafe { (self.EnzymeTypeTreeToMD)(tree, ctx) }
         }
 
Diff in /checkout/compiler/rustc_codegen_llvm/src/builder.rs:2:
 use std::iter;
 use std::ops::Deref;
 
-use rustc_ast::expand::typetree::FncTree;
-use rustc_ast::expand::typetree::TypeTree;
+use rustc_ast::expand::typetree::{FncTree, TypeTree};
 pub(crate) mod autodiff;
 pub(crate) mod gpu_offload;
 
Diff in /checkout/compiler/rustc_codegen_llvm/src/builder.rs:1260:
 
     fn extract_value(&mut self, agg_val: &'ll Value, idx: u64, tt: Option<TypeTree>) -> &'ll Value {
         assert_eq!(idx as c_uint as u64, idx);
-        let extract = unsafe { llvm::LLVMBuildExtractValue(self.llbuilder, agg_val, idx as c_uint, UNNAMED) };
+        let extract =
+            unsafe { llvm::LLVMBuildExtractValue(self.llbuilder, agg_val, idx as c_uint, UNNAMED) };
         if let Some(tt) = tt {
-            let fnc_tree = FncTree {
-                args: vec![],
-                ret: tt,
-            };
-            crate::typetree::add_tt(self.cx().llmod, self.cx().llcx, self.cx().tcx, extract, fnc_tree);
+            let fnc_tree = FncTree { args: vec![], ret: tt };
+            crate::typetree::add_tt(
+                self.cx().llmod,
+                self.cx().llcx,
+                self.cx().tcx,
+                extract,
+                fnc_tree,
+            );
         }
         extract
     }
error: encountered diff marker
##[error] --> /checkout/tests/run-make/autodiff/type-trees/iter/rmake.rs:6:1
  |
6 | <<<<<<< HEAD
  | ^^^^^^^ between this marker and `=======` is the code that you are merging into
  |
  = note: conflict markers indicate that a merge was started but could not be completed due to merge conflicts
          to resolve a conflict, keep only the code you want and then delete the lines containing conflict markers
  = help: if you are in a merge, the top section is the code you already had checked out and the bottom section is the new code
          if you are in a rebase, the top section is the code being rebased onto and the bottom section is the code you had checked out which is being rebased
  = note: for an explanation on these markers from the `git` documentation, visit <https://git-scm.com/book/en/v2/Git-Tools-Advanced-Merging#_checking_out_conflicts>

fmt: checked 6954 files
Bootstrap failed while executing `test src/tools/tidy tidyselftest --extra-checks=py,cpp,js,spellcheck`
Build completed unsuccessfully in 0:00:49
  local time: Tue Jun 30 02:56:07 UTC 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-run-make Area: port run-make Makefiles to rmake.rs F-autodiff `#![feature(autodiff)]` S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants