Skip to content

Unlock for i in 0..n loops! (by bumping rust-toolchain to nightly-2021-03-17) #493

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 17, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 15 additions & 18 deletions crates/rustc_codegen_spirv/src/attr.rs
Original file line number Diff line number Diff line change
@@ -43,9 +43,10 @@ struct CheckSpirvAttrVisitor<'tcx> {
}

impl CheckSpirvAttrVisitor<'_> {
fn check_spirv_attributes(&self, hir_id: HirId, attrs: &[Attribute], target: Target) {
fn check_spirv_attributes(&self, hir_id: HirId, target: Target) {
let parse_attrs = |attrs| crate::symbols::parse_attrs_for_checking(&self.sym, attrs);

let attrs = self.tcx.hir().attrs(hir_id);
for (attr, parse_attr_result) in parse_attrs(attrs) {
// Make sure to mark the whole `#[spirv(...)]` attribute as used,
// to avoid warnings about unused attributes.
@@ -144,48 +145,48 @@ impl<'tcx> Visitor<'tcx> for CheckSpirvAttrVisitor<'tcx> {

fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
let target = Target::from_item(item);
self.check_spirv_attributes(item.hir_id(), item.attrs, target);
self.check_spirv_attributes(item.hir_id(), target);
intravisit::walk_item(self, item)
}

fn visit_generic_param(&mut self, generic_param: &'tcx hir::GenericParam<'tcx>) {
let target = Target::from_generic_param(generic_param);
self.check_spirv_attributes(generic_param.hir_id, generic_param.attrs, target);
self.check_spirv_attributes(generic_param.hir_id, target);
intravisit::walk_generic_param(self, generic_param)
}

fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem<'tcx>) {
let target = Target::from_trait_item(trait_item);
self.check_spirv_attributes(trait_item.hir_id(), trait_item.attrs, target);
self.check_spirv_attributes(trait_item.hir_id(), target);
intravisit::walk_trait_item(self, trait_item)
}

fn visit_struct_field(&mut self, struct_field: &'tcx hir::StructField<'tcx>) {
self.check_spirv_attributes(struct_field.hir_id, struct_field.attrs, Target::Field);
self.check_spirv_attributes(struct_field.hir_id, Target::Field);
intravisit::walk_struct_field(self, struct_field);
}

fn visit_arm(&mut self, arm: &'tcx hir::Arm<'tcx>) {
self.check_spirv_attributes(arm.hir_id, arm.attrs, Target::Arm);
self.check_spirv_attributes(arm.hir_id, Target::Arm);
intravisit::walk_arm(self, arm);
}

fn visit_foreign_item(&mut self, f_item: &'tcx hir::ForeignItem<'tcx>) {
let target = Target::from_foreign_item(f_item);
self.check_spirv_attributes(f_item.hir_id(), f_item.attrs, target);
self.check_spirv_attributes(f_item.hir_id(), target);
intravisit::walk_foreign_item(self, f_item)
}

fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) {
let target = target_from_impl_item(self.tcx, impl_item);
self.check_spirv_attributes(impl_item.hir_id(), impl_item.attrs, target);
self.check_spirv_attributes(impl_item.hir_id(), target);
intravisit::walk_impl_item(self, impl_item)
}

fn visit_stmt(&mut self, stmt: &'tcx hir::Stmt<'tcx>) {
// When checking statements ignore expressions, they will be checked later.
if let hir::StmtKind::Local(l) = stmt.kind {
self.check_spirv_attributes(l.hir_id, &l.attrs, Target::Statement);
self.check_spirv_attributes(l.hir_id, Target::Statement);
}
intravisit::walk_stmt(self, stmt)
}
@@ -196,7 +197,7 @@ impl<'tcx> Visitor<'tcx> for CheckSpirvAttrVisitor<'tcx> {
_ => Target::Expression,
};

self.check_spirv_attributes(expr.hir_id, &expr.attrs, target);
self.check_spirv_attributes(expr.hir_id, target);
intravisit::walk_expr(self, expr)
}

@@ -206,17 +207,17 @@ impl<'tcx> Visitor<'tcx> for CheckSpirvAttrVisitor<'tcx> {
generics: &'tcx hir::Generics<'tcx>,
item_id: HirId,
) {
self.check_spirv_attributes(variant.id, variant.attrs, Target::Variant);
self.check_spirv_attributes(variant.id, Target::Variant);
intravisit::walk_variant(self, variant, generics, item_id)
}

fn visit_macro_def(&mut self, macro_def: &'tcx hir::MacroDef<'tcx>) {
self.check_spirv_attributes(macro_def.hir_id(), macro_def.attrs, Target::MacroDef);
self.check_spirv_attributes(macro_def.hir_id(), Target::MacroDef);
intravisit::walk_macro_def(self, macro_def);
}

fn visit_param(&mut self, param: &'tcx hir::Param<'tcx>) {
self.check_spirv_attributes(param.hir_id, param.attrs, Target::Param);
self.check_spirv_attributes(param.hir_id, Target::Param);

intravisit::walk_param(self, param);
}
@@ -254,11 +255,7 @@ fn check_mod_attrs(tcx: TyCtxt<'_>, module_def_id: LocalDefId) {
tcx.hir().krate().non_exported_macro_attrs,
);
if module_def_id.is_top_level_module() {
check_spirv_attr_visitor.check_spirv_attributes(
CRATE_HIR_ID,
tcx.hir().krate_attrs(),
Target::Mod,
);
check_spirv_attr_visitor.check_spirv_attributes(CRATE_HIR_ID, Target::Mod);
}
}

