Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gcc/rust/backend/rust-compile-base.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class HIRCompileBase
TyTy::BaseType *expected, location_t lvalue_locus,
location_t rvalue_locus);

tree coerce_to_dyn_object (tree compiled_ref, const TyTy::BaseType *actual,
tree coerce_to_dyn_object (tree compiled_ref, TyTy::BaseType *actual,
const TyTy::DynamicObjectType *ty,
location_t locus);

Expand Down
7 changes: 3 additions & 4 deletions gcc/rust/backend/rust-compile-expr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2209,11 +2209,10 @@ HIRCompileBase::resolve_unsized_dyn_adjustment (
tree rvalue = expression;
location_t rvalue_locus = locus;

const TyTy::BaseType *actual = adjustment.get_actual ();
const TyTy::BaseType *expected = adjustment.get_expected ();
auto actual = adjustment.get_actual ();
auto expected = adjustment.get_expected ();

const TyTy::DynamicObjectType *dyn
= static_cast<const TyTy::DynamicObjectType *> (expected);
const auto dyn = static_cast<const TyTy::DynamicObjectType *> (expected);

rust_debug ("resolve_unsized_dyn_adjustment actual={%s} dyn={%s}",
actual->debug_str ().c_str (), dyn->debug_str ().c_str ());
Expand Down
7 changes: 2 additions & 5 deletions gcc/rust/backend/rust-compile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,7 @@ HIRCompileBase::coercion_site1 (tree rvalue, TyTy::BaseType *rval,
}

tree
HIRCompileBase::coerce_to_dyn_object (tree compiled_ref,
const TyTy::BaseType *actual,
HIRCompileBase::coerce_to_dyn_object (tree compiled_ref, TyTy::BaseType *actual,
const TyTy::DynamicObjectType *ty,
location_t locus)
{
Expand All @@ -201,9 +200,7 @@ HIRCompileBase::coerce_to_dyn_object (tree compiled_ref,
// __trait_object_ptr
// [list of function ptrs]

std::vector<std::pair<Resolver::TraitReference *, HIR::ImplBlock *>>
probed_bounds_for_receiver = Resolver::TypeBoundsProbe::Probe (actual);

auto probed_bounds_for_receiver = Resolver::TypeBoundsProbe::Probe (actual);
tree address_of_compiled_ref = null_pointer_node;
if (!actual->is_unit ())
address_of_compiled_ref = address_expression (compiled_ref, locus);
Expand Down
3 changes: 2 additions & 1 deletion gcc/rust/typecheck/rust-coercion.cc
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,8 @@ TypeCoercionRules::select (TyTy::BaseType &autoderefed)
= unify_site_and (autoderefed.get_ref (), TyTy::TyWithLocation (expected),
TyTy::TyWithLocation (&autoderefed),
UNDEF_LOCATION /* locus */, false /*emit_errors*/,
false /*commit_if_ok*/, true /*infer*/, true /*cleanup*/);
!try_flag /*commit_if_ok*/, try_flag /*infer*/,
try_flag /*cleanup*/);
bool ok = result->get_kind () != TyTy::TypeKind::ERROR;
if (!ok)
return false;
Expand Down
9 changes: 4 additions & 5 deletions gcc/rust/typecheck/rust-hir-path-probe.cc
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,10 @@ PathProbeType::process_impl_item_candidate (HirId id, HIR::ImplItem *item,
if (!query_type (impl_ty_id, &impl_block_ty))
return;

if (!receiver->can_eq (impl_block_ty, false))
{
if (!impl_block_ty->can_eq (receiver, false))
return;
}
if (!types_compatable (TyTy::TyWithLocation (receiver),
TyTy::TyWithLocation (impl_block_ty),
impl->get_locus (), false))
return;

// lets visit the impl_item
item->accept_vis (*this);
Expand Down
6 changes: 3 additions & 3 deletions gcc/rust/typecheck/rust-hir-type-bounds.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class TypeBoundsProbe : public TypeCheckBase
{
public:
static std::vector<std::pair<TraitReference *, HIR::ImplBlock *>>
Probe (const TyTy::BaseType *receiver);
Probe (TyTy::BaseType *receiver);

static bool is_bound_satisfied_for_type (TyTy::BaseType *receiver,
TraitReference *ref);
Expand All @@ -46,9 +46,9 @@ class TypeBoundsProbe : public TypeCheckBase
void assemble_builtin_candidate (LangItem::Kind item);

private:
TypeBoundsProbe (const TyTy::BaseType *receiver);
TypeBoundsProbe (TyTy::BaseType *receiver);

const TyTy::BaseType *receiver;
TyTy::BaseType *receiver;
std::vector<std::pair<TraitReference *, HIR::ImplBlock *>> trait_references;
};

Expand Down
29 changes: 16 additions & 13 deletions gcc/rust/typecheck/rust-type-util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,12 @@ query_type (HirId reference, TyTy::BaseType **result)

bool
types_compatable (TyTy::TyWithLocation lhs, TyTy::TyWithLocation rhs,
location_t unify_locus, bool emit_errors)
location_t unify_locus, bool emit_errors, bool check_bounds)
{
TyTy::BaseType *result
= unify_site_and (UNKNOWN_HIRID, lhs, rhs, unify_locus, emit_errors,
false /*commit*/, true /*infer*/, true /*cleanup*/);
false /*commit*/, true /*infer*/, true /*cleanup*/,
check_bounds);
return result->get_kind () != TyTy::TypeKind::ERROR;
}

Expand All @@ -173,32 +174,34 @@ unify_site (HirId id, TyTy::TyWithLocation lhs, TyTy::TyWithLocation rhs,
std::vector<UnifyRules::CommitSite> commits;
std::vector<UnifyRules::InferenceSite> infers;
return UnifyRules::Resolve (lhs, rhs, unify_locus, true /*commit*/,
true /*emit_error*/, false /*infer*/, commits,
infers);
true /*emit_error*/, false /*infer*/,
true /*check_bounds*/, commits, infers);
}

TyTy::BaseType *
unify_site_and (HirId id, TyTy::TyWithLocation lhs, TyTy::TyWithLocation rhs,
location_t unify_locus, bool emit_errors, bool commit_if_ok,
bool implicit_infer_vars, bool cleanup)
bool implicit_infer_vars, bool cleanup, bool check_bounds)
{
TypeCheckContext &context = *TypeCheckContext::get ();

TyTy::BaseType *expected = lhs.get_ty ();
TyTy::BaseType *expr = rhs.get_ty ();

rust_debug_loc (
unify_locus,
"begin unify_site_and commit %s infer %s id={%u} expected={%s} expr={%s}",
commit_if_ok ? "true" : "false", implicit_infer_vars ? "true" : "false",
id == UNKNOWN_HIRID ? 0 : id, expected->debug_str ().c_str (),
expr->debug_str ().c_str ());
rust_debug_loc (unify_locus,
"begin unify_site_and commit %s infer %s check_bounds %s "
"id={%u} expected={%s} expr={%s}",
commit_if_ok ? "true" : "false",
implicit_infer_vars ? "true" : "false",
check_bounds ? "true" : "false", id == UNKNOWN_HIRID ? 0 : id,
expected->debug_str ().c_str (), expr->debug_str ().c_str ());

std::vector<UnifyRules::CommitSite> commits;
std::vector<UnifyRules::InferenceSite> infers;
TyTy::BaseType *result
= UnifyRules::Resolve (lhs, rhs, unify_locus, false /*commit inline*/,
emit_errors, implicit_infer_vars, commits, infers);
emit_errors, implicit_infer_vars, check_bounds,
commits, infers);
bool ok = result->get_kind () != TyTy::TypeKind::ERROR;

rust_debug_loc (unify_locus,
Expand Down Expand Up @@ -325,7 +328,7 @@ cast_site (HirId id, TyTy::TyWithLocation from, TyTy::TyWithLocation to,

AssociatedImplTrait *
lookup_associated_impl_block (const TyTy::TypeBoundPredicate &bound,
const TyTy::BaseType *binding, bool *ambigious)
TyTy::BaseType *binding, bool *ambigious)
{
auto context = TypeCheckContext::get ();

Expand Down
7 changes: 4 additions & 3 deletions gcc/rust/typecheck/rust-type-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ namespace Resolver {
bool query_type (HirId reference, TyTy::BaseType **result);

bool types_compatable (TyTy::TyWithLocation lhs, TyTy::TyWithLocation rhs,
location_t unify_locus, bool emit_errors);
location_t unify_locus, bool emit_errors,
bool check_bounds = true);

TyTy::BaseType *unify_site (HirId id, TyTy::TyWithLocation lhs,
TyTy::TyWithLocation rhs, location_t unify_locus);
Expand All @@ -37,7 +38,7 @@ TyTy::BaseType *unify_site_and (HirId id, TyTy::TyWithLocation lhs,
TyTy::TyWithLocation rhs,
location_t unify_locus, bool emit_errors,
bool commit_if_ok, bool implicit_infer_vars,
bool cleanup);
bool cleanup, bool check_bounds = true);

TyTy::BaseType *coercion_site (HirId id, TyTy::TyWithLocation lhs,
TyTy::TyWithLocation rhs,
Expand All @@ -52,7 +53,7 @@ TyTy::BaseType *cast_site (HirId id, TyTy::TyWithLocation from,

AssociatedImplTrait *
lookup_associated_impl_block (const TyTy::TypeBoundPredicate &bound,
const TyTy::BaseType *binding,
TyTy::BaseType *binding,
bool *ambigious = nullptr);

} // namespace Resolver
Expand Down
16 changes: 6 additions & 10 deletions gcc/rust/typecheck/rust-tyty-bounds.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
namespace Rust {
namespace Resolver {

TypeBoundsProbe::TypeBoundsProbe (const TyTy::BaseType *receiver)
TypeBoundsProbe::TypeBoundsProbe (TyTy::BaseType *receiver)
: TypeCheckBase (), receiver (receiver)
{}

std::vector<std::pair<TraitReference *, HIR::ImplBlock *>>
TypeBoundsProbe::Probe (const TyTy::BaseType *receiver)
TypeBoundsProbe::Probe (TyTy::BaseType *receiver)
{
TypeBoundsProbe probe (receiver);
probe.scan ();
Expand Down Expand Up @@ -75,20 +75,16 @@ TypeBoundsProbe::process_impl_block (
HIR::Trait *t = TraitResolver::ResolveHirItem (impl->get_trait_ref ());
if (t == nullptr)
return true;
// DefId trait_id = t->get_mappings ().get_defid ();
// if (context->trait_query_in_progress (trait_id))
// return true;

HirId impl_ty_id = impl->get_type ().get_mappings ().get_hirid ();
TyTy::BaseType *impl_type = nullptr;
if (!query_type (impl_ty_id, &impl_type))
return true;

if (!receiver->can_eq (impl_type, false))
{
if (!impl_type->can_eq (receiver, false))
return true;
}
if (!types_compatable (TyTy::TyWithLocation (receiver),
TyTy::TyWithLocation (impl_type), impl->get_locus (),
false /*emit_errors*/, false /*check-bounds*/))
return true;

possible_trait_paths.emplace_back (&impl->get_trait_ref (), impl);
return true;
Expand Down
Loading
Loading