Skip to content

Commit c8b87f0

Browse files
committed
Allow parsing of #[spirv(...)] attribute without CodegenCx
1 parent d35fa0f commit c8b87f0

File tree

4 files changed

+19
-9
lines changed

4 files changed

+19
-9
lines changed

crates/rustc_codegen_spirv/src/abi.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,11 @@ impl<'tcx> ConvSpirvType<'tcx> for TyAndLayout<'tcx> {
546546
span = cx.tcx.def_span(adt.did());
547547
}
548548

549-
let attrs = AggregatedSpirvAttributes::parse(cx, cx.tcx.get_attrs_unchecked(adt.did()));
549+
let attrs = AggregatedSpirvAttributes::parse(
550+
cx.tcx,
551+
&cx.sym,
552+
cx.tcx.get_attrs_unchecked(adt.did()),
553+
);
550554

551555
if let Some(intrinsic_type_attr) = attrs.intrinsic_type.map(|attr| attr.value)
552556
&& let Ok(spirv_type) =

crates/rustc_codegen_spirv/src/attr.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
//!
33
//! The attribute-checking parts of this try to follow `rustc_passes::check_attr`.
44
5-
use crate::codegen_cx::CodegenCx;
65
use crate::symbols::Symbols;
76
use rspirv::spirv::{BuiltIn, ExecutionMode, ExecutionModel, StorageClass};
87
use rustc_hir as hir;
@@ -147,16 +146,16 @@ impl AggregatedSpirvAttributes {
147146
///
148147
/// Any errors for malformed/duplicate attributes will have been reported
149148
/// prior to codegen, by the `attr` check pass.
150-
pub fn parse<'tcx>(cx: &CodegenCx<'tcx>, attrs: &'tcx [Attribute]) -> Self {
149+
pub fn parse<'tcx>(tcx: TyCtxt<'tcx>, sym: &Symbols, attrs: &'tcx [Attribute]) -> Self {
151150
let mut aggregated_attrs = Self::default();
152151

153152
// NOTE(eddyb) `span_delayed_bug` ensures that if attribute checking fails
154153
// to see an attribute error, it will cause an ICE instead.
155-
for parse_attr_result in crate::symbols::parse_attrs_for_checking(&cx.sym, attrs) {
154+
for parse_attr_result in crate::symbols::parse_attrs_for_checking(sym, attrs) {
156155
let (span, parsed_attr) = match parse_attr_result {
157156
Ok(span_and_parsed_attr) => span_and_parsed_attr,
158157
Err((span, msg)) => {
159-
cx.tcx.dcx().span_delayed_bug(span, msg);
158+
tcx.dcx().span_delayed_bug(span, msg);
160159
continue;
161160
}
162161
};
@@ -166,8 +165,7 @@ impl AggregatedSpirvAttributes {
166165
prev_span: _,
167166
category,
168167
}) => {
169-
cx.tcx
170-
.dcx()
168+
tcx.dcx()
171169
.span_delayed_bug(span, format!("multiple {category} attributes"));
172170
}
173171
}

crates/rustc_codegen_spirv/src/codegen_cx/declare.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,11 @@ impl<'tcx> CodegenCx<'tcx> {
133133
self.set_linkage(fn_id, symbol_name.to_owned(), linkage);
134134
}
135135

136-
let attrs = AggregatedSpirvAttributes::parse(self, self.tcx.get_attrs_unchecked(def_id));
136+
let attrs = AggregatedSpirvAttributes::parse(
137+
self.tcx,
138+
&self.sym,
139+
self.tcx.get_attrs_unchecked(def_id),
140+
);
137141
if let Some(entry) = attrs.entry.map(|attr| attr.value) {
138142
// HACK(eddyb) early insert to let `shader_entry_stub` call this
139143
// very function via `get_fn_addr`.

crates/rustc_codegen_spirv/src/codegen_cx/entry.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,11 @@ impl<'tcx> CodegenCx<'tcx> {
433433
call_args: &mut Vec<SpirvValue>,
434434
decoration_locations: &mut FxHashMap<StorageClass, u32>,
435435
) {
436-
let attrs = AggregatedSpirvAttributes::parse(self, self.tcx.hir_attrs(hir_param.hir_id));
436+
let attrs = AggregatedSpirvAttributes::parse(
437+
self.tcx,
438+
&self.sym,
439+
self.tcx.hir_attrs(hir_param.hir_id),
440+
);
437441

438442
let EntryParamDeducedFromRustRefOrValue {
439443
value_layout,

0 commit comments

Comments
 (0)