Skip to content

Commit 9036758

Browse files
committed
Next step in the type system change. Add task_type to the context.
1 parent 2a3ab10 commit 9036758

File tree

2 files changed

+43
-37
lines changed

2 files changed

+43
-37
lines changed

src/comp/back/upcall.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import trans::T_opaque_vec_ptr;
1616
import trans::T_ptr;
1717
import trans::T_size_t;
1818
import trans::T_str;
19-
import trans::T_taskptr;
2019
import trans::T_void;
2120
import lib::llvm::type_names;
2221
import lib::llvm::llvm::ModuleRef;
@@ -61,17 +60,19 @@ type upcalls =
6160
ValueRef ivec_resize_shared,
6261
ValueRef ivec_spill_shared);
6362

64-
fn declare_upcalls(type_names tn, TypeRef tydesc_type, ModuleRef llmod)
63+
fn declare_upcalls(type_names tn, TypeRef tydesc_type, TypeRef taskptr_type,
64+
ModuleRef llmod)
6565
-> @upcalls {
66-
fn decl(type_names tn, TypeRef tydesc_type, ModuleRef llmod, str name,
67-
vec[TypeRef] tys, TypeRef rv) -> ValueRef {
68-
let TypeRef[] arg_tys = ~[T_taskptr(tn)];
66+
fn decl(type_names tn, TypeRef tydesc_type, TypeRef taskptr_type,
67+
ModuleRef llmod, str name, vec[TypeRef] tys,
68+
TypeRef rv) -> ValueRef {
69+
let TypeRef[] arg_tys = ~[taskptr_type];
6970
for (TypeRef t in tys) { arg_tys += ~[t]; }
7071
auto fn_ty = T_fn(arg_tys, rv);
7172
ret trans::decl_cdecl_fn(llmod, "upcall_" + name, fn_ty);
7273
}
73-
auto dv = bind decl(tn, tydesc_type, llmod, _, _, T_void());
74-
auto d = bind decl(tn, tydesc_type, llmod, _, _, _);
74+
auto dv = bind decl(tn, tydesc_type, taskptr_type, llmod, _, _, T_void());
75+
auto d = bind decl(tn, tydesc_type, taskptr_type, llmod, _, _, _);
7576
// FIXME: Sigh:.. remove this when I fix the typechecker pushdown.
7677
// --pcwalton
7778

@@ -89,14 +90,14 @@ fn declare_upcalls(type_names tn, TypeRef tydesc_type, ModuleRef llmod)
8990
T_opaque_chan_ptr()),
9091
flush_chan=dv("flush_chan", [T_opaque_chan_ptr()]),
9192
del_chan=dv("del_chan", [T_opaque_chan_ptr()]),
92-
clone_chan=d("clone_chan", [T_taskptr(tn), T_opaque_chan_ptr()],
93+
clone_chan=d("clone_chan", [taskptr_type, T_opaque_chan_ptr()],
9394
T_opaque_chan_ptr()),
9495
_yield=dv("yield", empty_vec),
9596
sleep=dv("sleep", [T_size_t()]),
9697
send=dv("send", [T_opaque_chan_ptr(), T_ptr(T_i8())]),
9798
recv=dv("recv", [T_ptr(T_ptr(T_i8())), T_opaque_port_ptr()]),
9899
_fail=dv("fail", [T_ptr(T_i8()), T_ptr(T_i8()), T_size_t()]),
99-
kill=dv("kill", [T_taskptr(tn)]),
100+
kill=dv("kill", [taskptr_type]),
100101
exit=dv("exit", empty_vec),
101102
malloc=d("malloc", [T_size_t(), T_ptr(tydesc_type)],
102103
T_ptr(T_i8())),
@@ -107,7 +108,7 @@ fn declare_upcalls(type_names tn, TypeRef tydesc_type, ModuleRef llmod)
107108
mark=d("mark", [T_ptr(T_i8())], T_int()),
108109
new_str=d("new_str", [T_ptr(T_i8()), T_size_t()],
109110
T_ptr(T_str())),
110-
dup_str=d("dup_str", [T_taskptr(tn), T_ptr(T_str())],
111+
dup_str=d("dup_str", [taskptr_type, T_ptr(T_str())],
111112
T_ptr(T_str())),
112113
new_vec=d("new_vec", [T_size_t(), T_ptr(tydesc_type)],
113114
T_opaque_vec_ptr()),
@@ -119,10 +120,10 @@ fn declare_upcalls(type_names tn, TypeRef tydesc_type, ModuleRef llmod)
119120
[T_ptr(T_nil()), T_size_t(), T_size_t(),
120121
T_size_t(), T_ptr(T_ptr(tydesc_type))],
121122
T_ptr(tydesc_type)),
122-
new_task=d("new_task", [T_ptr(T_str())], T_taskptr(tn)),
123+
new_task=d("new_task", [T_ptr(T_str())], taskptr_type),
123124
start_task=d("start_task",
124-
[T_taskptr(tn), T_int(), T_int(), T_size_t()],
125-
T_taskptr(tn)),
125+
[taskptr_type, T_int(), T_int(), T_size_t()],
126+
taskptr_type),
126127
ivec_resize=d("ivec_resize", [T_ptr(T_opaque_ivec()), T_int()],
127128
T_void()),
128129
ivec_spill=d("ivec_spill", [T_ptr(T_opaque_ivec()), T_int()],

src/comp/middle/trans.rs

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ type crate_ctxt =
147147
ty::ctxt tcx,
148148
stats stats,
149149
@upcall::upcalls upcalls,
150-
TypeRef tydesc_type);
150+
TypeRef tydesc_type,
151+
TypeRef task_type);
151152

