From 52fa9daa645772603dc170a3f3bed5cab73d646d Mon Sep 17 00:00:00 2001
From: Christiaan Dirkx <christiaan@dirkx.email>
Date: Wed, 28 Apr 2021 15:51:14 +0200
Subject: [PATCH 1/4] Rework `wasm::thread` to `thread_atomics`

---
 library/std/src/sys/wasm/mod.rs               |  5 ++++-
 .../sys/wasm/{thread.rs => thread_atomics.rs} | 22 ++++---------------
 2 files changed, 8 insertions(+), 19 deletions(-)
 rename library/std/src/sys/wasm/{thread.rs => thread_atomics.rs} (83%)

diff --git a/library/std/src/sys/wasm/mod.rs b/library/std/src/sys/wasm/mod.rs
index 8705910c73a81..71877fce9934e 100644
--- a/library/std/src/sys/wasm/mod.rs
+++ b/library/std/src/sys/wasm/mod.rs
@@ -37,7 +37,6 @@ pub mod pipe;
 pub mod process;
 #[path = "../unsupported/stdio.rs"]
 pub mod stdio;
-pub mod thread;
 #[path = "../unsupported/thread_local_dtor.rs"]
 pub mod thread_local_dtor;
 #[path = "../unsupported/thread_local_key.rs"]
@@ -57,6 +56,8 @@ cfg_if::cfg_if! {
         pub mod rwlock;
         #[path = "futex_atomics.rs"]
         pub mod futex;
+        #[path = "thread_atomics.rs"]
+        pub mod thread;
     } else {
         #[path = "../unsupported/condvar.rs"]
         pub mod condvar;
@@ -64,6 +65,8 @@ cfg_if::cfg_if! {
         pub mod mutex;
         #[path = "../unsupported/rwlock.rs"]
         pub mod rwlock;
+        #[path = "../unsupported/thread.rs"]
+        pub mod thread;
     }
 }
 
diff --git a/library/std/src/sys/wasm/thread.rs b/library/std/src/sys/wasm/thread_atomics.rs
similarity index 83%
rename from library/std/src/sys/wasm/thread.rs
rename to library/std/src/sys/wasm/thread_atomics.rs
index b7bf95c89b482..54bc877aa7de7 100644
--- a/library/std/src/sys/wasm/thread.rs
+++ b/library/std/src/sys/wasm/thread_atomics.rs
@@ -13,20 +13,10 @@ impl Thread {
         unsupported()
     }
 
-    pub fn yield_now() {
-        // do nothing
-    }
+    pub fn yield_now() {}
 
-    pub fn set_name(_name: &CStr) {
-        // nope
-    }
+    pub fn set_name(_name: &CStr) {}
 
-    #[cfg(not(target_feature = "atomics"))]
-    pub fn sleep(_dur: Duration) {
-        panic!("can't sleep");
-    }
-
-    #[cfg(target_feature = "atomics")]
     pub fn sleep(dur: Duration) {
         use crate::arch::wasm32;
         use crate::cmp;
@@ -46,9 +36,7 @@ impl Thread {
         }
     }
 
-    pub fn join(self) {
-        self.0
-    }
+    pub fn join(self) {}
 }
 
 pub mod guard {
@@ -61,11 +49,9 @@ pub mod guard {
     }
 }
 
-// This is only used by atomics primitives when the `atomics` feature is
-// enabled. In that mode we currently just use our own thread-local to store our
+// We currently just use our own thread-local to store our
 // current thread's ID, and then we lazily initialize it to something allocated
 // from a global counter.
