Skip to content

Commit fef517e

Browse files
committed
Remove almost all remaining feature gates
Only rustc_private is still enabled as cg_clif by definition needs to use internal rustc api's.
1 parent cfc1a2c commit fef517e

File tree

5 files changed

+21
-11
lines changed

5 files changed

+21
-11
lines changed

Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ object = { version = "0.27.0", default-features = false, features = ["std", "rea
2121
ar = { git = "https://github.com/bjorn3/rust-ar.git", branch = "do_not_remove_cg_clif_ranlib" }
2222
indexmap = "1.8.0"
2323
libloading = { version = "0.6.0", optional = true }
24+
once_cell = { version = "1.10.0", optional = true }
2425
smallvec = "1.6.1"
2526

2627
[patch.crates-io]
@@ -37,7 +38,7 @@ smallvec = "1.6.1"
3738
[features]
3839
# Enable features not ready to be enabled when compiling as part of rustc
3940
unstable-features = ["jit", "inline_asm"]
40-
jit = ["cranelift-jit", "libloading"]
41+
jit = ["cranelift-jit", "libloading", "once_cell"]
4142
inline_asm = []
4243

4344
# Disable optimizations and debuginfo of build scripts and some of the heavy build deps, as the

src/debuginfo/unwind.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ impl UnwindContext {
8181

8282
#[cfg(all(feature = "jit", not(windows)))]
8383
pub(crate) unsafe fn register_jit(self, jit_module: &cranelift_jit::JITModule) {
84+
use std::mem::ManuallyDrop;
85+
8486
let mut eh_frame = EhFrame::from(super::emit::WriterRelocate::new(self.endian));
8587
self.frame_table.write_eh_frame(&mut eh_frame).unwrap();
8688

@@ -95,17 +97,16 @@ impl UnwindContext {
9597

9698
// FIXME support unregistering unwind tables once cranelift-jit supports deallocating
9799
// individual functions
98-
#[allow(unused_variables)]
99-
let (eh_frame, eh_frame_len, _) = Vec::into_raw_parts(eh_frame);
100+
let eh_frame = ManuallyDrop::new(eh_frame);
100101

101102
// =======================================================================
102103
// Everything after this line up to the end of the file is loosely based on
103104
// https://github.com/bytecodealliance/wasmtime/blob/4471a82b0c540ff48960eca6757ccce5b1b5c3e4/crates/jit/src/unwind/systemv.rs
104105
#[cfg(target_os = "macos")]
105106
{
106107
// On macOS, `__register_frame` takes a pointer to a single FDE
107-
let start = eh_frame;
108-
let end = start.add(eh_frame_len);
108+
let start = eh_frame.as_ptr();
109+
let end = start.add(eh_frame.len());
109110
let mut current = start;
110111

111112
// Walk all of the entries in the frame table and register them
@@ -124,7 +125,7 @@ impl UnwindContext {
124125
#[cfg(not(target_os = "macos"))]
125126
{
126127
// On other platforms, `__register_frame` will walk the FDEs until an entry of length 0
127-
__register_frame(eh_frame);
128+
__register_frame(eh_frame.as_ptr());
128129
}
129130
}
130131
}

src/driver/jit.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
44
use std::cell::RefCell;
55
use std::ffi::CString;
6-
use std::lazy::SyncOnceCell;
76
use std::os::raw::{c_char, c_int};
87
use std::sync::{mpsc, Mutex};
98

@@ -14,6 +13,9 @@ use rustc_span::Symbol;
1413

1514
use cranelift_jit::{JITBuilder, JITModule};
1615

16+
// FIXME use std::lazy::SyncOnceCell once it stabilizes
17+
use once_cell::sync::OnceCell;
18+
1719
use crate::{prelude::*, BackendConfig};
1820
use crate::{CodegenCx, CodegenMode};
1921

@@ -27,8 +29,7 @@ thread_local! {
2729
}
2830

2931
/// The Sender owned by the rustc thread
30-
static GLOBAL_MESSAGE_SENDER: SyncOnceCell<Mutex<mpsc::Sender<UnsafeMessage>>> =
31-
SyncOnceCell::new();
32+
static GLOBAL_MESSAGE_SENDER: OnceCell<Mutex<mpsc::Sender<UnsafeMessage>>> = OnceCell::new();
3233

3334
/// A message that is sent from the jitted runtime to the rustc thread.
3435
/// Senders are responsible for upholding `Send` semantics.

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![feature(rustc_private)]
2-
#![cfg_attr(feature = "jit", feature(never_type, vec_into_raw_parts, once_cell))]
2+
// Note: please avoid adding other feature gates where possible
33
#![warn(rust_2018_idioms)]
44
#![warn(unused_lifetimes)]
55
#![warn(unreachable_pub)]
@@ -196,7 +196,7 @@ impl CodegenBackend for CraneliftCodegenBackend {
196196
CodegenMode::Aot => driver::aot::run_aot(tcx, config, metadata, need_metadata_module),
197197
CodegenMode::Jit | CodegenMode::JitLazy => {
198198
#[cfg(feature = "jit")]
199-
let _: ! = driver::jit::run_jit(tcx, config);
199+
driver::jit::run_jit(tcx, config);
200200

201201
#[cfg(not(feature = "jit"))]
202202
tcx.sess.fatal("jit support was disabled when compiling rustc_codegen_cranelift");

0 commit comments

Comments
 (0)