Skip to content

Commit 31ae4a1

Browse files
committed
rustc: remove old bitrotted gc system.
1 parent 6fa98e3 commit 31ae4a1

File tree

12 files changed

+23
-581
lines changed

12 files changed

+23
-581
lines changed

src/librustc/driver/driver.rs

-6
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,6 @@ pub fn build_configuration(sess: Session, argv0: @~str, input: &input) ->
124124
// If the user wants a test runner, then add the test cfg
125125
let user_cfg = if sess.opts.test { append_configuration(user_cfg, ~"test") }
126126
else { user_cfg };
127-
// If the user requested GC, then add the GC cfg
128-
let user_cfg = append_configuration(
129-
user_cfg,
130-
if sess.opts.gc { ~"gc" } else { ~"nogc" });
131127
return vec::append(user_cfg, default_cfg);
132128
}
133129

@@ -651,7 +647,6 @@ pub fn build_session_options(binary: @~str,
651647
}
652648
} else { No }
653649
};
654-
let gc = debugging_opts & session::gc != 0;
655650
let jit = debugging_opts & session::jit != 0;
656651
let extra_debuginfo = debugging_opts & session::extra_debug_info != 0;
657652
let debuginfo = debugging_opts & session::debug_info != 0 ||
@@ -697,7 +692,6 @@ pub fn build_session_options(binary: @~str,
697692
let sopts = @session::options {
698693
crate_type: crate_type,
699694
is_static: statik,
700-
gc: gc,
701695
optimize: opt_level,
702696
custom_passes: custom_passes,
703697
debuginfo: debuginfo,

src/librustc/driver/session.rs

-4
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ pub static count_type_sizes: uint = 1 << 14;
6262
pub static meta_stats: uint = 1 << 15;
6363
pub static no_opt: uint = 1 << 16;
6464
pub static no_monomorphic_collapse: uint = 1 << 17;
65-
pub static gc: uint = 1 << 18;
6665
pub static jit: uint = 1 << 19;
6766
pub static debug_info: uint = 1 << 20;
6867
pub static extra_debug_info: uint = 1 << 21;
@@ -98,7 +97,6 @@ pub fn debugging_opts_map() -> ~[(~str, ~str, uint)] {
9897
(~"no-monomorphic-collapse", ~"do not collapse template instantiations",
9998
no_monomorphic_collapse),
10099
(~"print-link-args", ~"Print the arguments passed to the linker", print_link_args),
101-
(~"gc", ~"Garbage collect shared data (experimental)", gc),
102100
(~"jit", ~"Execute using JIT (experimental)", jit),
103101
(~"extra-debug-info", ~"Extra debugging info (experimental)",
104102
extra_debug_info),
@@ -127,7 +125,6 @@ pub struct options {
127125
// with additional crate configurations during the compile process
128126
crate_type: crate_type,
129127
is_static: bool,
130-
gc: bool,
131128
optimize: OptLevel,
132129
custom_passes: ~[~str],
133130
debuginfo: bool,
@@ -303,7 +300,6 @@ pub fn basic_options() -> @options {
303300
@options {
304301
crate_type: session::lib_crate,
305302
is_static: false,
306-
gc: false,
307303
optimize: No,
308304
custom_passes: ~[],
309305
debuginfo: false,

src/librustc/middle/trans/_match.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1387,19 +1387,17 @@ pub fn compile_submatch(bcx: block,
13871387
if any_box_pat(m, col) {
13881388
bcx = root_pats_as_necessary(bcx, m, col, val);
13891389
let llbox = Load(bcx, val);
1390-
let box_no_addrspace = non_gc_box_cast(bcx, llbox);
13911390
let unboxed =
1392-
GEPi(bcx, box_no_addrspace, [0u, abi::box_field_body]);
1391+
GEPi(bcx, llbox, [0u, abi::box_field_body]);
13931392
compile_submatch(bcx, enter_box(bcx, dm, m, col, val),
13941393
vec::append(~[unboxed], vals_left), chk);
13951394
return;
13961395
}
13971396

13981397
if any_uniq_pat(m, col) {
13991398
let llbox = Load(bcx, val);
1400-
let box_no_addrspace = non_gc_box_cast(bcx, llbox);
14011399
let unboxed =
1402-
GEPi(bcx, box_no_addrspace, [0u, abi::box_field_body]);
1400+
GEPi(bcx, llbox, [0u, abi::box_field_body]);
14031401
compile_submatch(bcx, enter_uniq(bcx, dm, m, col, val),
14041402
vec::append(~[unboxed], vals_left), chk);
14051403
return;

src/librustc/middle/trans/base.rs

+2-62
Original file line numberDiff line numberDiff line change
@@ -310,25 +310,6 @@ pub fn malloc_raw_dyn(bcx: block,
310310
r
311311
}
312312

313-
/**
314-
* Get the type of a box in the default address space.
315-
*
316-
* Shared box pointers live in address space 1 so the GC strategy can find
317-
* them. Before taking a pointer to the inside of a box it should be cast into
318-
* address space 0. Otherwise the resulting (non-box) pointer will be in the
319-
* wrong address space and thus be the wrong type.
320-
*/
321-
pub fn non_gc_box_cast(bcx: block, val: ValueRef) -> ValueRef {
322-
unsafe {
323-
debug!("non_gc_box_cast");
324-
add_comment(bcx, "non_gc_box_cast");
325-
assert!(llvm::LLVMGetPointerAddressSpace(val_ty(val)) ==
326-
gc_box_addrspace || bcx.unreachable);
327-
let non_gc_t = T_ptr(llvm::LLVMGetElementType(val_ty(val)));
328-
PointerCast(bcx, val, non_gc_t)
329-
}
330-
}
331-
332313
// malloc_raw: expects an unboxed type and returns a pointer to
333314
// enough space for a box of that type. This includes a rust_opaque_box
334315
// header.
@@ -348,8 +329,7 @@ pub fn malloc_general_dyn(bcx: block, t: ty::t, heap: heap, size: ValueRef)
348329
-> MallocResult {
349330
let _icx = bcx.insn_ctxt("malloc_general");
350331
let Result {bcx: bcx, val: llbox} = malloc_raw_dyn(bcx, t, heap, size);
351-
let non_gc_box = non_gc_box_cast(bcx, llbox);
352-
let body = GEPi(bcx, non_gc_box, [0u, abi::box_field_body]);
332+
let body = GEPi(bcx, llbox, [0u, abi::box_field_body]);
353333

354334
MallocResult { bcx: bcx, box: llbox, body: body }
355335
}
@@ -1853,16 +1833,6 @@ pub fn trans_closure(ccx: @CrateContext,
18531833
set_fixed_stack_segment(fcx.llfn);
18541834
}
18551835

1856-
// Set GC for function.
1857-
if ccx.sess.opts.gc {
1858-
do str::as_c_str("generic") |strategy| {
1859-
unsafe {
1860-
llvm::LLVMSetGC(fcx.llfn, strategy);
1861-
}
1862-
}
1863-
*ccx.uses_gc = true;
1864-
}
1865-
18661836
// Create the first basic block in the function and keep a handle on it to
18671837
// pass to finish_fn later.
18681838
let bcx_top = top_scope_block(fcx, body.info());
@@ -2654,14 +2624,7 @@ pub fn declare_intrinsics(llmod: ModuleRef) -> HashMap<~str, ValueRef> {
26542624
~[T_ptr(T_i8()), T_i8(), T_i64(), T_i32(), T_i1()];
26552625
let T_trap_args: ~[TypeRef] = ~[];
26562626
let T_frameaddress_args: ~[TypeRef] = ~[T_i32()];
2657-
let gcroot =
2658-
decl_cdecl_fn(llmod, "llvm.gcroot",
2659-
T_fn([T_ptr(T_ptr(T_i8())), T_ptr(T_i8())],
2660-
T_void()));
2661-
let gcread =
2662-
decl_cdecl_fn(llmod, "llvm.gcread",
2663-
T_fn([T_ptr(T_i8()), T_ptr(T_ptr(T_i8()))],
2664-
T_void()));
2627+
26652628
let memcpy32 =
26662629
decl_cdecl_fn(llmod, "llvm.memcpy.p0i8.p0i8.i32",
26672630
T_fn(copy T_memcpy32_args, T_void()));
@@ -2777,8 +2740,6 @@ pub fn declare_intrinsics(llmod: ModuleRef) -> HashMap<~str, ValueRef> {
27772740
T_fn([T_i64()], T_i64()));
27782741
27792742
let mut intrinsics = HashMap::new();
2780-
intrinsics.insert(~"llvm.gcroot", gcroot);
2781-
intrinsics.insert(~"llvm.gcread", gcread);
27822743
intrinsics.insert(~"llvm.memcpy.p0i8.p0i8.i32", memcpy32);
27832744
intrinsics.insert(~"llvm.memcpy.p0i8.p0i8.i64", memcpy64);
27842745
intrinsics.insert(~"llvm.memmove.p0i8.p0i8.i32", memmove32);
@@ -2856,24 +2817,6 @@ pub fn trap(bcx: block) {
28562817
}
28572818
}
28582819
2859-
pub fn decl_gc_metadata(ccx: @CrateContext, llmod_id: &str) {
2860-
if !ccx.sess.opts.gc || !*ccx.uses_gc {
2861-
return;
2862-
}
2863-
2864-
let gc_metadata_name = ~"_gc_module_metadata_" + llmod_id;
2865-
let gc_metadata = do str::as_c_str(gc_metadata_name) |buf| {
2866-
unsafe {
2867-
llvm::LLVMAddGlobal(ccx.llmod, T_i32(), buf)
2868-
}
2869-
};
2870-
unsafe {
2871-
llvm::LLVMSetGlobalConstant(gc_metadata, True);
2872-
lib::llvm::SetLinkage(gc_metadata, lib::llvm::ExternalLinkage);
2873-
ccx.module_data.insert(~"_gc_module_metadata", gc_metadata);
2874-
}
2875-
}
2876-
28772820
pub fn create_module_map(ccx: @CrateContext) -> ValueRef {
28782821
let elttype = T_struct([ccx.int_type, ccx.int_type], false);
28792822
let maptype = T_array(elttype, ccx.module_data.len() + 1);
@@ -3103,7 +3046,6 @@ pub fn trans_crate(sess: session::Session,
31033046
llsizingtypes: @mut HashMap::new(),
31043047
adt_reprs: @mut HashMap::new(),
31053048
names: new_namegen(sess.parse_sess.interner),
3106-
next_addrspace: new_addrspace_gen(),
31073049
symbol_hasher: symbol_hasher,
31083050
type_hashcodes: @mut HashMap::new(),
31093051
type_short_names: @mut HashMap::new(),
@@ -3131,7 +3073,6 @@ pub fn trans_crate(sess: session::Session,
31313073
builder: BuilderRef_res(unsafe { llvm::LLVMCreateBuilder() }),
31323074
shape_cx: mk_ctxt(llmod),
31333075
crate_map: crate_map,
3134-
uses_gc: @mut false,
31353076
dbg_cx: dbg_cx,
31363077
do_not_commit_warning_issued: @mut false
31373078
};
@@ -3146,7 +3087,6 @@ pub fn trans_crate(sess: session::Session,
31463087
trans_mod(ccx, &crate.node.module);
31473088
}
31483089
3149-
decl_gc_metadata(ccx, llmod_id);
31503090
fill_crate_map(ccx, crate_map);
31513091
glue::emit_tydescs(ccx);
31523092
write_abi_version(ccx);

src/librustc/middle/trans/common.rs

+8-53
Original file line numberDiff line numberDiff line change
@@ -66,29 +66,18 @@ pub fn new_namegen(intr: @ident_interner) -> namegen {
6666
f
6767
}
6868

69-
pub type addrspace = c_uint;
7069

71-
// Address spaces communicate to LLVM which destructors need to run for
72-
// specific types.
73-
// 0 is ignored by the GC, and is used for all non-GC'd pointers.
74-
// 1 is for opaque GC'd boxes.
75-
// >= 2 are for specific types (e.g. resources).
70+
// Multiple address spaces were at one time used to encode
71+
// GC information. They may be again someday. In the meantime
72+
// we only support a single addrspace.
73+
pub type addrspace = c_uint;
7674
pub static default_addrspace: addrspace = 0;
77-
pub static gc_box_addrspace: addrspace = 1;
78-
79-
pub type addrspace_gen = @fn() -> addrspace;
80-
pub fn new_addrspace_gen() -> addrspace_gen {
81-
let i = @mut 1;
82-
let result: addrspace_gen = || { *i += 1; *i };
83-
result
84-
}
8575

8676
pub struct tydesc_info {
8777
ty: ty::t,
8878
tydesc: ValueRef,
8979
size: ValueRef,
9080
align: ValueRef,
91-
addrspace: addrspace,
9281
take_glue: Option<ValueRef>,
9382
drop_glue: Option<ValueRef>,
9483
free_glue: Option<ValueRef>,
@@ -208,7 +197,6 @@ pub struct CrateContext {
208197
llsizingtypes: @mut HashMap<ty::t, TypeRef>,
209198
adt_reprs: @mut HashMap<ty::t, @adt::Repr>,
210199
names: namegen,
211-
next_addrspace: addrspace_gen,
212200
symbol_hasher: @mut hash::State,
213201
type_hashcodes: @mut HashMap<ty::t, @str>,
214202
type_short_names: @mut HashMap<ty::t, ~str>,
@@ -224,10 +212,6 @@ pub struct CrateContext {
224212
builder: BuilderRef_res,
225213
shape_cx: shape::Ctxt,
226214
crate_map: ValueRef,
227-
// Set when at least one function uses GC. Needed so that
228-
// decl_gc_metadata knows whether to link to the module metadata, which
229-
// is not emitted by LLVM's GC pass when no functions use GC.
230-
uses_gc: @mut bool,
231215
dbg_cx: Option<debuginfo::DebugContext>,
232216
do_not_commit_warning_issued: @mut bool
233217
}
@@ -426,38 +410,16 @@ pub fn cleanup_type(cx: ty::ctxt, ty: ty::t) -> cleantype {
426410
}
427411
}
428412

429-
// This is not the same as datum::Datum::root(), which is used to keep copies
430-
// of @ values live for as long as a borrowed pointer to the interior exists.
431-
// In the new GC, we can identify immediates on the stack without difficulty,
432-
// but have trouble knowing where non-immediates are on the stack. For
433-
// non-immediates, we must add an additional level of indirection, which
434-
// allows us to alloca a pointer with the right addrspace.
435-
pub fn root_for_cleanup(bcx: block, v: ValueRef, t: ty::t)
436-
-> (ValueRef, bool) {
437-
let ccx = bcx.ccx();
438-
439-
let addrspace = base::get_tydesc(ccx, t).addrspace;
440-
if addrspace > gc_box_addrspace {
441-
let llty = type_of::type_of_rooted(ccx, t);
442-
let root = base::alloca(bcx, llty);
443-
build::Store(bcx, build::PointerCast(bcx, v, llty), root);
444-
(root, true)
445-
} else {
446-
(v, false)
447-
}
448-
}
449-
450413
pub fn add_clean(bcx: block, val: ValueRef, t: ty::t) {
451414
if !ty::type_needs_drop(bcx.tcx(), t) { return; }
452415
debug!("add_clean(%s, %s, %s)",
453416
bcx.to_str(),
454417
val_str(bcx.ccx().tn, val),
455418
t.repr(bcx.tcx()));
456-
let (root, rooted) = root_for_cleanup(bcx, val, t);
457419
let cleanup_type = cleanup_type(bcx.tcx(), t);
458420
do in_scope_cx(bcx) |scope_info| {
459421
scope_info.cleanups.push(
460-
clean(|a| glue::drop_ty_root(a, root, rooted, t),
422+
clean(|a| glue::drop_ty(a, val, t),
461423
cleanup_type));
462424
scope_clean_changed(scope_info);
463425
}
@@ -481,11 +443,10 @@ pub fn add_clean_temp_mem(bcx: block, val: ValueRef, t: ty::t) {
481443
debug!("add_clean_temp_mem(%s, %s, %s)",
482444
bcx.to_str(), val_str(bcx.ccx().tn, val),
483445
t.repr(bcx.tcx()));
484-
let (root, rooted) = root_for_cleanup(bcx, val, t);
485446
let cleanup_type = cleanup_type(bcx.tcx(), t);
486447
do in_scope_cx(bcx) |scope_info| {
487448
scope_info.cleanups.push(
488-
clean_temp(val, |a| glue::drop_ty_root(a, root, rooted, t),
449+
clean_temp(val, |a| glue::drop_ty(a, val, t),
489450
cleanup_type));
490451
scope_clean_changed(scope_info);
491452
}
@@ -895,12 +856,6 @@ pub fn T_ptr(t: TypeRef) -> TypeRef {
895856
}
896857
}
897858

898-
pub fn T_root(t: TypeRef, addrspace: addrspace) -> TypeRef {
899-
unsafe {
900-
return llvm::LLVMPointerType(t, addrspace);
901-
}
902-
}
903-
904859
pub fn T_struct(elts: &[TypeRef], packed: bool) -> TypeRef {
905860
unsafe {
906861
return llvm::LLVMStructType(to_ptr(elts),
@@ -1054,7 +1009,7 @@ pub fn T_box(cx: @CrateContext, t: TypeRef) -> TypeRef {
10541009

10551010
pub fn T_box_ptr(t: TypeRef) -> TypeRef {
10561011
unsafe {
1057-
return llvm::LLVMPointerType(t, gc_box_addrspace);
1012+
return llvm::LLVMPointerType(t, default_addrspace);
10581013
}
10591014
}
10601015

@@ -1072,7 +1027,7 @@ pub fn T_unique(cx: @CrateContext, t: TypeRef) -> TypeRef {
10721027

10731028
pub fn T_unique_ptr(t: TypeRef) -> TypeRef {
10741029
unsafe {
1075-
return llvm::LLVMPointerType(t, gc_box_addrspace);
1030+
return llvm::LLVMPointerType(t, default_addrspace);
10761031
}
10771032
}
10781033

0 commit comments

Comments
 (0)