-#[cfg(target_feature = "atomics")]
 pub fn my_id() -> u32 {
     use crate::sync::atomic::{AtomicU32, Ordering::SeqCst};
 

From fab841080157b0ddc6e0a0d88c4b3fc43d32f147 Mon Sep 17 00:00:00 2001
From: Christiaan Dirkx <christiaan@dirkx.email>
Date: Wed, 28 Apr 2021 15:54:08 +0200
Subject: [PATCH 2/4] Move `wasm` atomics code to `wasm/atomics`

---
 .../wasm/{condvar_atomics.rs => atomics/condvar.rs}    |  0
 .../sys/wasm/{futex_atomics.rs => atomics/futex.rs}    |  0
 .../sys/wasm/{mutex_atomics.rs => atomics/mutex.rs}    |  0
 .../sys/wasm/{rwlock_atomics.rs => atomics/rwlock.rs}  |  0
 .../sys/wasm/{thread_atomics.rs => atomics/thread.rs}  |  0
 library/std/src/sys/wasm/mod.rs                        | 10 +++++-----
 6 files changed, 5 insertions(+), 5 deletions(-)
 rename library/std/src/sys/wasm/{condvar_atomics.rs => atomics/condvar.rs} (100%)
 rename library/std/src/sys/wasm/{futex_atomics.rs => atomics/futex.rs} (100%)
 rename library/std/src/sys/wasm/{mutex_atomics.rs => atomics/mutex.rs} (100%)
 rename library/std/src/sys/wasm/{rwlock_atomics.rs => atomics/rwlock.rs} (100%)
 rename library/std/src/sys/wasm/{thread_atomics.rs => atomics/thread.rs} (100%)

diff --git a/library/std/src/sys/wasm/condvar_atomics.rs b/library/std/src/sys/wasm/atomics/condvar.rs
similarity index 100%
rename from library/std/src/sys/wasm/condvar_atomics.rs
rename to library/std/src/sys/wasm/atomics/condvar.rs
diff --git a/library/std/src/sys/wasm/futex_atomics.rs b/library/std/src/sys/wasm/atomics/futex.rs
similarity index 100%
rename from library/std/src/sys/wasm/futex_atomics.rs
rename to library/std/src/sys/wasm/atomics/futex.rs
diff --git a/library/std/src/sys/wasm/mutex_atomics.rs b/library/std/src/sys/wasm/atomics/mutex.rs
similarity index 100%
rename from library/std/src/sys/wasm/mutex_atomics.rs
rename to library/std/src/sys/wasm/atomics/mutex.rs
diff --git a/library/std/src/sys/wasm/rwlock_atomics.rs b/library/std/src/sys/wasm/atomics/rwlock.rs
similarity index 100%
rename from library/std/src/sys/wasm/rwlock_atomics.rs
rename to library/std/src/sys/wasm/atomics/rwlock.rs
diff --git a/library/std/src/sys/wasm/thread_atomics.rs b/library/std/src/sys/wasm/atomics/thread.rs
similarity index 100%
rename from library/std/src/sys/wasm/thread_atomics.rs
rename to library/std/src/sys/wasm/atomics/thread.rs
diff --git a/library/std/src/sys/wasm/mod.rs b/library/std/src/sys/wasm/mod.rs
index 71877fce9934e..0bd2c0d0f9d4c 100644
--- a/library/std/src/sys/wasm/mod.rs
+++ b/library/std/src/sys/wasm/mod.rs
@@ -48,15 +48,15 @@ pub use crate::sys_common::os_str_bytes as os_str;
 
 cfg_if::cfg_if! {
     if #[cfg(target_feature = "atomics")] {
-        #[path = "condvar_atomics.rs"]
+        #[path = "atomics/condvar.rs"]
         pub mod condvar;
-        #[path = "mutex_atomics.rs"]
+        #[path = "atomics/mutex.rs"]
         pub mod mutex;
-        #[path = "rwlock_atomics.rs"]
+        #[path = "atomics/rwlock.rs"]
         pub mod rwlock;
-        #[path = "futex_atomics.rs"]
+        #[path = "atomics/futex.rs"]
         pub mod futex;
-        #[path = "thread_atomics.rs"]
+        #[path = "atomics/thread.rs"]
         pub mod thread;
     } else {
         #[path = "../unsupported/condvar.rs"]

From 45bc1930cae22b8b08adc9bb5ed4a494831d6678 Mon Sep 17 00:00:00 2001
From: Christiaan Dirkx <christiaan@dirkx.email>
Date: Wed, 28 Apr 2021 15:44:13 +0200
Subject: [PATCH 3/4] Reuse `unsupported::args` on `wasm`

---
 library/std/src/sys/wasm/args.rs | 42 --------------------------------
 library/std/src/sys/wasm/mod.rs  |  1 +
 2 files changed, 1 insertion(+), 42 deletions(-)
 delete mode 100644 library/std/src/sys/wasm/args.rs

diff --git a/library/std/src/sys/wasm/args.rs b/library/std/src/sys/wasm/args.rs
deleted file mode 100644
index fde1ab79e1f4b..0000000000000
--- a/library/std/src/sys/wasm/args.rs
+++ /dev/null
@@ -1,42 +0,0 @@
-use crate::ffi::OsString;
-use crate::fmt;
-use crate::vec;
-
-pub fn args() -> Args {
-    Args { iter: Vec::new().into_iter() }
-}
-
-pub struct Args {
-    iter: vec::IntoIter<OsString>,
-}
-
-impl !Send for Args {}
-impl !Sync for Args {}
-
-impl fmt::Debug for Args {
-    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-        self.iter.as_slice().fmt(f)
-    }
-}
-
-impl Iterator for Args {
-    type Item = OsString;
-    fn next(&mut self) -> Option<OsString> {
-        self.iter.next()
-    }
-    fn size_hint(&self) -> (usize, Option<usize>) {
-        self.iter.size_hint()
-    }
-}
-
-impl ExactSizeIterator for Args {
-    fn len(&self) -> usize {
-        self.iter.len()
-    }
-}
-
-impl DoubleEndedIterator for Args {
-    fn next_back(&mut self) -> Option<OsString> {
-        self.iter.next_back()
-    }
-}
diff --git a/library/std/src/sys/wasm/mod.rs b/library/std/src/sys/wasm/mod.rs
index 0bd2c0d0f9d4c..18d8ea183f733 100644
--- a/library/std/src/sys/wasm/mod.rs
+++ b/library/std/src/sys/wasm/mod.rs
@@ -17,6 +17,7 @@
 #![deny(unsafe_op_in_unsafe_fn)]
 
 pub mod alloc;
+#[path = "../unsupported/args.rs"]
 pub mod args;
 #[path = "../unsupported/cmath.rs"]
 pub mod cmath;

From cf79c06575f1710f05ee5309fb24bcdfff6f0140 Mon Sep 17 00:00:00 2001
From: Christiaan Dirkx <christiaan@dirkx.email>
Date: Wed, 28 Apr 2021 16:16:01 +0200
Subject: [PATCH 4/4] Fix missing import in `unsupported::args`

---
 library/std/src/sys/unsupported/args.rs | 1 +
 1 file changed, 1 insertion(+)

diff --git a/library/std/src/sys/unsupported/args.rs b/library/std/src/sys/unsupported/args.rs
index c924a7d8a2672..a2d75a6197633 100644
--- a/library/std/src/sys/unsupported/args.rs
+++ b/library/std/src/sys/unsupported/args.rs
@@ -1,4 +1,5 @@
 use crate::ffi::OsString;
+use crate::fmt;
 
 pub struct Args {}