Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
d661299
From: cleanup
hkBst Oct 6, 2025
6bce0bd
TryFrom<integer> for bool
hkBst Oct 6, 2025
65c1722
add CSE optimization tests for iterating over slice
is57primenumber Dec 16, 2025
eb101b1
Fix(lib/win/thread): Ensure `Sleep`'s usage passes over the requested…
PaulDance Dec 18, 2025
88d04b6
Minor refactorings
bjorn3 Jan 8, 2026
6435125
Move all std_detect unit tests to integration tests
bjorn3 Jan 8, 2026
76438f0
Add codegen test for issue 138497
jamie-osec Aug 14, 2025
bed40af
std: avoid tearing `dbg!` prints
joboet Dec 10, 2025
f80c137
update `dbg!` clippy lint
joboet Dec 12, 2025
ee24f22
update UI tests
joboet Dec 13, 2025
4b25ccd
Rename `DepKindStruct` to `DepKindVTable`
Zalathar Jan 24, 2026
23e5b69
Use rustc_proc_macro in rust-analyzer-proc-macro-srv
bjorn3 Jan 22, 2026
eec5320
Disable proc-macro-srv tests on stage 0
bjorn3 Jan 24, 2026
ef819e4
Remove a couple of unnecessary impls
bjorn3 Oct 3, 2025
dabae7e
Handle FreeFunctions outside with_api_handle_types
bjorn3 Oct 3, 2025
4dc28c5
Expand with_api_handle_types
bjorn3 Oct 3, 2025
2f44019
Move all bridge methods into a single type
bjorn3 Jan 22, 2026
9481890
Various simplifications after moving all bridge methods to a single type
bjorn3 Jan 22, 2026
8a119c3
Merge FreeFunctions trait into Server trait
bjorn3 Jan 22, 2026
d9ec1ae
Get rid of MarkedTypes
bjorn3 Oct 3, 2025
e8c48c6
Fix review comments
bjorn3 Jan 23, 2026
bc56f5d
Move std_detect tests into a separate crate
bjorn3 Jan 8, 2026
d24f4f4
Rollup merge of #145393 - clubby789:issue-138497, r=Mark-Simulacrum
matthiaskrgr Jan 24, 2026
76f3fe2
Rollup merge of #147400 - hkBst:convert-1, r=Mark-Simulacrum
matthiaskrgr Jan 24, 2026
b8279d5
Rollup merge of #149869 - joboet:torn-dbg, r=Mark-Simulacrum
matthiaskrgr Jan 24, 2026
c4f94f4
Rollup merge of #150065 - is57primenumber:add-slice-cse-test, r=Mark-…
matthiaskrgr Jan 24, 2026
0df0772
Rollup merge of #150813 - bjorn3:std_detect_split_tests, r=tgross35
matthiaskrgr Jan 24, 2026
7115d01
Rollup merge of #150842 - PaulDance:patches/fix-win7-sleep, r=Mark-Si…
matthiaskrgr Jan 24, 2026
6e38618
Rollup merge of #151505 - bjorn3:proc_macro_refactors, r=petrochenkov…
matthiaskrgr Jan 24, 2026
cac874b
Rollup merge of #151577 - Zalathar:dep-kind-vtable, r=Kivooeo
matthiaskrgr Jan 24, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge FreeFunctions trait into Server trait
And rename FreeFunctions struct to Methods.
  • Loading branch information
bjorn3 committed Jan 24, 2026
commit 8a119c3145f349f2ff7b2205cb37560e46b60720
39 changes: 17 additions & 22 deletions compiler/rustc_expand/src/proc_macro_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,8 +431,6 @@ impl ToInternal<rustc_errors::Level> for Level {
}
}

pub(crate) struct FreeFunctions;

