Skip to content

[WIP] Polymorphization - #160300

Draft
camelid wants to merge 4 commits into
rust-lang:mainfrom
camelid:poly
Draft

camelid wants to merge 4 commits into
rust-lang:mainfrom
camelid:poly

Conversation

@camelid

@camelid camelid commented Jul 31, 2026

Copy link
Copy Markdown
Member

No description provided.

@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. PG-exploit-mitigations Project group: Exploit mitigations S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Jul 31, 2026
@rust-log-analyzer

This comment has been minimized.

@rust-bors

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-bors

This comment has been minimized.

Make randomization_seed required again

For now it's fine to just check if conflicting CLI flags are passed.
Though it may still be good to ensure correctness by construction for
layouts (wrt randomization) in the future.

Add FIXME

Keep params in erased types, but prevent them from escaping

Remove outdated hacky check

It seems to be unneeded for now, but probably a principled solution to
the underlying problem will need to be added later once we erase params
with bounds.

Make polymorphization a query

Show full param layout info in type

Compute fixpoint set of polymorphizable functions

Functions that contain casts of generic functions to fnptrs cannot be
polymorphized (see Amanieu's talk on stable ABI for more detail). Also,
all callers of those functions cannot be polymorphized. Since functions
can recurse, we need to compute the set of tainted functions as a
fixpoint.

Disqualify non-Rustic ABIs from polymorphization

Functions that have or contain arguments (fn ptrs) with non-Rustic ABIs
are marked as tainted. It's probably overly conservative right now.

FIx inconsistency in instance lookup
@rust-log-analyzer

This comment has been minimized.

For now, we need to include its associated type in the param layout and
taint any functions that read discriminants. Ultimately we'll need to
put it in the vtable like a regular trait except it always needs to be
included because it has a blanket impl instead of being an auto trait
(sigh).
@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

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

Click to see the possible cause of the failure (guessed by this bot)
#10 2.576 + mv node-v24.22.2-linux-x64 /node
#10 2.578 + /node/bin/node /node/bin/npm install --global yarn@1.22.22
#10 3.136 
#10 3.136 added 1 package in 488ms
#10 3.138 npm warn install-scripts 1 package has install scripts not yet covered by allowScripts:
#10 3.138 npm warn install-scripts   yarn@1.22.22 (preinstall: :; (node ./preinstall.js > /dev/null 2>&1 || true))
#10 3.138 npm warn install-scripts
#10 3.138 npm warn install-scripts Run `npm install -g --allow-scripts=yarn` to allow these scripts once, or `npm config set allow-scripts=yarn --location=user` to allow them for all global installs.
#10 3.140 npm notice
#10 3.140 npm notice New major version of npm available! 11.19.1 -> 12.2.3
#10 3.140 npm notice Changelog: https://github.com/npm/cli/releases/tag/v12.2.3
#10 3.140 npm notice To update run: npm install -g npm@12.2.3
#10 3.140 npm notice
---
tidy check
x.py completions check
tidy [rustdoc_json (src)]: `rustdoc-json-types` modified, checking format version
tidy: Skipping binary file check, read-only filesystem
tidy [style (compiler)]: /checkout/compiler/rustc_symbol_mangling/src/v0.rs:368: TODO is used for tasks that should be done before merging a PR;
If you want to leave a message in the codebase use FIXME
 >> TODO: this hashing is a really hacky temporary approach
tidy [style (compiler)]: /checkout/compiler/rustc_symbol_mangling/src/v0.rs:587: TODO is used for tasks that should be done before merging a PR;
If you want to leave a message in the codebase use FIXME
 >> TODO: this needs more thought and design work
tidy [style (compiler)]: /checkout/compiler/rustc_symbol_mangling/src/lib.rs:147: TODO is used for tasks that should be done before merging a PR;
If you want to leave a message in the codebase use FIXME
 >> TODO: this is wrong, it should be handled correctly in the callers instead
tidy [style (compiler)]: /checkout/compiler/rustc_symbol_mangling/src/lib.rs:361: TODO is used for tasks that should be done before merging a PR;
If you want to leave a message in the codebase use FIXME
 >> TODO: handle erased params in demangling somehow
tidy [style (compiler)]: /checkout/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs:451: TODO is used for tasks that should be done before merging a PR;
If you want to leave a message in the codebase use FIXME
 >> TODO: should we include the param/layout as well?
tidy [style (compiler)]: /checkout/compiler/rustc_codegen_ssa/src/mir/mod.rs:217: TODO is used for tasks that should be done before merging a PR;
If you want to leave a message in the codebase use FIXME
 >> TODO: this is a hacky temporary thing, remove or make proper
tidy [style (compiler)]: /checkout/compiler/rustc_ty_utils/src/polymorphize.rs:21: TODO is used for tasks that should be done before merging a PR;
If you want to leave a message in the codebase use FIXME
 >> TODO: this should be used less ad hoc
tidy [style (compiler)]: /checkout/compiler/rustc_ty_utils/src/polymorphize.rs:33: TODO is used for tasks that should be done before merging a PR;
If you want to leave a message in the codebase use FIXME
 >> TODO: is there any way this is visible from generic user code that doesn't use intrinsics?
tidy [style (compiler)]: /checkout/compiler/rustc_ty_utils/src/polymorphize.rs:277: TODO is used for tasks that should be done before merging a PR;
If you want to leave a message in the codebase use FIXME
 >> TODO: maybe disqualify T: 'static since that's needed for TypeId on stable?
tidy [style (compiler)]: /checkout/compiler/rustc_monomorphize/src/collector.rs:1106: TODO is used for tasks that should be done before merging a PR;
If you want to leave a message in the codebase use FIXME
 >> TODO: polymorphize should not be ad hoc like this
tidy [style (compiler)]: /checkout/compiler/rustc_public/src/unstable/convert/stable/ty.rs:498: TODO is used for tasks that should be done before merging a PR;
If you want to leave a message in the codebase use FIXME
 >> TODO: should add new rustc_public::TyKind variant probably
tidy [style (compiler)]: /checkout/compiler/rustc_public/src/unstable/convert/stable/ty.rs:499: the `todo!` macro is used for tasks that should be done before merging a PR.
If you want to panic here, use `panic!`, `unimplemented!`, `unreachable!`, `rustc_middle::bug!` or an assertion
tidy [style (compiler)]: /checkout/compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/encode.rs:748: TODO is used for tasks that should be done before merging a PR;
If you want to leave a message in the codebase use FIXME
tidy [style (compiler)]: /checkout/compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/encode.rs:749: the `todo!` macro is used for tasks that should be done before merging a PR.
If you want to panic here, use `panic!`, `unimplemented!`, `unreachable!`, `rustc_middle::bug!` or an assertion
tidy [style (compiler)]: /checkout/compiler/rustc_trait_selection/src/traits/select/mod.rs:2073: TODO is used for tasks that should be done before merging a PR;
If you want to leave a message in the codebase use FIXME
 >> TODO: this is a bit sketchy since we checked sizedness of the layout before creating ty::Erased
tidy [style (compiler)]: /checkout/compiler/rustc_middle/src/ty/util.rs:1577: TODO is used for tasks that should be done before merging a PR;
If you want to leave a message in the codebase use FIXME
 >> TODO: this should be changed once Erased types can have drop impls
tidy [style (compiler)]: /checkout/compiler/rustc_middle/src/ty/instance.rs:996: TODO is used for tasks that should be done before merging a PR;
If you want to leave a message in the codebase use FIXME
 >> TODO: this and polymorphize should probably be queries,
tidy [style (compiler)]: /checkout/compiler/rustc_middle/src/ty/layout.rs:1075: TODO is used for tasks that should be done before merging a PR;
If you want to leave a message in the codebase use FIXME
 >> TODO: probably need to support this
tidy [style (compiler)]: FAIL
removing old virtual environment
creating virtual environment at '/checkout/obj/build/venv' using 'python3.12' and 'venv'
Requirement already satisfied: pip in ./build/venv/lib/python3.12/site-packages (24.0)
Collecting pip
  Downloading pip-26.3-py3-none-any.whl.metadata (4.6 kB)
---
Running eslint on rustdoc JS files
info: ES-Check: checking 7 files...
info: ✓ ES-Check passed! All files are ES10 compatible.
typechecking javascript files
tidy: The following check failed: style (compiler)
Command `/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-tools-bin/rust-tidy --root-path=/checkout --cargo-path=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo --output-dir=/checkout/obj/build --concurrency=4 --npm-path=/node/bin/yarn --ci=true --extra-checks=py,cpp,js,spellcheck` failed with exit code 1
Created at: src/bootstrap/src/core/build_steps/tool.rs:1668:23
Executed at: src/bootstrap/src/core/build_steps/test.rs:1834:24

Command has failed. Rerun with -v to see more details.
Bootstrap failed while executing `test src/tools/tidy tidyselftest --extra-checks=py,cpp,js,spellcheck`
Currently active steps:
test::Tidy {  } at src/bootstrap/src/core/build_steps/test.rs:1749
Build completed unsuccessfully in 0:02:45
  local time: Sun Nov 29 18:19:07 UTC 2026

This branch has not been deployed

No deployments
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. PG-exploit-mitigations Project group: Exploit mitigations S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants