Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nr2 unit struct #3299

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions gcc/rust/backend/rust-compile-item.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,13 @@ class CompileItem : private HIRCompileBase, protected HIR::HIRStmtVisitor
public:
static tree compile (HIR::Item *item, Context *ctx,
TyTy::BaseType *concrete = nullptr,
bool is_query_mode = false,
location_t ref_locus = UNDEF_LOCATION)
{
CompileItem compiler (ctx, concrete, ref_locus);
item->accept_vis (compiler);

if (is_query_mode && compiler.reference == error_mark_node)
rust_internal_error_at (ref_locus, "failed to compile item: %s",
item->as_string ().c_str ());
if (compiler.reference == error_mark_node)
rust_debug ("failed to compile item: %s", item->as_string ().c_str ());

return compiler.reference;
}
Expand Down
6 changes: 2 additions & 4 deletions gcc/rust/backend/rust-compile-resolve-path.cc
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,9 @@ HIRCompileBase::query_compile (HirId ref, TyTy::BaseType *lookup,
if (auto resolved_item = ctx->get_mappings ().lookup_hir_item (ref))
{
if (!lookup->has_substitutions_defined ())
return CompileItem::compile (*resolved_item, ctx, nullptr, true,
expr_locus);
return CompileItem::compile (*resolved_item, ctx, nullptr, expr_locus);
else
return CompileItem::compile (*resolved_item, ctx, lookup, true,
expr_locus);
return CompileItem::compile (*resolved_item, ctx, lookup, expr_locus);
}
else if (auto hir_extern_item
= ctx->get_mappings ().lookup_hir_extern_item (ref))
Expand Down
6 changes: 4 additions & 2 deletions gcc/rust/hir/rust-hir-dump.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2254,8 +2254,10 @@ Dump::visit (LetStmt &e)

put_field ("variable_pattern", e.get_pattern ().as_string ());

visit_field ("type", e.get_type ());
visit_field ("init_expr", e.get_init_expr ());
if (e.has_type ())
visit_field ("type", e.get_type ());
if (e.has_init_expr ())
visit_field ("init_expr", e.get_init_expr ());

end ("LetStmt");
}
Expand Down
14 changes: 7 additions & 7 deletions gcc/rust/resolve/rust-ast-resolve-expr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ ResolveExpr::visit (AST::IfLetExpr &expr)
resolver->get_label_scope ().push (scope_node_id);
resolver->push_new_name_rib (resolver->get_name_scope ().peek ());
resolver->push_new_type_rib (resolver->get_type_scope ().peek ());
resolver->push_new_label_rib (resolver->get_type_scope ().peek ());
resolver->push_new_label_rib (resolver->get_label_scope ().peek ());

// We know expr.get_patterns () has one pattern at most
// so there's no reason to handle it like an AltPattern.
Expand Down Expand Up @@ -278,7 +278,7 @@ ResolveExpr::visit (AST::IfLetExprConseqElse &expr)
resolver->get_label_scope ().push (scope_node_id);
resolver->push_new_name_rib (resolver->get_name_scope ().peek ());
resolver->push_new_type_rib (resolver->get_type_scope ().peek ());
resolver->push_new_label_rib (resolver->get_type_scope ().peek ());
resolver->push_new_label_rib (resolver->get_label_scope ().peek ());

// We know expr.get_patterns () has one pattern at most
// so there's no reason to handle it like an AltPattern.
Expand Down Expand Up @@ -307,7 +307,7 @@ ResolveExpr::visit (AST::BlockExpr &expr)
resolver->get_label_scope ().push (scope_node_id);
resolver->push_new_name_rib (resolver->get_name_scope ().peek ());
resolver->push_new_type_rib (resolver->get_type_scope ().peek ());
resolver->push_new_label_rib (resolver->get_type_scope ().peek ());
resolver->push_new_label_rib (resolver->get_label_scope ().peek ());

