mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Improve support for qualification conversions. (#5999)
* Treat `MaybeUnformed` and `partial` as qualifiers, like `const`. * Allow pointer conversions to add qualifiers. * Allow unsafe pointer conversions to remove qualifiers. * Allow conversions on non-reference expressions to drop `const`. * Allow unsafe conversions on any expression to drop `const`. * Allow unsafe conversions on non-initializing expressions to drop `partial`. For initializing expressions, we should initialize the vptr when dropping `partial`; this is not yet supported so we reject. * Allow conversions on reference expressions to add `MaybeUnformed`. * Allow unsafe conversions on reference expressions to drop `MaybeUnformed`. For non-reference expressions, additional work is required, because the value / initializing representation may not match between `T` and `MaybeUnformed(T)`, so those are rejected for now.
This commit is contained in:
@@ -26,6 +26,7 @@
|
||||
#include "toolchain/sem_ir/ids.h"
|
||||
#include "toolchain/sem_ir/import_ir.h"
|
||||
#include "toolchain/sem_ir/inst.h"
|
||||
#include "toolchain/sem_ir/inst_categories.h"
|
||||
#include "toolchain/sem_ir/inst_kind.h"
|
||||
#include "toolchain/sem_ir/type_info.h"
|
||||
#include "toolchain/sem_ir/typed_insts.h"
|
||||
@@ -1823,14 +1824,16 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver,
|
||||
.object_repr_type_inst_id = object_repr_type_inst_id});
|
||||
}
|
||||
|
||||
static auto TryResolveTypedInst(ImportRefResolver& resolver,
|
||||
SemIR::ConstType inst) -> ResolveResult {
|
||||
template <typename InstT>
|
||||
requires SemIR::Internal::HasInstCategory<SemIR::AnyQualifiedType, InstT>
|
||||
static auto TryResolveTypedInst(ImportRefResolver& resolver, InstT inst)
|
||||
-> ResolveResult {
|
||||
CARBON_CHECK(inst.type_id == SemIR::TypeType::TypeId);
|
||||
auto inner_id = GetLocalTypeInstId(resolver, inst.inner_id);
|
||||
if (resolver.HasNewWork()) {
|
||||
return ResolveResult::Retry();
|
||||
}
|
||||
return ResolveAsDeduplicated<SemIR::ConstType>(
|
||||
return ResolveAsDeduplicated<InstT>(
|
||||
resolver, {.type_id = SemIR::TypeType::TypeId, .inner_id = inner_id});
|
||||
}
|
||||
|
||||
@@ -3183,12 +3186,18 @@ static auto TryResolveInstCanonical(ImportRefResolver& resolver,
|
||||
case CARBON_KIND(SemIR::IntType inst): {
|
||||
return TryResolveTypedInst(resolver, inst);
|
||||
}
|
||||
case CARBON_KIND(SemIR::MaybeUnformedType inst): {
|
||||
return TryResolveTypedInst(resolver, inst);
|
||||
}
|
||||
case CARBON_KIND(SemIR::Namespace inst): {
|
||||
return TryResolveTypedInst(resolver, inst, inst_id);
|
||||
}
|
||||
case CARBON_KIND(SemIR::OutParamPattern inst): {
|
||||
return TryResolveTypedInst(resolver, inst, inst_id);
|
||||
}
|
||||
case CARBON_KIND(SemIR::PartialType inst): {
|
||||
return TryResolveTypedInst(resolver, inst);
|
||||
}
|
||||
case CARBON_KIND(SemIR::PatternType inst): {
|
||||
return TryResolveTypedInst(resolver, inst);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user