1
Fork 0

compiler: use rustc_abi in rustc_ast_*

This commit is contained in:
Jubilee Young 2024-11-02 19:33:28 -07:00
parent eddfe8f503
commit 221416deea
6 changed files with 19 additions and 16 deletions

View file

@ -3400,6 +3400,7 @@ dependencies = [
name = "rustc_ast_lowering" name = "rustc_ast_lowering"
version = "0.0.0" version = "0.0.0"
dependencies = [ dependencies = [
"rustc_abi",
"rustc_ast", "rustc_ast",
"rustc_ast_pretty", "rustc_ast_pretty",
"rustc_data_structures", "rustc_data_structures",
@ -3422,6 +3423,7 @@ name = "rustc_ast_passes"
version = "0.0.0" version = "0.0.0"
dependencies = [ dependencies = [
"itertools", "itertools",
"rustc_abi",
"rustc_ast", "rustc_ast",
"rustc_ast_pretty", "rustc_ast_pretty",
"rustc_attr_parsing", "rustc_attr_parsing",

View file

@ -3225,7 +3225,7 @@ pub enum Extern {
/// ///
/// E.g. `extern fn foo() {}`. /// E.g. `extern fn foo() {}`.
/// ///
/// This is just `extern "C"` (see `rustc_target::spec::abi::Abi::FALLBACK`). /// This is just `extern "C"` (see `rustc_abi::ExternAbi::FALLBACK`).
Implicit(Span), Implicit(Span),
/// An explicit extern keyword was used with an explicit ABI. /// An explicit extern keyword was used with an explicit ABI.
/// ///

View file

@ -8,6 +8,7 @@ doctest = false
[dependencies] [dependencies]
# tidy-alphabetical-start # tidy-alphabetical-start
rustc_abi = { path = "../rustc_abi" }
rustc_ast = { path = "../rustc_ast" } rustc_ast = { path = "../rustc_ast" }
rustc_ast_pretty = { path = "../rustc_ast_pretty" } rustc_ast_pretty = { path = "../rustc_ast_pretty" }
rustc_data_structures = { path = "../rustc_data_structures" } rustc_data_structures = { path = "../rustc_data_structures" }

View file

@ -1,3 +1,4 @@
use rustc_abi::ExternAbi;
use rustc_ast::ptr::P; use rustc_ast::ptr::P;
use rustc_ast::visit::AssocCtxt; use rustc_ast::visit::AssocCtxt;
use rustc_ast::*; use rustc_ast::*;
@ -11,7 +12,6 @@ use rustc_middle::span_bug;
use rustc_middle::ty::{ResolverAstLowering, TyCtxt}; use rustc_middle::ty::{ResolverAstLowering, TyCtxt};
use rustc_span::edit_distance::find_best_match_for_name; use rustc_span::edit_distance::find_best_match_for_name;
use rustc_span::{DesugaringKind, Ident, Span, Symbol, kw, sym}; use rustc_span::{DesugaringKind, Ident, Span, Symbol, kw, sym};
use rustc_target::spec::abi;
use smallvec::{SmallVec, smallvec}; use smallvec::{SmallVec, smallvec};
use thin_vec::ThinVec; use thin_vec::ThinVec;
use tracing::instrument; use tracing::instrument;
@ -275,7 +275,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
ModKind::Unloaded => panic!("`mod` items should have been loaded by now"), ModKind::Unloaded => panic!("`mod` items should have been loaded by now"),
}, },
ItemKind::ForeignMod(fm) => hir::ItemKind::ForeignMod { ItemKind::ForeignMod(fm) => hir::ItemKind::ForeignMod {
abi: fm.abi.map_or(abi::Abi::FALLBACK, |abi| self.lower_abi(abi)), abi: fm.abi.map_or(ExternAbi::FALLBACK, |abi| self.lower_abi(abi)),
items: self items: self
.arena .arena
.alloc_from_iter(fm.items.iter().map(|x| self.lower_foreign_item_ref(x))), .alloc_from_iter(fm.items.iter().map(|x| self.lower_foreign_item_ref(x))),
@ -1470,23 +1470,23 @@ impl<'hir> LoweringContext<'_, 'hir> {
} }
} }
pub(super) fn lower_abi(&mut self, abi: StrLit) -> abi::Abi { pub(super) fn lower_abi(&mut self, abi: StrLit) -> ExternAbi {
abi::lookup(abi.symbol_unescaped.as_str()).unwrap_or_else(|err| { rustc_abi::lookup(abi.symbol_unescaped.as_str()).unwrap_or_else(|err| {
self.error_on_invalid_abi(abi, err); self.error_on_invalid_abi(abi, err);
abi::Abi::Rust ExternAbi::Rust
}) })
} }
pub(super) fn lower_extern(&mut self, ext: Extern) -> abi::Abi { pub(super) fn lower_extern(&mut self, ext: Extern) -> ExternAbi {
match ext { match ext {
Extern::None => abi::Abi::Rust, Extern::None => ExternAbi::Rust,
Extern::Implicit(_) => abi::Abi::FALLBACK, Extern::Implicit(_) => ExternAbi::FALLBACK,
Extern::Explicit(abi, _) => self.lower_abi(abi), Extern::Explicit(abi, _) => self.lower_abi(abi),
} }
} }
fn error_on_invalid_abi(&self, abi: StrLit, err: abi::AbiUnsupported) { fn error_on_invalid_abi(&self, abi: StrLit, err: rustc_abi::AbiUnsupported) {
let abi_names = abi::enabled_names(self.tcx.features(), abi.span) let abi_names = rustc_abi::enabled_names(self.tcx.features(), abi.span)
.iter() .iter()
.map(|s| Symbol::intern(s)) .map(|s| Symbol::intern(s))
.collect::<Vec<_>>(); .collect::<Vec<_>>();
@ -1495,7 +1495,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
abi: abi.symbol_unescaped, abi: abi.symbol_unescaped,
span: abi.span, span: abi.span,
explain: match err { explain: match err {
abi::AbiUnsupported::Reason { explain } => Some(InvalidAbiReason(explain)), rustc_abi::AbiUnsupported::Reason { explain } => Some(InvalidAbiReason(explain)),
_ => None, _ => None,
}, },
suggestion: suggested_name.map(|suggested_name| InvalidAbiSuggestion { suggestion: suggested_name.map(|suggested_name| InvalidAbiSuggestion {

View file

@ -6,6 +6,7 @@ edition = "2021"
[dependencies] [dependencies]
# tidy-alphabetical-start # tidy-alphabetical-start
itertools = "0.12" itertools = "0.12"
rustc_abi = { path = "../rustc_abi" }
rustc_ast = { path = "../rustc_ast" } rustc_ast = { path = "../rustc_ast" }
rustc_ast_pretty = { path = "../rustc_ast_pretty" } rustc_ast_pretty = { path = "../rustc_ast_pretty" }
rustc_attr_parsing = { path = "../rustc_attr_parsing" } rustc_attr_parsing = { path = "../rustc_attr_parsing" }

View file

@ -6,7 +6,6 @@ use rustc_session::Session;
use rustc_session::parse::{feature_err, feature_err_issue, feature_warn}; use rustc_session::parse::{feature_err, feature_err_issue, feature_warn};
use rustc_span::source_map::Spanned; use rustc_span::source_map::Spanned;
use rustc_span::{Span, Symbol, sym}; use rustc_span::{Span, Symbol, sym};
use rustc_target::spec::abi;
use thin_vec::ThinVec; use thin_vec::ThinVec;
use crate::errors; use crate::errors;
@ -77,12 +76,12 @@ impl<'a> PostExpansionVisitor<'a> {
fn check_abi(&self, abi: ast::StrLit) { fn check_abi(&self, abi: ast::StrLit) {
let ast::StrLit { symbol_unescaped, span, .. } = abi; let ast::StrLit { symbol_unescaped, span, .. } = abi;
match abi::is_enabled(self.features, span, symbol_unescaped.as_str()) { match rustc_abi::is_enabled(self.features, span, symbol_unescaped.as_str()) {
Ok(()) => (), Ok(()) => (),
Err(abi::AbiDisabled::Unstable { feature, explain }) => { Err(rustc_abi::AbiDisabled::Unstable { feature, explain }) => {
feature_err_issue(&self.sess, feature, span, GateIssue::Language, explain).emit(); feature_err_issue(&self.sess, feature, span, GateIssue::Language, explain).emit();
} }
Err(abi::AbiDisabled::Unrecognized) => { Err(rustc_abi::AbiDisabled::Unrecognized) => {
if self.sess.opts.pretty.is_none_or(|ppm| ppm.needs_hir()) { if self.sess.opts.pretty.is_none_or(|ppm| ppm.needs_hir()) {
self.sess.dcx().span_delayed_bug( self.sess.dcx().span_delayed_bug(
span, span,