Skip to content

Commit e5e6333

Browse files
committed
---
yaml --- r: 4461 b: refs/heads/master c: d7828e6 h: refs/heads/master i: 4459: b172142 v: v3
1 parent e477844 commit e5e6333

File tree

2 files changed

+71
-49
lines changed

2 files changed

+71
-49
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 50670eb4267b165441b8cb36739a636887cc683c
2+
refs/heads/master: d7828e694df3b345317ab3d8390582779fef6560

trunk/src/rt/rust_shape.cpp

Lines changed: 70 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -577,9 +577,16 @@ class size_of : public ctxt<size_of> {
577577

578578
public:
579579
size_of(const size_of &other,
580-
const uint8_t *in_sp,
581-
const type_param *in_params,
582-
const rust_shape_tables *in_tables)
580+
const uint8_t *in_sp = NULL,
581+
const type_param *in_params = NULL,
582+
const rust_shape_tables *in_tables = NULL)
583+
: ctxt<size_of>(other, in_sp, in_params, in_tables) {}
584+
585+
template<typename T>
586+
size_of(const ctxt<T> &other,
587+
const uint8_t *in_sp = NULL,
588+
const type_param *in_params = NULL,
589+
const rust_shape_tables *in_tables = NULL)
583590
: ctxt<size_of>(other, in_sp, in_params, in_tables) {}
584591

585592
void walk_tag(bool align, tag_info &tinfo);
@@ -612,25 +619,31 @@ class size_of : public ctxt<size_of> {
612619
template<typename T>
613620
void walk_number(bool align) { sa.set(sizeof(T), ALIGNOF(T)); }
614621

622+
void compute_tag_size(tag_info &tinfo);
623+
624+
template<typename T>
625+
static void compute_tag_size(const ctxt<T> &other_cx, tag_info &tinfo) {
626+
size_of cx(other_cx);
627+
cx.compute_tag_size(tinfo);
628+
}
629+
615630
template<typename T>
616631
static size_align get(const ctxt<T> &other_cx, unsigned back_up = 0) {
617-
size_of cx(*other_cx, other_cx->sp - back_up);
632+
size_of cx(other_cx, other_cx->sp - back_up);
618633
cx.walk(false);
619634
assert(cx.sa.alignment > 0);
620635
return cx.sa;
621636
}
622637
};
623638

