Add @safe(unchecked) to allow unsafe code within a declaration.

Introduce an attribute to allow unsafe code within the annotated
declaration without presenting an unsafe interface to users. This is,
by its nature, and unsafe construct, and is used to document where
unsafe behavior is encapsulated in safe constructs.

There is an optional message that can be used as part of an audit
trail.
This commit is contained in:
Doug Gregor
2024-12-13 11:36:40 -08:00
parent cf7fcf2da9
commit e260d65f71
13 changed files with 138 additions and 5 deletions

View File

@@ -3376,6 +3376,15 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
return;
}
case DeclAttrKind::Safe: {
auto *theAttr = cast<SafeAttr>(DA);
auto abbrCode = S.DeclTypeAbbrCodes[SafeDeclAttrLayout::Code];
SafeDeclAttrLayout::emitRecord(S.Out, S.ScratchRecord, abbrCode,
theAttr->isImplicit(),
theAttr->message);
return;
}
case DeclAttrKind::MacroRole: {
auto *theAttr = cast<MacroRoleAttr>(DA);
auto abbrCode = S.DeclTypeAbbrCodes[MacroRoleDeclAttrLayout::Code];