summaryrefslogtreecommitdiff
path: root/src/ast/ast.cpp
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2015-03-31 14:20:18 +0800
committerJohn Hodge <tpg@mutabah.net>2015-03-31 14:20:18 +0800
commitf725889aedd5b64141e8f8e9924e4e59f716c225 (patch)
tree7a132887475f67c26478b3c4738e1646652e169e /src/ast/ast.cpp
parentf5819ef88927734bcc36769b50d1b69de377b5db (diff)
downloadmrust-f725889aedd5b64141e8f8e9924e4e59f716c225.tar.gz
Partial comparisons of types/paths to speed up impl searches
Diffstat (limited to 'src/ast/ast.cpp')
-rw-r--r--src/ast/ast.cpp24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/ast/ast.cpp b/src/ast/ast.cpp
index b8e6d381..4c400a47 100644
--- a/src/ast/ast.cpp
+++ b/src/ast/ast.cpp
@@ -80,7 +80,29 @@ Impl Impl::make_concrete(const ::std::vector<TypeRef>& types) const
::rust::option<Impl&> Impl::matches(const Path& trait, const TypeRef& type)
{
- DEBUG("this = " << *this);
+ //DEBUG("this = " << *this);
+
+ // 1. Check the type/trait counting parameters as wildcards (but flagging if one was seen)
+ // > If that fails, just early return
+ int trait_match = m_trait.equal_no_generic(trait);
+ if( trait_match < 0 )
+ return ::rust::option<Impl&>();
+ DEBUG("Trait " << trait << " matches " << trait_match);
+ int type_match = m_type.equal_no_generic(type);
+ if( type_match < 0 )
+ return ::rust::option<Impl&>();
+ DEBUG("Type " << type << " matches " << type_match);
+ // 2. If a parameter was seen, do the more expensive generic checks
+ // > Involves checking that parameters are valid
+ if( trait_match > 0 )
+ {
+ throw CompileError::Todo("Generic-ised match of impl trait");
+ }
+ if( type_match > 0 )
+ {
+ throw CompileError::Todo("Generic-ised match of impl type");
+ }
+ // 3. Return success
if( m_params.ty_params().size() > 0 )
{