pub(crate) struct Rustc<'a, 'b> {
ecx: &'a mut ExtCtxt<'b>,
def_site: Span,
Expand Down Expand Up @@ -461,13 +459,28 @@ impl<'a, 'b> Rustc<'a, 'b> {
}

impl server::Types for Rustc<'_, '_> {
type FreeFunctions = FreeFunctions;
type TokenStream = TokenStream;
type Span = Span;
type Symbol = Symbol;
}

impl server::FreeFunctions for Rustc<'_, '_> {
impl server::Server for Rustc<'_, '_> {
fn globals(&mut self) -> ExpnGlobals<Self::Span> {
ExpnGlobals {
def_site: self.def_site,
call_site: self.call_site,
mixed_site: self.mixed_site,
}
}

fn intern_symbol(string: &str) -> Self::Symbol {
Symbol::intern(string)
}

fn with_symbol_string(symbol: &Self::Symbol, f: impl FnOnce(&str)) {
f(symbol.as_str())
}

fn injected_env_var(&mut self, var: &str) -> Option<String> {
self.ecx.sess.opts.logical_env.get(var).cloned()
}
Expand Down Expand Up @@ -843,21 +856,3 @@ impl server::FreeFunctions for Rustc<'_, '_> {
if rustc_lexer::is_ident(sym.as_str()) { Ok(sym) } else { Err(()) }
}
}

impl server::Server for Rustc<'_, '_> {
fn globals(&mut self) -> ExpnGlobals<Self::Span> {
ExpnGlobals {
def_site: self.def_site,
call_site: self.call_site,
mixed_site: self.mixed_site,
}
}

fn intern_symbol(string: &str) -> Self::Symbol {
Symbol::intern(string)
}

fn with_symbol_string(symbol: &Self::Symbol, f: impl FnOnce(&str)) {
f(symbol.as_str())
}
}
12 changes: 6 additions & 6 deletions library/proc_macro/src/bridge/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl !Sync for TokenStream {}
// Forward `Drop::drop` to the inherent `drop` method.
impl Drop for TokenStream {
fn drop(&mut self) {
FreeFunctions::tt_drop(TokenStream { handle: self.handle });
Methods::tt_drop(TokenStream { handle: self.handle });
}
}

Expand Down Expand Up @@ -75,7 +75,7 @@ impl<S> Decode<'_, '_, S> for Span {

impl Clone for TokenStream {
fn clone(&self) -> Self {
FreeFunctions::tt_clone(self)
Methods::tt_clone(self)
}
}

Expand All @@ -95,21 +95,21 @@ impl Span {

impl fmt::Debug for Span {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&FreeFunctions::span_debug(*self))
f.write_str(&Methods::span_debug(*self))
}
}

pub(crate) use super::FreeFunctions;
pub(crate) use super::Methods;
pub(crate) use super::symbol::Symbol;

macro_rules! define_client_side {
(
FreeFunctions {
Methods {
$(fn $method:ident($($arg:ident: $arg_ty:ty),* $(,)?) $(-> $ret_ty:ty)*;)*
},
$($name:ident),* $(,)?
) => {
impl FreeFunctions {
impl Methods {
$(pub(crate) fn $method($($arg: $arg_ty),*) $(-> $ret_ty)? {
Bridge::with(|bridge| {
let mut buf = bridge.cached_buffer.take();
Expand Down
8 changes: 4 additions & 4 deletions library/proc_macro/src/bridge/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::{Delimiter, Level, Spacing};
/// `with_api!(MySelf, my_self, my_macro)` expands to:
/// ```rust,ignore (pseudo-code)
/// my_macro! {
/// FreeFunctions {
/// Methods {
/// // ...
/// fn lit_character(ch: char) -> MySelf::Literal;
/// // ...
Expand Down Expand Up @@ -49,7 +49,7 @@ use crate::{Delimiter, Level, Spacing};
macro_rules! with_api {
($S:ident, $self:ident, $m:ident) => {
$m! {
FreeFunctions {
Methods {
fn injected_env_var(var: &str) -> Option<String>;
fn track_env_var(var: &str, value: Option<&str>);
fn track_path(path: &str);
Expand Down Expand Up @@ -103,7 +103,7 @@ macro_rules! with_api {
};
}

pub(crate) struct FreeFunctions;
pub(crate) struct Methods;

#[allow(unsafe_code)]
mod arena;
Expand Down Expand Up @@ -158,7 +158,7 @@ mod api_tags {

macro_rules! declare_tags {
(
FreeFunctions {
Methods {
$(fn $method:ident($($arg:ident: $arg_ty:ty),* $(,)?) $(-> $ret_ty:ty)*;)*
},
$($name:ident),* $(,)?
Expand Down
46 changes: 19 additions & 27 deletions library/proc_macro/src/bridge/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,65 +54,59 @@ impl<S: Types> Decode<'_, '_, HandleStore<MarkedTypes<S>>> for Marked<S::Span, c
}

pub trait Types {
type FreeFunctions: 'static;
type TokenStream: 'static + Clone;
type Span: 'static + Copy + Eq + Hash;
type Symbol: 'static;
}

macro_rules! declare_server_traits {
(
FreeFunctions {
Methods {
$(fn $method:ident($($arg:ident: $arg_ty:ty),* $(,)?) $(-> $ret_ty:ty)*;)*
},
$($name:ident),* $(,)?
) => {
pub trait FreeFunctions: Types {
$(fn $method(&mut self, $($arg: $arg_ty),*) $(-> $ret_ty)?;)*
}

pub trait Server: Types + FreeFunctions {
pub trait Server: Types {
fn globals(&mut self) -> ExpnGlobals<Self::Span>;

/// Intern a symbol received from RPC
fn intern_symbol(ident: &str) -> Self::Symbol;

/// Recover the string value of a symbol, and invoke a callback with it.
fn with_symbol_string(symbol: &Self::Symbol, f: impl FnOnce(&str));

$(fn $method(&mut self, $($arg: $arg_ty),*) $(-> $ret_ty)?;)*
}
}
}
with_api!(Self, self_, declare_server_traits);

pub(super) struct MarkedTypes<S: Types>(S);

impl<S: Server> Server for MarkedTypes<S> {
fn globals(&mut self) -> ExpnGlobals<Self::Span> {
<_>::mark(Server::globals(&mut self.0))
}
fn intern_symbol(ident: &str) -> Self::Symbol {
<_>::mark(S::intern_symbol(ident))
}
fn with_symbol_string(symbol: &Self::Symbol, f: impl FnOnce(&str)) {
S::with_symbol_string(symbol.unmark(), f)
}
}

macro_rules! define_mark_types_impls {
(
FreeFunctions {
Methods {
$(fn $method:ident($($arg:ident: $arg_ty:ty),* $(,)?) $(-> $ret_ty:ty)*;)*
},
$($name:ident),* $(,)?
) => {
impl<S: Types> Types for MarkedTypes<S> {
type FreeFunctions = Marked<S::FreeFunctions, client::FreeFunctions>;
$(type $name = Marked<S::$name, client::$name>;)*
}

impl<S: FreeFunctions> FreeFunctions for MarkedTypes<S> {
impl<S: Server> Server for MarkedTypes<S> {
fn globals(&mut self) -> ExpnGlobals<Self::Span> {
<_>::mark(Server::globals(&mut self.0))
}
fn intern_symbol(ident: &str) -> Self::Symbol {
<_>::mark(S::intern_symbol(ident))
}
fn with_symbol_string(symbol: &Self::Symbol, f: impl FnOnce(&str)) {
S::with_symbol_string(symbol.unmark(), f)
}

$(fn $method(&mut self, $($arg: $arg_ty),*) $(-> $ret_ty)? {
<_>::mark(FreeFunctions::$method(&mut self.0, $($arg.unmark()),*))
<_>::mark(S::$method(&mut self.0, $($arg.unmark()),*))
})*
}
}
Expand All @@ -126,22 +120,20 @@ struct Dispatcher<S: Types> {

macro_rules! define_dispatcher_impl {
(
FreeFunctions {
Methods {
$(fn $method:ident($($arg:ident: $arg_ty:ty),* $(,)?) $(-> $ret_ty:ty)*;)*
},
$($name:ident),* $(,)?
) => {
// FIXME(eddyb) `pub` only for `ExecutionStrategy` below.
pub trait DispatcherTrait {
// HACK(eddyb) these are here to allow `Self::$name` to work below.
type FreeFunctions;
$(type $name;)*

fn dispatch(&mut self, buf: Buffer) -> Buffer;
}

impl<S: Server> DispatcherTrait for Dispatcher<MarkedTypes<S>> {
type FreeFunctions = <MarkedTypes<S> as Types>::FreeFunctions;
$(type $name = <MarkedTypes<S> as Types>::$name;)*

fn dispatch(&mut self, mut buf: Buffer) -> Buffer {
Expand All @@ -152,7 +144,7 @@ macro_rules! define_dispatcher_impl {
$(api_tags::Method::$method => {
let mut call_method = || {
$(let $arg = <$arg_ty>::decode(&mut reader, handle_store);)*
FreeFunctions::$method(server, $($arg),*)
server.$method($($arg),*)
};
// HACK(eddyb) don't use `panic::catch_unwind` in a panic.
// If client and server happen to use the same `std`,
Expand Down
2 changes: 1 addition & 1 deletion library/proc_macro/src/bridge/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl Symbol {
if string.is_ascii() {
Err(())
} else {
client::FreeFunctions::symbol_normalize_and_validate_ident(string)
client::Methods::symbol_normalize_and_validate_ident(string)
}
.unwrap_or_else(|_| panic!("`{:?}` is not a valid identifier", string))
}
Expand Down
2 changes: 1 addition & 1 deletion library/proc_macro/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,6 @@ impl Diagnostic {
}
}

crate::bridge::client::FreeFunctions::emit_diagnostic(to_internal(self));
crate::bridge::client::Methods::emit_diagnostic(to_internal(self));
}
}
Loading