1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
#![experimental]
#![allow(missing_doc)]#[cfg(test)]
pub use realcore::intrinsics::{TyDesc, Opaque, TyVisitor, TypeId};
pub type GlueFn = extern "Rust" fn(*i8);
#[lang="ty_desc"]
#[cfg(not(test))]
pub struct TyDesc {pub size: uint,pub align: uint,pub drop_glue: GlueFn,pub visit_glue: GlueFn,pub name: &'static str,
}
#[lang="opaque"]
#[cfg(not(test))]
pub enum Opaque { }
pub type Disr = u64;
#[lang="ty_visitor"]
#[cfg(not(test))]
pub trait TyVisitor {
fn visit_bot(&mut self) -> bool;
fn visit_nil(&mut self) -> bool;
fn visit_bool(&mut self) -> bool;
fn visit_int(&mut self) -> bool;
fn visit_i8(&mut self) -> bool;
fn visit_i16(&mut self) -> bool;
fn visit_i32(&mut self) -> bool;
fn visit_i64(&mut self) -> bool;
fn visit_uint(&mut self) -> bool;
fn visit_u8(&mut self) -> bool;
fn visit_u16(&mut self) -> bool;
fn visit_u32(&mut self) -> bool;
fn visit_u64(&mut self) -> bool;
fn visit_f32(&mut self) -> bool;
fn visit_f64(&mut self) -> bool;
fn visit_char(&mut self) -> bool;
fn visit_estr_slice(&mut self) -> bool;
fn visit_estr_fixed(&mut self, n: uint, sz: uint, align: uint) -> bool;
fn visit_box(&mut self, mtbl: uint, inner: *TyDesc) -> bool;
fn visit_uniq(&mut self, mtbl: uint, inner: *TyDesc) -> bool;
fn visit_ptr(&mut self, mtbl: uint, inner: *TyDesc) -> bool;
fn visit_rptr(&mut self, mtbl: uint, inner: *TyDesc) -> bool;
fn visit_evec_slice(&mut self, mtbl: uint, inner: *TyDesc) -> bool;
fn visit_evec_fixed(&mut self, n: uint, sz: uint, align: uint,
mtbl: uint, inner: *TyDesc) -> bool;
fn visit_enter_rec(&mut self, n_fields: uint,
sz: uint, align: uint) -> bool;
fn visit_rec_field(&mut self, i: uint, name: &str,
mtbl: uint, inner: *TyDesc) -> bool;
fn visit_leave_rec(&mut self, n_fields: uint,
sz: uint, align: uint) -> bool;
fn visit_enter_class(&mut self, name: &str, named_fields: bool, n_fields: uint,
sz: uint, align: uint) -> bool;
fn visit_class_field(&mut self, i: uint, name: &str, named: bool,
mtbl: uint, inner: *TyDesc) -> bool;
fn visit_leave_class(&mut self, name: &str, named_fields: bool, n_fields: uint,
sz: uint, align: uint) -> bool;
fn visit_enter_tup(&mut self, n_fields: uint,
sz: uint, align: uint) -> bool;
fn visit_tup_field(&mut self, i: uint, inner: *TyDesc) -> bool;
fn visit_leave_tup(&mut self, n_fields: uint,
sz: uint, align: uint) -> bool;
fn visit_enter_enum(&mut self, n_variants: uint,
get_disr: unsafe extern fn(ptr: *Opaque) -> Disr,
sz: uint, align: uint) -> bool;
fn visit_enter_enum_variant(&mut self, variant: uint,
disr_val: Disr,
n_fields: uint,
name: &str) -> bool;
fn visit_enum_variant_field(&mut self, i: uint, offset: uint, inner: *TyDesc) -> bool;
fn visit_leave_enum_variant(&mut self, variant: uint,
disr_val: Disr,
n_fields: uint,
name: &str) -> bool;
fn visit_leave_enum(&mut self, n_variants: uint,
get_disr: unsafe extern fn(ptr: *Opaque) -> Disr,
sz: uint, align: uint) -> bool;
fn visit_enter_fn(&mut self, purity: uint, proto: uint,
n_inputs: uint, retstyle: uint) -> bool;
fn visit_fn_input(&mut self, i: uint, mode: uint, inner: *TyDesc) -> bool;
fn visit_fn_output(&mut self, retstyle: uint, variadic: bool, inner: *TyDesc) -> bool;
fn visit_leave_fn(&mut self, purity: uint, proto: uint,
n_inputs: uint, retstyle: uint) -> bool;
fn visit_trait(&mut self, name: &str) -> bool;
fn visit_param(&mut self, i: uint) -> bool;
fn visit_self(&mut self) -> bool;
}
extern "rust-intrinsic" {pub fn atomic_cxchg<T>(dst: *mut T, old: T, src: T) -> T;
pub fn atomic_cxchg_acq<T>(dst: *mut T, old: T, src: T) -> T;
pub fn atomic_cxchg_rel<T>(dst: *mut T, old: T, src: T) -> T;
pub fn atomic_cxchg_acqrel<T>(dst: *mut T, old: T, src: T) -> T;
pub fn atomic_cxchg_relaxed<T>(dst: *mut T, old: T, src: T) -> T;
pub fn atomic_load<T>(src: *T) -> T;
pub fn atomic_load_acq<T>(src: *T) -> T;
pub fn atomic_load_relaxed<T>(src: *T) -> T;
pub fn atomic_store<T>(dst: *mut T, val: T);
pub fn atomic_store_rel<T>(dst: *mut T, val: T);
pub fn atomic_store_relaxed<T>(dst: *mut T, val: T);
pub fn atomic_xchg<T>(dst: *mut T, src: T) -> T;
pub fn atomic_xchg_acq<T>(dst: *mut T, src: T) -> T;
pub fn atomic_xchg_rel<T>(dst: *mut T, src: T) -> T;
pub fn atomic_xchg_acqrel<T>(dst: *mut T, src: T) -> T;
pub fn atomic_xchg_relaxed<T>(dst: *mut T, src: T) -> T;
pub fn atomic_xadd<T>(dst: *mut T, src: T) -> T;
pub fn atomic_xadd_acq<T>(dst: *mut T, src: T) -> T;
pub fn atomic_xadd_rel<T>(dst: *mut T, src: T) -> T;
pub fn atomic_xadd_acqrel<T>(dst: *mut T, src: T) -> T;
pub fn atomic_xadd_relaxed<T>(dst: *mut T, src: T) -> T;
pub fn atomic_xsub<T>(dst: *mut T, src: T) -> T;
pub fn atomic_xsub_acq<T>(dst: *mut T, src: T) -> T;
pub fn atomic_xsub_rel<T>(dst: *mut T, src: T) -> T;
pub fn atomic_xsub_acqrel<T>(dst: *mut T, src: T) -> T;
pub fn atomic_xsub_relaxed<T>(dst: *mut T, src: T) -> T;
pub fn atomic_and<T>(dst: *mut T, src: T) -> T;
pub fn atomic_and_acq<T>(dst: *mut T, src: T) -> T;
pub fn atomic_and_rel<T>(dst: *mut T, src: T) -> T;
pub fn atomic_and_acqrel<T>(dst: *mut T, src: T) -> T;
pub fn atomic_and_relaxed<T>(dst: *mut T, src: T) -> T;
pub fn atomic_nand<T>(dst: *mut T, src: T) -> T;
pub fn atomic_nand_acq<T>(dst: *mut T, src: T) -> T;
pub fn atomic_nand_rel<T>(dst: *mut T, src: T) -> T;
pub fn atomic_nand_acqrel<T>(dst: *mut T, src: T) -> T;
pub fn atomic_nand_relaxed<T>(dst: *mut T, src: T) -> T;
pub fn atomic_or<T>(dst: *mut T, src: T) -> T;
pub fn atomic_or_acq<T>(dst: *mut T, src: T) -> T;
pub fn atomic_or_rel<T>(dst: *mut T, src: T) -> T;
pub fn atomic_or_acqrel<T>(dst: *mut T, src: T) -> T;
pub fn atomic_or_relaxed<T>(dst: *mut T, src: T) -> T;
pub fn atomic_xor<T>(dst: *mut T, src: T) -> T;
pub fn atomic_xor_acq<T>(dst: *mut T, src: T) -> T;
pub fn atomic_xor_rel<T>(dst: *mut T, src: T) -> T;
pub fn atomic_xor_acqrel<T>(dst: *mut T, src: T) -> T;
pub fn atomic_xor_relaxed<T>(dst: *mut T, src: T) -> T;
pub fn atomic_max<T>(dst: *mut T, src: T) -> T;
pub fn atomic_max_acq<T>(dst: *mut T, src: T) -> T;
pub fn atomic_max_rel<T>(dst: *mut T, src: T) -> T;
pub fn atomic_max_acqrel<T>(dst: *mut T, src: T) -> T;
pub fn atomic_max_relaxed<T>(dst: *mut T, src: T) -> T;
pub fn atomic_min<T>(dst: *mut T, src: T) -> T;
pub fn atomic_min_acq<T>(dst: *mut T, src: T) -> T;
pub fn atomic_min_rel<T>(dst: *mut T, src: T) -> T;
pub fn atomic_min_acqrel<T>(dst: *mut T, src: T) -> T;
pub fn atomic_min_relaxed<T>(dst: *mut T, src: T) -> T;
pub fn atomic_umin<T>(dst: *mut T, src: T) -> T;
pub fn atomic_umin_acq<T>(dst: *mut T, src: T) -> T;
pub fn atomic_umin_rel<T>(dst: *mut T, src: T) -> T;
pub fn atomic_umin_acqrel<T>(dst: *mut T, src: T) -> T;
pub fn atomic_umin_relaxed<T>(dst: *mut T, src: T) -> T;
pub fn atomic_umax<T>(dst: *mut T, src: T) -> T;
pub fn atomic_umax_acq<T>(dst: *mut T, src: T) -> T;
pub fn atomic_umax_rel<T>(dst: *mut T, src: T) -> T;
pub fn atomic_umax_acqrel<T>(dst: *mut T, src: T) -> T;
pub fn atomic_umax_relaxed<T>(dst: *mut T, src: T) -> T;
}
extern "rust-intrinsic" {
pub fn atomic_fence();
pub fn atomic_fence_acq();
pub fn atomic_fence_rel();
pub fn atomic_fence_acqrel();
pub fn abort() -> !;
pub fn breakpoint();
pub fn size_of<T>() -> uint;
pub fn move_val_init<T>(dst: &mut T, src: T);
pub fn min_align_of<T>() -> uint;
pub fn pref_align_of<T>() -> uint;
pub fn get_tydesc<T>() -> *TyDesc;
pub fn type_id<T: 'static>() -> TypeId;
pub fn init<T>() -> T;
pub fn uninit<T>() -> T;
pub fn forget<T>(_: T) -> ();
pub fn transmute<T,U>(e: T) -> U;
pub fn needs_drop<T>() -> bool;
pub fn owns_managed<T>() -> bool;
pub fn visit_tydesc(td: *TyDesc, tv: &mut TyVisitor);
pub fn offset<T>(dst: *T, offset: int) -> *T;
pub fn copy_nonoverlapping_memory<T>(dst: *mut T, src: *T, count: uint);
pub fn copy_memory<T>(dst: *mut T, src: *T, count: uint);
pub fn set_memory<T>(dst: *mut T, val: u8, count: uint);
pub fn volatile_copy_nonoverlapping_memory<T>(dst: *mut T, src: *T, count: uint);
pub fn volatile_copy_memory<T>(dst: *mut T, src: *T, count: uint);
pub fn volatile_set_memory<T>(dst: *mut T, val: u8, count: uint);
pub fn volatile_load<T>(src: *T) -> T;
pub fn volatile_store<T>(dst: *mut T, val: T);
pub fn sqrtf32(x: f32) -> f32;
pub fn sqrtf64(x: f64) -> f64;
pub fn powif32(a: f32, x: i32) -> f32;
pub fn powif64(a: f64, x: i32) -> f64;
pub fn sinf32(x: f32) -> f32;
pub fn sinf64(x: f64) -> f64;
pub fn cosf32(x: f32) -> f32;
pub fn cosf64(x: f64) -> f64;
pub fn powf32(a: f32, x: f32) -> f32;
pub fn powf64(a: f64, x: f64) -> f64;
pub fn expf32(x: f32) -> f32;
pub fn expf64(x: f64) -> f64;
pub fn exp2f32(x: f32) -> f32;
pub fn exp2f64(x: f64) -> f64;
pub fn logf32(x: f32) -> f32;
pub fn logf64(x: f64) -> f64;
pub fn log10f32(x: f32) -> f32;
pub fn log10f64(x: f64) -> f64;
pub fn log2f32(x: f32) -> f32;
pub fn log2f64(x: f64) -> f64;
pub fn fmaf32(a: f32, b: f32, c: f32) -> f32;
pub fn fmaf64(a: f64, b: f64, c: f64) -> f64;
pub fn fabsf32(x: f32) -> f32;
pub fn fabsf64(x: f64) -> f64;
pub fn copysignf32(x: f32, y: f32) -> f32;
pub fn copysignf64(x: f64, y: f64) -> f64;
pub fn floorf32(x: f32) -> f32;
pub fn floorf64(x: f64) -> f64;
pub fn ceilf32(x: f32) -> f32;
pub fn ceilf64(x: f64) -> f64;
pub fn truncf32(x: f32) -> f32;
pub fn truncf64(x: f64) -> f64;
pub fn rintf32(x: f32) -> f32;
pub fn rintf64(x: f64) -> f64;
pub fn nearbyintf32(x: f32) -> f32;
pub fn nearbyintf64(x: f64) -> f64;
pub fn roundf32(x: f32) -> f32;
pub fn roundf64(x: f64) -> f64;
pub fn ctpop8(x: u8) -> u8;
pub fn ctpop16(x: u16) -> u16;
pub fn ctpop32(x: u32) -> u32;
pub fn ctpop64(x: u64) -> u64;
pub fn ctlz8(x: u8) -> u8;
pub fn ctlz16(x: u16) -> u16;
pub fn ctlz32(x: u32) -> u32;
pub fn ctlz64(x: u64) -> u64;
pub fn cttz8(x: u8) -> u8;
pub fn cttz16(x: u16) -> u16;
pub fn cttz32(x: u32) -> u32;
pub fn cttz64(x: u64) -> u64;
pub fn bswap16(x: u16) -> u16;
pub fn bswap32(x: u32) -> u32;
pub fn bswap64(x: u64) -> u64;
pub fn i8_add_with_overflow(x: i8, y: i8) -> (i8, bool);
pub fn i16_add_with_overflow(x: i16, y: i16) -> (i16, bool);
pub fn i32_add_with_overflow(x: i32, y: i32) -> (i32, bool);
pub fn i64_add_with_overflow(x: i64, y: i64) -> (i64, bool);
pub fn u8_add_with_overflow(x: u8, y: u8) -> (u8, bool);
pub fn u16_add_with_overflow(x: u16, y: u16) -> (u16, bool);
pub fn u32_add_with_overflow(x: u32, y: u32) -> (u32, bool);
pub fn u64_add_with_overflow(x: u64, y: u64) -> (u64, bool);
pub fn i8_sub_with_overflow(x: i8, y: i8) -> (i8, bool);
pub fn i16_sub_with_overflow(x: i16, y: i16) -> (i16, bool);
pub fn i32_sub_with_overflow(x: i32, y: i32) -> (i32, bool);
pub fn i64_sub_with_overflow(x: i64, y: i64) -> (i64, bool);
pub fn u8_sub_with_overflow(x: u8, y: u8) -> (u8, bool);
pub fn u16_sub_with_overflow(x: u16, y: u16) -> (u16, bool);
pub fn u32_sub_with_overflow(x: u32, y: u32) -> (u32, bool);
pub fn u64_sub_with_overflow(x: u64, y: u64) -> (u64, bool);
pub fn i8_mul_with_overflow(x: i8, y: i8) -> (i8, bool);
pub fn i16_mul_with_overflow(x: i16, y: i16) -> (i16, bool);
pub fn i32_mul_with_overflow(x: i32, y: i32) -> (i32, bool);
pub fn i64_mul_with_overflow(x: i64, y: i64) -> (i64, bool);
pub fn u8_mul_with_overflow(x: u8, y: u8) -> (u8, bool);
pub fn u16_mul_with_overflow(x: u16, y: u16) -> (u16, bool);
pub fn u32_mul_with_overflow(x: u32, y: u32) -> (u32, bool);
pub fn u64_mul_with_overflow(x: u64, y: u64) -> (u64, bool);
}
#[lang="type_id"]#[deriving(PartialEq, Eq, Show)]
#[cfg(not(test))]
pub struct TypeId {
t: u64,
}
#[cfg(not(test))]
impl TypeId {
pub fn of<T: 'static>() -> TypeId {
unsafe { type_id::<T>() }
}
pub fn hash(&self) -> u64 { self.t }
}