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 8 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
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 @@ -648,7 +648,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 @@ -1053,7 +1053,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
6 changes: 3 additions & 3 deletions gcc/rust/resolve/rust-forever-stack.h
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ template <Namespace N> class ForeverStack
tl::optional<Rib &> to_rib (NodeId rib_id);
tl::optional<const Rib &> to_rib (NodeId rib_id) const;

std::string as_debug_string ();
std::string as_debug_string () const;

/**
* Used to check if a module is a descendant of another module
Expand Down Expand Up @@ -601,9 +601,9 @@ template <Namespace N> class ForeverStack
std::reference_wrapper<Node> cursor_reference;

void stream_rib (std::stringstream &stream, const Rib &rib,
const std::string &next, const std::string &next_next);
const std::string &next, const std::string &next_next) const;
void stream_node (std::stringstream &stream, unsigned indentation,
const Node &node);
const Node &node) const;

/* Helper types and functions for `resolve_path` */

Expand Down
6 changes: 3 additions & 3 deletions gcc/rust/resolve/rust-forever-stack.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ template <Namespace N>
void
ForeverStack<N>::stream_rib (std::stringstream &stream, const Rib &rib,
const std::string &next,
const std::string &next_next)
const std::string &next_next) const
{
if (rib.get_values ().empty ())
{
Expand All @@ -718,7 +718,7 @@ ForeverStack<N>::stream_rib (std::stringstream &stream, const Rib &rib,
template <Namespace N>
void
ForeverStack<N>::stream_node (std::stringstream &stream, unsigned indentation,
const ForeverStack<N>::Node &node)
const ForeverStack<N>::Node &node) const
{
auto indent = std::string (indentation, ' ');
auto next = std::string (indentation + 4, ' ');
Expand Down Expand Up @@ -750,7 +750,7 @@ ForeverStack<N>::stream_node (std::stringstream &stream, unsigned indentation,

template <Namespace N>
std::string
ForeverStack<N>::as_debug_string ()
ForeverStack<N>::as_debug_string () const
{
std::stringstream stream;

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
6 changes: 4 additions & 2 deletions gcc/rust/typecheck/rust-hir-trait-resolve.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,10 @@ TraitResolver::resolve_path_to_trait (const HIR::TypePath &path,
}
else
{
ok = resolver->lookup_resolved_type (path.get_mappings ().get_nodeid (),
&ref);
auto path_nodeid = path.get_mappings ().get_nodeid ();
ok = resolver->lookup_resolved_type (path_nodeid, &ref)
|| resolver->lookup_resolved_name (path_nodeid, &ref)
|| resolver->lookup_resolved_macro (path_nodeid, &ref);
}

if (!ok)
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 @@ -8,18 +8,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 @@ -69,7 +64,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 All @@ -93,16 +87,13 @@ 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/macro23.rs
macros/mbe/macro40.rs
macros/mbe/macro43.rs
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 @@ -143,7 +134,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
stmt_with_block_dot.rs
Expand Down
Loading