Skip to content

Wrong path attribute handling in inline modules #4180

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

Closed
Lokathor opened this issue Apr 28, 2020 · 10 comments
Closed

Wrong path attribute handling in inline modules #4180

Lokathor opened this issue Apr 28, 2020 · 10 comments
Labels
A-nameres name, path and module resolution E-has-instructions Issue has some instructions and pointers to code to get started E-medium S-actionable Someone could pick this issue up and work on it right now

Comments

@Lokathor
Copy link

Lokathor commented Apr 28, 2020

This seems related to #3898 but my file is inside the workspace so even if files outside the workspace aren't supported, I think that my use case should be.

I've got a crate that deals with CPU intrinsics. As I'm sure you're aware, x86 and x86_64 are very closely related. I want to write CPU specific modules but also I want to write things once and then use it in both places as much as possible.

This leads to a file system that looks like this:

src/
    intel_family/
        m128_.rs
        sse.rs
    lib.rs

And then a lib.rs that looks like this:

#[cfg(target_arch = "x86")]
pub mod x86 {
  //! Types and functions for safe `x86` intrinsic usage.
  use super::*;
  use core::arch::x86::*;

  #[path = "../intel_family/m128_.rs"]
  mod m128_;
  pub use m128_::*;
  #[path = "../intel_family/sse.rs"]
  mod sse;
  pub use sse::*;
}
#[cfg(target_arch = "x86")]
pub use x86::*;

#[cfg(target_arch = "x86_64")]
pub mod x86_64 {
  //! Types and functions for safe `x86_64` intrinsic usage.
  use super::*;
  use core::arch::x86_64::*;

  #[path = "../intel_family/m128_.rs"]
  mod m128_;
  pub use m128_::*;
  #[path = "../intel_family/sse.rs"]
  mod sse;
  pub use sse::*;
}
#[cfg(target_arch = "x86_64")]
pub use x86_64::*;

Now the compiler itself is totally able to follow those relative paths from the fake x86 directory up one level to src/ and then down into src/intel_family/ and get the code where it's supposed to go. RA just shows fake errors about unresolved module because it doesn't understand.

@flodiebold
Copy link
Member

Huh, so the path is relative to a hypothetical src/x86 path instead of the actual path of the file? 🤔

@flodiebold flodiebold changed the title path attribute not supported Wrong path attribute handling in inline modules Apr 28, 2020
@matklad matklad added E-medium E-has-instructions Issue has some instructions and pointers to code to get started labels Apr 28, 2020
@flodiebold
Copy link
Member

From the tests it looks like we should already do this correctly, so the first step would probably be adding this case as a test to see whether it breaks...

@Lokathor
Copy link
Author

Lokathor commented Apr 28, 2020

@flodiebold yeah, so, what happens is basically like this:

  1. We're in src/lib.rs
  2. We declare mod x86 inline which (in the compiler's eyes) puts us into a virtual src/x86/ folder (which doesn't really exist on disk)
  3. We declare #[path = "../intel_family/m128_.rs"] mod m128_; which makes a module name m128_ and looks for its content in a relative path that's relative to the virtual src/x86/ directory:
  • up 1 to src/
  • then down one to src/intel_family/ (a real folder)
  • and then a file within that directory.

@lnicola lnicola added the S-actionable Someone could pick this issue up and work on it right now label Jan 27, 2021
@jonas-schievink jonas-schievink added the A-nameres name, path and module resolution label Mar 25, 2021
@jonas-schievink
Copy link
Contributor

I'm unable to reproduce this, is there a repo available with the required directory layout? Or maybe this has just been fixed in the meantime

@lnicola
Copy link
Member

lnicola commented Jul 22, 2021

Could it have been fixed in #9353?

@jonas-schievink
Copy link
Contributor

Seems unlikely, all files are below src in this case

@lnicola
Copy link
Member

lnicola commented Jul 22, 2021

Ah, right.

@Lokathor
Copy link
Author

I can try to remember to check on if this is still a problem, though i think that i have updated the repo to work around this issue.

@Lokathor
Copy link
Author

I'm going to just close this. The current version of the crate doesn't seem to have the problem anymore, so I can't reproduce it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-nameres name, path and module resolution E-has-instructions Issue has some instructions and pointers to code to get started E-medium S-actionable Someone could pick this issue up and work on it right now
Projects
None yet
Development

No branches or pull requests

5 participants