diff options
author | Philip Herron <philip.herron@embecosm.com> | 2022-02-02 14:25:50 +0000 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2022-02-02 15:50:13 +0000 |
commit | d2a0fa7fc5fd3332e9f180339a262f29641f62c6 (patch) | |
tree | 0a911f2033756f2ef2a29c840d0ea61413b20ffb /gcc | |
parent | f7f14de056eb3887e70f29b0f29da4025f746559 (diff) | |
download | gcc-d2a0fa7fc5fd3332e9f180339a262f29641f62c6.zip gcc-d2a0fa7fc5fd3332e9f180339a262f29641f62c6.tar.gz gcc-d2a0fa7fc5fd3332e9f180339a262f29641f62c6.tar.bz2 |
Add new RustIdent struct to track canonical-path and location info
This refactors our TyTy type abstractions to contain their repspective
canonical-path and location info. This cleans up alot of location tracking
for example when we have generic structures we create implicit hirids which
may or may not have location info this now tracks the location info of
the declaration of the type avoiding any confustion.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/backend/rust-compile-type.cc | 35 | ||||
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve.cc | 3 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-hir-type-check-enumitem.h | 12 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-hir-type-check-expr.h | 62 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-hir-type-check-implitem.h | 33 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-hir-type-check-stmt.h | 83 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-hir-type-check-toplevel.h | 82 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-hir-type-check-type.cc | 8 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-hir-type-check-type.h | 13 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-hir-type-check.cc | 19 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-hir-type-check.h | 5 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-tyty-cast.h | 11 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-tyty-coercion.h | 11 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-tyty-rules.h | 11 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-tyty.cc | 43 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-tyty.h | 327 | ||||
-rw-r--r-- | gcc/rust/util/rust-identifier.h | 49 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/torture/struct_decl.rs | 14 |
18 files changed, 580 insertions, 241 deletions
diff --git a/gcc/rust/backend/rust-compile-type.cc b/gcc/rust/backend/rust-compile-type.cc index f4bc2e4..11784c9 100644 --- a/gcc/rust/backend/rust-compile-type.cc +++ b/gcc/rust/backend/rust-compile-type.cc @@ -132,13 +132,14 @@ TyTyResolveCompile::visit (const TyTy::FnType &type) } if (!type.is_varadic ()) - translated = ctx->get_backend ()->function_type ( - receiver, parameters, results, NULL, - ctx->get_mappings ()->lookup_location (type.get_ref ())); + translated + = ctx->get_backend ()->function_type (receiver, parameters, results, NULL, + type.get_ident ().locus); else - translated = ctx->get_backend ()->function_type_varadic ( - receiver, parameters, results, NULL, - ctx->get_mappings ()->lookup_location (type.get_ref ())); + translated + = ctx->get_backend ()->function_type_varadic (receiver, parameters, + results, NULL, + type.get_ident ().locus); } void @@ -153,9 +154,8 @@ TyTyResolveCompile::visit (const TyTy::FnPtr &type) return true; }); - translated = ctx->get_backend ()->function_ptr_type ( - result_type, parameters, - ctx->get_mappings ()->lookup_location (type.get_ref ())); + translated = ctx->get_backend ()->function_ptr_type (result_type, parameters, + type.get_ident ().locus); } void @@ -248,8 +248,8 @@ TyTyResolveCompile::visit (const TyTy::ADTType &type) tree variant_record = ctx->get_backend ()->struct_type (fields); tree named_variant_record = ctx->get_backend ()->named_type ( - variant->get_identifier (), variant_record, - ctx->get_mappings ()->lookup_location (variant->get_id ())); + variant->get_ident ().path.get (), variant_record, + variant->get_ident ().locus); // set the qualifier to be a builtin DECL_ARTIFICIAL (TYPE_FIELDS (variant_record)) = 1; @@ -278,10 +278,11 @@ TyTyResolveCompile::visit (const TyTy::ADTType &type) type_record = ctx->get_backend ()->union_type (enum_fields); } + std::string named_struct_str + = type.get_ident ().path.get () + type.subst_as_string (); tree named_struct - = ctx->get_backend ()->named_type (type.get_name (), type_record, - ctx->get_mappings ()->lookup_location ( - type.get_ref ())); + = ctx->get_backend ()->named_type (named_struct_str, type_record, + type.get_ident ().locus); ctx->push_type (named_struct); translated = named_struct; @@ -324,8 +325,7 @@ TyTyResolveCompile::visit (const TyTy::TupleType &type) tree struct_type_record = ctx->get_backend ()->struct_type (fields); tree named_struct = ctx->get_backend ()->named_type (type.as_string (), struct_type_record, - ctx->get_mappings ()->lookup_location ( - type.get_ty_ref ())); + type.get_ident ().locus); ctx->push_type (named_struct); ctx->insert_compiled_type (type.get_ty_ref (), named_struct, &type); @@ -496,8 +496,7 @@ TyTyResolveCompile::visit (const TyTy::DynamicObjectType &type) tree type_record = ctx->get_backend ()->struct_type (fields); tree named_struct = ctx->get_backend ()->named_type (type.get_name (), type_record, - ctx->get_mappings ()->lookup_location ( - type.get_ty_ref ())); + type.get_ident ().locus); ctx->push_type (named_struct); translated = named_struct; diff --git a/gcc/rust/resolve/rust-ast-resolve.cc b/gcc/rust/resolve/rust-ast-resolve.cc index 96524d2..8aef313 100644 --- a/gcc/rust/resolve/rust-ast-resolve.cc +++ b/gcc/rust/resolve/rust-ast-resolve.cc @@ -187,9 +187,8 @@ Resolver::generate_builtins () MKBUILTIN_TYPE ("str", builtins, str); // unit type () - TyTy::TupleType *unit_tyty - = new TyTy::TupleType (mappings->get_next_hir_id ()); + = TyTy::TupleType::get_unit_type (mappings->get_next_hir_id ()); std::vector<std::unique_ptr<AST::Type> > elems; AST::TupleType *unit_type = new AST::TupleType (std::move (elems), Linemap::predeclared_location ()); diff --git a/gcc/rust/typecheck/rust-hir-type-check-enumitem.h b/gcc/rust/typecheck/rust-hir-type-check-enumitem.h index 83d9cf5..9701a20 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-enumitem.h +++ b/gcc/rust/typecheck/rust-hir-type-check-enumitem.h @@ -70,8 +70,9 @@ public: &canonical_path); rust_assert (ok); + RustIdent ident{*canonical_path, item.get_locus ()}; variant = new TyTy::VariantDef (item.get_mappings ().get_hirid (), - item.get_identifier (), discim_expr); + item.get_identifier (), ident, discim_expr); } void visit (HIR::EnumItemDiscriminant &item) override @@ -99,8 +100,9 @@ public: &canonical_path); rust_assert (ok); + RustIdent ident{*canonical_path, item.get_locus ()}; variant = new TyTy::VariantDef (item.get_mappings ().get_hirid (), - item.get_identifier (), + item.get_identifier (), ident, item.get_discriminant_expression ().get ()); } @@ -146,8 +148,9 @@ public: &canonical_path); rust_assert (ok); + RustIdent ident{*canonical_path, item.get_locus ()}; variant = new TyTy::VariantDef (item.get_mappings ().get_hirid (), - item.get_identifier (), + item.get_identifier (), ident, TyTy::VariantDef::VariantType::TUPLE, discim_expr, fields); } @@ -192,8 +195,9 @@ public: &canonical_path); rust_assert (ok); + RustIdent ident{*canonical_path, item.get_locus ()}; variant = new TyTy::VariantDef (item.get_mappings ().get_hirid (), - item.get_identifier (), + item.get_identifier (), ident, TyTy::VariantDef::VariantType::STRUCT, discrim_expr, fields); } diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.h b/gcc/rust/typecheck/rust-hir-type-check-expr.h index 482ad02..150eb1a 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-expr.h +++ b/gcc/rust/typecheck/rust-hir-type-check-expr.h @@ -158,7 +158,8 @@ public: auto field_ty = TypeCheckExpr::Resolve (elem.get (), false); fields.push_back (TyTy::TyVar (field_ty->get_ref ())); } - infered = new TyTy::TupleType (expr.get_mappings ().get_hirid (), fields); + infered = new TyTy::TupleType (expr.get_mappings ().get_hirid (), + expr.get_locus (), fields); } void visit (HIR::ReturnExpr &expr) override @@ -166,18 +167,10 @@ public: auto fn_return_tyty = context->peek_return_type (); rust_assert (fn_return_tyty != nullptr); - TyTy::BaseType *expr_ty; - if (expr.has_return_expr ()) - expr_ty = TypeCheckExpr::Resolve (expr.get_expr (), false); - else - expr_ty = new TyTy::TupleType (expr.get_mappings ().get_hirid ()); - - if (expr_ty == nullptr) - { - rust_error_at (expr.get_locus (), - "failed to resolve type for ReturnExpr"); - return; - } + TyTy::BaseType *expr_ty + = expr.has_return_expr () + ? TypeCheckExpr::Resolve (expr.get_expr (), false) + : TyTy::TupleType::get_unit_type (expr.get_mappings ().get_hirid ()); infered = fn_return_tyty->unify (expr_ty); fn_return_tyty->append_reference (expr_ty->get_ref ()); @@ -405,7 +398,8 @@ public: void visit (HIR::AssignmentExpr &expr) override { - infered = new TyTy::TupleType (expr.get_mappings ().get_hirid ()); + infered + = TyTy::TupleType::get_unit_type (expr.get_mappings ().get_hirid ()); auto lhs = TypeCheckExpr::Resolve (expr.get_lhs (), false); auto rhs = TypeCheckExpr::Resolve (expr.get_rhs (), false); @@ -454,7 +448,8 @@ public: void visit (HIR::CompoundAssignmentExpr &expr) override { - infered = new TyTy::TupleType (expr.get_mappings ().get_hirid ()); + infered + = TyTy::TupleType::get_unit_type (expr.get_mappings ().get_hirid ()); auto lhs = TypeCheckExpr::Resolve (expr.get_left_expr ().get (), false); auto rhs = TypeCheckExpr::Resolve (expr.get_right_expr ().get (), false); @@ -603,9 +598,10 @@ public: default: ok = true; - infered = new TyTy::InferType ( - expr.get_mappings ().get_hirid (), - TyTy::InferType::InferTypeKind::INTEGRAL); + infered + = new TyTy::InferType (expr.get_mappings ().get_hirid (), + TyTy::InferType::InferTypeKind::INTEGRAL, + expr.get_locus ()); break; } rust_assert (ok); @@ -628,7 +624,8 @@ public: ok = true; infered = new TyTy::InferType (expr.get_mappings ().get_hirid (), - TyTy::InferType::InferTypeKind::FLOAT); + TyTy::InferType::InferTypeKind::FLOAT, + expr.get_locus ()); break; } rust_assert (ok); @@ -701,7 +698,7 @@ public: TyTy::ArrayType *array = new TyTy::ArrayType (array_mapping.get_hirid (), - *literal_capacity, + expr.get_locus (), *literal_capacity, TyTy::TyVar (u8->get_ref ())); context->insert_type (array_mapping, array); @@ -842,7 +839,8 @@ public: TypeCheckExpr::Resolve (expr.get_if_condition (), false); TypeCheckExpr::Resolve (expr.get_if_block (), inside_loop); - infered = new TyTy::TupleType (expr.get_mappings ().get_hirid ()); + infered + = TyTy::TupleType::get_unit_type (expr.get_mappings ().get_hirid ()); } void visit (HIR::IfExprConseqElse &expr) override @@ -1000,9 +998,9 @@ public: break; } - infered - = new TyTy::ArrayType (expr.get_mappings ().get_hirid (), *capacity_expr, - TyTy::TyVar (element_type->get_ref ())); + infered = new TyTy::ArrayType (expr.get_mappings ().get_hirid (), + expr.get_locus (), *capacity_expr, + TyTy::TyVar (element_type->get_ref ())); } // empty struct @@ -1078,7 +1076,8 @@ public: void visit (HIR::LoopExpr &expr) override { - context->push_new_loop_context (expr.get_mappings ().get_hirid ()); + context->push_new_loop_context (expr.get_mappings ().get_hirid (), + expr.get_locus ()); TyTy::BaseType *block_expr = TypeCheckExpr::Resolve (expr.get_loop_block ().get (), true); if (!block_expr->is_unit ()) @@ -1097,9 +1096,10 @@ public: && (((TyTy::InferType *) loop_context_type)->get_infer_kind () != TyTy::InferType::GENERAL)); - infered = loop_context_type_infered - ? loop_context_type - : new TyTy::TupleType (expr.get_mappings ().get_hirid ()); + infered + = loop_context_type_infered + ? loop_context_type + : TyTy::TupleType::get_unit_type (expr.get_mappings ().get_hirid ()); } void visit (HIR::WhileLoopExpr &expr) override @@ -1119,7 +1119,8 @@ public: } context->pop_loop_context (); - infered = new TyTy::TupleType (expr.get_mappings ().get_hirid ()); + infered + = TyTy::TupleType::get_unit_type (expr.get_mappings ().get_hirid ()); } void visit (HIR::BreakExpr &expr) override @@ -1262,7 +1263,8 @@ public: if (kase_block_tys.size () == 0) { - infered = new TyTy::TupleType (expr.get_mappings ().get_hirid ()); + infered + = TyTy::TupleType::get_unit_type (expr.get_mappings ().get_hirid ()); return; } diff --git a/gcc/rust/typecheck/rust-hir-type-check-implitem.h b/gcc/rust/typecheck/rust-hir-type-check-implitem.h index ccf52fb..10d4ea8 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-implitem.h +++ b/gcc/rust/typecheck/rust-hir-type-check-implitem.h @@ -77,7 +77,8 @@ public: TyTy::BaseType *ret_type = nullptr; if (!function.has_return_type ()) - ret_type = new TyTy::TupleType (function.get_mappings ().get_hirid ()); + ret_type = TyTy::TupleType::get_unit_type ( + function.get_mappings ().get_hirid ()); else { auto resolved @@ -121,11 +122,19 @@ public: if (function.is_variadic ()) flags |= TyTy::FnType::FNTYPE_IS_VARADIC_FLAG; - auto fnType = new TyTy::FnType ( - function.get_mappings ().get_hirid (), - function.get_mappings ().get_defid (), function.get_item_name (), flags, - ::Backend::get_abi_from_string (parent.get_abi (), parent.get_locus ()), - std::move (params), ret_type, std::move (substitutions)); + RustIdent ident{ + CanonicalPath::new_seg (function.get_mappings ().get_nodeid (), + function.get_item_name ()), + function.get_locus ()}; + auto fnType + = new TyTy::FnType (function.get_mappings ().get_hirid (), + function.get_mappings ().get_defid (), + function.get_item_name (), ident, flags, + ::Backend::get_abi_from_string (parent.get_abi (), + parent.get_locus ()), + std::move (params), ret_type, + std::move (substitutions)); + context->insert_type (function.get_mappings (), fnType); } @@ -206,7 +215,8 @@ public: TyTy::BaseType *ret_type = nullptr; if (!function.has_function_return_type ()) - ret_type = new TyTy::TupleType (function.get_mappings ().get_hirid ()); + ret_type = TyTy::TupleType::get_unit_type ( + function.get_mappings ().get_hirid ()); else { auto resolved @@ -291,9 +301,16 @@ public: context->insert_type (param.get_mappings (), param_tyty); } + const CanonicalPath *canonical_path = nullptr; + bool ok = mappings->lookup_canonical_path ( + function.get_mappings ().get_crate_num (), + function.get_mappings ().get_nodeid (), &canonical_path); + rust_assert (ok); + + RustIdent ident{*canonical_path, function.get_locus ()}; auto fnType = new TyTy::FnType (function.get_mappings ().get_hirid (), function.get_mappings ().get_defid (), - function.get_function_name (), + function.get_function_name (), ident, function.is_method () ? TyTy::FnType::FNTYPE_IS_METHOD_FLAG : TyTy::FnType::FNTYPE_DEFAULT_FLAGS, diff --git a/gcc/rust/typecheck/rust-hir-type-check-stmt.h b/gcc/rust/typecheck/rust-hir-type-check-stmt.h index b287fe5..f2196b7 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-stmt.h +++ b/gcc/rust/typecheck/rust-hir-type-check-stmt.h @@ -68,7 +68,8 @@ public: void visit (HIR::LetStmt &stmt) override { - infered = new TyTy::TupleType (stmt.get_mappings ().get_hirid ()); + infered + = TyTy::TupleType::get_unit_type (stmt.get_mappings ().get_hirid ()); TyTy::BaseType *init_expr_ty = nullptr; if (stmt.has_init_expr ()) @@ -115,7 +116,8 @@ public: context->insert_type ( stmt.get_mappings (), new TyTy::InferType (stmt.get_mappings ().get_hirid (), - TyTy::InferType::InferTypeKind::GENERAL)); + TyTy::InferType::InferTypeKind::GENERAL, + stmt.get_locus ())); } } @@ -167,16 +169,26 @@ public: idx++; } + // get the path + const CanonicalPath *canonical_path = nullptr; + bool ok = mappings->lookup_canonical_path ( + struct_decl.get_mappings ().get_crate_num (), + struct_decl.get_mappings ().get_nodeid (), &canonical_path); + rust_assert (ok); + RustIdent ident{*canonical_path, struct_decl.get_locus ()}; + // there is only a single variant std::vector<TyTy::VariantDef *> variants; - variants.push_back (new TyTy::VariantDef ( - struct_decl.get_mappings ().get_hirid (), struct_decl.get_identifier (), - TyTy::VariantDef::VariantType::TUPLE, nullptr, std::move (fields))); + variants.push_back ( + new TyTy::VariantDef (struct_decl.get_mappings ().get_hirid (), + struct_decl.get_identifier (), ident, + TyTy::VariantDef::VariantType::TUPLE, nullptr, + std::move (fields))); TyTy::BaseType *type = new TyTy::ADTType (struct_decl.get_mappings ().get_hirid (), mappings->get_next_hir_id (), - struct_decl.get_identifier (), + struct_decl.get_identifier (), ident, TyTy::ADTType::ADTKind::TUPLE_STRUCT, std::move (variants), std::move (substitutions)); @@ -223,10 +235,18 @@ public: variants.push_back (field_type); } + // get the path + const CanonicalPath *canonical_path = nullptr; + bool ok = mappings->lookup_canonical_path ( + enum_decl.get_mappings ().get_crate_num (), + enum_decl.get_mappings ().get_nodeid (), &canonical_path); + rust_assert (ok); + RustIdent ident{*canonical_path, enum_decl.get_locus ()}; + TyTy::BaseType *type = new TyTy::ADTType (enum_decl.get_mappings ().get_hirid (), mappings->get_next_hir_id (), - enum_decl.get_identifier (), + enum_decl.get_identifier (), ident, TyTy::ADTType::ADTKind::ENUM, std::move (variants), std::move (substitutions)); @@ -275,16 +295,26 @@ public: ty_field->get_field_type ()); } + // get the path + const CanonicalPath *canonical_path = nullptr; + bool ok = mappings->lookup_canonical_path ( + struct_decl.get_mappings ().get_crate_num (), + struct_decl.get_mappings ().get_nodeid (), &canonical_path); + rust_assert (ok); + RustIdent ident{*canonical_path, struct_decl.get_locus ()}; + // there is only a single variant std::vector<TyTy::VariantDef *> variants; - variants.push_back (new TyTy::VariantDef ( - struct_decl.get_mappings ().get_hirid (), struct_decl.get_identifier (), - TyTy::VariantDef::VariantType::STRUCT, nullptr, std::move (fields))); + variants.push_back ( + new TyTy::VariantDef (struct_decl.get_mappings ().get_hirid (), + struct_decl.get_identifier (), ident, + TyTy::VariantDef::VariantType::STRUCT, nullptr, + std::move (fields))); TyTy::BaseType *type = new TyTy::ADTType (struct_decl.get_mappings ().get_hirid (), mappings->get_next_hir_id (), - struct_decl.get_identifier (), + struct_decl.get_identifier (), ident, TyTy::ADTType::ADTKind::STRUCT_STRUCT, std::move (variants), std::move (substitutions)); @@ -333,16 +363,26 @@ public: ty_variant->get_field_type ()); } + // get the path + const CanonicalPath *canonical_path = nullptr; + bool ok = mappings->lookup_canonical_path ( + union_decl.get_mappings ().get_crate_num (), + union_decl.get_mappings ().get_nodeid (), &canonical_path); + rust_assert (ok); + RustIdent ident{*canonical_path, union_decl.get_locus ()}; + // there is only a single variant std::vector<TyTy::VariantDef *> variants; - variants.push_back (new TyTy::VariantDef ( - union_decl.get_mappings ().get_hirid (), union_decl.get_identifier (), - TyTy::VariantDef::VariantType::STRUCT, nullptr, std::move (fields))); + variants.push_back ( + new TyTy::VariantDef (union_decl.get_mappings ().get_hirid (), + union_decl.get_identifier (), ident, + TyTy::VariantDef::VariantType::STRUCT, nullptr, + std::move (fields))); TyTy::BaseType *type = new TyTy::ADTType (union_decl.get_mappings ().get_hirid (), mappings->get_next_hir_id (), - union_decl.get_identifier (), + union_decl.get_identifier (), ident, TyTy::ADTType::ADTKind::UNION, std::move (variants), std::move (substitutions)); @@ -380,7 +420,8 @@ public: TyTy::BaseType *ret_type = nullptr; if (!function.has_function_return_type ()) - ret_type = new TyTy::TupleType (function.get_mappings ().get_hirid ()); + ret_type = TyTy::TupleType::get_unit_type ( + function.get_mappings ().get_hirid ()); else { auto resolved @@ -409,9 +450,17 @@ public: context->insert_type (param.get_mappings (), param_tyty); } + // get the path + const CanonicalPath *canonical_path = nullptr; + bool ok = mappings->lookup_canonical_path ( + function.get_mappings ().get_crate_num (), + function.get_mappings ().get_nodeid (), &canonical_path); + rust_assert (ok); + + RustIdent ident{*canonical_path, function.get_locus ()}; auto fnType = new TyTy::FnType (function.get_mappings ().get_hirid (), function.get_mappings ().get_defid (), - function.get_function_name (), + function.get_function_name (), ident, TyTy::FnType::FNTYPE_DEFAULT_FLAGS, ABI::RUST, std::move (params), ret_type, std::move (substitutions)); diff --git a/gcc/rust/typecheck/rust-hir-type-check-toplevel.h b/gcc/rust/typecheck/rust-hir-type-check-toplevel.h index c447920..2271dace 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-toplevel.h +++ b/gcc/rust/typecheck/rust-hir-type-check-toplevel.h @@ -102,16 +102,26 @@ public: idx++; } - // there is only a single variant + // get the path + const CanonicalPath *canonical_path = nullptr; + bool ok = mappings->lookup_canonical_path ( + struct_decl.get_mappings ().get_crate_num (), + struct_decl.get_mappings ().get_nodeid (), &canonical_path); + rust_assert (ok); + RustIdent ident{*canonical_path, struct_decl.get_locus ()}; + + // its a single variant ADT std::vector<TyTy::VariantDef *> variants; - variants.push_back (new TyTy::VariantDef ( - struct_decl.get_mappings ().get_hirid (), struct_decl.get_identifier (), - TyTy::VariantDef::VariantType::TUPLE, nullptr, std::move (fields))); + variants.push_back ( + new TyTy::VariantDef (struct_decl.get_mappings ().get_hirid (), + struct_decl.get_identifier (), ident, + TyTy::VariantDef::VariantType::TUPLE, nullptr, + std::move (fields))); TyTy::BaseType *type = new TyTy::ADTType (struct_decl.get_mappings ().get_hirid (), mappings->get_next_hir_id (), - struct_decl.get_identifier (), + struct_decl.get_identifier (), ident, TyTy::ADTType::ADTKind::TUPLE_STRUCT, std::move (variants), std::move (substitutions)); @@ -158,7 +168,6 @@ public: } std::vector<TyTy::StructFieldType *> fields; - for (auto &field : struct_decl.get_fields ()) { TyTy::BaseType *field_type @@ -171,16 +180,26 @@ public: ty_field->get_field_type ()); } - // there is only a single variant + // get the path + const CanonicalPath *canonical_path = nullptr; + bool ok = mappings->lookup_canonical_path ( + struct_decl.get_mappings ().get_crate_num (), + struct_decl.get_mappings ().get_nodeid (), &canonical_path); + rust_assert (ok); + RustIdent ident{*canonical_path, struct_decl.get_locus ()}; + + // its a single variant ADT std::vector<TyTy::VariantDef *> variants; - variants.push_back (new TyTy::VariantDef ( - struct_decl.get_mappings ().get_hirid (), struct_decl.get_identifier (), - TyTy::VariantDef::VariantType::STRUCT, nullptr, std::move (fields))); + variants.push_back ( + new TyTy::VariantDef (struct_decl.get_mappings ().get_hirid (), + struct_decl.get_identifier (), ident, + TyTy::VariantDef::VariantType::STRUCT, nullptr, + std::move (fields))); TyTy::BaseType *type = new TyTy::ADTType (struct_decl.get_mappings ().get_hirid (), mappings->get_next_hir_id (), - struct_decl.get_identifier (), + struct_decl.get_identifier (), ident, TyTy::ADTType::ADTKind::STRUCT_STRUCT, std::move (variants), std::move (substitutions)); @@ -226,10 +245,19 @@ public: variants.push_back (field_type); } + // get the path + const CanonicalPath *canonical_path = nullptr; + bool ok = mappings->lookup_canonical_path ( + enum_decl.get_mappings ().get_crate_num (), + enum_decl.get_mappings ().get_nodeid (), &canonical_path); + rust_assert (ok); + RustIdent ident{*canonical_path, enum_decl.get_locus ()}; + + // multi variant ADT TyTy::BaseType *type = new TyTy::ADTType (enum_decl.get_mappings ().get_hirid (), mappings->get_next_hir_id (), - enum_decl.get_identifier (), + enum_decl.get_identifier (), ident, TyTy::ADTType::ADTKind::ENUM, std::move (variants), std::move (substitutions)); @@ -282,16 +310,26 @@ public: ty_variant->get_field_type ()); } + // get the path + const CanonicalPath *canonical_path = nullptr; + bool ok = mappings->lookup_canonical_path ( + union_decl.get_mappings ().get_crate_num (), + union_decl.get_mappings ().get_nodeid (), &canonical_path); + rust_assert (ok); + RustIdent ident{*canonical_path, union_decl.get_locus ()}; + // there is only a single variant std::vector<TyTy::VariantDef *> variants; - variants.push_back (new TyTy::VariantDef ( - union_decl.get_mappings ().get_hirid (), union_decl.get_identifier (), - TyTy::VariantDef::VariantType::STRUCT, nullptr, std::move (fields))); + variants.push_back ( + new TyTy::VariantDef (union_decl.get_mappings ().get_hirid (), + union_decl.get_identifier (), ident, + TyTy::VariantDef::VariantType::STRUCT, nullptr, + std::move (fields))); TyTy::BaseType *type = new TyTy::ADTType (union_decl.get_mappings ().get_hirid (), mappings->get_next_hir_id (), - union_decl.get_identifier (), + union_decl.get_identifier (), ident, TyTy::ADTType::ADTKind::UNION, std::move (variants), std::move (substitutions)); @@ -350,7 +388,8 @@ public: TyTy::BaseType *ret_type = nullptr; if (!function.has_function_return_type ()) - ret_type = new TyTy::TupleType (function.get_mappings ().get_hirid ()); + ret_type = TyTy::TupleType::get_unit_type ( + function.get_mappings ().get_hirid ()); else { auto resolved @@ -379,9 +418,16 @@ public: context->insert_type (param.get_mappings (), param_tyty); } + const CanonicalPath *canonical_path = nullptr; + bool ok = mappings->lookup_canonical_path ( + function.get_mappings ().get_crate_num (), + function.get_mappings ().get_nodeid (), &canonical_path); + rust_assert (ok); + + RustIdent ident{*canonical_path, function.get_locus ()}; auto fnType = new TyTy::FnType (function.get_mappings ().get_hirid (), function.get_mappings ().get_defid (), - function.get_function_name (), + function.get_function_name (), ident, TyTy::FnType::FNTYPE_DEFAULT_FLAGS, ABI::RUST, std::move (params), ret_type, std::move (substitutions)); diff --git a/gcc/rust/typecheck/rust-hir-type-check-type.cc b/gcc/rust/typecheck/rust-hir-type-check-type.cc index fb0816b..9902614 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-type.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-type.cc @@ -572,8 +572,10 @@ TypeCheckType::visit (HIR::TraitObjectType &type) specified_bounds.push_back (std::move (predicate)); } - translated = new TyTy::DynamicObjectType (type.get_mappings ().get_hirid (), - std::move (specified_bounds)); + RustIdent ident{CanonicalPath::create_empty (), type.get_locus ()}; + translated + = new TyTy::DynamicObjectType (type.get_mappings ().get_hirid (), ident, + std::move (specified_bounds)); } void @@ -594,7 +596,7 @@ TypeCheckType::visit (HIR::ArrayType &type) TyTy::BaseType *base = TypeCheckType::Resolve (type.get_element_type ()); translated = new TyTy::ArrayType (type.get_mappings ().get_hirid (), - *type.get_size_expr (), + type.get_locus (), *type.get_size_expr (), TyTy::TyVar (base->get_ref ())); } diff --git a/gcc/rust/typecheck/rust-hir-type-check-type.h b/gcc/rust/typecheck/rust-hir-type-check-type.h index d78412c..400328c 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-type.h +++ b/gcc/rust/typecheck/rust-hir-type-check-type.h @@ -74,7 +74,8 @@ public: TyTy::BaseType *return_type = fntype.has_return_type () ? TypeCheckType::Resolve (fntype.get_return_type ().get ()) - : new TyTy::TupleType (fntype.get_mappings ().get_hirid ()); + : TyTy::TupleType::get_unit_type ( + fntype.get_mappings ().get_hirid ()); std::vector<TyTy::TyVar> params; for (auto ¶m : fntype.get_function_params ()) @@ -85,7 +86,7 @@ public: } translated = new TyTy::FnPtr (fntype.get_mappings ().get_hirid (), - std::move (params), + fntype.get_locus (), std::move (params), TyTy::TyVar (return_type->get_ref ())); } @@ -109,8 +110,8 @@ public: fields.push_back (TyTy::TyVar (field_ty->get_ref ())); } - translated - = new TyTy::TupleType (tuple.get_mappings ().get_hirid (), fields); + translated = new TyTy::TupleType (tuple.get_mappings ().get_hirid (), + tuple.get_locus (), fields); } void visit (HIR::TypePath &path) override; @@ -140,7 +141,8 @@ public: void visit (HIR::InferredType &type) override { translated = new TyTy::InferType (type.get_mappings ().get_hirid (), - TyTy::InferType::InferTypeKind::GENERAL); + TyTy::InferType::InferTypeKind::GENERAL, + type.get_locus ()); } void visit (HIR::TraitObjectType &type) override; @@ -265,6 +267,7 @@ public: } resolved = new TyTy::ParamType (param.get_type_representation (), + param.get_locus (), param.get_mappings ().get_hirid (), param, specified_bounds); } diff --git a/gcc/rust/typecheck/rust-hir-type-check.cc b/gcc/rust/typecheck/rust-hir-type-check.cc index 5a216a2..6666603 100644 --- a/gcc/rust/typecheck/rust-hir-type-check.cc +++ b/gcc/rust/typecheck/rust-hir-type-check.cc @@ -119,7 +119,8 @@ TypeCheckExpr::visit (HIR::BlockExpr &expr) if (s->is_unit_check_needed () && !resolved->is_unit ()) { - auto unit = new TyTy::TupleType (s->get_mappings ().get_hirid ()); + auto unit + = TyTy::TupleType::get_unit_type (s->get_mappings ().get_hirid ()); resolved = unit->unify (resolved); } } @@ -129,7 +130,8 @@ TypeCheckExpr::visit (HIR::BlockExpr &expr) = TypeCheckExpr::Resolve (expr.get_final_expr ().get (), inside_loop) ->clone (); else if (expr.is_tail_reachable ()) - infered = new TyTy::TupleType (expr.get_mappings ().get_hirid ()); + infered + = TyTy::TupleType::get_unit_type (expr.get_mappings ().get_hirid ()); else infered = new TyTy::NeverType (expr.get_mappings ().get_hirid ()); } @@ -234,7 +236,7 @@ TraitItemReference::get_type_from_fn (/*const*/ HIR::TraitItemFunc &fn) const TyTy::BaseType *ret_type = nullptr; if (!function.has_return_type ()) - ret_type = new TyTy::TupleType (fn.get_mappings ().get_hirid ()); + ret_type = TyTy::TupleType::get_unit_type (fn.get_mappings ().get_hirid ()); else { auto resolved @@ -320,10 +322,19 @@ TraitItemReference::get_type_from_fn (/*const*/ HIR::TraitItemFunc &fn) const context->insert_type (param.get_mappings (), param_tyty); } + auto mappings = Analysis::Mappings::get (); + const CanonicalPath *canonical_path = nullptr; + bool ok + = mappings->lookup_canonical_path (fn.get_mappings ().get_crate_num (), + fn.get_mappings ().get_nodeid (), + &canonical_path); + rust_assert (ok); + + RustIdent ident{*canonical_path, fn.get_locus ()}; auto resolved = new TyTy::FnType (fn.get_mappings ().get_hirid (), fn.get_mappings ().get_defid (), - function.get_function_name (), + function.get_function_name (), ident, function.is_method () ? TyTy::FnType::FNTYPE_IS_METHOD_FLAG : TyTy::FnType::FNTYPE_DEFAULT_FLAGS, diff --git a/gcc/rust/typecheck/rust-hir-type-check.h b/gcc/rust/typecheck/rust-hir-type-check.h index c40c239..49141b3 100644 --- a/gcc/rust/typecheck/rust-hir-type-check.h +++ b/gcc/rust/typecheck/rust-hir-type-check.h @@ -125,10 +125,11 @@ public: } } - void push_new_loop_context (HirId id) + void push_new_loop_context (HirId id, Location locus) { TyTy::BaseType *infer_var - = new TyTy::InferType (id, TyTy::InferType::InferTypeKind::GENERAL); + = new TyTy::InferType (id, TyTy::InferType::InferTypeKind::GENERAL, + locus); loop_type_stack.push_back (infer_var); } diff --git a/gcc/rust/typecheck/rust-tyty-cast.h b/gcc/rust/typecheck/rust-tyty-cast.h index 0658d47..b9f4e14 100644 --- a/gcc/rust/typecheck/rust-tyty-cast.h +++ b/gcc/rust/typecheck/rust-tyty-cast.h @@ -806,9 +806,10 @@ public: return; } - resolved = new ArrayType (type.get_ref (), type.get_ty_ref (), - type.get_capacity_expr (), - TyVar (base_resolved->get_ref ())); + resolved + = new ArrayType (type.get_ref (), type.get_ty_ref (), + type.get_ident ().locus, type.get_capacity_expr (), + TyVar (base_resolved->get_ref ())); } private: @@ -1063,8 +1064,8 @@ public: fields.push_back (TyVar (unified_ty->get_ref ())); } - resolved - = new TyTy::TupleType (type.get_ref (), type.get_ty_ref (), fields); + resolved = new TyTy::TupleType (type.get_ref (), type.get_ty_ref (), + type.get_ident ().locus, fields); } private: diff --git a/gcc/rust/typecheck/rust-tyty-coercion.h b/gcc/rust/typecheck/rust-tyty-coercion.h index 8d5aa3e..75913f0 100644 --- a/gcc/rust/typecheck/rust-tyty-coercion.h +++ b/gcc/rust/typecheck/rust-tyty-coercion.h @@ -824,9 +824,10 @@ public: return; } - resolved = new ArrayType (type.get_ref (), type.get_ty_ref (), - type.get_capacity_expr (), - TyVar (base_resolved->get_ref ())); + resolved + = new ArrayType (type.get_ref (), type.get_ty_ref (), + type.get_ident ().locus, type.get_capacity_expr (), + TyVar (base_resolved->get_ref ())); } private: @@ -1071,8 +1072,8 @@ public: fields.push_back (TyVar (unified_ty->get_ref ())); } - resolved - = new TyTy::TupleType (type.get_ref (), type.get_ty_ref (), fields); + resolved = new TyTy::TupleType (type.get_ref (), type.get_ty_ref (), + type.get_ident ().locus, fields); } private: diff --git a/gcc/rust/typecheck/rust-tyty-rules.h b/gcc/rust/typecheck/rust-tyty-rules.h index e662684..906e33d 100644 --- a/gcc/rust/typecheck/rust-tyty-rules.h +++ b/gcc/rust/typecheck/rust-tyty-rules.h @@ -838,9 +838,10 @@ public: return; } - resolved = new ArrayType (type.get_ref (), type.get_ty_ref (), - type.get_capacity_expr (), - TyVar (base_resolved->get_ref ())); + resolved + = new ArrayType (type.get_ref (), type.get_ty_ref (), + type.get_ident ().locus, type.get_capacity_expr (), + TyVar (base_resolved->get_ref ())); } private: @@ -1083,8 +1084,8 @@ public: fields.push_back (TyVar (unified_ty->get_ref ())); } - resolved - = new TyTy::TupleType (type.get_ref (), type.get_ty_ref (), fields); + resolved = new TyTy::TupleType (type.get_ref (), type.get_ty_ref (), + type.get_ident ().locus, fields); } private: diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc index d064ba3..6a65923 100644 --- a/gcc/rust/typecheck/rust-tyty.cc +++ b/gcc/rust/typecheck/rust-tyty.cc @@ -159,7 +159,7 @@ TyVar::get_implicit_infer_var (Location locus) auto context = Resolver::TypeCheckContext::get (); InferType *infer = new InferType (mappings->get_next_hir_id (), - InferType::InferTypeKind::GENERAL); + InferType::InferTypeKind::GENERAL, locus); context->insert_type (Analysis::NodeMapping (mappings->get_current_crate (), UNKNOWN_NODEID, infer->get_ref (), @@ -229,7 +229,7 @@ BaseType * InferType::clone () const { return new InferType (get_ref (), get_ty_ref (), get_infer_kind (), - get_combined_refs ()); + get_ident ().locus, get_combined_refs ()); } bool @@ -316,14 +316,14 @@ StructFieldType::is_equal (const StructFieldType &other) const { bool names_eq = get_name ().compare (other.get_name ()) == 0; - TyTy::BaseType &o = *other.get_field_type (); - if (o.get_kind () == TypeKind::PARAM) + TyTy::BaseType *o = other.get_field_type (); + if (o->get_kind () == TypeKind::PARAM) { - ParamType &op = static_cast<ParamType &> (o); - o = *op.resolve (); + ParamType *op = static_cast<ParamType *> (o); + o = op->resolve (); } - bool types_eq = get_field_type ()->is_equal (o); + bool types_eq = get_field_type ()->is_equal (*o); return names_eq && types_eq; } @@ -749,9 +749,9 @@ ADTType::clone () const for (auto &variant : variants) cloned_variants.push_back (variant->clone ()); - return new ADTType (get_ref (), get_ty_ref (), identifier, get_adt_kind (), - cloned_variants, clone_substs (), used_arguments, - get_combined_refs ()); + return new ADTType (get_ref (), get_ty_ref (), identifier, ident, + get_adt_kind (), cloned_variants, clone_substs (), + used_arguments, get_combined_refs ()); } static bool @@ -916,7 +916,7 @@ TupleType::is_equal (const BaseType &other) const BaseType * TupleType::clone () const { - return new TupleType (get_ref (), get_ty_ref (), fields, + return new TupleType (get_ref (), get_ty_ref (), get_ident ().locus, fields, get_combined_refs ()); } @@ -1043,7 +1043,7 @@ FnType::clone () const std::pair<HIR::Pattern *, BaseType *> (p.first, p.second->clone ())); return new FnType (get_ref (), get_ty_ref (), get_id (), get_identifier (), - flags, abi, std::move (cloned_params), + ident, flags, abi, std::move (cloned_params), get_return_type ()->clone (), clone_substs (), get_combined_refs ()); } @@ -1246,8 +1246,9 @@ FnPtr::clone () const for (auto &p : params) cloned_params.push_back (TyVar (p.get_ref ())); - return new FnPtr (get_ref (), get_ty_ref (), std::move (cloned_params), - result_type, get_combined_refs ()); + return new FnPtr (get_ref (), get_ty_ref (), ident.locus, + std::move (cloned_params), result_type, + get_combined_refs ()); } void @@ -1306,7 +1307,7 @@ ClosureType::is_equal (const BaseType &other) const BaseType * ClosureType::clone () const { - return new ClosureType (get_ref (), get_ty_ref (), id, parameter_types, + return new ClosureType (get_ref (), get_ty_ref (), ident, id, parameter_types, result_type, clone_substs (), get_combined_refs ()); } @@ -1386,8 +1387,8 @@ ArrayType::get_element_type () const BaseType * ArrayType::clone () const { - return new ArrayType (get_ref (), get_ty_ref (), capacity_expr, element_type, - get_combined_refs ()); + return new ArrayType (get_ref (), get_ty_ref (), ident.locus, capacity_expr, + element_type, get_combined_refs ()); } void @@ -2068,8 +2069,8 @@ ParamType::can_eq (const BaseType *other, bool emit_errors) const BaseType * ParamType::clone () const { - return new ParamType (get_symbol (), get_ref (), get_ty_ref (), param, - get_specified_bounds (), get_combined_refs ()); + return new ParamType (get_symbol (), ident.locus, get_ref (), get_ty_ref (), + param, get_specified_bounds (), get_combined_refs ()); } std::string @@ -2516,8 +2517,8 @@ DynamicObjectType::cast (BaseType *other) BaseType * DynamicObjectType::clone () const { - return new DynamicObjectType (get_ref (), get_ty_ref (), specified_bounds, - get_combined_refs ()); + return new DynamicObjectType (get_ref (), get_ty_ref (), ident, + specified_bounds, get_combined_refs ()); } std::string diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h index 6f392b0..6c9daf7 100644 --- a/gcc/rust/typecheck/rust-tyty.h +++ b/gcc/rust/typecheck/rust-tyty.h @@ -24,6 +24,7 @@ #include "rust-diagnostics.h" #include "rust-abi.h" #include "rust-common.h" +#include "rust-identifier.h" namespace Rust { @@ -393,24 +394,30 @@ public: const BaseType *get_root () const; + const RustIdent &get_ident () const { return ident; } + + Location get_locus () const { return ident.locus; } + protected: - BaseType (HirId ref, HirId ty_ref, TypeKind kind, + BaseType (HirId ref, HirId ty_ref, TypeKind kind, RustIdent ident, std::set<HirId> refs = std::set<HirId> ()) : TypeBoundsMappings ({}), kind (kind), ref (ref), ty_ref (ty_ref), - combined (refs), mappings (Analysis::Mappings::get ()) + combined (refs), ident (ident), mappings (Analysis::Mappings::get ()) {} - BaseType (HirId ref, HirId ty_ref, TypeKind kind, + BaseType (HirId ref, HirId ty_ref, TypeKind kind, RustIdent ident, std::vector<TypeBoundPredicate> specified_bounds, std::set<HirId> refs = std::set<HirId> ()) : TypeBoundsMappings (specified_bounds), kind (kind), ref (ref), - ty_ref (ty_ref), combined (refs), mappings (Analysis::Mappings::get ()) + ty_ref (ty_ref), combined (refs), ident (ident), + mappings (Analysis::Mappings::get ()) {} TypeKind kind; HirId ref; HirId ty_ref; std::set<HirId> combined; + RustIdent ident; Analysis::Mappings *mappings; }; @@ -441,14 +448,18 @@ public: FLOAT }; - InferType (HirId ref, InferTypeKind infer_kind, + InferType (HirId ref, InferTypeKind infer_kind, Location locus, std::set<HirId> refs = std::set<HirId> ()) - : BaseType (ref, ref, TypeKind::INFER, refs), infer_kind (infer_kind) + : BaseType (ref, ref, TypeKind::INFER, + {Resolver::CanonicalPath::create_empty (), locus}, refs), + infer_kind (infer_kind) {} - InferType (HirId ref, HirId ty_ref, InferTypeKind infer_kind, + InferType (HirId ref, HirId ty_ref, InferTypeKind infer_kind, Location locus, std::set<HirId> refs = std::set<HirId> ()) - : BaseType (ref, ty_ref, TypeKind::INFER, refs), infer_kind (infer_kind) + : BaseType (ref, ty_ref, TypeKind::INFER, + {Resolver::CanonicalPath::create_empty (), locus}, refs), + infer_kind (infer_kind) {} void accept_vis (TyVisitor &vis) override; @@ -481,11 +492,13 @@ class ErrorType : public BaseType { public: ErrorType (HirId ref, std::set<HirId> refs = std::set<HirId> ()) - : BaseType (ref, ref, TypeKind::ERROR, refs) + : BaseType (ref, ref, TypeKind::ERROR, + {Resolver::CanonicalPath::create_empty (), Location ()}, refs) {} ErrorType (HirId ref, HirId ty_ref, std::set<HirId> refs = std::set<HirId> ()) - : BaseType (ref, ty_ref, TypeKind::ERROR, refs) + : BaseType (ref, ty_ref, TypeKind::ERROR, + {Resolver::CanonicalPath::create_empty (), Location ()}, refs) {} void accept_vis (TyVisitor &vis) override; @@ -511,18 +524,25 @@ class SubstitutionArgumentMappings; class ParamType : public BaseType { public: - ParamType (std::string symbol, HirId ref, HIR::GenericParam ¶m, + ParamType (std::string symbol, Location locus, HirId ref, + HIR::GenericParam ¶m, std::vector<TypeBoundPredicate> specified_bounds, std::set<HirId> refs = std::set<HirId> ()) - : BaseType (ref, ref, TypeKind::PARAM, specified_bounds, refs), + : BaseType (ref, ref, TypeKind::PARAM, + {Resolver::CanonicalPath::new_seg (UNKNOWN_NODEID, symbol), + locus}, + specified_bounds, refs), symbol (symbol), param (param) {} - ParamType (std::string symbol, HirId ref, HirId ty_ref, + ParamType (std::string symbol, Location locus, HirId ref, HirId ty_ref, HIR::GenericParam ¶m, std::vector<TypeBoundPredicate> specified_bounds, std::set<HirId> refs = std::set<HirId> ()) - : BaseType (ref, ty_ref, TypeKind::PARAM, specified_bounds, refs), + : BaseType (ref, ty_ref, TypeKind::PARAM, + {Resolver::CanonicalPath::new_seg (UNKNOWN_NODEID, symbol), + locus}, + specified_bounds, refs), symbol (symbol), param (param) {} @@ -600,18 +620,26 @@ private: class TupleType : public BaseType { public: - TupleType (HirId ref, std::vector<TyVar> fields = std::vector<TyVar> (), + TupleType (HirId ref, Location locus, + std::vector<TyVar> fields = std::vector<TyVar> (), std::set<HirId> refs = std::set<HirId> ()) - : BaseType (ref, ref, TypeKind::TUPLE, refs), fields (fields) + : BaseType (ref, ref, TypeKind::TUPLE, + {Resolver::CanonicalPath::create_empty (), locus}, refs), + fields (fields) {} - TupleType (HirId ref, HirId ty_ref, + TupleType (HirId ref, HirId ty_ref, Location locus, std::vector<TyVar> fields = std::vector<TyVar> (), std::set<HirId> refs = std::set<HirId> ()) - : BaseType (ref, ty_ref, TypeKind::TUPLE, refs), fields (fields) + : BaseType (ref, ty_ref, TypeKind::TUPLE, + {Resolver::CanonicalPath::create_empty (), locus}, refs), + fields (fields) {} - static TupleType *get_unit_type (HirId ref) { return new TupleType (ref); } + static TupleType *get_unit_type (HirId ref) + { + return new TupleType (ref, Linemap::predeclared_location ()); + } void accept_vis (TyVisitor &vis) override; void accept_vis (TyConstVisitor &vis) const override; @@ -1027,16 +1055,20 @@ public: return ""; } - VariantDef (HirId id, std::string identifier, HIR::Expr *discriminant) - : id (id), identifier (identifier), discriminant (discriminant) + VariantDef (HirId id, std::string identifier, RustIdent ident, + HIR::Expr *discriminant) + : id (id), identifier (identifier), ident (ident), + discriminant (discriminant) + { type = VariantType::NUM; fields = {}; } - VariantDef (HirId id, std::string identifier, VariantType type, - HIR::Expr *discriminant, std::vector<StructFieldType *> fields) - : id (id), identifier (identifier), type (type), + VariantDef (HirId id, std::string identifier, RustIdent ident, + VariantType type, HIR::Expr *discriminant, + std::vector<StructFieldType *> fields) + : id (id), identifier (identifier), ident (ident), type (type), discriminant (discriminant), fields (fields) { rust_assert ( @@ -1044,9 +1076,32 @@ public: || (type == VariantType::TUPLE || type == VariantType::STRUCT)); } + VariantDef (const VariantDef &other) + : id (other.id), identifier (other.identifier), ident (other.ident), + type (other.type), discriminant (other.discriminant), + fields (other.fields) + {} + + VariantDef &operator= (const VariantDef &other) + { + id = other.id; + identifier = other.identifier; + type = other.type; + discriminant = other.discriminant; + fields = other.fields; + ident = other.ident; + + return *this; + } + static VariantDef &get_error_node () { - static VariantDef node = VariantDef (UNKNOWN_HIRID, "", nullptr); + static VariantDef node + = VariantDef (UNKNOWN_HIRID, "", + {Resolver::CanonicalPath::create_empty (), + Linemap::unknown_location ()}, + nullptr); + return node; } @@ -1063,7 +1118,7 @@ public: size_t num_fields () const { return fields.size (); } StructFieldType *get_field_at_index (size_t index) { - // FIXME this is not safe + rust_assert (index < fields.size ()); return fields.at (index); } @@ -1148,12 +1203,16 @@ public: for (auto &f : fields) cloned_fields.push_back ((StructFieldType *) f->clone ()); - return new VariantDef (id, identifier, type, discriminant, cloned_fields); + return new VariantDef (id, identifier, ident, type, discriminant, + cloned_fields); } + const RustIdent &get_ident () const { return ident; } + private: HirId id; std::string identifier; + RustIdent ident; VariantType type; // can either be a structure or a discriminant value HIR::Expr *discriminant; @@ -1171,24 +1230,24 @@ public: ENUM }; - ADTType (HirId ref, std::string identifier, ADTKind adt_kind, + ADTType (HirId ref, std::string identifier, RustIdent ident, ADTKind adt_kind, std::vector<VariantDef *> variants, std::vector<SubstitutionParamMapping> subst_refs, SubstitutionArgumentMappings generic_arguments = SubstitutionArgumentMappings::error (), std::set<HirId> refs = std::set<HirId> ()) - : BaseType (ref, ref, TypeKind::ADT, refs), + : BaseType (ref, ref, TypeKind::ADT, ident, refs), SubstitutionRef (std::move (subst_refs), std::move (generic_arguments)), identifier (identifier), variants (variants), adt_kind (adt_kind) {} - ADTType (HirId ref, HirId ty_ref, std::string identifier, ADTKind adt_kind, - std::vector<VariantDef *> variants, + ADTType (HirId ref, HirId ty_ref, std::string identifier, RustIdent ident, + ADTKind adt_kind, std::vector<VariantDef *> variants, std::vector<SubstitutionParamMapping> subst_refs, SubstitutionArgumentMappings generic_arguments = SubstitutionArgumentMappings::error (), std::set<HirId> refs = std::set<HirId> ()) - : BaseType (ref, ty_ref, TypeKind::ADT, refs), + : BaseType (ref, ty_ref, TypeKind::ADT, ident, refs), SubstitutionRef (std::move (subst_refs), std::move (generic_arguments)), identifier (identifier), variants (variants), adt_kind (adt_kind) {} @@ -1312,11 +1371,12 @@ public: static const uint8_t FNTYPE_IS_EXTERN_FLAG = 0x02; static const uint8_t FNTYPE_IS_VARADIC_FLAG = 0X04; - FnType (HirId ref, DefId id, std::string identifier, uint8_t flags, ABI abi, + FnType (HirId ref, DefId id, std::string identifier, RustIdent ident, + uint8_t flags, ABI abi, std::vector<std::pair<HIR::Pattern *, BaseType *>> params, BaseType *type, std::vector<SubstitutionParamMapping> subst_refs, std::set<HirId> refs = std::set<HirId> ()) - : BaseType (ref, ref, TypeKind::FNDEF, refs), + : BaseType (ref, ref, TypeKind::FNDEF, ident, refs), SubstitutionRef (std::move (subst_refs), SubstitutionArgumentMappings::error ()), params (std::move (params)), type (type), flags (flags), @@ -1327,11 +1387,11 @@ public: } FnType (HirId ref, HirId ty_ref, DefId id, std::string identifier, - uint8_t flags, ABI abi, + RustIdent ident, uint8_t flags, ABI abi, std::vector<std::pair<HIR::Pattern *, BaseType *>> params, BaseType *type, std::vector<SubstitutionParamMapping> subst_refs, std::set<HirId> refs = std::set<HirId> ()) - : BaseType (ref, ty_ref, TypeKind::FNDEF, refs), + : BaseType (ref, ty_ref, TypeKind::FNDEF, ident, refs), SubstitutionRef (std::move (subst_refs), SubstitutionArgumentMappings::error ()), params (params), type (type), flags (flags), identifier (identifier), @@ -1444,16 +1504,18 @@ private: class FnPtr : public BaseType { public: - FnPtr (HirId ref, std::vector<TyVar> params, TyVar result_type, - std::set<HirId> refs = std::set<HirId> ()) - : BaseType (ref, ref, TypeKind::FNPTR, refs), params (std::move (params)), - result_type (result_type) + FnPtr (HirId ref, Location locus, std::vector<TyVar> params, + TyVar result_type, std::set<HirId> refs = std::set<HirId> ()) + : BaseType (ref, ref, TypeKind::FNPTR, + {Resolver::CanonicalPath::create_empty (), locus}, refs), + params (std::move (params)), result_type (result_type) {} - FnPtr (HirId ref, HirId ty_ref, std::vector<TyVar> params, TyVar result_type, - std::set<HirId> refs = std::set<HirId> ()) - : BaseType (ref, ty_ref, TypeKind::FNPTR, refs), params (params), - result_type (result_type) + FnPtr (HirId ref, HirId ty_ref, Location locus, std::vector<TyVar> params, + TyVar result_type, std::set<HirId> refs = std::set<HirId> ()) + : BaseType (ref, ty_ref, TypeKind::FNPTR, + {Resolver::CanonicalPath::create_empty (), locus}, refs), + params (params), result_type (result_type) {} std::string get_name () const override final { return as_string (); } @@ -1505,11 +1567,11 @@ private: class ClosureType : public BaseType, public SubstitutionRef { public: - ClosureType (HirId ref, DefId id, std::vector<TyVar> parameter_types, - TyVar result_type, + ClosureType (HirId ref, DefId id, RustIdent ident, + std::vector<TyVar> parameter_types, TyVar result_type, std::vector<SubstitutionParamMapping> subst_refs, std::set<HirId> refs = std::set<HirId> ()) - : BaseType (ref, ref, TypeKind::CLOSURE, refs), + : BaseType (ref, ref, TypeKind::CLOSURE, ident, refs), SubstitutionRef (std::move (subst_refs), SubstitutionArgumentMappings::error ()), parameter_types (std::move (parameter_types)), @@ -1519,11 +1581,11 @@ public: rust_assert (local_def_id != UNKNOWN_LOCAL_DEFID); } - ClosureType (HirId ref, HirId ty_ref, DefId id, + ClosureType (HirId ref, HirId ty_ref, RustIdent ident, DefId id, std::vector<TyVar> parameter_types, TyVar result_type, std::vector<SubstitutionParamMapping> subst_refs, std::set<HirId> refs = std::set<HirId> ()) - : BaseType (ref, ty_ref, TypeKind::CLOSURE, refs), + : BaseType (ref, ty_ref, TypeKind::CLOSURE, ident, refs), SubstitutionRef (std::move (subst_refs), SubstitutionArgumentMappings::error ()), parameter_types (std::move (parameter_types)), @@ -1583,16 +1645,18 @@ private: class ArrayType : public BaseType { public: - ArrayType (HirId ref, HIR::Expr &capacity_expr, TyVar base, + ArrayType (HirId ref, Location locus, HIR::Expr &capacity_expr, TyVar base, std::set<HirId> refs = std::set<HirId> ()) - : BaseType (ref, ref, TypeKind::ARRAY, refs), element_type (base), - capacity_expr (capacity_expr) + : BaseType (ref, ref, TypeKind::ARRAY, + {Resolver::CanonicalPath::create_empty (), locus}, refs), + element_type (base), capacity_expr (capacity_expr) {} - ArrayType (HirId ref, HirId ty_ref, HIR::Expr &capacity_expr, TyVar base, - std::set<HirId> refs = std::set<HirId> ()) - : BaseType (ref, ty_ref, TypeKind::ARRAY, refs), element_type (base), - capacity_expr (capacity_expr) + ArrayType (HirId ref, HirId ty_ref, Location locus, HIR::Expr &capacity_expr, + TyVar base, std::set<HirId> refs = std::set<HirId> ()) + : BaseType (ref, ty_ref, TypeKind::ARRAY, + {Resolver::CanonicalPath::create_empty (), locus}, refs), + element_type (base), capacity_expr (capacity_expr) {} void accept_vis (TyVisitor &vis) override; @@ -1629,11 +1693,17 @@ class BoolType : public BaseType { public: BoolType (HirId ref, std::set<HirId> refs = std::set<HirId> ()) - : BaseType (ref, ref, TypeKind::BOOL, refs) + : BaseType (ref, ref, TypeKind::BOOL, + {Resolver::CanonicalPath::create_empty (), + Linemap::predeclared_location ()}, + refs) {} BoolType (HirId ref, HirId ty_ref, std::set<HirId> refs = std::set<HirId> ()) - : BaseType (ref, ty_ref, TypeKind::BOOL, refs) + : BaseType (ref, ty_ref, TypeKind::BOOL, + {Resolver::CanonicalPath::create_empty (), + Linemap::predeclared_location ()}, + refs) {} void accept_vis (TyVisitor &vis) override; @@ -1665,12 +1735,20 @@ public: }; IntType (HirId ref, IntKind kind, std::set<HirId> refs = std::set<HirId> ()) - : BaseType (ref, ref, TypeKind::INT, refs), int_kind (kind) + : BaseType (ref, ref, TypeKind::INT, + {Resolver::CanonicalPath::create_empty (), + Linemap::predeclared_location ()}, + refs), + int_kind (kind) {} IntType (HirId ref, HirId ty_ref, IntKind kind, std::set<HirId> refs = std::set<HirId> ()) - : BaseType (ref, ty_ref, TypeKind::INT, refs), int_kind (kind) + : BaseType (ref, ty_ref, TypeKind::INT, + {Resolver::CanonicalPath::create_empty (), + Linemap::predeclared_location ()}, + refs), + int_kind (kind) {} void accept_vis (TyVisitor &vis) override; @@ -1709,12 +1787,20 @@ public: }; UintType (HirId ref, UintKind kind, std::set<HirId> refs = std::set<HirId> ()) - : BaseType (ref, ref, TypeKind::UINT, refs), uint_kind (kind) + : BaseType (ref, ref, TypeKind::UINT, + {Resolver::CanonicalPath::create_empty (), + Linemap::predeclared_location ()}, + refs), + uint_kind (kind) {} UintType (HirId ref, HirId ty_ref, UintKind kind, std::set<HirId> refs = std::set<HirId> ()) - : BaseType (ref, ty_ref, TypeKind::UINT, refs), uint_kind (kind) + : BaseType (ref, ty_ref, TypeKind::UINT, + {Resolver::CanonicalPath::create_empty (), + Linemap::predeclared_location ()}, + refs), + uint_kind (kind) {} void accept_vis (TyVisitor &vis) override; @@ -1751,12 +1837,20 @@ public: FloatType (HirId ref, FloatKind kind, std::set<HirId> refs = std::set<HirId> ()) - : BaseType (ref, ref, TypeKind::FLOAT, refs), float_kind (kind) + : BaseType (ref, ref, TypeKind::FLOAT, + {Resolver::CanonicalPath::create_empty (), + Linemap::predeclared_location ()}, + refs), + float_kind (kind) {} FloatType (HirId ref, HirId ty_ref, FloatKind kind, std::set<HirId> refs = std::set<HirId> ()) - : BaseType (ref, ty_ref, TypeKind::FLOAT, refs), float_kind (kind) + : BaseType (ref, ty_ref, TypeKind::FLOAT, + {Resolver::CanonicalPath::create_empty (), + Linemap::predeclared_location ()}, + refs), + float_kind (kind) {} void accept_vis (TyVisitor &vis) override; @@ -1786,11 +1880,17 @@ class USizeType : public BaseType { public: USizeType (HirId ref, std::set<HirId> refs = std::set<HirId> ()) - : BaseType (ref, ref, TypeKind::USIZE, refs) + : BaseType (ref, ref, TypeKind::USIZE, + {Resolver::CanonicalPath::create_empty (), + Linemap::predeclared_location ()}, + refs) {} USizeType (HirId ref, HirId ty_ref, std::set<HirId> refs = std::set<HirId> ()) - : BaseType (ref, ty_ref, TypeKind::USIZE, refs) + : BaseType (ref, ty_ref, TypeKind::USIZE, + {Resolver::CanonicalPath::create_empty (), + Linemap::predeclared_location ()}, + refs) {} void accept_vis (TyVisitor &vis) override; @@ -1813,11 +1913,17 @@ class ISizeType : public BaseType { public: ISizeType (HirId ref, std::set<HirId> refs = std::set<HirId> ()) - : BaseType (ref, ref, TypeKind::ISIZE, refs) + : BaseType (ref, ref, TypeKind::ISIZE, + {Resolver::CanonicalPath::create_empty (), + Linemap::predeclared_location ()}, + refs) {} ISizeType (HirId ref, HirId ty_ref, std::set<HirId> refs = std::set<HirId> ()) - : BaseType (ref, ty_ref, TypeKind::ISIZE, refs) + : BaseType (ref, ty_ref, TypeKind::ISIZE, + {Resolver::CanonicalPath::create_empty (), + Linemap::predeclared_location ()}, + refs) {} void accept_vis (TyVisitor &vis) override; @@ -1840,11 +1946,17 @@ class CharType : public BaseType { public: CharType (HirId ref, std::set<HirId> refs = std::set<HirId> ()) - : BaseType (ref, ref, TypeKind::CHAR, refs) + : BaseType (ref, ref, TypeKind::CHAR, + {Resolver::CanonicalPath::create_empty (), + Linemap::predeclared_location ()}, + refs) {} CharType (HirId ref, HirId ty_ref, std::set<HirId> refs = std::set<HirId> ()) - : BaseType (ref, ty_ref, TypeKind::CHAR, refs) + : BaseType (ref, ty_ref, TypeKind::CHAR, + {Resolver::CanonicalPath::create_empty (), + Linemap::predeclared_location ()}, + refs) {} void accept_vis (TyVisitor &vis) override; @@ -1868,12 +1980,20 @@ class ReferenceType : public BaseType public: ReferenceType (HirId ref, TyVar base, Mutability mut, std::set<HirId> refs = std::set<HirId> ()) - : BaseType (ref, ref, TypeKind::REF, refs), base (base), mut (mut) + : BaseType (ref, ref, TypeKind::REF, + {Resolver::CanonicalPath::create_empty (), + Linemap::predeclared_location ()}, + refs), + base (base), mut (mut) {} ReferenceType (HirId ref, HirId ty_ref, TyVar base, Mutability mut, std::set<HirId> refs = std::set<HirId> ()) - : BaseType (ref, ty_ref, TypeKind::REF, refs), base (base), mut (mut) + : BaseType (ref, ty_ref, TypeKind::REF, + {Resolver::CanonicalPath::create_empty (), + Linemap::predeclared_location ()}, + refs), + base (base), mut (mut) {} BaseType *get_base () const; @@ -1918,12 +2038,20 @@ class PointerType : public BaseType public: PointerType (HirId ref, TyVar base, Mutability mut, std::set<HirId> refs = std::set<HirId> ()) - : BaseType (ref, ref, TypeKind::POINTER, refs), base (base), mut (mut) + : BaseType (ref, ref, TypeKind::POINTER, + {Resolver::CanonicalPath::create_empty (), + Linemap::predeclared_location ()}, + refs), + base (base), mut (mut) {} PointerType (HirId ref, HirId ty_ref, TyVar base, Mutability mut, std::set<HirId> refs = std::set<HirId> ()) - : BaseType (ref, ty_ref, TypeKind::POINTER, refs), base (base), mut (mut) + : BaseType (ref, ty_ref, TypeKind::POINTER, + {Resolver::CanonicalPath::create_empty (), + Linemap::predeclared_location ()}, + refs), + base (base), mut (mut) {} BaseType *get_base () const; @@ -1969,11 +2097,17 @@ class StrType : public BaseType { public: StrType (HirId ref, std::set<HirId> refs = std::set<HirId> ()) - : BaseType (ref, ref, TypeKind::STR, refs) + : BaseType (ref, ref, TypeKind::STR, + {Resolver::CanonicalPath::create_empty (), + Linemap::predeclared_location ()}, + refs) {} StrType (HirId ref, HirId ty_ref, std::set<HirId> refs = std::set<HirId> ()) - : BaseType (ref, ty_ref, TypeKind::STR, refs) + : BaseType (ref, ty_ref, TypeKind::STR, + {Resolver::CanonicalPath::create_empty (), + Linemap::predeclared_location ()}, + refs) {} std::string get_name () const override final { return as_string (); } @@ -2008,11 +2142,17 @@ class NeverType : public BaseType { public: NeverType (HirId ref, std::set<HirId> refs = std::set<HirId> ()) - : BaseType (ref, ref, TypeKind::NEVER, refs) + : BaseType (ref, ref, TypeKind::NEVER, + {Resolver::CanonicalPath::create_empty (), + Linemap::predeclared_location ()}, + refs) {} NeverType (HirId ref, HirId ty_ref, std::set<HirId> refs = std::set<HirId> ()) - : BaseType (ref, ty_ref, TypeKind::NEVER, refs) + : BaseType (ref, ty_ref, TypeKind::NEVER, + {Resolver::CanonicalPath::create_empty (), + Linemap::predeclared_location ()}, + refs) {} void accept_vis (TyVisitor &vis) override; @@ -2040,13 +2180,20 @@ class PlaceholderType : public BaseType public: PlaceholderType (std::string symbol, HirId ref, std::set<HirId> refs = std::set<HirId> ()) - : BaseType (ref, ref, TypeKind::PLACEHOLDER, refs), symbol (symbol) - + : BaseType (ref, ref, TypeKind::PLACEHOLDER, + {Resolver::CanonicalPath::create_empty (), + Linemap::predeclared_location ()}, + refs), + symbol (symbol) {} PlaceholderType (std::string symbol, HirId ref, HirId ty_ref, std::set<HirId> refs = std::set<HirId> ()) - : BaseType (ref, ty_ref, TypeKind::PLACEHOLDER, refs), symbol (symbol) + : BaseType (ref, ty_ref, TypeKind::PLACEHOLDER, + {Resolver::CanonicalPath::create_empty (), + Linemap::predeclared_location ()}, + refs), + symbol (symbol) {} void accept_vis (TyVisitor &vis) override; @@ -2101,7 +2248,10 @@ public: SubstitutionArgumentMappings generic_arguments = SubstitutionArgumentMappings::error (), std::set<HirId> refs = std::set<HirId> ()) - : BaseType (ref, ref, TypeKind::PROJECTION, refs), + : BaseType (ref, ref, TypeKind::PROJECTION, + {Resolver::CanonicalPath::create_empty (), + Linemap::predeclared_location ()}, + refs), SubstitutionRef (std::move (subst_refs), std::move (generic_arguments)), base (base), trait (trait), item (item) {} @@ -2112,7 +2262,10 @@ public: SubstitutionArgumentMappings generic_arguments = SubstitutionArgumentMappings::error (), std::set<HirId> refs = std::set<HirId> ()) - : BaseType (ref, ty_ref, TypeKind::PROJECTION, refs), + : BaseType (ref, ty_ref, TypeKind::PROJECTION, + {Resolver::CanonicalPath::create_empty (), + Linemap::predeclared_location ()}, + refs), SubstitutionRef (std::move (subst_refs), std::move (generic_arguments)), base (base), trait (trait), item (item) {} @@ -2162,16 +2315,16 @@ private: class DynamicObjectType : public BaseType { public: - DynamicObjectType (HirId ref, + DynamicObjectType (HirId ref, RustIdent ident, std::vector<TypeBoundPredicate> specified_bounds, std::set<HirId> refs = std::set<HirId> ()) - : BaseType (ref, ref, TypeKind::DYNAMIC, specified_bounds, refs) + : BaseType (ref, ref, TypeKind::DYNAMIC, ident, specified_bounds, refs) {} - DynamicObjectType (HirId ref, HirId ty_ref, + DynamicObjectType (HirId ref, HirId ty_ref, RustIdent ident, std::vector<TypeBoundPredicate> specified_bounds, std::set<HirId> refs = std::set<HirId> ()) - : BaseType (ref, ty_ref, TypeKind::DYNAMIC, specified_bounds, refs) + : BaseType (ref, ty_ref, TypeKind::DYNAMIC, ident, specified_bounds, refs) {} void accept_vis (TyVisitor &vis) override; diff --git a/gcc/rust/util/rust-identifier.h b/gcc/rust/util/rust-identifier.h new file mode 100644 index 0000000..0b5cb70 --- /dev/null +++ b/gcc/rust/util/rust-identifier.h @@ -0,0 +1,49 @@ +// Copyright (C) 2020-2022 Free Software Foundation, Inc. + +// This file is part of GCC. + +// GCC is free software; you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation; either version 3, or (at your option) any later +// version. + +// GCC is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. + +// You should have received a copy of the GNU General Public License +// along with GCC; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#ifndef RUST_IDENTIFIER +#define RUST_IDENTIFIER + +#include "rust-canonical-path.h" +#include "rust-location.h" + +namespace Rust { + +struct RustIdent +{ + Resolver::CanonicalPath path; + Location locus; + + RustIdent (const Resolver::CanonicalPath &path, Location locus) + : path (path), locus (locus) + {} + + RustIdent (const RustIdent &other) : path (other.path), locus (other.locus) {} + + RustIdent &operator= (const RustIdent &other) + { + path = other.path; + locus = other.locus; + + return *this; + } +}; + +} // namespace Rust + +#endif // RUST_IDENTIFIER diff --git a/gcc/testsuite/rust/compile/torture/struct_decl.rs b/gcc/testsuite/rust/compile/torture/struct_decl.rs index 3966928..965666e 100644 --- a/gcc/testsuite/rust/compile/torture/struct_decl.rs +++ b/gcc/testsuite/rust/compile/torture/struct_decl.rs @@ -1,14 +1,14 @@ // { dg-additional-options -fdump-tree-gimple } struct Foo { - a: u16, -// { dg-warning "field is never read" "" { target *-*-* } .-1 } - b: u8, -// { dg-warning "field is never read" "" { target *-*-* } .-1 } + a: u16, + // { dg-warning "field is never read" "" { target *-*-* } .-1 } + b: u8, + // { dg-warning "field is never read" "" { target *-*-* } .-1 } } fn main() { - let my_foo = Foo { a: 1, b: 2 }; - // { dg-warning "unused name" "" { target *-*-* } .-1 } - // { dg-final { scan-tree-dump-times {(?n)const struct Foo my_foo;$} 1 gimple } } + let my_foo = Foo { a: 1, b: 2 }; + // { dg-warning "unused name" "" { target *-*-* } .-1 } + // { dg-final { scan-tree-dump-times {(?n)const struct example::Foo my_foo;$} 1 gimple } } } |