Skip to content

Remove redundant is_dyn_thread_safe checks#153776

Open
zetanumbers wants to merge 2 commits intorust-lang:mainfrom
zetanumbers:curry-howard-dyn-thread-safe
Open

Remove redundant is_dyn_thread_safe checks#153776
zetanumbers wants to merge 2 commits intorust-lang:mainfrom
zetanumbers:curry-howard-dyn-thread-safe

Conversation

@zetanumbers
Copy link
Contributor

@zetanumbers zetanumbers commented Mar 12, 2026

Refactor uses of FromDyn to reduce number of redundant is_dyn_thread_safe checks and add DynThreadSafe type to encourage users to avoid those in the future.

PR is split up into multiple commits for an easier review.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 12, 2026
@rustbot
Copy link
Collaborator

rustbot commented Mar 12, 2026

r? @JonathanBrouwer

rustbot has assigned @JonathanBrouwer.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 69 candidates
  • Random selection from 16 candidates

@zetanumbers zetanumbers changed the title Reduce is_dyn_thread_safe checks Remove redundant is_dyn_thread_safe checks Mar 12, 2026
@Zoxc
Copy link
Contributor

Zoxc commented Mar 12, 2026

The change to reduce the number of checks is good here.

I'm not sure about adding a separate type for it. The new type DynThreadSafe is equivalent to FromDyn<()> and the same change could be done by adding a FromDyn::try_from method. The naming of DynThreadSafe seem quite trait-like to me too. It seems like it could be more something like DynThreadSafetyEnabled.

@zetanumbers
Copy link
Contributor Author

zetanumbers commented Mar 12, 2026

The naming of DynThreadSafe seem quite trait-like to me too.

Yes. That's because traits are predicates over types. Analogously DynThreadSafe is also a predicate but over a static variable. These are the same in dependent type systems.

@zetanumbers
Copy link
Contributor Author

I'm not sure about adding a separate type for it. The new type DynThreadSafe is equivalent to FromDyn<()> and the same change could be done by adding a FromDyn::try_from method.

FromDyn is simply a newtype over a pair (T, DynThreadSafe) to implement Send and Sync. If those weren't rust traits which require a unique implementation then having a newtype wouldn't be necessary.

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

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. 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.

4 participants