From 671cefe61254bedd4a9f526f8912fe68368cbe72 Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Fri, 18 Dec 2020 17:27:03 +0000 Subject: When compiling a block it might reference a GIMPLE node that is not resolved yet. Such as: fn main() -> i32 { call() } fn call() -> i32 { return 1; } The compilation pass acts on the first function main and detects the other node call is not compiled yet we can go resolve it. This is a toplevel item since it has a local_def_id and therefore it has a NULL enclosing scope for the block. Fixes #72 --- gcc/rust/backend/rust-compile-item.h | 13 ++++++------- gcc/rust/backend/rust-compile-resolve-path.cc | 7 ------- 2 files changed, 6 insertions(+), 14 deletions(-) (limited to 'gcc/rust/backend') diff --git a/gcc/rust/backend/rust-compile-item.h b/gcc/rust/backend/rust-compile-item.h index dd07435..f131a89 100644 --- a/gcc/rust/backend/rust-compile-item.h +++ b/gcc/rust/backend/rust-compile-item.h @@ -48,11 +48,7 @@ public: { // has this been added to the list then it must be finished if (ctx->function_completed (lookup)) - { - printf ("returning early the function [%s] is completed!\n", - function.as_string ().c_str ()); - return; - } + return; } TyTy::TyBase *fnType; @@ -123,9 +119,12 @@ public: return true; }); - Bblock *enclosing_scope = ctx->peek_enclosing_scope (); - HIR::BlockExpr *function_body = function.function_body.get (); + bool toplevel_item + = function.get_mappings ().get_local_defid () != UNKNOWN_LOCAL_DEFID; + Bblock *enclosing_scope + = toplevel_item ? NULL : ctx->peek_enclosing_scope (); + HIR::BlockExpr *function_body = function.function_body.get (); Location start_location = function_body->get_locus (); Location end_location = function_body->get_closing_locus (); diff --git a/gcc/rust/backend/rust-compile-resolve-path.cc b/gcc/rust/backend/rust-compile-resolve-path.cc index e6683fa..c5c646d 100644 --- a/gcc/rust/backend/rust-compile-resolve-path.cc +++ b/gcc/rust/backend/rust-compile-resolve-path.cc @@ -36,10 +36,6 @@ ResolvePath::visit (HIR::PathInExpression &expr) return; } - printf ("PATHIN have ast node id %u ref %u for expr [%s]\n", - expr.get_mappings ().get_nodeid (), ref_node_id, - expr.as_string ().c_str ()); - HirId ref; if (!ctx->get_mappings ()->lookup_node_to_hir ( expr.get_mappings ().get_crate_num (), ref_node_id, &ref)) @@ -52,9 +48,6 @@ ResolvePath::visit (HIR::PathInExpression &expr) Bfunction *fn; if (!ctx->lookup_function_decl (ref, &fn)) { - printf ( - "path failed to lookup function attempting to forward resolve!\n"); - // this might fail because its a forward decl so we can attempt to // resolve it now HIR::Item *resolved_item = ctx->get_mappings ()->lookup_hir_item ( -- cgit v1.1