mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 14:01:05 +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:
@@ -138,10 +138,20 @@ auto GetConstType(Context& context, SemIR::TypeInstId inner_type_id)
|
||||
|
||||
auto GetQualifiedType(Context& context, SemIR::TypeId type_id,
|
||||
SemIR::TypeQualifiers quals) -> SemIR::TypeId {
|
||||
if ((quals & SemIR::TypeQualifiers::Const) != SemIR::TypeQualifiers::None) {
|
||||
if (HasTypeQualifier(quals, SemIR::TypeQualifiers::Const)) {
|
||||
type_id = GetConstType(context, context.types().GetInstId(type_id));
|
||||
quals &= ~SemIR::TypeQualifiers::Const;
|
||||
}
|
||||
if (HasTypeQualifier(quals, SemIR::TypeQualifiers::MaybeUnformed)) {
|
||||
type_id = GetTypeImpl<SemIR::MaybeUnformedType>(
|
||||
context, context.types().GetInstId(type_id));
|
||||
quals &= ~SemIR::TypeQualifiers::MaybeUnformed;
|
||||
}
|
||||
if (HasTypeQualifier(quals, SemIR::TypeQualifiers::Partial)) {
|
||||
type_id = GetTypeImpl<SemIR::PartialType>(
|
||||
context, context.types().GetInstId(type_id));
|
||||
quals &= ~SemIR::TypeQualifiers::Partial;
|
||||
}
|
||||
CARBON_CHECK(quals == SemIR::TypeQualifiers::None);
|
||||
return type_id;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user