152153
type local_ctxt =
153154
rec(str[] path,
@@ -477,9 +478,8 @@ fn T_struct(&TypeRef[] elts) -> TypeRef {
477478

478479
fn T_opaque() -> TypeRef { ret llvm::LLVMOpaqueType(); }
479480

480-
fn T_task(&type_names tn) -> TypeRef {
481+
fn T_task2() -> TypeRef {
481482
auto s = "task";
482-
if (tn.name_has_type(s)) { ret tn.get_type(s); }
483483
auto t =
484484
T_struct(~[T_int(), // Refcount
485485
T_int(), // Delegate pointer
@@ -491,7 +491,6 @@ fn T_task(&type_names tn) -> TypeRef {
491491
T_int(), // Domain pointer
492492
// Crate cache pointer
493493
T_int()]);
494-
tn.associate(s, t);
495494
ret t;
496495
}
497496

@@ -527,16 +526,16 @@ fn T_cmp_glue_fn(&crate_ctxt cx) -> TypeRef {
527526
ret t;
528527
}
529528

530-
fn T_tydesc(&type_names tn) -> TypeRef {
529+
fn T_tydesc(TypeRef taskptr_type) -> TypeRef {
531530
auto th = mk_type_handle();
532531
auto abs_tydesc = llvm::LLVMResolveTypeHandle(th.llth);
533532
auto tydescpp = T_ptr(T_ptr(abs_tydesc));
534533
auto pvoid = T_ptr(T_i8());
535534
auto glue_fn_ty =
536-
T_ptr(T_fn(~[T_ptr(T_nil()), T_taskptr(tn), T_ptr(T_nil()), tydescpp,
535+
T_ptr(T_fn(~[T_ptr(T_nil()), taskptr_type, T_ptr(T_nil()), tydescpp,
537536
pvoid], T_void()));
538537
auto cmp_glue_fn_ty =
539-
T_ptr(T_fn(~[T_ptr(T_i1()), T_taskptr(tn), T_ptr(T_nil()), tydescpp,
538+
T_ptr(T_fn(~[T_ptr(T_i1()), taskptr_type, T_ptr(T_nil()), tydescpp,
540539
pvoid, pvoid, T_i8()], T_void()));
541540
auto tydesc =
542541
T_struct(~[tydescpp, // first_param
@@ -633,7 +632,7 @@ fn T_chan(TypeRef t) -> TypeRef {
633632

634633
}
635634

636-
fn T_taskptr(&type_names tn) -> TypeRef { ret T_ptr(T_task(tn)); }
635+
fn T_taskptr(&crate_ctxt cx) -> TypeRef { ret T_ptr(cx.task_type); }
637636

638637

639638
// This type must never be used directly; it must always be cast away.
@@ -766,7 +765,7 @@ fn type_of_fn_full(&@crate_ctxt cx, &span sp, ast::proto proto,
766765
}
767766

768767
// Arg 1: task pointer.
769-
atys += ~[T_taskptr(cx.tn)];
768+
atys += ~[T_taskptr(*cx)];
770769

771770
// Arg 2: Env (closure-bindings / self-obj)
772771
alt (obj_self) {
@@ -811,7 +810,7 @@ fn type_of_native_fn(&@crate_ctxt cx, &span sp, ast::native_abi abi,
811810
-> TypeRef {
812811
let TypeRef[] atys = ~[];
813812
if (abi == ast::native_abi_rust) {
814-
atys += ~[T_taskptr(cx.tn)];
813+
atys += ~[T_taskptr(*cx)];
815814
auto i = 0u;
816815
while (i < ty_param_count) {
817816
atys += ~[T_ptr(cx.tydesc_type)];
@@ -874,7 +873,7 @@ fn type_of_inner(&@crate_ctxt cx, &span sp, &ty::t t) -> TypeRef {
874873
case (ty::ty_chan(?t)) {
875874
llty = T_ptr(T_chan(type_of_inner(cx, sp, t)));
876875
}
877-
case (ty::ty_task) { llty = T_taskptr(cx.tn); }
876+
case (ty::ty_task) { llty = T_taskptr(*cx); }
878877
case (ty::ty_tup(?elts)) {
879878
let TypeRef[] tys = ~[];
880879
for (ty::mt elt in elts) {
@@ -1136,8 +1135,8 @@ fn decl_internal_fastcall_fn(ModuleRef llmod, &str name, TypeRef llty) ->
11361135
ret llfn;
11371136
}
11381137

1139-
fn decl_glue(ModuleRef llmod, type_names tn, &str s) -> ValueRef {
1140-
ret decl_cdecl_fn(llmod, s, T_fn(~[T_taskptr(tn)], T_void()));
1138+
fn decl_glue(ModuleRef llmod, &crate_ctxt cx, &str s) -> ValueRef {
1139+
ret decl_cdecl_fn(llmod, s, T_fn(~[T_taskptr(cx)], T_void()));
11411140
}
11421141

11431142
fn get_extern_fn(&hashmap[str, ValueRef] externs, ModuleRef llmod, &str name,
@@ -8999,7 +8998,7 @@ fn i2p(ValueRef v, TypeRef t) -> ValueRef {
89998998
}
90008999

90019000
fn create_typedefs(&@crate_ctxt cx) {
9002-
llvm::LLVMAddTypeName(cx.llmod, str::buf("task"), T_task(cx.tn));
9001+
llvm::LLVMAddTypeName(cx.llmod, str::buf("task"), cx.task_type);
90039002
llvm::LLVMAddTypeName(cx.llmod, str::buf("tydesc"), cx.tydesc_type);
90049003
}
90059004

@@ -9057,8 +9056,8 @@ fn trap(&@block_ctxt bcx) {
90579056
}
90589057
}
90599058

9060-
fn decl_no_op_type_glue(ModuleRef llmod, type_names tn) -> ValueRef {
9061-
auto ty = T_fn(~[T_taskptr(tn), T_ptr(T_i8())], T_void());
9059+
fn decl_no_op_type_glue(ModuleRef llmod, TypeRef taskptr_type) -> ValueRef {
9060+
auto ty = T_fn(~[taskptr_type, T_ptr(T_i8())], T_void());
90629061
ret decl_fastcall_fn(llmod, abi::no_op_type_glue_name(), ty);
90639062
}
90649063

@@ -9078,24 +9077,26 @@ fn vec_p0(&@block_ctxt bcx, ValueRef v) -> ValueRef {
90789077
ret bcx.build.PointerCast(p, T_ptr(T_i8()));
90799078
}
90809079

9081-
fn make_glues(ModuleRef llmod, &type_names tn) -> @glue_fns {
9082-
ret @rec(no_op_type_glue=decl_no_op_type_glue(llmod, tn));
9080+
fn make_glues(ModuleRef llmod, TypeRef taskptr_type) -> @glue_fns {
9081+
ret @rec(no_op_type_glue=decl_no_op_type_glue(llmod, taskptr_type));
90839082
}
90849083

90859084
fn make_common_glue(&session::session sess, &str output) {
90869085
// FIXME: part of this is repetitive and is probably a good idea
90879086
// to autogen it.
90889087

9088+
auto task_type = T_task2();
9089+
auto taskptr_type = T_ptr(task_type);
9090+
90899091
auto llmod =
90909092
llvm::LLVMModuleCreateWithNameInContext(str::buf("rust_out"),
90919093
llvm::LLVMGetGlobalContext());
90929094
llvm::LLVMSetDataLayout(llmod, str::buf(x86::get_data_layout()));
90939095
llvm::LLVMSetTarget(llmod, str::buf(x86::get_target_triple()));
90949096
mk_target_data(x86::get_data_layout());
9095-
auto tn = mk_type_names();
90969097
declare_intrinsics(llmod);
90979098
llvm::LLVMSetModuleInlineAsm(llmod, str::buf(x86::get_module_asm()));
9098-
make_glues(llmod, tn);
9099+
make_glues(llmod, taskptr_type);
90999100
link::write::run_passes(sess, llmod, output);
91009101
}
91019102

@@ -9170,7 +9171,10 @@ fn trans_crate(&session::session sess, &@ast::crate crate, &ty::ctxt tcx,
91709171
auto td = mk_target_data(x86::get_data_layout());
91719172
auto tn = mk_type_names();
91729173
auto intrinsics = declare_intrinsics(llmod);
9173-
auto glues = make_glues(llmod, tn);
9174+
auto task_type = T_task2();
9175+
auto taskptr_type = T_ptr(task_type);
9176+
auto tydesc_type = T_tydesc(taskptr_type);
9177+
auto glues = make_glues(llmod, taskptr_type);
91749178
auto hasher = ty::hash_ty;
91759179
auto eqer = ty::eq_ty;
91769180
auto tag_sizes = map::mk_hashmap[ty::t, uint](hasher, eqer);
@@ -9179,7 +9183,6 @@ fn trans_crate(&session::session sess, &@ast::crate crate, &ty::ctxt tcx,
91799183
auto sha1s = map::mk_hashmap[ty::t, str](hasher, eqer);
91809184
auto short_names = map::mk_hashmap[ty::t, str](hasher, eqer);
91819185
auto sha = std::sha1::mk_sha1();
9182-
auto tydesc_type = T_tydesc(tn);
91839186
auto ccx =
91849187
@rec(sess=sess,
91859188
llmod=llmod,
@@ -9212,8 +9215,10 @@ fn trans_crate(&session::session sess, &@ast::crate crate, &ty::ctxt tcx,
92129215
mutable n_glues_created=0u,
92139216
mutable n_null_glues=0u,
92149217
mutable n_real_glues=0u),
9215-
upcalls=upcall::declare_upcalls(tn, tydesc_type, llmod),
9216-
tydesc_type=tydesc_type);
9218+
upcalls=upcall::declare_upcalls(tn, tydesc_type, taskptr_type,
9219+
llmod),
9220+
tydesc_type=tydesc_type,
9221+
task_type=task_type);
92179222
auto cx = new_local_ctxt(ccx);
92189223
create_typedefs(ccx);
92199224
collect_items(ccx, crate);

0 commit comments

Comments
 (0)