624639
void
625-
size_of::walk_tag(bool align, tag_info &tinfo) {
640+
size_of::compute_tag_size(tag_info &tinfo) {
626641
// If the precalculated size and alignment are good, use them.
627-
if (tinfo.tag_sa.is_set()) {
628-
sa = tinfo.tag_sa;
642+
if (tinfo.tag_sa.is_set())
629643
return;
630-
}
631644

632645
uint16_t n_largest_variants = get_u16_bump(tinfo.largest_variants_ptr);
633-
sa.set(0, 0);
646+
tinfo.tag_sa.set(0, 0);
634647
for (uint16_t i = 0; i < n_largest_variants; i++) {
635648
uint16_t variant_id = get_u16_bump(tinfo.largest_variants_ptr);
636649
uint16_t variant_offset = get_u16(tinfo.info_ptr +
@@ -654,19 +667,25 @@ size_of::walk_tag(bool align, tag_info &tinfo) {
654667
variant_sa.add(sub.sa.size, sub.sa.alignment);
655668
}
656669

657-
if (sa.size < variant_sa.size)
658-
sa = variant_sa;
670+
if (tinfo.tag_sa.size < variant_sa.size)
671+
tinfo.tag_sa = variant_sa;
659672
}
660673

661674
if (tinfo.variant_count == 1) {
662-
if (!sa.size)
663-
sa.set(1, 1);
675+
if (!tinfo.tag_sa.size)
676+
tinfo.tag_sa.set(1, 1);
664677
} else {
665678
// Add in space for the tag.
666-
sa.add(sizeof(uint32_t), ALIGNOF(uint32_t));
679+
tinfo.tag_sa.add(sizeof(uint32_t), ALIGNOF(uint32_t));
667680
}
668681
}
669682

683+
void
684+
size_of::walk_tag(bool align, tag_info &tinfo) {
685+
compute_tag_size(*this, tinfo);
686+
sa = tinfo.tag_sa;
687+
}
688+
670689
void
671690
size_of::walk_struct(bool align, const uint8_t *end_sp) {
672691
size_align struct_sa(0, 1);
@@ -696,32 +715,27 @@ size_of::walk_ivec(bool align, bool is_pod, size_align &elem_sa) {
696715
}
697716

698717

699-
#if 0
700-
701718
// An abstract class (again using the curiously recurring template pattern)
702719
// for methods that actually manipulate the data involved.
703720

704721
#define DATA_SIMPLE(ty, call) \
705-
if (align) dp.align(sizeof(ty)); \
722+
if (align) dp.align_to(sizeof(ty)); \
706723
static_cast<T *>(this)->call; \
707724
dp += sizeof(ty);
708725

709-
template<typename T,typename U>
710-
class data : public ctxt<data> {
726+
template<typename T>
727+
class data : public ctxt< data<T> > {
711728
private:
712-
U dp;
729+
typename T::data_ptr dp;
713730

714731
public:
715-
void walk_tag(bool align, uint16_t tag_id, const uint8_t *info_ptr,
716-
uint16_t variant_count, const uint8_t *largest_variants_ptr,
717-
size_align &tag_sa, uint16_t n_params,
718-
const type_param *params);
732+
void walk_tag(bool align, tag_info &tinfo);
719733
void walk_ivec(bool align, bool is_pod, size_align &elem_sa);
720734

721735
void walk_struct(bool align, const uint8_t *end_sp) {
722-
while (sp != end_sp) {
736+
while (this->sp != end_sp) {
723737
// TODO: Allow subclasses to optimize for POD if they want to.
724-
walk(align);
738+
this->walk(align);
725739
align = true;
726740
}
727741
}
@@ -736,14 +750,14 @@ class data : public ctxt<data> {
736750
void walk_task(bool align) { DATA_SIMPLE(void *, walk_task(align)); }
737751

738752
void walk_fn(bool align) {
739-
if (align) dp.align(sizeof(void *));
740-
static_cast<T *>(this)->walk_fn(args);
753+
if (align) dp.align_to(sizeof(void *));
754+
static_cast<T *>(this)->walk_fn(align);
741755
dp += sizeof(void *) * 2;
742756
}
743757

744758
void walk_obj(bool align) {
745-
if (align) dp.align(sizeof(void *));
746-
static_cast<T *>(this)->walk_obj(args);
759+
if (align) dp.align_to(sizeof(void *));
760+
static_cast<T *>(this)->walk_obj(align);
747761
dp += sizeof(void *) * 2;
748762
}
749763

@@ -757,46 +771,54 @@ class data : public ctxt<data> {
757771
}
758772
};
759773

760-
template<typename T,typename U>
774+
template<typename T>
761775
void
762-
data<T,U>::walk_ivec(bool align, bool is_pod, size_align &elem_sa) {
776+
data<T>::walk_ivec(bool align, bool is_pod, size_align &elem_sa) {
763777
if (!elem_sa.is_set())
764778
elem_sa = size_of::get(*this);
765779
else if (elem_sa.alignment == 8)
766780
elem_sa.alignment = 4; // FIXME: This is an awful hack.
767781

768782
// Get a pointer to the interior vector, and skip over it.
769-
if (align) dp.align(ALIGNOF(rust_ivec *));
770-
U end_dp = dp + sizeof(rust_ivec) - sizeof(uintptr_t) + elem_sa.size * 4;
783+
if (align) dp.align_to(ALIGNOF(rust_ivec *));
784+
typename T::data_ptr end_dp = dp + sizeof(rust_ivec) - sizeof(uintptr_t) +
785+
elem_sa.size * 4;
771786

772787
// Call to the implementation.
773788
static_cast<T *>(this)->walk_ivec(align, is_pod, elem_sa);
774789

775790
dp = end_dp;
776791
}
777792

778-
template<typename T,typename U>
793+
template<typename T>
779794
void
780-
data<T,U>::walk_tag(bool align, uint16_t tag_id, const uint8_t *info_ptr,
781-
uint16_t variant_count,
782-
const uint8_t *largest_variants_ptr, size_align &tag_sa,
783-
uint16_t n_params, const type_param *params) {
784-
uint32_t tag_variant;
785-
U end_dp;
786-
if (variant_count > 1) {
787-
if (align) dp.align(ALIGNOF(uint32_t));
788-
process_tag_variant_ids(
789-
U::data<uint32_t> tag_variant =
790-
}
795+
data<T>::walk_tag(bool align, tag_info &tinfo) {
796+
size_of::compute_tag_size(tinfo);
791797

792-
#endif
798+
if (tinfo.variant_count > 1 && align)
799+
dp.align_to(ALIGNOF(uint32_t));
800+
801+
typename T::data_ptr end_dp = tinfo.tag_sa.size;
802+
803+
typename T::template data<uint32_t> tag_variant;
804+
if (tinfo.variant_count > 1)
805+
tag_variant = dp.template get_bump<uint32_t>();
806+
else
807+
tag_variant = 0;
808+
809+
static_cast<T *>(this)->walk_tag(align, tinfo, tag_variant);
810+
}
793811

794812

795813
// Copy constructors
796814

797-
class copy : public ctxt<copy> {
815+
#if 0
816+
817+
class copy : public data<copy> {
798818
// TODO
799819
};
800820

821+
#endif
822+
801823
} // end namespace shape
802824

0 commit comments

Comments
 (0)