summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/hir/type.cpp8
-rw-r--r--src/hir/type.hpp2
-rw-r--r--src/hir_conv/bind.cpp8
-rw-r--r--src/hir_conv/constant_evaluation.cpp3
-rw-r--r--src/hir_typeck/expr_check.cpp9
-rw-r--r--src/hir_typeck/expr_cs.cpp13
-rw-r--r--src/hir_typeck/helpers.cpp9
-rw-r--r--src/mir/from_hir.cpp3
-rw-r--r--src/mir/from_hir_match.cpp29
9 files changed, 81 insertions, 3 deletions
diff --git a/src/hir/type.cpp b/src/hir/type.cpp
index b430f2b5..1e67d60c 100644
--- a/src/hir/type.cpp
+++ b/src/hir/type.cpp
@@ -81,9 +81,10 @@ void ::HIR::TypeRef::fmt(::std::ostream& os) const
(Path,
os << e.path;
TU_MATCH(::HIR::TypeRef::TypePathBinding, (e.binding), (be),
- (Unbound, os << "/*U*/";),
+ (Unbound, os << "/*?*/";),
(Opaque, os << "/*O*/";),
(Struct, os << "/*S*/";),
+ (Union, os << "/*U*/";),
(Enum, os << "/*E*/";)
)
),
@@ -748,8 +749,9 @@ bool ::HIR::TypeRef::match_test_generics(const Span& sp, const ::HIR::TypeRef& x
TU_MATCH(::HIR::TypeRef::TypePathBinding, (*this), (e),
(Unbound, return ::HIR::TypeRef::TypePathBinding::make_Unbound({}); ),
(Opaque , return ::HIR::TypeRef::TypePathBinding::make_Opaque({}); ),
- (Struct , return ::HIR::TypeRef::TypePathBinding(e); ),
- (Enum , return ::HIR::TypeRef::TypePathBinding(e); )
+ (Struct, return ::HIR::TypeRef::TypePathBinding(e); ),
+ (Union , return ::HIR::TypeRef::TypePathBinding(e); ),
+ (Enum , return ::HIR::TypeRef::TypePathBinding(e); )
)
assert(!"Fell off end of clone_binding");
}
diff --git a/src/hir/type.hpp b/src/hir/type.hpp
index 653777db..52c77fc5 100644
--- a/src/hir/type.hpp
+++ b/src/hir/type.hpp
@@ -17,6 +17,7 @@
namespace HIR {
class Struct;
+class Union;
class Enum;
struct ExprNode_Closure;
@@ -112,6 +113,7 @@ public:
(Unbound, struct {}), // Not yet bound, either during lowering OR during resolution (when associated and still being resolved)
(Opaque, struct {}), // Opaque, i.e. An associated type of a generic (or Self in a trait)
(Struct, const ::HIR::Struct*),
+ (Union, const ::HIR::Union*),
(Enum, const ::HIR::Enum*)
), (), (), (
TypePathBinding clone() const;
diff --git a/src/hir_conv/bind.cpp b/src/hir_conv/bind.cpp
index 9841a7fb..8217aa09 100644
--- a/src/hir_conv/bind.cpp
+++ b/src/hir_conv/bind.cpp
@@ -362,6 +362,11 @@ namespace {
e.binding = ::HIR::TypeRef::TypePathBinding::make_Struct(&e3);
DEBUG("- " << ty);
),
+ (Union,
+ fix_param_count(sp, pe, e3.m_params, pe.m_params);
+ e.binding = ::HIR::TypeRef::TypePathBinding::make_Union(&e3);
+ DEBUG("- " << ty);
+ ),
(Enum,
fix_param_count(sp, pe, e3.m_params, pe.m_params);
e.binding = ::HIR::TypeRef::TypePathBinding::make_Enum(&e3);
@@ -494,6 +499,9 @@ namespace {
(Struct,
markings = &const_cast<HIR::Struct*>(tpb)->m_markings;
),
+ (Union,
+ markings = &const_cast<HIR::Union*>(tpb)->m_markings;
+ ),
(Enum,
markings = &const_cast<HIR::Enum*>(tpb)->m_markings;
)
diff --git a/src/hir_conv/constant_evaluation.cpp b/src/hir_conv/constant_evaluation.cpp
index 06489f37..dfb008e3 100644
--- a/src/hir_conv/constant_evaluation.cpp
+++ b/src/hir_conv/constant_evaluation.cpp
@@ -652,6 +652,9 @@ namespace {
),
(Enum,
TODO(sp, "Field access on enum variant - " << m_rv_type);
+ ),
+ (Union,
+ TODO(sp, "Field access on union - " << m_rv_type);
)
)
),
diff --git a/src/hir_typeck/expr_check.cpp b/src/hir_typeck/expr_check.cpp
index 9102652a..6dde6e84 100644
--- a/src/hir_typeck/expr_check.cpp
+++ b/src/hir_typeck/expr_check.cpp
@@ -413,6 +413,9 @@ namespace {
ASSERT_BUG(sp, it->second.is_Tuple(), "Pointed variant of TupleVariant (" << node.m_path << ") isn't a Tuple");
fields_ptr = &it->second.as_Tuple();
),
+ (Union,
+ BUG(sp, "Union in TupleVariant");
+ ),
(Struct,
ASSERT_BUG(sp, e->m_data.is_Tuple(), "Pointed struct in TupleVariant (" << node.m_path << ") isn't a Tuple");
fields_ptr = &e->m_data.as_Tuple();
@@ -463,6 +466,9 @@ namespace {
assert(it != enm.m_variants.end());
fields_ptr = &it->second.as_Struct();
),
+ (Union,
+ TODO(sp, "Union in StructLiteral");
+ ),
(Struct,
fields_ptr = &e->m_data.as_Named();
)
@@ -533,6 +539,9 @@ namespace {
assert(it != enm.m_variants.end());
assert( it->second.is_Unit() || it->second.is_Value() );
),
+ (Union,
+ BUG(sp, "Union with _UnitVariant");
+ ),
(Struct,
assert( e->m_data.is_Unit() );
)
diff --git a/src/hir_typeck/expr_cs.cpp b/src/hir_typeck/expr_cs.cpp
index 24c13135..5836cbef 100644
--- a/src/hir_typeck/expr_cs.cpp
+++ b/src/hir_typeck/expr_cs.cpp
@@ -1066,6 +1066,9 @@ namespace {
(Struct,
ASSERT_BUG(sp, e->m_data.is_Tuple(), "Pointed struct in TupleVariant (" << node.m_path << ") isn't a Tuple");
fields_ptr = &e->m_data.as_Tuple();
+ ),
+ (Union,
+ BUG(sp, "TupleVariant pointing to a union");
)
)
assert(fields_ptr);
@@ -1140,6 +1143,9 @@ namespace {
fields_ptr = &it->second.as_Struct();
generics = &enm.m_params;
),
+ (Union,
+ TODO(node.span(), "StructLiteral of a union - " << ty);
+ ),
(Struct,
fields_ptr = &e->m_data.as_Named();
generics = &e->m_params;
@@ -1978,6 +1984,10 @@ namespace {
if( !be->m_markings.can_coerce )
ERROR(sp, E0000, "Non-scalar cast to " << this->context.m_ivars.fmt_type(tgt_ty));
),
+ (Union,
+ if( !be->m_markings.can_coerce )
+ ERROR(sp, E0000, "Non-scalar cast to " << this->context.m_ivars.fmt_type(tgt_ty));
+ ),
(Enum,
if( !be->m_markings.can_coerce )
ERROR(sp, E0000, "Non-scalar cast to " << this->context.m_ivars.fmt_type(tgt_ty));
@@ -4229,6 +4239,9 @@ namespace {
(Struct,
return pbe->m_markings.can_coerce;
),
+ (Union,
+ return pbe->m_markings.can_coerce;
+ ),
(Enum,
return pbe->m_markings.can_coerce;
)
diff --git a/src/hir_typeck/helpers.cpp b/src/hir_typeck/helpers.cpp
index 359e0c19..88a4624f 100644
--- a/src/hir_typeck/helpers.cpp
+++ b/src/hir_typeck/helpers.cpp
@@ -2374,6 +2374,9 @@ bool TraitResolution::find_trait_impls_crate(const Span& sp,
(Struct,
markings = &tpb->m_markings;
),
+ (Union,
+ markings = &tpb->m_markings;
+ ),
(Enum,
markings = &tpb->m_markings;
)
@@ -2645,6 +2648,9 @@ bool TraitResolution::find_trait_impls_crate(const Span& sp,
)
)
}
+ ),
+ (Union,
+ TODO(sp, "Check auto trait destructure on union " << type);
)
)
DEBUG("- Nothing failed, calling callback");
@@ -3561,6 +3567,9 @@ bool TraitResolution::find_field(const Span& sp, const ::HIR::TypeRef& ty, const
),
(Enum,
// No fields on enums either
+ ),
+ (Union,
+ TODO(sp, "Field search on union");
)
)
)
diff --git a/src/mir/from_hir.cpp b/src/mir/from_hir.cpp
index 9d71ea01..9f8a91e3 100644
--- a/src/mir/from_hir.cpp
+++ b/src/mir/from_hir.cpp
@@ -1667,6 +1667,9 @@ namespace {
assert(it != enm.m_variants.end());
fields_ptr = &it->second.as_Struct();
),
+ (Union,
+ TODO(node.span(), "_StructLiteral Union");
+ ),
(Struct,
fields_ptr = &e->m_data.as_Named();
)
diff --git a/src/mir/from_hir_match.cpp b/src/mir/from_hir_match.cpp
index 860bb5bb..b8020506 100644
--- a/src/mir/from_hir_match.cpp
+++ b/src/mir/from_hir_match.cpp
@@ -492,6 +492,9 @@ void PatternRulesetBuilder::append_from_lit(const Span& sp, const ::HIR::Literal
)
)
),
+ (Union,
+ TODO(sp, "Match union");
+ ),
(Enum,
ASSERT_BUG(sp, lit.is_Variant(), "Matching enum non-variant literal - " << lit);
auto var_idx = lit.as_Variant().idx;
@@ -892,6 +895,9 @@ void PatternRulesetBuilder::append_from(const Span& sp, const ::HIR::Pattern& pa
)
)
),
+ (Union,
+ TODO(sp, "Match over union - " << ty);
+ ),
(Enum,
auto monomorph = [&](const auto& ty) {
auto rv = monomorphise_type(sp, pbe->m_params, e.path.m_data.as_Generic().m_params, ty);
@@ -1199,6 +1205,23 @@ namespace {
)
)
),
+ (Union,
+ auto monomorph = [&](const auto& ty) {
+ auto rv = monomorphise_type(sp, pbe->m_params, e.path.m_data.as_Generic().m_params, ty);
+ resolve.expand_associated_types(sp, rv);
+ return rv;
+ };
+ assert(idx < pbe->m_variants.size());
+ const auto& fld = pbe->m_variants[idx];
+ if( monomorphise_type_needed(fld.second.ent) ) {
+ tmp_ty = monomorph(fld.second.ent);
+ cur_ty = &tmp_ty;
+ }
+ else {
+ cur_ty = &fld.second.ent;
+ }
+ lval = ::MIR::LValue::make_Downcast({ box$(lval), idx });
+ ),
(Enum,
BUG(sp, "Destructuring an enum - " << *cur_ty);
)
@@ -1473,6 +1496,9 @@ int MIR_LowerHIR_Match_Simple__GeneratePattern(MirBuilder& builder, const Span&
)
)
),
+ (Union,
+ TODO(sp, "Match over Union");
+ ),
(Enum,
auto monomorph = [&](const auto& ty) { return monomorphise_type(sp, pbe->m_params, te.path.m_data.as_Generic().m_params, ty); };
ASSERT_BUG(sp, rule.is_Variant(), "Rule for enum isn't Any or Variant");
@@ -3023,6 +3049,9 @@ void DecisionTreeGen::generate_tree_code(
)
)
),
+ (Union,
+ TODO(sp, "Decision node on Union");
+ ),
(Enum,
ASSERT_BUG(sp, node.m_branches.is_Variant(), "Tree for enum isn't a Variant - node="<<node);
assert(pbe);