Skip to content

Conversation

@sbillig
Copy link
Collaborator

@sbillig sbillig commented Jan 20, 2026

MIR was resolving any function in core/std named "mload", "mstore", etc as an intrinsic (including trait methods). Fixing this by tracking and checking func.is_extern (this should be tightened up more, to check a specific path) revealed that these methods weren't resolvable to concrete impls when used in free functions called from contracts, because the concrete effect provider type from the contract wasn't being propagated to the functions called within the contract.

So, some reworking of how we do things to make this tidy(er):

  • We treat all effect params as implicit generic params with a trait bound. For an effect that resolves to a concrete type T, the implicit generic param is __effprov0: EffectRef<T>. This has been the mental model for a while, now we're just fully leaning into it.
  • Each resolved effect arg now carries key_kind (type vs trait) and (for type effects) the instantiated target type, so MIR doesn’t need to resolve/normalize effect keys/types.
  • MIR now computes effect-param address spaces from HIR’s provider-param index map and uses HIR metadata instead of MIR path resolution.
  • Removed obsolete contract RootEffect folding in MIR
  • Improved monomorphization root seeding: use effect_bindings() as the source of truth and only seed the target default root effect instance when it satisfies the trait (error otherwise for now).
  • Propagate address-space provenance for by-ref trait-effect providers via monomorphization specialization (and fix trait-method receiver-space for Self-typed trait methods), so storage-backed providers generate sload.
  • Reduce redundant monomorphizations: canonicalize receiver_space=Memory to “no specialization”, eliminating duplicate *_mem instances.

@sbillig sbillig marked this pull request as ready for review January 22, 2026 20:21
@sbillig sbillig requested a review from micahscopes January 22, 2026 20:21
@sbillig sbillig changed the title fix stuff Fix intrinsic resolution; fix effect param address space propagation; more mir cleanup Jan 22, 2026
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

PathRes::Trait(trait_inst) => {
let mut instantiation_args = Vec::with_capacity(1 + callable.generic_args().len());
instantiation_args.push(provided_ty);
instantiation_args.extend_from_slice(callable.generic_args());

P2 Badge Instantiate trait-effect generics with correct args

In resolve_effect_requirement, trait effects are instantiated with instantiation_args = [provided_ty] + callable.generic_args(). After this change, callable.generic_args() includes the implicit effect-provider parameters that were inserted ahead of user generics, so a key like uses (ctx: Ctx<T>) will be instantiated as Ctx<__effprov0> instead of Ctx<T>. This misbinds trait requirements and can cause valid calls to fail (or invalid ones to pass) whenever the effect key depends on function generics. You likely need to exclude the effect-provider params (or otherwise realign indices) when building instantiation_args for trait effects.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@sbillig sbillig force-pushed the fix-intrinsic-res branch 2 times, most recently from 8daf1ca to bc7a5a3 Compare January 25, 2026 02:20
@sbillig
Copy link
Collaborator Author

sbillig commented Jan 25, 2026

@codex review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bc7a5a3fc5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

- Monomorphize by-ref trait effect providers by call-site address space, overriding default mem when the provider comes from storage.\n- Fix trait method receiver-space inference to use the trait instantiation’s Self type so storage-backed by-ref receivers generate sload-based code.\n- Update MIR + codegen snapshots.
- Treat receiver address space = memory as the default (no specialization) so method calls don’t force separate *_mem monomorphizations.\n- Canonicalize receiver space in monomorphization/mangling for consistency.\n- Update MIR + Yul snapshots.
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.

1 participant