[gcc r14-8063] gccrs: typecheck: add loop ctx for labelled block

Arthur Cohen cohenarthur@gcc.gnu.org
Tue Jan 16 18:15:24 GMT 2024


https://gcc.gnu.org/g:1f40ed03c56a3801ee7c8be463d25d175505b713

commit r14-8063-g1f40ed03c56a3801ee7c8be463d25d175505b713
Author: Jakub Dupak <dev@jakubdupak.com>
Date:   Mon Oct 16 15:28:03 2023 +0200

    gccrs: typecheck: add loop ctx for labelled block
    
    gcc/rust/ChangeLog:
    
            * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Add loop ctx.
    
    Signed-off-by: Jakub Dupak <dev@jakubdupak.com>

Diff:
---
 gcc/rust/typecheck/rust-hir-type-check-expr.cc | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
index 4ed84840e88..7bcd87ec555 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-expr.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
@@ -566,6 +566,10 @@ TypeCheckExpr::visit (HIR::UnsafeBlockExpr &expr)
 void
 TypeCheckExpr::visit (HIR::BlockExpr &expr)
 {
+  if (expr.has_label ())
+    context->push_new_loop_context (expr.get_mappings ().get_hirid (),
+				    expr.get_locus ());
+
   for (auto &s : expr.get_statements ())
     {
       if (!s->is_item ())
@@ -602,6 +606,20 @@ TypeCheckExpr::visit (HIR::BlockExpr &expr)
   else if (expr.is_tail_reachable ())
     infered
       = TyTy::TupleType::get_unit_type (expr.get_mappings ().get_hirid ());
+  else if (expr.has_label ())
+    {
+      TyTy::BaseType *loop_context_type = context->pop_loop_context ();
+
+      bool loop_context_type_infered
+	= (loop_context_type->get_kind () != TyTy::TypeKind::INFER)
+	  || ((loop_context_type->get_kind () == TyTy::TypeKind::INFER)
+	      && (((TyTy::InferType *) loop_context_type)->get_infer_kind ()
+		  != TyTy::InferType::GENERAL));
+
+      infered = loop_context_type_infered ? loop_context_type
+					  : TyTy::TupleType::get_unit_type (
+					    expr.get_mappings ().get_hirid ());
+    }
   else
     {
       // FIXME this seems wrong


More information about the Gcc-cvs mailing list