Skip to content
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

Can not call function with sub-slice as argument #752

Open
SiebenCorgie opened this issue Sep 13, 2021 · 3 comments
Open

Can not call function with sub-slice as argument #752

SiebenCorgie opened this issue Sep 13, 2021 · 3 comments
Labels
s: qptr may fix This might be fixed by the "qptr" experiment (https://github.com/EmbarkStudios/spirt/pull/24) t: enhancement A new feature or improvement to an existing one.

Comments

@SiebenCorgie
Copy link
Contributor

When calling a function with a sub-slice of some other slice, the compiler throws a strange error:

Small example:

pub fn t1(main: &[f32]){
    let a = t2(&main[10..13]);
}

fn t2(sub: &[f32]) -> u32{
    1
}

throws

  error: Cannot cast between pointer types
    --> /.../rustup/toolchains/nightly-2021-08-27-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/const_ptr.rs:49:6
     |
  49 |     }
     |      ^
     |
     = note: from: *f32
     = note: to: *struct () {  }

  error: Cannot cast between pointer types
     --> /.../.rustup/toolchains/nightly-2021-08-27-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/metadata.rs:117:14
      |
  117 |     unsafe { PtrRepr { components: PtrComponents { data_address, metadata } }.const_ptr }
      |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      |
      = note: from: *[u8; 8]
      = note: to: *struct core::ptr::metadata::PtrComponents<[f32]> { *struct () {  }, u32 }

  error: Cannot cast between pointer types
     --> /.../.rustup/toolchains/nightly-2021-08-27-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/metadata.rs:117:14
      |
  117 |     unsafe { PtrRepr { components: PtrComponents { data_address, metadata } }.const_ptr }
      |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      |
      = note: from: *[u8; 8]
      = note: to: *struct *const [f32] { *[f32], u32 }

  error: Cannot offset a pointer to an arbitrary element
     --> /.../.rustup/toolchains/nightly-2021-08-27-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/const_ptr.rs:235:18
      |
  235 |         unsafe { intrinsics::offset(self, count) }
      |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

This is probably a similar problem like this, however, under different circumstances. If this is viewed as a duplicate, just close the Issue please.

@SiebenCorgie SiebenCorgie added the t: enhancement A new feature or improvement to an existing one. label Sep 13, 2021
@khyperia
Copy link
Contributor

Unfortunately yeah, SPIR-V does not have an easy representation of subslices - we would need to tack on a (offset, length) pair to all regular arrays to support slicing, which then would change the ABI of the generated SPIR-V to be significantly different than what rustc tells us to do, which we've managed to avoid doing so far (it gets really, really complicated).

Hopefully at some point we can support slicing, though!

@SiebenCorgie
Copy link
Contributor Author

I see, I'll track the start and end of my sub-slice via additional arguments, works in glsl too! Good luck with finding a way to do that! I'd help, but I do not understand compilers enough to be a real help to you :(.

@oisyn
Copy link
Contributor

oisyn commented Nov 17, 2022

We probably won't be supporting slices any time soon

@oisyn oisyn closed this as not planned Won't fix, can't repro, duplicate, stale Nov 17, 2022
@eddyb eddyb reopened this Mar 29, 2023
@eddyb eddyb added the s: qptr may fix This might be fixed by the "qptr" experiment (https://github.com/EmbarkStudios/spirt/pull/24) label Mar 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
s: qptr may fix This might be fixed by the "qptr" experiment (https://github.com/EmbarkStudios/spirt/pull/24) t: enhancement A new feature or improvement to an existing one.
Projects
None yet
Development

No branches or pull requests

5 participants
@eddyb @khyperia @SiebenCorgie @oisyn and others