if (expr.has_label ())
{
Expand Down Expand Up @@ -615,7 +615,7 @@ ResolveExpr::visit (AST::ForLoopExpr &expr)
resolver->get_label_scope ().push (scope_node_id);
resolver->push_new_name_rib (resolver->get_name_scope ().peek ());
resolver->push_new_type_rib (resolver->get_type_scope ().peek ());
resolver->push_new_label_rib (resolver->get_type_scope ().peek ());
resolver->push_new_label_rib (resolver->get_label_scope ().peek ());

// resolve the expression
PatternDeclaration::go (expr.get_pattern (), Rib::ItemType::Var);
Expand Down Expand Up @@ -681,7 +681,7 @@ ResolveExpr::visit (AST::MatchExpr &expr)
resolver->get_label_scope ().push (scope_node_id);
resolver->push_new_name_rib (resolver->get_name_scope ().peek ());
resolver->push_new_type_rib (resolver->get_type_scope ().peek ());
resolver->push_new_label_rib (resolver->get_type_scope ().peek ());
resolver->push_new_label_rib (resolver->get_label_scope ().peek ());

// resolve
AST::MatchArm &arm = match_case.get_arm ();
Expand Down Expand Up @@ -750,7 +750,7 @@ ResolveExpr::visit (AST::ClosureExprInner &expr)
resolver->get_label_scope ().push (scope_node_id);
resolver->push_new_name_rib (resolver->get_name_scope ().peek ());
resolver->push_new_type_rib (resolver->get_type_scope ().peek ());
resolver->push_new_label_rib (resolver->get_type_scope ().peek ());
resolver->push_new_label_rib (resolver->get_label_scope ().peek ());

std::vector<PatternBinding> bindings
= {PatternBinding (PatternBoundCtx::Product, std::set<Identifier> ())};
Expand Down Expand Up @@ -780,7 +780,7 @@ ResolveExpr::visit (AST::ClosureExprInnerTyped &expr)
resolver->get_label_scope ().push (scope_node_id);
resolver->push_new_name_rib (resolver->get_name_scope ().peek ());
resolver->push_new_type_rib (resolver->get_type_scope ().peek ());
resolver->push_new_label_rib (resolver->get_type_scope ().peek ());
resolver->push_new_label_rib (resolver->get_label_scope ().peek ());

std::vector<PatternBinding> bindings
= {PatternBinding (PatternBoundCtx::Product, std::set<Identifier> ())};
Expand Down
10 changes: 5 additions & 5 deletions gcc/rust/resolve/rust-ast-resolve-item.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ ResolveTraitItems::visit (AST::Function &function)
resolver->get_label_scope ().push (scope_node_id);
resolver->push_new_name_rib (resolver->get_name_scope ().peek ());
resolver->push_new_type_rib (resolver->get_type_scope ().peek ());
resolver->push_new_label_rib (resolver->get_type_scope ().peek ());
resolver->push_new_label_rib (resolver->get_label_scope ().peek ());

if (function.has_generics ())
for (auto &generic : function.get_generic_params ())
Expand Down Expand Up @@ -216,7 +216,7 @@ ResolveItem::visit (AST::Module &module)
resolver->get_label_scope ().push (scope_node_id);
resolver->push_new_name_rib (resolver->get_name_scope ().peek ());
resolver->push_new_type_rib (resolver->get_type_scope ().peek ());
resolver->push_new_label_rib (resolver->get_type_scope ().peek ());
resolver->push_new_label_rib (resolver->get_label_scope ().peek ());

// FIXME: Should we reinsert a child here? Any reason we ResolveTopLevel::go
// in ResolveTopLevel::visit (AST::Module) as well as here?
Expand Down Expand Up @@ -473,7 +473,7 @@ ResolveItem::visit (AST::Function &function)
resolver->get_label_scope ().push (scope_node_id);
resolver->push_new_name_rib (resolver->get_name_scope ().peek ());
resolver->push_new_type_rib (resolver->get_type_scope ().peek ());
resolver->push_new_label_rib (resolver->get_type_scope ().peek ());
resolver->push_new_label_rib (resolver->get_label_scope ().peek ());

if (function.has_generics ())
for (auto &generic : function.get_generic_params ())
Expand Down Expand Up @@ -641,7 +641,7 @@ ResolveItem::visit (AST::TraitImpl &impl_block)
resolver->get_label_scope ().push (scope_node_id);
resolver->push_new_name_rib (resolver->get_name_scope ().peek ());
resolver->push_new_type_rib (resolver->get_type_scope ().peek ());
resolver->push_new_label_rib (resolver->get_type_scope ().peek ());
resolver->push_new_label_rib (resolver->get_label_scope ().peek ());

if (impl_block.has_generics ())
for (auto &generic : impl_block.get_generic_params ())
Expand Down Expand Up @@ -1019,7 +1019,7 @@ ResolveExternItem::visit (AST::Function &function)
resolver->get_label_scope ().push (scope_node_id);
resolver->push_new_name_rib (resolver->get_name_scope ().peek ());
resolver->push_new_type_rib (resolver->get_type_scope ().peek ());
resolver->push_new_label_rib (resolver->get_type_scope ().peek ());
resolver->push_new_label_rib (resolver->get_label_scope ().peek ());

// resolve the generics
if (function.has_generics ())
Expand Down
2 changes: 1 addition & 1 deletion gcc/rust/resolve/rust-ast-resolve-stmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ class ResolveStmt : public ResolverBase
resolver->get_label_scope ().push (scope_node_id);
resolver->push_new_name_rib (resolver->get_name_scope ().peek ());
resolver->push_new_type_rib (resolver->get_type_scope ().peek ());
resolver->push_new_label_rib (resolver->get_type_scope ().peek ());
resolver->push_new_label_rib (resolver->get_label_scope ().peek ());

if (function.has_generics ())
for (auto &generic : function.get_generic_params ())
Expand Down
23 changes: 15 additions & 8 deletions gcc/rust/resolve/rust-ast-resolve-toplevel.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,21 @@ class ResolveTopLevel : public ResolverBase
auto path = prefix.append (decl);
auto cpath = canonical_prefix.append (decl);

resolver->get_type_scope ().insert (
path, struct_decl.get_node_id (), struct_decl.get_locus (), false,
Rib::ItemType::Type,
[&] (const CanonicalPath &, NodeId, location_t locus) -> void {
rich_location r (line_table, struct_decl.get_locus ());
r.add_range (locus);
rust_error_at (r, "redefined multiple times");
});
auto duplicate_item
= [&] (const CanonicalPath &, NodeId, location_t locus) -> void {
rich_location r (line_table, struct_decl.get_locus ());
r.add_range (locus);
rust_error_at (r, "redefined multiple times");
};

resolver->get_type_scope ().insert (path, struct_decl.get_node_id (),
struct_decl.get_locus (), false,
Rib::ItemType::Type, duplicate_item);

if (struct_decl.is_unit_struct ())
resolver->get_name_scope ().insert (path, struct_decl.get_node_id (),
struct_decl.get_locus (), false,
Rib::ItemType::Type, duplicate_item);

NodeId current_module = resolver->peek_current_module_scope ();
mappings.insert_module_child_item (current_module, decl);
Expand Down
2 changes: 1 addition & 1 deletion gcc/rust/resolve/rust-ast-resolve.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ NameResolution::go (AST::Crate &crate)
resolver->get_label_scope ().push (scope_node_id);
resolver->push_new_name_rib (resolver->get_name_scope ().peek ());
resolver->push_new_type_rib (resolver->get_type_scope ().peek ());
resolver->push_new_label_rib (resolver->get_type_scope ().peek ());
resolver->push_new_label_rib (resolver->get_label_scope ().peek ());

// get the root segment
CanonicalPath crate_prefix
Expand Down
35 changes: 35 additions & 0 deletions gcc/rust/resolve/rust-name-resolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,41 @@ class Resolver
void insert_captured_item (NodeId id);
const std::set<NodeId> &get_captures (NodeId id) const;

std::string as_debug_string () const
{
std::stringstream ss;

ss << "Names:\n";
for (auto &n : name_ribs)
{
ss << "\tNodeID: " << n.first << " Rib: " << n.second->debug_str ()
<< "\n";
}
ss << "Types:\n";
for (auto &n : type_ribs)
{
ss << "\tNodeID: " << n.first << " Rib: " << n.second->debug_str ()
<< "\n";
}
ss << "Macros:\n";

for (auto &n : macro_ribs)
{
ss << "\tNodeID: " << n.first << " Rib: " << n.second->debug_str ()
<< "\n";
}

ss << "Labels:\n";

for (auto &n : label_ribs)
{
ss << "\tNodeID: " << n.first << " Rib: " << n.second->debug_str ()
<< "\n";
}

return ss.str ();
}

protected:
bool decl_needs_capture (NodeId decl_rib_node_id, NodeId closure_rib_node_id,
const Scope &scope);
Expand Down
9 changes: 5 additions & 4 deletions gcc/rust/typecheck/rust-hir-type-check-enumitem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,11 @@ TypeCheckEnumItem::visit (HIR::EnumItemDiscriminant &item)
rust_assert (canonical_path.has_value ());

RustIdent ident{*canonical_path, item.get_locus ()};
variant = new TyTy::VariantDef (item.get_mappings ().get_hirid (),
item.get_mappings ().get_defid (),
item.get_identifier ().as_string (), ident,
item.take_discriminant_expression ());
variant
= new TyTy::VariantDef (item.get_mappings ().get_hirid (),
item.get_mappings ().get_defid (),
item.get_identifier ().as_string (), ident,
item.get_discriminant_expression ().clone_expr ());
}

