Skip to content

GEP not implemented for type struct [_; 0] #151

Description

@Firestar99

Original issue: EmbarkStudios/rust-gpu#1075

Expected Behaviour

This compiles fine with rustc (I guess this bit is probably eliminated?).

Example & Steps To Reproduce

I was using const generic parameters to determine the length of some arrays. At some point, a base case ended up declaring a zero-length array, like so:

#![cfg_attr(target_arch = "spirv", no_std)]
use spirv_std::spirv;

fn example<const LENGTH: usize>() {
    let mut array = [0; LENGTH];
    for i in 0..array.len() {
        array[i] += i;
    }
}

#[spirv(compute(threads(1, 1, 1)))]
pub fn compute() {
    example::<0>();
}

Resulting in:

error: GEP not implemented for type struct [usize; 0] {  }
 --> examples/shaders/compute-shader/src/lib.rs:7:9
  |
7 |         array[i] += i;
  |         ^^^^^^^^^^^^^

System Info

* rustc: 1.71.0-nightly (1a5f8bce7 2023-05-26)

* rust-gpu: [b2e5eb7](https://github.com/EmbarkStudios/rust-gpu/commit/b2e5eb75951545782b121665c20f9f1c66fe5bdd)

Activity

  1. JulianKnodt commented on Dec 3, 2024

    @JulianKnodt
    Contributor

    Is it alright if I check this out?

  2. Firestar99 commented on Dec 3, 2024

    @Firestar99
    MemberAuthor

    Feel free to give it a try. This old patch won't be directly cherry-pickable due to some larger gep changes.

  3. JulianKnodt commented on Dec 7, 2024

    @JulianKnodt
    Contributor

    I'm a bit confused what should be emitted, since it doesn't make sense to have a GEP to an array with zero elements. Should it just emit a constant value?

    For context I added the patch you linked here (which is very WIP), but it still fails with this:
    image

    Ah I realize we're hitting this because we're emitting a struct and not an array now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions