Skip to content

Commit e3e93f2

Browse files
committed
Use GrowableBitSet to store positional indexes in asm!
1 parent 1590350 commit e3e93f2

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -3164,6 +3164,7 @@ dependencies = [
31643164
"rustc_expand",
31653165
"rustc_feature",
31663166
"rustc_fluent_macro",
3167+
"rustc_index",
31673168
"rustc_lexer",
31683169
"rustc_lint_defs",
31693170
"rustc_macros",

compiler/rustc_builtin_macros/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ rustc_data_structures = { path = "../rustc_data_structures" }
1414
rustc_errors = { path = "../rustc_errors" }
1515
rustc_expand = { path = "../rustc_expand" }
1616
rustc_feature = { path = "../rustc_feature" }
17+
rustc_index = { path = "../rustc_index" }
1718
rustc_lexer = { path = "../rustc_lexer" }
1819
rustc_lint_defs = { path = "../rustc_lint_defs" }
1920
rustc_macros = { path = "../rustc_macros" }

compiler/rustc_builtin_macros/src/asm.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ use rustc_ast as ast;
22
use rustc_ast::ptr::P;
33
use rustc_ast::token::{self, Delimiter};
44
use rustc_ast::tokenstream::TokenStream;
5-
use rustc_data_structures::fx::{FxHashMap, FxIndexMap, FxIndexSet};
5+
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
66
use rustc_errors::PResult;
77
use rustc_expand::base::{self, *};
8+
use rustc_index::bit_set::GrowableBitSet;
89
use rustc_parse::parser::Parser;
910
use rustc_parse_format as parse;
1011
use rustc_session::lint;
@@ -21,7 +22,7 @@ pub struct AsmArgs {
2122
pub templates: Vec<P<ast::Expr>>,
2223
pub operands: Vec<(ast::InlineAsmOperand, Span)>,
2324
named_args: FxIndexMap<Symbol, usize>,
24-
reg_args: FxIndexSet<usize>,
25+
reg_args: GrowableBitSet<usize>,
2526
pub clobber_abis: Vec<(Symbol, Span)>,
2627
options: ast::InlineAsmOptions,
2728
pub options_spans: Vec<Span>,
@@ -213,7 +214,7 @@ pub fn parse_asm_args<'a>(
213214
} else {
214215
if !args.named_args.is_empty() || !args.reg_args.is_empty() {
215216
let named = args.named_args.values().map(|p| args.operands[*p].1).collect();
216-
let explicit = args.reg_args.iter().map(|p| args.operands[*p].1).collect();
217+
let explicit = args.reg_args.iter().map(|p| args.operands[p].1).collect();
217218

218219
diag.emit_err(errors::AsmPositionalAfter { span, named, explicit });
219220
}
@@ -446,8 +447,8 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option<ast::Inl
446447
// Register operands are implicitly used since they are not allowed to be
447448
// referenced in the template string.
448449
let mut used = vec![false; args.operands.len()];
449-
for pos in &args.reg_args {
450-
used[*pos] = true;
450+
for pos in args.reg_args.iter() {
451+
used[pos] = true;
451452
}
452453
let named_pos: FxHashMap<usize, Symbol> =
453454
args.named_args.iter().map(|(&sym, &idx)| (idx, sym)).collect();
@@ -581,7 +582,7 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option<ast::Inl
581582
parse::ArgumentIs(idx) | parse::ArgumentImplicitlyIs(idx) => {
582583
if idx >= args.operands.len()
583584
|| named_pos.contains_key(&idx)
584-
|| args.reg_args.contains(&idx)
585+
|| args.reg_args.contains(idx)
585586
{
586587
let msg = format!("invalid reference to argument at index {}", idx);
587588
let mut err = ecx.struct_span_err(span, &msg);
@@ -608,7 +609,7 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option<ast::Inl
608609
args.operands[idx].1,
609610
"named arguments cannot be referenced by position",
610611
);
611-
} else if args.reg_args.contains(&idx) {
612+
} else if args.reg_args.contains(idx) {
612613
err.span_label(
613614
args.operands[idx].1,
614615
"explicit register argument",

0 commit comments

Comments
 (0)