From 1590350836e36dde1190c28af0e521f63994b47f Mon Sep 17 00:00:00 2001 From: clubby789 Date: Sun, 30 Apr 2023 20:54:43 +0100 Subject: [PATCH 1/2] Remove `allow(rustc::potential_query_instability)` for `builtin_macros` --- compiler/rustc_builtin_macros/src/asm.rs | 10 +++++----- compiler/rustc_builtin_macros/src/lib.rs | 1 - 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_builtin_macros/src/asm.rs b/compiler/rustc_builtin_macros/src/asm.rs index 0ea8454db0893..c632ae41d962e 100644 --- a/compiler/rustc_builtin_macros/src/asm.rs +++ b/compiler/rustc_builtin_macros/src/asm.rs @@ -2,7 +2,7 @@ use rustc_ast as ast; use rustc_ast::ptr::P; use rustc_ast::token::{self, Delimiter}; use rustc_ast::tokenstream::TokenStream; -use rustc_data_structures::fx::{FxHashMap, FxHashSet}; +use rustc_data_structures::fx::{FxHashMap, FxIndexMap, FxIndexSet}; use rustc_errors::PResult; use rustc_expand::base::{self, *}; use rustc_parse::parser::Parser; @@ -20,8 +20,8 @@ use crate::errors; pub struct AsmArgs { pub templates: Vec>, pub operands: Vec<(ast::InlineAsmOperand, Span)>, - named_args: FxHashMap, - reg_args: FxHashSet, + named_args: FxIndexMap, + reg_args: FxIndexSet, pub clobber_abis: Vec<(Symbol, Span)>, options: ast::InlineAsmOptions, pub options_spans: Vec, @@ -56,8 +56,8 @@ pub fn parse_asm_args<'a>( let mut args = AsmArgs { templates: vec![first_template], operands: vec![], - named_args: FxHashMap::default(), - reg_args: FxHashSet::default(), + named_args: Default::default(), + reg_args: Default::default(), clobber_abis: Vec::new(), options: ast::InlineAsmOptions::empty(), options_spans: vec![], diff --git a/compiler/rustc_builtin_macros/src/lib.rs b/compiler/rustc_builtin_macros/src/lib.rs index 8f86ef44aa3ab..c7da61d72b384 100644 --- a/compiler/rustc_builtin_macros/src/lib.rs +++ b/compiler/rustc_builtin_macros/src/lib.rs @@ -1,7 +1,6 @@ //! This crate contains implementations of built-in macros and other code generating facilities //! injecting code into the crate before it is lowered to HIR. -#![allow(rustc::potential_query_instability)] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![feature(array_windows)] #![feature(box_patterns)] From e3e93f28679b58c28c02720d2281f1a79751394e Mon Sep 17 00:00:00 2001 From: clubby789 Date: Tue, 2 May 2023 16:42:36 +0100 Subject: [PATCH 2/2] Use `GrowableBitSet` to store positional indexes in `asm!` --- Cargo.lock | 1 + compiler/rustc_builtin_macros/Cargo.toml | 1 + compiler/rustc_builtin_macros/src/asm.rs | 15 ++++++++------- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d7806b5daa63a..6679cfbae7735 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3164,6 +3164,7 @@ dependencies = [ "rustc_expand", "rustc_feature", "rustc_fluent_macro", + "rustc_index", "rustc_lexer", "rustc_lint_defs", "rustc_macros", diff --git a/compiler/rustc_builtin_macros/Cargo.toml b/compiler/rustc_builtin_macros/Cargo.toml index 5f6441660e3bc..44012e802aa7b 100644 --- a/compiler/rustc_builtin_macros/Cargo.toml +++ b/compiler/rustc_builtin_macros/Cargo.toml @@ -14,6 +14,7 @@ rustc_data_structures = { path = "../rustc_data_structures" } rustc_errors = { path = "../rustc_errors" } rustc_expand = { path = "../rustc_expand" } rustc_feature = { path = "../rustc_feature" } +rustc_index = { path = "../rustc_index" } rustc_lexer = { path = "../rustc_lexer" } rustc_lint_defs = { path = "../rustc_lint_defs" } rustc_macros = { path = "../rustc_macros" } diff --git a/compiler/rustc_builtin_macros/src/asm.rs b/compiler/rustc_builtin_macros/src/asm.rs index c632ae41d962e..58b976109243b 100644 --- a/compiler/rustc_builtin_macros/src/asm.rs +++ b/compiler/rustc_builtin_macros/src/asm.rs @@ -2,9 +2,10 @@ use rustc_ast as ast; use rustc_ast::ptr::P; use rustc_ast::token::{self, Delimiter}; use rustc_ast::tokenstream::TokenStream; -use rustc_data_structures::fx::{FxHashMap, FxIndexMap, FxIndexSet}; +use rustc_data_structures::fx::{FxHashMap, FxIndexMap}; use rustc_errors::PResult; use rustc_expand::base::{self, *}; +use rustc_index::bit_set::GrowableBitSet; use rustc_parse::parser::Parser; use rustc_parse_format as parse; use rustc_session::lint; @@ -21,7 +22,7 @@ pub struct AsmArgs { pub templates: Vec>, pub operands: Vec<(ast::InlineAsmOperand, Span)>, named_args: FxIndexMap, - reg_args: FxIndexSet, + reg_args: GrowableBitSet, pub clobber_abis: Vec<(Symbol, Span)>, options: ast::InlineAsmOptions, pub options_spans: Vec, @@ -213,7 +214,7 @@ pub fn parse_asm_args<'a>( } else { if !args.named_args.is_empty() || !args.reg_args.is_empty() { let named = args.named_args.values().map(|p| args.operands[*p].1).collect(); - let explicit = args.reg_args.iter().map(|p| args.operands[*p].1).collect(); + let explicit = args.reg_args.iter().map(|p| args.operands[p].1).collect(); diag.emit_err(errors::AsmPositionalAfter { span, named, explicit }); } @@ -446,8 +447,8 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option = args.named_args.iter().map(|(&sym, &idx)| (idx, sym)).collect(); @@ -581,7 +582,7 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option { if idx >= args.operands.len() || named_pos.contains_key(&idx) - || args.reg_args.contains(&idx) + || args.reg_args.contains(idx) { let msg = format!("invalid reference to argument at index {}", idx); let mut err = ecx.struct_span_err(span, &msg); @@ -608,7 +609,7 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option