diff options
author | Philip Herron <philip.herron@embecosm.com> | 2022-08-11 14:10:05 +0100 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2022-08-11 15:55:28 +0100 |
commit | d4ddd73b0b8ddd44204844a4d650424539335899 (patch) | |
tree | 26fb40b1fcbc93baa1c122286e7dc4e9bf806272 /gcc/rust/backend/rust-compile-expr.cc | |
parent | 70a0039b82b3419820359c8a1552470e48b458f6 (diff) | |
download | gcc-d4ddd73b0b8ddd44204844a4d650424539335899.zip gcc-d4ddd73b0b8ddd44204844a4d650424539335899.tar.gz gcc-d4ddd73b0b8ddd44204844a4d650424539335899.tar.bz2 |
Desugar HIR::IdentifierExpr into HIR::PathInExpression
This completly removes the HIR::IdentifierExpr and unifies how we handle
generics in general. There was a hack from last year that did not infer
generic arguments on IdentifierExpr's which leads to a type inferencing
behvaiour mismatch which was becoming difficult to debug. This simplifies
everything.
The changes to the test case reflect making our code more compliant to
real rustc apart from compile/traits3.rs which will be fixed as part of the
refactoring effort going on in the type system.
Fixes #1456
Diffstat (limited to 'gcc/rust/backend/rust-compile-expr.cc')
-rw-r--r-- | gcc/rust/backend/rust-compile-expr.cc | 120 |
1 files changed, 0 insertions, 120 deletions
diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc index 38d10d2..bfaa7fc 100644 --- a/gcc/rust/backend/rust-compile-expr.cc +++ b/gcc/rust/backend/rust-compile-expr.cc @@ -692,12 +692,6 @@ CompileExpr::visit (HIR::MatchExpr &expr) } break; - case HIR::Expr::ExprType::Ident: { - // FIXME - gcc_unreachable (); - } - break; - case HIR::Expr::ExprType::Path: { // FIXME gcc_unreachable (); @@ -1809,120 +1803,6 @@ HIRCompileBase::resolve_unsized_adjustment (Resolver::Adjustment &adjustment, } void -CompileExpr::visit (HIR::IdentifierExpr &expr) -{ - NodeId ast_node_id = expr.get_mappings ().get_nodeid (); - - bool is_value = false; - NodeId ref_node_id = UNKNOWN_NODEID; - if (ctx->get_resolver ()->lookup_resolved_name (ast_node_id, &ref_node_id)) - { - is_value = true; - } - else if (!ctx->get_resolver ()->lookup_resolved_type (ast_node_id, - &ref_node_id)) - { - rust_error_at (expr.get_locus (), - "Failed to lookup type reference for node: %s", - expr.as_string ().c_str ()); - return; - } - - if (ref_node_id == UNKNOWN_NODEID) - { - rust_fatal_error (expr.get_locus (), "unresolved IdentifierExpr: %s", - expr.as_string ().c_str ()); - return; - } - - // node back to HIR - HirId ref; - if (!ctx->get_mappings ()->lookup_node_to_hir (ref_node_id, &ref)) - { - rust_error_at (expr.get_locus (), "reverse lookup failure"); - return; - } - - TyTy::BaseType *lookup = nullptr; - if (!ctx->get_tyctx ()->lookup_type (ref, &lookup)) - { - rust_fatal_error (expr.get_locus (), - "failed to find type relevant to this context: %s", - expr.get_mappings ().as_string ().c_str ()); - return; - } - - bool is_type_ref = !is_value; - if (is_type_ref) - { - // this might be a case for - // - // struct S; - // - // fn main() { - // let s = S; - // } - - if (lookup->is_unit ()) - { - translated = ctx->get_backend ()->unit_expression (); - return; - } - - // rust actually treats like this an fn call or structs with fields but - // unit structs are just the struct name lets catch it with an is-unit - // check - gcc_unreachable (); - } - - tree fn = NULL_TREE; - Bvariable *var = nullptr; - if (ctx->lookup_const_decl (ref, &translated)) - { - TREE_USED (translated) = 1; - return; - } - else if (ctx->lookup_function_decl (ref, &fn)) - { - TREE_USED (fn) = 1; - translated = address_expression (fn, expr.get_locus ()); - } - else if (ctx->lookup_var_decl (ref, &var)) - { - // TREE_USED is setup in the gcc abstraction here - translated = ctx->get_backend ()->var_expression (var, expr.get_locus ()); - } - else if (ctx->lookup_pattern_binding (ref, &translated)) - { - TREE_USED (translated) = 1; - return; - } - else - { - // lets try and query compile it to an item/impl item - HIR::Item *resolved_item = ctx->get_mappings ()->lookup_hir_item (ref); - bool is_hir_item = resolved_item != nullptr; - if (!is_hir_item) - { - translated = error_mark_node; - return; - } - - if (!lookup->has_subsititions_defined ()) - translated = CompileItem::compile (resolved_item, ctx, nullptr, true, - expr.get_locus ()); - else - translated = CompileItem::compile (resolved_item, ctx, lookup, true, - expr.get_locus ()); - - if (translated != error_mark_node) - { - TREE_USED (translated) = 1; - } - } -} - -void CompileExpr::visit (HIR::RangeFromToExpr &expr) { tree from = CompileExpr::Compile (expr.get_from_expr ().get (), ctx); |