@@ -677,13 +677,41 @@ static inline jl_cgval_t ghostValue(jl_value_t *typ)
677
677
{
678
678
if (typ == jl_bottom_type)
679
679
return jl_cgval_t (); // Undef{}
680
+ if (typ == (jl_value_t *)jl_bottomtype_type) {
681
+ // normalize BottomType to Type{Union{}}
682
+ typ = (jl_value_t *)jl_wrap_Type (jl_bottom_type);
683
+ }
684
+ if (jl_is_type_type (typ)) {
685
+ // replace T::Type{T} with T, by assuming that T must be a leaftype of some sort
686
+ jl_cgval_t constant (NULL , NULL , true , typ, NULL );
687
+ constant.constant = jl_tparam0 (typ);
688
+ return constant;
689
+ }
680
690
return jl_cgval_t (typ);
681
691
}
682
692
static inline jl_cgval_t ghostValue (jl_datatype_t *typ)
683
693
{
684
694
return ghostValue ((jl_value_t *)typ);
685
695
}
686
696
697
+ static inline jl_cgval_t mark_julia_const (jl_value_t *jv)
698
+ {
699
+ jl_value_t *typ;
700
+ if (jl_is_type (jv)) {
701
+ typ = (jl_value_t *)jl_wrap_Type (jv); // TODO: gc-root this?
702
+ }
703
+ else {
704
+ typ = jl_typeof (jv);
705
+ if (type_is_ghost (julia_type_to_llvm (typ))) {
706
+ return ghostValue (typ);
707
+ }
708
+ }
709
+ jl_cgval_t constant (NULL , NULL , true , typ, NULL );
710
+ constant.constant = jv;
711
+ return constant;
712
+ }
713
+
714
+
687
715
static inline jl_cgval_t mark_julia_slot (Value *v, jl_value_t *typ, Value *tindex, MDNode *tbaa)
688
716
{
689
717
// this enables lazy-copying of immutable values and stack or argument slots
@@ -700,11 +728,12 @@ static inline jl_cgval_t mark_julia_type(Value *v, bool isboxed, jl_value_t *typ
700
728
// no need to explicitly load/store a constant/ghost value
701
729
return ghostValue (typ);
702
730
}
703
- if (jl_is_type_type (typ) && jl_is_leaf_type (jl_tparam0 (typ))) {
704
- // replace T::Type{T} with T
705
- jl_cgval_t constant (NULL , NULL , true , typ, NULL );
706
- constant.constant = jl_tparam0 (typ);
707
- return constant;
731
+ if (jl_is_type_type (typ)) {
732
+ jl_value_t *tp0 = jl_tparam0 (typ);
733
+ if (jl_is_leaf_type (tp0) || tp0 == jl_bottom_type) {
734
+ // replace T::Type{T} with T
735
+ return ghostValue (typ);
736
+ }
708
737
}
709
738
Type *T = julia_type_to_llvm (typ);
710
739
if (type_is_ghost (T)) {
@@ -733,7 +762,7 @@ static inline jl_cgval_t mark_julia_type(Value *v, bool isboxed, jl_datatype_t *
733
762
// see if it might be profitable (and cheap) to change the type of v to typ
734
763
static inline jl_cgval_t update_julia_type (const jl_cgval_t &v, jl_value_t *typ, jl_codectx_t *ctx)
735
764
{
736
- if (v.typ == typ || v.typ == jl_bottom_type || jl_egal (v. typ , typ) || typ == (jl_value_t *)jl_any_type)
765
+ if (v.typ == typ || v.typ == jl_bottom_type || v. constant || typ == (jl_value_t *)jl_any_type || jl_egal (v. typ , typ) )
737
766
return v; // fast-path
738
767
if (jl_is_leaf_type (v.typ ) && !jl_is_kind (v.typ )) {
739
768
if (jl_is_leaf_type (typ) && !jl_is_kind (typ) && !((jl_datatype_t *)typ)->abstract && !((jl_datatype_t *)v.typ )->abstract ) {
@@ -764,21 +793,6 @@ static inline jl_cgval_t update_julia_type(const jl_cgval_t &v, jl_value_t *typ,
764
793
return jl_cgval_t (v, typ, NULL );
765
794
}
766
795
767
- static inline jl_cgval_t mark_julia_const (jl_value_t *jv)
768
- {
769
- jl_value_t *typ;
770
- if (jl_is_type (jv))
771
- typ = (jl_value_t *)jl_wrap_Type (jv); // TODO: gc-root this?
772
- else
773
- typ = jl_typeof (jv);
774
- if (type_is_ghost (julia_type_to_llvm (typ))) {
775
- return ghostValue (typ);
776
- }
777
- jl_cgval_t constant (NULL , NULL , true , typ, NULL );
778
- constant.constant = jv;
779
- return constant;
780
- }
781
-
782
796
// --- allocating local variables ---
783
797
784
798
static jl_sym_t *slot_symbol (int s, jl_codectx_t *ctx)
@@ -859,6 +873,8 @@ static void jl_rethrow_with_add(const char *fmt, ...)
859
873
// given a value marked with type `v.typ`, compute the mapping and/or boxing to return a value of type `typ`
860
874
static jl_cgval_t convert_julia_type (const jl_cgval_t &v, jl_value_t *typ, jl_codectx_t *ctx, bool needsroot = true )
861
875
{
876
+ if (typ == (jl_value_t *)jl_bottomtype_type)
877
+ return ghostValue (typ); // normalize BottomType to Type{Union{}}
862
878
if (v.typ == typ || v.typ == jl_bottom_type || jl_egal (v.typ , typ))
863
879
return v; // fast-path
864
880
Type *T = julia_type_to_llvm (typ);
0 commit comments