Add the @exclusivity attribute.

The `@exclusivity(unchecked)` attribute can be used on variables to selectively disable exclusivity checking.
For completeness, also the `@exclusivity(checked)` variant is supported: it turns on exclusivity checking for specific variables if exclusivity enforcement is disabled by the command line option.

This new attribute is a missing implementation part of SE-0176 (https://github.com/apple/swift-evolution/blob/main/proposals/0176-enforce-exclusive-access-to-memory.md).

rdar://31121356
This commit is contained in:
Erik Eckstein
2022-01-24 21:08:18 +01:00
parent 83484f8516
commit 5fd941eb67
14 changed files with 215 additions and 2 deletions

View File

@@ -2520,6 +2520,14 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
return;
}
case DAK_Exclusivity: {
auto *theAttr = cast<ExclusivityAttr>(DA);
auto abbrCode = S.DeclTypeAbbrCodes[ExclusivityDeclAttrLayout::Code];
ExclusivityDeclAttrLayout::emitRecord(S.Out, S.ScratchRecord, abbrCode,
(unsigned)theAttr->getMode());
return;
}
case DAK_Effects: {
auto *theAttr = cast<EffectsAttr>(DA);
auto abbrCode = S.DeclTypeAbbrCodes[EffectsDeclAttrLayout::Code];