Skip to content

Sealed Windows FileTypeExt extensible trait broke FileTypeExt in wasi-common #102260

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
pinkforest opened this issue Sep 25, 2022 · 2 comments
Closed

Comments

@pinkforest
Copy link
Contributor

pinkforest commented Sep 25, 2022

EDIT: So Sealing happened via 2nd commit on: #98583 - which I had originally traced down here but didn't have PR ref

Unknowns / TODO

Note: I can't find windows_file_type_ext feature from unstable book or it's tracking issue ?

So the Sealed trait was designed to prevent people rolling own trait impl's ?

I suspect that cap-primitives may need to deal with the Sealed trait instead of rolling own trait / impl like it's done now ?

But I think that may be troublematic.. going by guessing what was intended in cap-primitives

Don't know yet enough about the sealed feature (yet) as it doesn't seem to have much docs around and I need to dig deeper on this.

Issue

On Windows builds that rely on wasi-common on which we rely on at lunatic:

wasi-common v0.40.0
├── cap-std v0.25.2
    ├── cap-primitives v0.25.2

We now get via cap-primitives this in 1.66.0-nightly (4a14677 2022-09-23):

    error[E0277]: the trait bound file_type::FileType: std::sealed::Sealed is not satisfied
    <snip>
        |
    134 | impl std::os::windows::fs::FileTypeExt for FileType {
        |      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait std::sealed::Sealed is not implemented for file_type::FileType
        |
    <snip>
    error: could not compile cap-primitives due to previous error
    warning: build failed, waiting for other jobs to finish...
    error: failed to compile lunatic-runtime v0.10.0, intermediate artifacts can be found at <snip>

Now this was probably very intentional but

Sealed

So Sealed acts as some kind of guard for the ecosystem not to mess with it ?

mod sealed {
    /// This trait being unreachable from outside the crate
    /// prevents outside implementations of our extension traits.
    /// This allows adding more trait methods in the future.
    #[unstable(feature = "sealed", issue = "none")]
    pub trait Sealed {}
}

Related earlier changes

I see the below changes re: stabilisation related to feature windows_file_type_ext

commits a4cb0b9 and e374c91

library/std/src/os/windows/fs.rs      2022-06-27 09:57:56 -0700  10) use crate::sealed::Sealed;
library/std/src/os/windows/fs.rs      2022-06-27 09:41:12 -0700 506) #[stable(feature = "windows_file_type_ext", since = "1.64.0")]
library/std/src/os/windows/fs.rs      2022-06-27 09:57:56 -0700 507) pub trait FileTypeExt: Sealed {

wasi/cap-primitives Related

This works okay in OSX, Linux but Windows builds are now broken with this where the error comes from:

cap-primitives/src/fs/file_type.rs - https://docs.rs/cap-primitives/latest/src/cap_primitives/fs/file_type.rs.html#125-147

/// Windows-specific extensions for [`FileType`].                                                                                                                                         
///                                                                                                                                                                                       
/// This corresponds to [`std::os::windows::fs::FileTypeExt`].                                                                                                                            
#[cfg(all(windows, windows_file_type_ext))]
pub trait FileTypeExt {
    /// Returns `true` if this file type is a symbolic link that is also a directory.                                                                                                     
    fn is_symlink_dir(&self) -> bool;
    /// Returns `true` if this file type is a symbolic link that is also a file.                                                                                                          
    fn is_symlink_file(&self) -> bool;
}

#[cfg(all(windows, windows_file_type_ext))]
impl FileTypeExt for FileType {
    #[inline]
    fn is_symlink_dir(&self) -> bool {
	self.0 == Inner::Ext(ImplFileTypeExt::symlink_dir())
    }

    #[inline]
    fn is_symlink_file(&self) -> bool {
	self.0 == Inner::Ext(ImplFileTypeExt::symlink_file())
    }
}

git b

0a96e089bade library/std/src/sys/windows/ext/fs.rs (Prabakaran Kumaresshan 2020-08-16 22:28:45 +0530 503) /// Windows-specific extensions to [`fs::FileType`].
182d99cfd1a5 src/libstd/sys/windows/ext/fs.rs      (Dylan MacKenzie        2018-04-09 17:44:28 -0700 504) ///
182d99cfd1a5 src/libstd/sys/windows/ext/fs.rs      (Dylan MacKenzie        2018-04-09 17:44:28 -0700 505) /// On Windows, a symbolic link knows whether it is a file or directory.
e374c911af9a library/std/src/os/windows/fs.rs      (Josh Triplett          2022-06-27 09:41:12 -0700 506) #[stable(feature = "windows_file_type_ext", since = "1.64.0")]
a4cb0b90c049 library/std/src/os/windows/fs.rs      (Josh Triplett          2022-06-27 09:57:56 -0700 507) pub trait FileTypeExt: Sealed {
99ed06eb8864 src/libstd/sys/windows/ext/fs.rs      (Alexander Regueiro     2019-02-09 22:16:58 +0000 508)     /// Returns `true` if this file type is a symbolic link that is also a directory.
e374c911af9a library/std/src/os/windows/fs.rs      (Josh Triplett          2022-06-27 09:41:12 -0700 509)     #[stable(feature = "windows_file_type_ext", since = "1.64.0")]
9269e83b37e8 src/libstd/sys/windows/ext/fs.rs      (Peter Atashian         2018-02-11 13:40:46 -0500 510)     fn is_symlink_dir(&self) -> bool;
99ed06eb8864 src/libstd/sys/windows/ext/fs.rs      (Alexander Regueiro     2019-02-09 22:16:58 +0000 511)     /// Returns `true` if this file type is a symbolic link that is also a file.
e374c911af9a library/std/src/os/windows/fs.rs      (Josh Triplett          2022-06-27 09:41:12 -0700 512)     #[stable(feature = "windows_file_type_ext", since = "1.64.0")]
9269e83b37e8 src/libstd/sys/windows/ext/fs.rs      (Peter Atashian         2018-02-11 13:40:46 -0500 513)     fn is_symlink_file(&self) -> bool;
9269e83b37e8 src/libstd/sys/windows/ext/fs.rs      (Peter Atashian         2018-02-11 13:40:46 -0500 514) }
9269e83b37e8 src/libstd/sys/windows/ext/fs.rs      (Peter Atashian         2018-02-11 13:40:46 -0500 515) 
a4cb0b90c049 library/std/src/os/windows/fs.rs      (Josh Triplett          2022-06-27 09:57:56 -0700 516) #[stable(feature = "windows_file_type_ext", since = "1.64.0")]
a4cb0b90c049 library/std/src/os/windows/fs.rs      (Josh Triplett          2022-06-27 09:57:56 -0700 517) impl Sealed for fs::FileType {}
a4cb0b90c049 library/std/src/os/windows/fs.rs      (Josh Triplett          2022-06-27 09:57:56 -0700 518) 
e374c911af9a library/std/src/os/windows/fs.rs      (Josh Triplett          2022-06-27 09:41:12 -0700 519) #[stable(feature = "windows_file_type_ext", since = "1.64.0")]
9269e83b37e8 src/libstd/sys/windows/ext/fs.rs      (Peter Atashian         2018-02-11 13:40:46 -0500 520) impl FileTypeExt for fs::FileType {
c34fbfaad38c src/libstd/sys/windows/ext/fs.rs      (David Tolnay           2019-11-27 10:28:39 -0800 521)     fn is_symlink_dir(&self) -> bool {
c34fbfaad38c src/libstd/sys/windows/ext/fs.rs      (David Tolnay           2019-11-27 10:28:39 -0800 522)         self.as_inner().is_symlink_dir()
c34fbfaad38c src/libstd/sys/windows/ext/fs.rs      (David Tolnay           2019-11-27 10:28:39 -0800 523)     }
c34fbfaad38c src/libstd/sys/windows/ext/fs.rs      (David Tolnay           2019-11-27 10:28:39 -0800 524)     fn is_symlink_file(&self) -> bool {
c34fbfaad38c src/libstd/sys/windows/ext/fs.rs      (David Tolnay           2019-11-27 10:28:39 -0800 525)         self.as_inner().is_symlink_file()
c34fbfaad38c src/libstd/sys/windows/ext/fs.rs      (David Tolnay           2019-11-27 10:28:39 -0800 526)     }
9269e83b37e8 src/libstd/sys/windows/ext/fs.rs      (Peter Atashian         2018-02-11 13:40:46 -0500 527) }

Refs

https://docs.rs/cap-primitives/latest/src/cap_primitives/fs/file_type.rs.html#125-147
https://github.com/bytecodealliance/cap-std
https://doc.rust-lang.org/std/os/windows/fs/trait.FileTypeExt.html
https://stdrs.dev/nightly/x86_64-unknown-linux-gnu/std/sealed/trait.Sealed.html
https://stdrs.dev/nightly/x86_64-unknown-linux-gnu/std/sealed/trait.Sealed.html
lunatic-solutions/lunatic#136

@pinkforest pinkforest closed this as not planned Won't fix, can't repro, duplicate, stale Sep 25, 2022
@pinkforest pinkforest reopened this Sep 25, 2022
@pinkforest
Copy link
Contributor Author

So there is now wasmtime 0.40 which will break when / if this will into stable release

bytecodealliance/wasmtime#4957
bytecodealliance/cap-std#270 (comment)

I'll try to get a point release there so it continues to work under 0.40 at least

I also asked re: process about sealing traits that were previously not sealed
https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/.23102260.20Sealed.20Windows.20FileTypeExt/near/300660648

@pinkforest
Copy link
Contributor Author

I'll see what wasmtime can provide to support 0.40 users. The sealed is working as intended - wasmtime was relying on unstable feature so no issue here.

@pinkforest pinkforest closed this as not planned Won't fix, can't repro, duplicate, stale Sep 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant