mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Support explicit conversion between adapters and their adapted types. (#3889)
Allow an explicit `as` conversion to convert between adapters and their adapted types. Also make the value representation of an adapter be the same as the value representation of the adapted type so that the conversion is always possible. --------- Co-authored-by: josh11b <15258583+josh11b@users.noreply.github.com>
This commit is contained in:
@@ -957,6 +957,7 @@ class TypeCompleter {
|
||||
case SemIR::AddrPattern::Kind:
|
||||
case SemIR::ArrayIndex::Kind:
|
||||
case SemIR::ArrayInit::Kind:
|
||||
case SemIR::AsCompatible::Kind:
|
||||
case SemIR::Assign::Kind:
|
||||
case SemIR::AssociatedConstantDecl::Kind:
|
||||
case SemIR::AssociatedEntity::Kind:
|
||||
@@ -1031,13 +1032,18 @@ class TypeCompleter {
|
||||
return BuildTupleTypeValueRepr(type_id, tuple_type);
|
||||
}
|
||||
case CARBON_KIND(SemIR::ClassType class_type): {
|
||||
// The value representation for a class is a pointer to the object
|
||||
// representation.
|
||||
auto& class_info = context_.classes().Get(class_type.class_id);
|
||||
// The value representation of an adapter is the value representation of
|
||||
// its adapted type.
|
||||
if (class_info.adapt_id.is_valid()) {
|
||||
return GetNestedValueRepr(class_info.object_repr_id);
|
||||
}
|
||||
// Otherwise, the value representation for a class is a pointer to the
|
||||
// object representation.
|
||||
// TODO: Support customized value representations for classes.
|
||||
// TODO: Pick a better value representation when possible.
|
||||
return MakePointerValueRepr(
|
||||
context_.classes().Get(class_type.class_id).object_repr_id,
|
||||
SemIR::ValueRepr::ObjectAggregate);
|
||||
return MakePointerValueRepr(class_info.object_repr_id,
|
||||
SemIR::ValueRepr::ObjectAggregate);
|
||||
}
|
||||
case SemIR::InterfaceType::Kind: {
|
||||
// TODO: Should we model the value representation as a witness?
|
||||
|
||||
Reference in New Issue
Block a user