void
Expand Down
10 changes: 0 additions & 10 deletions gcc/testsuite/rust/compile/nr2/exclude
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,13 @@ macros/builtin/include3.rs
macros/builtin/include4.rs
canonical_paths1.rs
cfg1.rs
cfg3.rs
cfg4.rs
cfg5.rs
closure_no_type_anno.rs
complex-path1.rs
complex_qualified_path_in_expr.rs
const-issue1440.rs
const_generics_3.rs
const_generics_4.rs
const_generics_5.rs
const_generics_7.rs
derive_empty.rs
derive_macro1.rs
derive_macro3.rs
derive_macro4.rs
Expand Down Expand Up @@ -74,7 +69,6 @@ issue-2070.rs
issue-2105.rs
issue-2135.rs
issue-2136-1.rs
issue-2136-2.rs
issue-2139.rs
issue-2142.rs
issue-2165.rs
Expand Down Expand Up @@ -102,8 +96,6 @@ iterators1.rs
lookup_err1.rs
macros/mbe/macro-issue1233.rs
macros/mbe/macro-issue1400.rs
macros/mbe/macro13.rs
macros/mbe/macro15.rs
macros/mbe/macro20.rs
macros/mbe/macro23.rs
macros/mbe/macro40.rs
Expand All @@ -112,7 +104,6 @@ macros/mbe/macro44.rs
macros/mbe/macro50.rs
macros/mbe/macro54.rs
macros/mbe/macro6.rs
macros/mbe/macro_rules_macro_rules.rs
macros/mbe/macro_use1.rs
match-never-ltype.rs
match-never-rtype.rs
Expand Down Expand Up @@ -153,7 +144,6 @@ redef_error2.rs
redef_error4.rs
redef_error5.rs
redef_error6.rs
self-path1.rs
self-path2.rs
sizeof-stray-infer-var-bug.rs
specify-crate-name.rs
Expand Down
Loading