diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2022-07-07 09:34:02 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-07 09:34:02 +0000 |
commit | c8a9218a5bab48fffe1f5fa02244954d55f8945c (patch) | |
tree | 46593ffd2c9b242b801f7cf021a4b9d380baf55a /gcc/rust/resolve | |
parent | ad0e01dfbba94c0a10019db7c11b13fa0758c1fb (diff) | |
parent | 1f32e5b4558126d872f455c65a94d9640a93c285 (diff) | |
download | gcc-c8a9218a5bab48fffe1f5fa02244954d55f8945c.zip gcc-c8a9218a5bab48fffe1f5fa02244954d55f8945c.tar.gz gcc-c8a9218a5bab48fffe1f5fa02244954d55f8945c.tar.bz2 |
Merge #1355
1355: Ambiguous generic arg r=CohenArthur a=CohenArthur
Needs #1354. Only review the last commit :)
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.
Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
Diffstat (limited to 'gcc/rust/resolve')
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-type.cc | 47 |
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 > : 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 > : 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 |