aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/resolve
diff options
context:
space:
mode:
authorArthur Cohen <arthur.cohen@embecosm.com>2022-07-05 16:40:38 +0200
committerArthur Cohen <arthur.cohen@embecosm.com>2022-07-07 11:35:06 +0200
commit1f32e5b4558126d872f455c65a94d9640a93c285 (patch)
tree46593ffd2c9b242b801f7cf021a4b9d380baf55a /gcc/rust/resolve
parentad0e01dfbba94c0a10019db7c11b13fa0758c1fb (diff)
downloadgcc-1f32e5b4558126d872f455c65a94d9640a93c285.zip
gcc-1f32e5b4558126d872f455c65a94d9640a93c285.tar.gz
gcc-1f32e5b4558126d872f455c65a94d9640a93c285.tar.bz2
ast: Rename ConstGenericArg -> GenericArg
This makes the class clearer and exposes the fact that it may contain a type OR a const value clearer. Because we now run in ambiguous cases later in the compiler pipeline, this commit also adds horrible hacks to simply ignore ambiguous generic arguments and treat them as type arguments.
Diffstat (limited to 'gcc/rust/resolve')
-rw-r--r--gcc/rust/resolve/rust-ast-resolve-type.cc47
1 files changed, 40 insertions, 7 deletions
diff --git a/gcc/rust/resolve/rust-ast-resolve-type.cc b/gcc/rust/resolve/rust-ast-resolve-type.cc
index 910468e..e875688 100644
--- a/gcc/rust/resolve/rust-ast-resolve-type.cc
+++ b/gcc/rust/resolve/rust-ast-resolve-type.cc
@@ -384,12 +384,35 @@ ResolveTypeToCanonicalPath::visit (AST::TypePath &path)
std::vector<CanonicalPath> args;
if (s->has_generic_args ())
{
- for (auto &gt : s->get_generic_args ().get_type_args ())
+ for (auto &generic : s->get_generic_args ().get_generic_args ())
{
- CanonicalPath arg = CanonicalPath::create_empty ();
- bool ok = ResolveTypeToCanonicalPath::go (gt.get (), arg);
- if (ok)
- args.push_back (std::move (arg));
+ // FIXME: What do we want to do here in case there is a
+ // constant or an ambiguous const generic?
+ // TODO: At that point, will all generics have been
+ // disambiguated? Can we thus canonical resolve types and
+ // const and `gcc_unreachable` on ambiguous types?
+ //
+ // FIXME: Arthur: This is an ugly hack to resolve just as
+ // much as before despite not handling ambiguity yet. The
+ // calls to `clone_type` will be removed.
+ std::unique_ptr<AST::Type> gt = nullptr;
+
+ if (generic.get_kind () == AST::GenericArg::Kind::Type)
+ gt = generic.get_type ()->clone_type ();
+ else if (generic.get_kind ()
+ == AST::GenericArg::Kind::Either)
+ gt = generic.disambiguate_to_type ()
+ .get_type ()
+ ->clone_type ();
+
+ if (gt)
+ {
+ CanonicalPath arg = CanonicalPath::create_empty ();
+ bool ok
+ = ResolveTypeToCanonicalPath::go (gt.get (), arg);
+ if (ok)
+ args.push_back (std::move (arg));
+ }
}
}
@@ -472,8 +495,18 @@ ResolveTypeToCanonicalPath::ResolveTypeToCanonicalPath ()
void
ResolveGenericArgs::go (AST::GenericArgs &args)
{
- for (auto &gt : args.get_type_args ())
- ResolveType::go (gt.get ());
+ for (auto &arg : args.get_generic_args ())
+ {
+ // FIXME: Arthur: Ugly hack while waiting for disambiguation
+ if (arg.get_kind () == AST::GenericArg::Kind::Either)
+ arg = arg.disambiguate_to_type ();
+
+ if (arg.get_kind () == AST::GenericArg::Kind::Type)
+ ResolveType::go (arg.get_type ().get ());
+
+ // else...
+ // We need to use a switch instead
+ }
}
} // namespace Resolver