Skip to content

Commit 2c24f70

Browse files
jyasskingraydon
authored andcommitted
Fix simple generic type parameters in LLVM.
1 parent 09885b5 commit 2c24f70

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

src/Makefile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,8 +427,6 @@ TEST_XFAILS_LLVM := $(addprefix test/run-pass/, \
427427
generic-recursive-tag.rs \
428428
generic-tag-alt.rs \
429429
generic-tag.rs \
430-
generic-type-synonym.rs \
431-
generic-type.rs \
432430
import.rs \
433431
inner-module.rs \
434432
large-records.rs \

src/boot/llvm/llabi.ml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ type abi = {
66
crate_ty: Llvm.lltype;
77
task_ty: Llvm.lltype;
88
word_ty: Llvm.lltype;
9+
tydesc_ty: Llvm.lltype;
910
rust_start: Llvm.llvalue;
1011
};;
1112

1213
let declare_abi (llctx:Llvm.llcontext) (llmod:Llvm.llmodule) : abi =
1314
let i32 = Llvm.i32_type llctx in
1415
(* FIXME: Use Llvm_target.intptr_type for more platform support. *)
1516
let word_ty = i32 in
17+
let p ty = Llvm.pointer_type ty in
1618

1719
let crate_ty =
1820
(* TODO: other architectures besides x86 *)
@@ -53,6 +55,27 @@ let declare_abi (llctx:Llvm.llcontext) (llmod:Llvm.llmodule) : abi =
5355
in
5456
ignore (Llvm.define_type_name "rust_task" task_ty llmod);
5557

58+
(* This is the type_desc struct in rust_internal.h *)
59+
let tydesc_ty =
60+
(* TODO: other architectures besides x86 *)
61+
let tydesc_opaque_ty = Llvm.opaque_type llctx in
62+
let tydesc_tyhandle = Llvm.handle_to_type (Llvm.struct_type llctx [|
63+
p (p tydesc_opaque_ty); (* const type_desc **first_param *)
64+
word_ty; (* size_t size *)
65+
word_ty; (* size_t align *)
66+
word_ty; (* uintptr_t copy_glue_off *)
67+
word_ty; (* uintptr_t drop_glue_off *)
68+
word_ty; (* uintptr_t free_glue_off *)
69+
word_ty; (* uintptr_t sever_glue_off *)
70+
word_ty; (* uintptr_t mark_glue_off *)
71+
word_ty; (* uintptr_t obj_drop_glue_off *)
72+
|])
73+
in
74+
Llvm.refine_type tydesc_opaque_ty (Llvm.type_of_handle tydesc_tyhandle);
75+
Llvm.type_of_handle tydesc_tyhandle
76+
in
77+
ignore (Llvm.define_type_name "type_desc" tydesc_ty llmod);
78+
5679
let rust_start_ty =
5780
(* Rust's main function can have several types, so we cast them
5881
all to uintptr_t. *)
@@ -64,6 +87,7 @@ let declare_abi (llctx:Llvm.llcontext) (llmod:Llvm.llmodule) : abi =
6487
crate_ty = crate_ty;
6588
task_ty = task_ty;
6689
word_ty = word_ty;
90+
tydesc_ty = tydesc_ty;
6791
rust_start = Llvm.declare_function "rust_start" rust_start_ty llmod
6892
}
6993
;;

src/boot/llvm/lltrans.ml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,12 +346,13 @@ let trans_crate
346346
| Ast.TY_native _ ->
347347
word_ty
348348

349+
| Ast.TY_param _ ->
350+
abi.Llabi.tydesc_ty
351+
349352
| Ast.TY_tag _ | Ast.TY_iso _ | Ast.TY_idx _
350-
| Ast.TY_obj _ | Ast.TY_type ->
353+
| Ast.TY_obj _ | Ast.TY_type | Ast.TY_named _ ->
351354
Common.unimpl None "LLVM type translation for: %a" Ast.sprintf_ty ty
352355

353-
| Ast.TY_param _ | Ast.TY_named _ ->
354-
bug () "unresolved type in lltrans"
355356

356357
and trans_ty t =
357358
htab_search_or_add lltys t (fun _ -> trans_ty_full t)

0 commit comments

Comments
 (0)