Skip to content

Commit a34dc97

Browse files
committed
api: avoid triggering the LTO bug
1 parent cb4fe52 commit a34dc97

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

api/async.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
#include <cstddef>
4646

4747
#include "types.hpp"
48-
#include "ptr.hpp"
4948

5049
#define __jule_AsyncRet co_return // Equivalent to `ret` in async functions.
5150
#define __jule_AsyncAwait co_await // Equivalent to `await` in async functions.
@@ -80,7 +79,11 @@ class __jule_thread;
8079

8180
// Each OS thread executing Jule code has a TLS pointer to its associated
8281
// runtime thread object.
83-
inline thread_local __jule_Ptr<__jule_thread> __jule_ct;
82+
//
83+
// Historically, this field was a smart pointer.
84+
// However, due to a toolchain bug in Windows, it's supposed to be a trivial type.
85+
// See: https://github.com/mstorsjo/llvm-mingw/issues/541
86+
inline thread_local __jule_thread *__jule_ct = nullptr;
8487

8588
// Non-templated coroutine handle used by the runtime.
8689
// The runtime never needs promise-type information.

std/runtime/thread.jule

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD 3-Clause
33
// license that can be found in the LICENSE file.
44

5-
extern let mut __jule_ct: &thread
5+
extern let mut __jule_ct: *thread
66

77
const (
88
// Thread roles.
@@ -41,13 +41,13 @@ struct thread {
4141
// Returns the current thread.
4242
// Uses the thread-local data.
4343
fn gett(): &thread {
44-
ret extern.__jule_ct
44+
ret unsafe { (&thread)(extern.__jule_ct) }
4545
}
4646

4747
// Sets the current thread as t.
4848
// Writes to the thread-local data.
4949
fn sett(mut t: &thread) {
50-
extern.__jule_ct = t
50+
extern.__jule_ct = (*thread)(t)
5151
}
5252

5353
// Pointer to the main M, the main program thread.

0 commit comments

Comments
 (0)