-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Add Feature: NonescapableAccessorOnTrivial #82380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Feature: NonescapableAccessorOnTrivial #82380
Conversation
@swift-ci test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM for 6.2, just two minor nitpicks for main
include/swift/AST/Types.h
Outdated
@@ -700,6 +700,13 @@ class alignas(1 << TypeAlignInBits) TypeBase | |||
/// Returns true if this contextual type is (Escapable && !isNoEscape). | |||
bool mayEscape() { return !isNoEscape() && isEscapable(); } | |||
|
|||
/// Returns true if this contextual type satisfies a conformance to Escapable. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this doc comment and the next need s/Escapable/BitwiseCopyable/
lib/AST/FeatureSet.cpp
Outdated
auto sig = nominal->getGenericSignature(); | ||
return !var->getInterfaceType()->isEscapable(sig); | ||
auto sig = dc->getGenericSignatureOfContext(); | ||
return !var->getInterfaceType()->isEscapable(sig); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var->getTypeInContext()->isEscapable()
also works and avoids having to fish out sig
entirely
lib/AST/FeatureSet.cpp
Outdated
} | ||
if (auto dc = var->getDeclContext()) { | ||
auto sig = dc->getGenericSignatureOfContext(); | ||
if (!var->getInterfaceType()->isEscapable(sig)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same remark here about getInterfaceType() vs getTypeInContext()
ae31edc
to
8272a63
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I folded away the if (auto dc = var->getDeclContext())
checks. Presumably a VarDecl always has a context.
And added a unit test.
@swift-ci test |
To guard the new UnsafeMutablePointer.mutableSpan APIs. This allows older compilers to ignore the new APIs. Otherwise, the type checker will crash on the synthesized _read accessor for a non-Escapable type: error: cannot infer lifetime dependence on the '_read' accessor because 'self' is BitwiseCopyable, specify '@Lifetime(borrow self)' I don't know why the _read is synthesized in these cases, but apparently it's always been that way. Fixes: rdar://153773093 ([nonescapable] add a compiler feature to guard ~Escapable accessors when self is trivial)
8272a63
to
cc357f4
Compare
@swift-ci test |
To guard the new UnsafeMutablePointer.mutableSpan APIs.
This allows older compilers to ignore the new APIs. Otherwise, the type checker
will crash on the synthesized _read accessor for a non-Escapable type:
I don't know why the _read is synthesized in these cases, but apparently it's
always been that way.
Fixes: rdar://153773093 ([nonescapable] add a compiler feature to guard
~Escapable accessors when self is trivial)