diff options
author | Philip Herron <philip.herron@embecosm.com> | 2021-03-10 18:10:06 +0000 |
---|---|---|
committer | Philip Herron <herron.philip@googlemail.com> | 2021-03-22 20:01:30 +0000 |
commit | 280ac5bd99b4d66ea10d0aa8d4edba53bf460b10 (patch) | |
tree | e67968afbe4668e6a2679ed961d137cdb409166d /gcc/rust/backend/rust-compile-resolve-path.cc | |
parent | eb33139efa7bbbd09ad26403c36a5dcf31e1b14e (diff) | |
download | gcc-280ac5bd99b4d66ea10d0aa8d4edba53bf460b10.zip gcc-280ac5bd99b4d66ea10d0aa8d4edba53bf460b10.tar.gz gcc-280ac5bd99b4d66ea10d0aa8d4edba53bf460b10.tar.bz2 |
Generics continued this adds more type resolution to ADT and Functions
Adds recursive generic argument handling for structs and functions. With a
new substitution mapper class to coerce the HIR::GenericArgs appropriately.
This is the building block to work on impl blocks with generics and
better Monomorphization support to handle duplicate functions etc.
Fixes: #236 #234 #235
Addresses: #237
Diffstat (limited to 'gcc/rust/backend/rust-compile-resolve-path.cc')
-rw-r--r-- | gcc/rust/backend/rust-compile-resolve-path.cc | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/gcc/rust/backend/rust-compile-resolve-path.cc b/gcc/rust/backend/rust-compile-resolve-path.cc index 1a798ee..4fbaae3 100644 --- a/gcc/rust/backend/rust-compile-resolve-path.cc +++ b/gcc/rust/backend/rust-compile-resolve-path.cc @@ -67,24 +67,35 @@ ResolvePathRef::visit (HIR::PathInExpression &expr) return; } - // must be a function call + // must be a function call but it might be a generic function which needs to + // be compiled first + TyTy::BaseType *lookup = nullptr; + bool ok = ctx->get_tyctx ()->lookup_type (expr.get_mappings ().get_hirid (), + &lookup); + rust_assert (ok); + rust_assert (lookup->get_kind () == TyTy::TypeKind::FNDEF); + Bfunction *fn = nullptr; - if (!ctx->lookup_function_decl (ref, &fn)) + if (!ctx->lookup_function_decl (lookup->get_ty_ref (), &fn)) { - // this might fail because its a forward decl so we can attempt to - // resolve it now + // it must resolve to some kind of HIR::Item HIR::Item *resolved_item = ctx->get_mappings ()->lookup_hir_item ( expr.get_mappings ().get_crate_num (), ref); if (resolved_item == nullptr) { - rust_error_at (expr.get_locus (), "failed to lookup forward decl"); + rust_error_at (expr.get_locus (), "failed to lookup definition decl"); return; } - CompileItem::compile (resolved_item, ctx); - if (!ctx->lookup_function_decl (ref, &fn)) + if (!lookup->has_subsititions_defined ()) + CompileItem::compile (resolved_item, ctx); + else + CompileItem::compile (resolved_item, ctx, true, lookup); + + if (!ctx->lookup_function_decl (lookup->get_ty_ref (), &fn)) { - rust_error_at (expr.get_locus (), "forward decl was not compiled 1"); + rust_fatal_error (expr.get_locus (), + "forward decl was not compiled 1"); return; } } |