Skip to content

Commit bc4a681

Browse files
committed
Auto merge of #151535 - JonathanBrouwer:rollup-SM3t94Y, r=JonathanBrouwer
Rollup of 3 pull requests Successful merges: - #150556 (Add Tier 3 Thumb-mode targets for Armv7-A, Armv7-R and Armv8-R) - #151065 (abi: add a rust-preserve-none calling convention) - #151505 (Various refactors to the proc_macro bridge) r? @ghost
2 parents 5944b12 + 450bd4c commit bc4a681

59 files changed

Lines changed: 881 additions & 669 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

compiler/rustc_abi/src/canon_abi.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub enum CanonAbi {
2727
C,
2828
Rust,
2929
RustCold,
30+
RustPreserveNone,
3031

3132
/// An ABI that rustc does not know how to call or define.
3233
Custom,
@@ -54,7 +55,7 @@ pub enum CanonAbi {
5455
impl CanonAbi {
5556
pub fn is_rustic_abi(self) -> bool {
5657
match self {
57-
CanonAbi::Rust | CanonAbi::RustCold => true,
58+
CanonAbi::Rust | CanonAbi::RustCold | CanonAbi::RustPreserveNone => true,
5859
CanonAbi::C
5960
| CanonAbi::Custom
6061
| CanonAbi::Arm(_)
@@ -74,6 +75,7 @@ impl fmt::Display for CanonAbi {
7475
CanonAbi::C => ExternAbi::C { unwind: false },
7576
CanonAbi::Rust => ExternAbi::Rust,
7677
CanonAbi::RustCold => ExternAbi::RustCold,
78+
CanonAbi::RustPreserveNone => ExternAbi::RustPreserveNone,
7779
CanonAbi::Custom => ExternAbi::Custom,
7880
CanonAbi::Arm(arm_call) => match arm_call {
7981
ArmCall::Aapcs => ExternAbi::Aapcs { unwind: false },

compiler/rustc_abi/src/extern_abi.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ pub enum ExternAbi {
4242
/// in a platform-agnostic way.
4343
RustInvalid,
4444

45+
/// Preserves no registers.
46+
///
47+
/// Note, that this ABI is not stable in the registers it uses, is intended as an optimization
48+
/// and may fall-back to a more conservative calling convention if the backend does not support
49+
/// forcing callers to save all registers.
50+
RustPreserveNone,
51+
4552
/// Unstable impl detail that directly uses Rust types to describe the ABI to LLVM.
4653
/// Even normally-compatible Rust types can become ABI-incompatible with this ABI!
4754
Unadjusted,
@@ -163,6 +170,7 @@ abi_impls! {
163170
RustCall =><= "rust-call",
164171
RustCold =><= "rust-cold",
165172
RustInvalid =><= "rust-invalid",
173+
RustPreserveNone =><= "rust-preserve-none",
166174
Stdcall { unwind: false } =><= "stdcall",
167175
Stdcall { unwind: true } =><= "stdcall-unwind",
168176
System { unwind: false } =><= "system",
@@ -243,7 +251,7 @@ impl ExternAbi {
243251
/// - are subject to change between compiler versions
244252
pub fn is_rustic_abi(self) -> bool {
245253
use ExternAbi::*;
246-
matches!(self, Rust | RustCall | RustCold)
254+
matches!(self, Rust | RustCall | RustCold | RustPreserveNone)
247255
}
248256

249257
/// Returns whether the ABI supports C variadics. This only controls whether we allow *imports*
@@ -315,7 +323,8 @@ impl ExternAbi {
315323
| Self::Thiscall { .. }
316324
| Self::Vectorcall { .. }
317325
| Self::SysV64 { .. }
318-
| Self::Win64 { .. } => true,
326+
| Self::Win64 { .. }
327+
| Self::RustPreserveNone => true,
319328
}
320329
}
321330
}

compiler/rustc_ast_lowering/src/stability.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ pub fn extern_abi_stability(abi: ExternAbi) -> Result<(), UnstableAbi> {
9595
ExternAbi::RustCold => {
9696
Err(UnstableAbi { abi, feature: sym::rust_cold_cc, explain: GateReason::Experimental })
9797
}
98+
ExternAbi::RustPreserveNone => Err(UnstableAbi {
99+
abi,
100+
feature: sym::rust_preserve_none_cc,
101+
explain: GateReason::Experimental,
102+
}),
98103
ExternAbi::RustInvalid => {
99104
Err(UnstableAbi { abi, feature: sym::rustc_attrs, explain: GateReason::ImplDetail })
100105
}

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@ impl<'a> AstValidator<'a> {
400400
CanonAbi::C
401401
| CanonAbi::Rust
402402
| CanonAbi::RustCold
403+
| CanonAbi::RustPreserveNone
403404
| CanonAbi::Arm(_)
404405
| CanonAbi::X86(_) => { /* nothing to check */ }
405406

compiler/rustc_codegen_cranelift/src/abi/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ pub(crate) fn conv_to_call_conv(
5656
CanonAbi::Rust | CanonAbi::C => default_call_conv,
5757
CanonAbi::RustCold => CallConv::Cold,
5858

59+
// Cranelift doesn't currently have anything for this.
60+
CanonAbi::RustPreserveNone => default_call_conv,
61+
5962
// Functions with this calling convention can only be called from assembly, but it is
6063
// possible to declare an `extern "custom"` block, so the backend still needs a calling
6164
// convention for declaring foreign functions.

compiler/rustc_codegen_gcc/src/abi.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,8 @@ impl<'gcc, 'tcx> FnAbiGccExt<'gcc, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
243243
pub fn conv_to_fn_attribute<'gcc>(conv: CanonAbi, arch: &Arch) -> Option<FnAttribute<'gcc>> {
244244
let attribute = match conv {
245245
CanonAbi::C | CanonAbi::Rust => return None,
246+
// gcc/gccjit does not have anything for this.
247+
CanonAbi::RustPreserveNone => return None,
246248
CanonAbi::RustCold => FnAttribute::Cold,
247249
// Functions with this calling convention can only be called from assembly, but it is
248250
// possible to declare an `extern "custom"` block, so the backend still needs a calling

compiler/rustc_codegen_llvm/src/abi.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,7 @@ pub(crate) fn to_llvm_calling_convention(sess: &Session, abi: CanonAbi) -> llvm:
694694
match abi {
695695
CanonAbi::C | CanonAbi::Rust => llvm::CCallConv,
696696
CanonAbi::RustCold => llvm::PreserveMost,
697+
CanonAbi::RustPreserveNone => llvm::PreserveNone,
697698
// Functions with this calling convention can only be called from assembly, but it is
698699
// possible to declare an `extern "custom"` block, so the backend still needs a calling
699700
// convention for declaring foreign functions.

compiler/rustc_codegen_llvm/src/attributes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ fn create_alloc_family_attr(llcx: &llvm::Context) -> &llvm::Attribute {
370370
llvm::CreateAttrStringValue(llcx, "alloc-family", "__rust_alloc")
371371
}
372372

373-
/// Helper for `FnAbi::apply_attrs_llfn`:
373+
/// Helper for `FnAbiLlvmExt::apply_attrs_llfn`:
374374
/// Composite function which sets LLVM attributes for function depending on its AST (`#[attribute]`)
375375
/// attributes.
376376
pub(crate) fn llfn_attrs_from_instance<'ll, 'tcx>(

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ pub(crate) enum CallConv {
167167
PreserveMost = 14,
168168
PreserveAll = 15,
169169
Tail = 18,
170+
PreserveNone = 21,
170171
X86StdcallCallConv = 64,
171172
X86FastcallCallConv = 65,
172173
ArmAapcsCallConv = 67,

compiler/rustc_expand/src/proc_macro_server.rs

Lines changed: 50 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -431,8 +431,6 @@ impl ToInternal<rustc_errors::Level> for Level {
431431
}
432432
}
433433

434-
pub(crate) struct FreeFunctions;
435-
436434
pub(crate) struct Rustc<'a, 'b> {
437435
ecx: &'a mut ExtCtxt<'b>,
438436
def_site: Span,
@@ -461,13 +459,28 @@ impl<'a, 'b> Rustc<'a, 'b> {
461459
}
462460

463461
impl server::Types for Rustc<'_, '_> {
464-
type FreeFunctions = FreeFunctions;
465462
type TokenStream = TokenStream;
466463
type Span = Span;
467464
type Symbol = Symbol;
468465
}
469466

470-
impl server::FreeFunctions for Rustc<'_, '_> {
467+
impl server::Server for Rustc<'_, '_> {
468+
fn globals(&mut self) -> ExpnGlobals<Self::Span> {
469+
ExpnGlobals {
470+
def_site: self.def_site,
471+
call_site: self.call_site,
472+
mixed_site: self.mixed_site,
473+
}
474+
}
475+
476+
fn intern_symbol(string: &str) -> Self::Symbol {
477+
Symbol::intern(string)
478+
}
479+
480+
fn with_symbol_string(symbol: &Self::Symbol, f: impl FnOnce(&str)) {
481+
f(symbol.as_str())
482+
}
483+
471484
fn injected_env_var(&mut self, var: &str) -> Option<String> {
472485
self.ecx.sess.opts.logical_env.get(var).cloned()
473486
}
@@ -552,14 +565,20 @@ impl server::FreeFunctions for Rustc<'_, '_> {
552565
}
553566
diag.emit();
554567
}
555-
}
556568

557-
impl server::TokenStream for Rustc<'_, '_> {
558-
fn is_empty(&mut self, stream: &Self::TokenStream) -> bool {
569+
fn ts_drop(&mut self, stream: Self::TokenStream) {
570+
drop(stream);
571+
}
572+
573+
fn ts_clone(&mut self, stream: &Self::TokenStream) -> Self::TokenStream {
574+
stream.clone()
575+
}
576+
577+
fn ts_is_empty(&mut self, stream: &Self::TokenStream) -> bool {
559578
stream.is_empty()
560579
}
561580

562-
fn from_str(&mut self, src: &str) -> Self::TokenStream {
581+
fn ts_from_str(&mut self, src: &str) -> Self::TokenStream {
563582
unwrap_or_emit_fatal(source_str_to_stream(
564583
self.psess(),
565584
FileName::proc_macro_source_code(src),
@@ -568,11 +587,11 @@ impl server::TokenStream for Rustc<'_, '_> {
568587
))
569588
}
570589

571-
fn to_string(&mut self, stream: &Self::TokenStream) -> String {
590+
fn ts_to_string(&mut self, stream: &Self::TokenStream) -> String {
572591
pprust::tts_to_string(stream)
573592
}
574593

575-
fn expand_expr(&mut self, stream: &Self::TokenStream) -> Result<Self::TokenStream, ()> {
594+
fn ts_expand_expr(&mut self, stream: &Self::TokenStream) -> Result<Self::TokenStream, ()> {
576595
// Parse the expression from our tokenstream.
577596
let expr: PResult<'_, _> = try {
578597
let mut p = Parser::new(self.psess(), stream.clone(), Some("proc_macro expand expr"));
@@ -633,14 +652,14 @@ impl server::TokenStream for Rustc<'_, '_> {
633652
}
634653
}
635654

636-
fn from_token_tree(
655+
fn ts_from_token_tree(
637656
&mut self,
638657
tree: TokenTree<Self::TokenStream, Self::Span, Self::Symbol>,
639658
) -> Self::TokenStream {
640659
Self::TokenStream::new((tree, &mut *self).to_internal().into_iter().collect::<Vec<_>>())
641660
}
642661

643-
fn concat_trees(
662+
fn ts_concat_trees(
644663
&mut self,
645664
base: Option<Self::TokenStream>,
646665
trees: Vec<TokenTree<Self::TokenStream, Self::Span, Self::Symbol>>,
@@ -654,7 +673,7 @@ impl server::TokenStream for Rustc<'_, '_> {
654673
stream
655674
}
656675

657-
fn concat_streams(
676+
fn ts_concat_streams(
658677
&mut self,
659678
base: Option<Self::TokenStream>,
660679
streams: Vec<Self::TokenStream>,
@@ -666,24 +685,22 @@ impl server::TokenStream for Rustc<'_, '_> {
666685
stream
667686
}
668687

669-
fn into_trees(
688+
fn ts_into_trees(
670689
&mut self,
671690
stream: Self::TokenStream,
672691
) -> Vec<TokenTree<Self::TokenStream, Self::Span, Self::Symbol>> {
673692
FromInternal::from_internal((stream, self))
674693
}
675-
}
676694

677-
impl server::Span for Rustc<'_, '_> {
678-
fn debug(&mut self, span: Self::Span) -> String {
695+
fn span_debug(&mut self, span: Self::Span) -> String {
679696
if self.ecx.ecfg.span_debug {
680697
format!("{span:?}")
681698
} else {
682699
format!("{:?} bytes({}..{})", span.ctxt(), span.lo().0, span.hi().0)
683700
}
684701
}
685702

686-
fn file(&mut self, span: Self::Span) -> String {
703+
fn span_file(&mut self, span: Self::Span) -> String {
687704
self.psess()
688705
.source_map()
689706
.lookup_char_pos(span.lo())
@@ -693,7 +710,7 @@ impl server::Span for Rustc<'_, '_> {
693710
.to_string()
694711
}
695712

696-
fn local_file(&mut self, span: Self::Span) -> Option<String> {
713+
fn span_local_file(&mut self, span: Self::Span) -> Option<String> {
697714
self.psess()
698715
.source_map()
699716
.lookup_char_pos(span.lo())
@@ -708,41 +725,41 @@ impl server::Span for Rustc<'_, '_> {
708725
})
709726
}
710727

711-
fn parent(&mut self, span: Self::Span) -> Option<Self::Span> {
728+
fn span_parent(&mut self, span: Self::Span) -> Option<Self::Span> {
712729
span.parent_callsite()
713730
}
714731

715-
fn source(&mut self, span: Self::Span) -> Self::Span {
732+
fn span_source(&mut self, span: Self::Span) -> Self::Span {
716733
span.source_callsite()
717734
}
718735

719-
fn byte_range(&mut self, span: Self::Span) -> Range<usize> {
736+
fn span_byte_range(&mut self, span: Self::Span) -> Range<usize> {
720737
let source_map = self.psess().source_map();
721738

722739
let relative_start_pos = source_map.lookup_byte_offset(span.lo()).pos;
723740
let relative_end_pos = source_map.lookup_byte_offset(span.hi()).pos;
724741

725742
Range { start: relative_start_pos.0 as usize, end: relative_end_pos.0 as usize }
726743
}
727-
fn start(&mut self, span: Self::Span) -> Self::Span {
744+
fn span_start(&mut self, span: Self::Span) -> Self::Span {
728745
span.shrink_to_lo()
729746
}
730747

731-
fn end(&mut self, span: Self::Span) -> Self::Span {
748+
fn span_end(&mut self, span: Self::Span) -> Self::Span {
732749
span.shrink_to_hi()
733750
}
734751

735-
fn line(&mut self, span: Self::Span) -> usize {
752+
fn span_line(&mut self, span: Self::Span) -> usize {
736753
let loc = self.psess().source_map().lookup_char_pos(span.lo());
737754
loc.line
738755
}
739756

740-
fn column(&mut self, span: Self::Span) -> usize {
757+
fn span_column(&mut self, span: Self::Span) -> usize {
741758
let loc = self.psess().source_map().lookup_char_pos(span.lo());
742759
loc.col.to_usize() + 1
743760
}
744761

745-
fn join(&mut self, first: Self::Span, second: Self::Span) -> Option<Self::Span> {
762+
fn span_join(&mut self, first: Self::Span, second: Self::Span) -> Option<Self::Span> {
746763
let self_loc = self.psess().source_map().lookup_char_pos(first.lo());
747764
let other_loc = self.psess().source_map().lookup_char_pos(second.lo());
748765

@@ -753,7 +770,7 @@ impl server::Span for Rustc<'_, '_> {
753770
Some(first.to(second))
754771
}
755772

756-
fn subspan(
773+
fn span_subspan(
757774
&mut self,
758775
span: Self::Span,
759776
start: Bound<usize>,
@@ -789,11 +806,11 @@ impl server::Span for Rustc<'_, '_> {
789806
Some(span.with_lo(new_lo).with_hi(new_hi))
790807
}
791808

792-
fn resolved_at(&mut self, span: Self::Span, at: Self::Span) -> Self::Span {
809+
fn span_resolved_at(&mut self, span: Self::Span, at: Self::Span) -> Self::Span {
793810
span.with_ctxt(at.ctxt())
794811
}
795812

796-
fn source_text(&mut self, span: Self::Span) -> Option<String> {
813+
fn span_source_text(&mut self, span: Self::Span) -> Option<String> {
797814
self.psess().source_map().span_to_snippet(span).ok()
798815
}
799816

@@ -821,41 +838,21 @@ impl server::Span for Rustc<'_, '_> {
821838
/// span from the metadata of `my_proc_macro` (which we have access to,
822839
/// since we've loaded `my_proc_macro` from disk in order to execute it).
823840
/// In this way, we have obtained a span pointing into `my_proc_macro`
824-
fn save_span(&mut self, span: Self::Span) -> usize {
841+
fn span_save_span(&mut self, span: Self::Span) -> usize {
825842
self.psess().save_proc_macro_span(span)
826843
}
827844

828-
fn recover_proc_macro_span(&mut self, id: usize) -> Self::Span {
845+
fn span_recover_proc_macro_span(&mut self, id: usize) -> Self::Span {
829846
let (resolver, krate, def_site) = (&*self.ecx.resolver, self.krate, self.def_site);
830847
*self.rebased_spans.entry(id).or_insert_with(|| {
831848
// FIXME: `SyntaxContext` for spans from proc macro crates is lost during encoding,
832849
// replace it with a def-site context until we are encoding it properly.
833850
resolver.get_proc_macro_quoted_span(krate, id).with_ctxt(def_site.ctxt())
834851
})
835852
}
836-
}
837853

838-
impl server::Symbol for Rustc<'_, '_> {
839-
fn normalize_and_validate_ident(&mut self, string: &str) -> Result<Self::Symbol, ()> {
854+
fn symbol_normalize_and_validate_ident(&mut self, string: &str) -> Result<Self::Symbol, ()> {
840855
let sym = nfc_normalize(string);
841856
if rustc_lexer::is_ident(sym.as_str()) { Ok(sym) } else { Err(()) }
842857
}
843858
}
844-
845-
impl server::Server for Rustc<'_, '_> {
846-
fn globals(&mut self) -> ExpnGlobals<Self::Span> {
847-
ExpnGlobals {
848-
def_site: self.def_site,
849-
call_site: self.call_site,
850-
mixed_site: self.mixed_site,
851-
}
852-
}
853-
854-
fn intern_symbol(string: &str) -> Self::Symbol {
855-
Symbol::intern(string)
856-
}
857-
858-
fn with_symbol_string(symbol: &Self::Symbol, f: impl FnOnce(&str)) {
859-
f(symbol.as_str())
860-
}
861-
}

0 commit comments

Comments
 (0)