2 changes: 1 addition & 1 deletion crates/rustc_codegen_spirv/src/builder/intrinsics.rs
Original file line number Diff line number Diff line change
@@ -504,7 +504,7 @@ impl<'a, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'tcx> {
cond
}

fn sideeffect(&mut self, _: bool) {
fn sideeffect(&mut self) {
// TODO: This is currently ignored.
// It corresponds to the llvm.sideeffect intrinsic - does spir-v have an equivalent?
}
2 changes: 1 addition & 1 deletion crates/rustc_codegen_spirv/src/codegen_cx/entry.rs
Original file line number Diff line number Diff line change
@@ -166,7 +166,7 @@ impl<'tcx> CodegenCx<'tcx> {
if let hir::PatKind::Binding(_, _, ident, _) = &hir_param.pat.kind {
self.emit_global().name(variable, ident.to_string());
}
for attr in parse_attrs(self, hir_param.attrs) {
for attr in parse_attrs(self, self.tcx.hir().attrs(hir_param.hir_id)) {
match attr {
SpirvAttribute::Builtin(builtin) => {
self.emit_global().decorate(
4 changes: 2 additions & 2 deletions crates/rustc_codegen_spirv/src/lib.rs
Original file line number Diff line number Diff line change
@@ -313,7 +313,7 @@ impl CodegenBackend for SpirvCodegenBackend {
// capture variables. Fortunately, the defaults are exposed (thanks rustdoc), so use that instead.
let result = (rustc_interface::DEFAULT_QUERY_PROVIDERS.fn_sig)(tcx, def_id);
result.map_bound(|mut inner| {
if inner.abi == Abi::C {
if let Abi::C { .. } = inner.abi {
inner.abi = Abi::Rust;
}
inner
@@ -329,7 +329,7 @@ impl CodegenBackend for SpirvCodegenBackend {
providers.fn_sig = |tcx, def_id| {
let result = (rustc_interface::DEFAULT_EXTERN_QUERY_PROVIDERS.fn_sig)(tcx, def_id);
result.map_bound(|mut inner| {
if inner.abi == Abi::C {
if let Abi::C { .. } = inner.abi {
inner.abi = Abi::Rust;
}
inner
1 change: 1 addition & 0 deletions crates/rustc_codegen_spirv/src/linker/test.rs
Original file line number Diff line number Diff line change
@@ -78,6 +78,7 @@ fn assemble_and_link(binaries: &[&[u8]]) -> Result<Module, String> {
diagnostic_output: DiagnosticOutput::Raw(Box::new(write_diags)),
stderr: None,
lint_caps: Default::default(),
parse_sess_created: None,
register_lints: None,
override_queries: None,
make_codegen_backend: None,
19 changes: 16 additions & 3 deletions crates/spirv-builder/src/test/control_flow.rs
Original file line number Diff line number Diff line change
@@ -377,9 +377,11 @@ pub fn main() {
}"#);
}

// HACK(eddyb) test that `for` loop desugaring (with its call to `Iterator::next`
// and matching on the resulting `Option`) works, without a working `Range`
// iterator (due to the use of `mem::swap` and its block-wise implementation).
// NOTE(eddyb) this tests `for` loop desugaring (with its call to `Iterator::next`
// and matching on the resulting `Option`), without relying on a `Range` iterator.
// More precisely, `Range` used to not compile, due to it using `mem::replace`,
// which, before https://github.com/rust-lang/rust/pull/83022, used to just call
// `mem::swap` (which has a block-wise optimization that can't work on SPIR-V).
#[test]
fn cf_for_with_custom_range_iter() {
val(r#"
@@ -408,3 +410,14 @@ pub fn main(i: Input<i32>) {
}
"#);
}

#[test]
fn cf_for_range() {
val(r#"
#[spirv(fragment)]
pub fn main(i: Input<i32>) {
for _ in 0..*i {
}
}
"#);
}
4 changes: 2 additions & 2 deletions examples/runners/ash/src/main.rs
Original file line number Diff line number Diff line change
@@ -1217,15 +1217,15 @@ impl PipelineDescriptor {
.build();

Self {
color_blend_attachments,
dynamic_state,
shader_stages,
vertex_input,
input_assembly,
rasterization,
multisample,
depth_stencil,
color_blend_attachments,
color_blend,
dynamic_state,
dynamic_state_info,
}
}
5 changes: 1 addition & 4 deletions examples/shaders/mouse-shader/src/lib.rs
Original file line number Diff line number Diff line change
@@ -226,9 +226,7 @@ pub fn main_fs(
.intersect(mouse_circle)
};

// FIXME(eddyb) use a `for i in 0..3` loop when that works.
let mut i = 0;
while i < 3 {
for i in 0..3 {
painter.fill(
mouse_button(i),
RED.lerp(
@@ -242,7 +240,6 @@ pub fn main_fs(
),
),
);
i += 1;
}

painter.fill_with_contrast_border(
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -5,5 +5,5 @@
# to the user in the error, instead of "error: invalid channel name '[toolchain]'".

[toolchain]
channel = "nightly-2021-03-04"
channel = "nightly-2021-03-17"
components = ["rust-src", "rustc-dev", "llvm-tools-preview"]