Skip to content

Commit

Permalink
for-loop: Progress!
Browse files Browse the repository at this point in the history
  • Loading branch information
CohenArthur committed Dec 18, 2024
1 parent 3562b60 commit 8326417
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 13 deletions.
14 changes: 12 additions & 2 deletions gcc/rust/hir/tree/rust-hir-path.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "rust-hir-type-no-bounds.h"
#include "rust-hir-pattern-abstract.h"
#include "rust-hir-expr-abstract.h"
#include "rust-system.h"

namespace Rust {
namespace HIR {
Expand Down Expand Up @@ -281,8 +282,11 @@ class PathPattern : public Pattern
size_t get_num_segments () const
{
if (kind == Kind::LangItem)
rust_fatal_error (UNKNOWN_LOCATION, "[ARTHUR] %s",
LangItem::ToString (*lang_item).c_str ());
{
// rust_fatal_error (UNKNOWN_LOCATION, "[ARTHUR] %s",
// LangItem::ToString (*lang_item).c_str ());
rust_unreachable ();
}

rust_assert (kind == Kind::Segmented);
return segments.size ();
Expand Down Expand Up @@ -317,6 +321,12 @@ class PathPattern : public Pattern
return PatternType::PATH;
}

LangItem::Kind get_lang_item_kind () const
{
rust_assert (kind == Kind::LangItem);
return *lang_item;
}

Kind get_path_kind () const { return kind; }
};

Expand Down
48 changes: 37 additions & 11 deletions gcc/rust/typecheck/rust-hir-type-check-path.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
// along with GCC; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.

#include "rust-diagnostics.h"
#include "rust-hir-map.h"
#include "rust-hir-path.h"
#include "rust-hir-type-check-expr.h"
#include "rust-hir-type-check-type.h"
#include "rust-hir-type-check-item.h"
Expand All @@ -24,6 +27,7 @@
#include "rust-hir-path-probe.h"
#include "rust-type-util.h"
#include "rust-hir-type-bounds.h"
#include "rust-hir-item.h"
#include "rust-session-manager.h"
#include "rust-immutable-name-resolution-context.h"

Expand Down Expand Up @@ -179,20 +183,42 @@ void
TypeCheckExpr::visit (HIR::PathInExpression &expr)
{
NodeId resolved_node_id = UNKNOWN_NODEID;
size_t offset = -1;
TyTy::BaseType *tyseg = resolve_root_path (expr, &offset, &resolved_node_id);
if (tyseg->get_kind () == TyTy::TypeKind::ERROR)
return;

bool fully_resolved = offset == expr.get_segments ().size ();
if (fully_resolved)
if (expr.get_path_kind () == HIR::PathPattern::Kind::LangItem)
{
infered = tyseg;
return;
if (auto lookup = Analysis::Mappings::get ().lookup_lang_item_node (
expr.get_lang_item_kind ()))
{
auto hir_id = mappings.lookup_node_to_hir (*lookup);

TyTy::BaseType *resolved = nullptr;
context->lookup_type (*hir_id, &resolved);

infered = resolved;
return;
}
else
rust_fatal_error (
expr.get_locus (), "lang item missing: %s",
LangItem::ToString (expr.get_lang_item_kind ()).c_str ());
}
else
{
size_t offset = -1;
TyTy::BaseType *tyseg
= resolve_root_path (expr, &offset, &resolved_node_id);
if (tyseg->get_kind () == TyTy::TypeKind::ERROR)
return;

bool fully_resolved = offset == expr.get_segments ().size ();
if (fully_resolved)
{
infered = tyseg;
return;
}

resolve_segments (resolved_node_id, expr.get_segments (), offset, tyseg,
expr.get_mappings (), expr.get_locus ());
resolve_segments (resolved_node_id, expr.get_segments (), offset, tyseg,
expr.get_mappings (), expr.get_locus ());
}
}

TyTy::BaseType *
Expand Down

0 comments on commit 8326417

Please sign in to comment.