diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/hir/from_ast.cpp | 62 | ||||
-rw-r--r-- | src/resolve/absolute.cpp | 9 | ||||
-rw-r--r-- | src/trans/target.cpp | 29 |
3 files changed, 63 insertions, 37 deletions
diff --git a/src/hir/from_ast.cpp b/src/hir/from_ast.cpp index ce9b2490..062b4ff8 100644 --- a/src/hir/from_ast.cpp +++ b/src/hir/from_ast.cpp @@ -15,6 +15,7 @@ #include "visitor.hpp" #include <macro_rules/macro_rules.hpp> #include <hir/item_path.hpp> +#include <limits.h> ::HIR::Module LowerHIR_Module(const ::AST::Module& module, ::HIR::ItemPath path, ::std::vector< ::HIR::SimplePath> traits = {}); ::HIR::Function LowerHIR_Function(::HIR::ItemPath path, const ::AST::MetaItems& attrs, const ::AST::Function& f, const ::HIR::TypeRef& self_type); @@ -63,7 +64,7 @@ (IsTrait, auto type = LowerHIR_Type(e.type); - // TODO: Check for `Sized` + // TODO: Check if this trait is `Sized` and ignore if it is rv.m_bounds.push_back(::HIR::GenericBound::make_TraitBound({ mv$(type), LowerHIR_TraitPath(bound.span, e.trait) })); rv.m_bounds.back().as_TraitBound().trait.m_hrls = e.hrls; @@ -478,7 +479,7 @@ }; ) ) - throw ::std::runtime_error("TODO: LowerHIR_Pattern"); + throw "unreachable"; } ::HIR::ExprPtr LowerHIR_Expr(const ::std::shared_ptr< ::AST::ExprNode>& e) @@ -722,7 +723,9 @@ { if( ptr->m_datatype == CORETYPE_UINT || ptr->m_datatype == CORETYPE_ANY ) { - // TODO: Limit check. + if( ptr->m_value > UINT_MAX ) { + ERROR(ty.span(), E0000, "Array size out of bounds - " << ptr->m_value << " > " << UINT_MAX); + } auto size_val = static_cast<unsigned int>( ptr->m_value ); return ::HIR::TypeRef::new_array( mv$(inner), size_val ); } @@ -833,7 +836,7 @@ namespace { } } -::HIR::Struct LowerHIR_Struct(::HIR::ItemPath path, const ::AST::Struct& ent) +::HIR::Struct LowerHIR_Struct(::HIR::ItemPath path, const ::AST::Struct& ent, const ::AST::MetaItems& attrs) { TRACE_FUNCTION_F(path); ::HIR::Struct::Data data; @@ -858,10 +861,41 @@ namespace { ) ) + auto struct_repr = ::HIR::Struct::Repr::Rust; + if( const auto* attr_repr = attrs.get("repr") ) + { + ASSERT_BUG(Span(), attr_repr->has_sub_items(), "#[repr] attribute malformed, " << *attr_repr); + bool is_c = false; + bool is_packed = false; + ASSERT_BUG(Span(), attr_repr->items().size() > 0, "#[repr] attribute malformed, " << *attr_repr); + for( const auto& a : attr_repr->items() ) + { + ASSERT_BUG(Span(), a.has_noarg(), "#[repr] attribute malformed, " << *attr_repr); + const auto& repr_str = a.name(); + if( repr_str == "C" ) { + is_c = true; + } + else if( repr_str == "packed" ) { + is_packed = true; + } + else { + TODO(attrs.m_span, "Handle struct repr '" << repr_str << "'"); + } + } + + if( is_packed ) { + struct_repr = ::HIR::Struct::Repr::Packed; + } + else if( is_c ) { + struct_repr = ::HIR::Struct::Repr::C; + } + else { + } + } + return ::HIR::Struct { LowerHIR_GenericParams(ent.params(), nullptr), - // TODO: Get repr from attributes - ::HIR::Struct::Repr::Rust, + struct_repr, mv$(data) }; } @@ -933,7 +967,6 @@ namespace { repr = ::HIR::Enum::Repr::Usize; } else { - // TODO: Other repr types ERROR(Span(), E0000, "Unknown enum repr '" << repr_str << "'"); } } @@ -1031,7 +1064,7 @@ namespace { repr = ::HIR::Union::Repr::C; } else { - // TODO: Error? + ERROR(attrs.m_span, E0000, "Unknown union repr '" << repr_str << "'"); } } @@ -1240,7 +1273,7 @@ namespace { // Leave linkage.name as empty } - // If there's no code, demangle the name (TODO: By ABI) and set linkage. + // If there's no code, mangle the name (According to the ABI) and set linkage. if( linkage.name == "" && ! f.code().is_valid() ) { linkage.name = p.get_name(); @@ -1336,10 +1369,10 @@ void _add_mod_val_item(::HIR::Module& mod, ::std::string name, bool is_pub, ::H } ), (Impl, - //TODO(sp, "Expand Item::Impl"); + // NOTE: impl blocks are handled in a second pass ), (NegImpl, - //TODO(sp, "Expand Item::NegImpl"); + // NOTE: impl blocks are handled in a second pass ), (Use, // Ignore - The index is used to add `Import`s @@ -1365,7 +1398,7 @@ void _add_mod_val_item(::HIR::Module& mod, ::std::string name, bool is_pub, ::H } else { } - _add_mod_ns_item( mod, item.name, item.is_pub, LowerHIR_Struct(item_path, e) ); + _add_mod_ns_item( mod, item.name, item.is_pub, LowerHIR_Struct(item_path, e, item.data.attrs) ); ), (Enum, auto enm = LowerHIR_Enum(item_path, e, item.data.attrs, [&](auto name, auto str){ _add_mod_ns_item(mod, name, item.is_pub, mv$(str)); }); @@ -1771,7 +1804,8 @@ public: // Set all pointers in the HIR to the correct (now fixed) locations IndexVisitor(rv).visit_crate( rv ); - // TODO: If the current crate is libcore, store the paths to various non-lang ops items + // HACK: If the current crate is libcore, store the paths to various non-lang ops items + // - Some operators aren't tagged with #[lang], so this works around that if( crate.m_crate_name == "core" ) { struct H { @@ -1831,7 +1865,7 @@ public: } } }; - // TODO: Check for existing defintions of lang items + // Check for existing defintions of lang items before adding magic ones if( rv.m_lang_items.count("boxed_trait") == 0 ) { rv.m_lang_items.insert(::std::make_pair( ::std::string("boxed_trait"), H::resolve_path(rv, false, {"ops", "Boxed"}) )); diff --git a/src/resolve/absolute.cpp b/src/resolve/absolute.cpp index aece0032..5e9cb51c 100644 --- a/src/resolve/absolute.cpp +++ b/src/resolve/absolute.cpp @@ -714,7 +714,7 @@ namespace { TU_MATCH(::HIR::ValueItem, (it->second->ent), (e), (Import, // Wait? is this even valid? - TODO(sp, "HIR Import item pointed to an import"); + BUG(sp, "HIR Import item pointed to an import"); ), (Constant, pb = ::AST::PathBinding::make_Static({nullptr, nullptr}); @@ -741,7 +741,7 @@ namespace { TU_MATCH(::HIR::TypeItem, (it->second->ent), (e), (Import, // Wait? is this even valid? - TODO(sp, "HIR Import item pointed to an import"); + BUG(sp, "HIR Import item pointed to an import"); ), (Module, pb = ::AST::PathBinding::make_Module({nullptr, &e}); @@ -787,7 +787,7 @@ namespace { path.bind( ::AST::PathBinding::make_Module({nullptr, &crate.m_hir->m_root_module}) ); return ; default: - TODO(sp, ""); + TODO(sp, "Looking up a non-namespace, but pointed to crate root"); } } @@ -1180,7 +1180,6 @@ void Resolve_Absolute_Path_BindAbsolute(Context& context, const Span& sp, Contex ), (Module, if( name_ref.is_import ) { - //TODO(sp, "Replace path component with new path - " << path << "[.."<<i+1<<"] with " << name_ref.path); auto newpath = name_ref.path; for(unsigned int j = i+1; j < path_abs.nodes.size(); j ++) { @@ -1304,8 +1303,6 @@ void Resolve_Absolute_Path(/*const*/ Context& context, const Span& sp, Context:: } if( !found ) { - //TODO(sp, "Switch back to primitive from " << p << " for " << path); - //p = ::AST::Path( ::AST::Path::TagLocal(), e.nodes[0].name() ); auto ct = coretype_fromstring(e.nodes[0].name()); p = ::AST::Path( ::AST::Path::TagUfcs(), TypeRef(Span("-",0,0,0,0), ct), ::AST::Path(), ::std::vector< ::AST::PathNode>() ); } diff --git a/src/trans/target.cpp b/src/trans/target.cpp index 7aa46b35..e37de2aa 100644 --- a/src/trans/target.cpp +++ b/src/trans/target.cpp @@ -445,7 +445,7 @@ namespace { { case ::HIR::Struct::Repr::Packed: packed = true; - TODO(sp, "make_struct_repr - repr(packed)"); // needs codegen help + TODO(sp, "make_struct_repr - repr(packed)"); // needs codegen to know to pack the structure break; case ::HIR::Struct::Repr::C: // No sorting, no packing @@ -526,8 +526,6 @@ const StructRepr* Target_GetStructRepr(const Span& sp, const StaticTraitResolve& return ires.first->second.get(); } -// TODO: Include NonZero and other repr optimisations here - bool Target_GetSizeAndAlignOf(const Span& sp, const StaticTraitResolve& resolve, const ::HIR::TypeRef& ty, size_t& out_size, size_t& out_align) { TRACE_FUNCTION_FR(ty, "size=" << out_size << ", align=" << out_align); @@ -684,8 +682,7 @@ bool Target_GetSizeAndAlignOf(const Span& sp, const StaticTraitResolve& resolve, return true; ), (Closure, - // TODO. - DEBUG("TODO Closure - " << ty); + BUG(sp, "Encountered closure type at trans stage - " << ty); ) ) return false; @@ -769,8 +766,9 @@ namespace { switch(str.m_repr) { case ::HIR::Struct::Repr::Packed: + // packed, not sorted packed = true; - TODO(sp, "make_struct_repr - repr(packed)"); // needs codegen help + // NOTE: codegen_c checks m_repr for packing too break; case ::HIR::Struct::Repr::C: // No sorting, no packing @@ -792,10 +790,6 @@ namespace { DEBUG("Can't get size/align of " << t); return nullptr; } - if( size == SIZE_MAX ) - { - TODO(sp, "Unsized type in struct - " << t); - } ents.push_back(Ent { idx++, size, align }); fields.push_back(TypeRepr::Field { 0, t.clone() }); } @@ -808,9 +802,12 @@ namespace { if( allow_sort ) { - // TODO: Sort by alignment then size (largest first) - // - Requires codegen to use this information + // Sort by alignment then size (largest first) // - NOTE: ?Sized fields (which includes unsized fields) MUST be at the end, even after monomorph + // - This means that this code needs to know if a field was ?Sized + // TODO: Determine if a field was from a ?Sized generic (so should be fixed as last) + //auto cmpfn_lt = [](const Ent& a, const Ent& b){ return a.align == b.align ? a.size < b.size : a.align < b.size; }; + //::std::sort(ents.begin(), ents.end(), cmpfn_lt); } TypeRepr rv; @@ -831,7 +828,7 @@ namespace { fields[e.field].offset = cur_ofs; if( e.size == SIZE_MAX ) { - // TODO: Ensure that this is the last item + // Ensure that this is the last item ASSERT_BUG(sp, &e == &ents.back(), "Unsized item isn't the last item in " << ty); cur_ofs = SIZE_MAX; } @@ -876,7 +873,7 @@ namespace { return true; } } - // Handle the NonZero lang item (TODO: Cleaner?) + // Handle the NonZero lang item (Note: Checks just the simplepath part) if( te.path.m_data.as_Generic().m_path == resolve.m_crate.get_lang_item_path(sp, "non_zero") ) { out_path.sub_fields.push_back(0); @@ -977,7 +974,7 @@ namespace { max_size ++; } size_t tag_size = 0; - // TODO: repr(C) enums + // TODO: repr(C) enums - they have different rules if( mono_types.size() == 0 ) { // Unreachable } @@ -1022,8 +1019,6 @@ namespace { { ASSERT_BUG(sp, max_size == 0, "Zero alignment, but non-zero size"); } - - // TODO: Variants. } } break; TU_ARM(enm.m_data, Value, e) { |