Skip to content

Instantiate body instead of using ParamTypeMapper#13

Merged
coord-e merged 3 commits into
mainfrom
subst-body
Dec 14, 2025
Merged

Instantiate body instead of using ParamTypeMapper#13
coord-e merged 3 commits into
mainfrom
subst-body

Conversation

@coord-e

@coord-e coord-e commented Dec 14, 2025

Copy link
Copy Markdown
Owner

follow-up of #8 for #10

Translating ParamTy in TypeBuilder (via ParamTypeMapper) is insufficient for resolving traits in #10 because the actual GenericArgs are unknown when typing function calls.

In the call to generic within the following example, def_ty_with_args attempts to check generic using int as a type argument (note: this is not i32, as it is already converted to rty::Type). However, BasicBlockAnalyzer unable to find the DefId of <i32 as Trait>::t because it only knows that T=int, but does not know T=i32, making it impossible to use Instance::resolve with fully substituted type arguments (i32 here).

trait Trait {
  fn t(self);
}

impl Trait for i32 {
  fn t(self) { assert!(self != 0); }
}

fn generic<T: Trait>(x: T) {
  x.t()
}

fn main() {
  generic(1_i32);
}

@coord-e coord-e requested a review from Copilot December 14, 2025 08:52
@coord-e coord-e changed the title Subst body Instantiate body instead of using ParamTypeMapper Dec 14, 2025

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements body substitution for generic functions to enable proper trait resolution. Instead of using a ParamTypeMapper to translate type parameters symbolically, the PR substitutes the MIR body with concrete generic arguments (e.g., i32), allowing trait method resolution to work correctly when analyzing generic functions with trait bounds.

Key Changes:

  • Replace the ParamTypeMapper approach with direct MIR body substitution using EarlyBinder::instantiate
  • Update def_ty_with_args to work with mir_ty::GenericArgsRef instead of rty::TypeArgs
  • Add placeholder_generic_args method to generate placeholder arguments for generic functions during analysis

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/rty.rs Remove Hash and PartialEq derives from types that don't need them; remove TypeArgs from public API
src/refine/template.rs Remove ParamTypeMapper trait and related machinery; simplify translate_param_type
src/chc.rs Remove Hash and PartialEq derives from CHC types
src/analyze.rs Update caching to use GenericArgsRef; add local_fn_sig_with_body helper method
src/analyze/crate_.rs Replace type_builder with generic_args approach; add placeholder_generic_args method
src/analyze/local_def.rs Update to use local_fn_sig_with_body; add generic_args method for body substitution
src/analyze/basic_block.rs Simplify function call type resolution to pass GenericArgsRef directly

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/analyze/local_def.rs
Comment thread src/analyze/crate_.rs
Comment thread src/analyze/crate_.rs
Comment thread src/analyze/crate_.rs
Comment thread src/analyze.rs
@coord-e coord-e merged commit b41df50 into main Dec 14, 2025
3 checks passed
@coord-e coord-e deleted the subst-body branch December 14, 2025 09:20
coeff-aij pushed a commit to coeff-aij/thrust that referenced this pull request Jan 12, 2026
Instantiate body instead of using ParamTypeMapper
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

Successfully merging this pull request may close these issues.

2 participants