mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[ASTPrinter] Escape @_lifetime arguments when needed
rdar://159992995
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
|
||||
#include "swift/AST/LifetimeDependence.h"
|
||||
#include "swift/AST/ASTContext.h"
|
||||
#include "swift/AST/ASTPrinter.h"
|
||||
#include "swift/AST/Builtins.h"
|
||||
#include "swift/AST/ConformanceLookup.h"
|
||||
#include "swift/AST/Decl.h"
|
||||
@@ -30,8 +31,14 @@ namespace swift {
|
||||
|
||||
std::string LifetimeDescriptor::getString() const {
|
||||
switch (kind) {
|
||||
case DescriptorKind::Named:
|
||||
case DescriptorKind::Named: {
|
||||
bool shouldEscape =
|
||||
escapeIdentifierInContext(getName(), PrintNameContext::Normal);
|
||||
if (shouldEscape) {
|
||||
return ("`" + getName().str() + "`").str();
|
||||
}
|
||||
return getName().str().str();
|
||||
}
|
||||
case DescriptorKind::Ordered:
|
||||
return std::to_string(getIndex());
|
||||
case DescriptorKind::Self:
|
||||
|
||||
@@ -24,6 +24,14 @@ public func barFunc(_ bar: inout S) -> S {
|
||||
@_lifetime(`func`: copy `func`)
|
||||
public func funcFunc(func: inout S) {}
|
||||
|
||||
public struct T : ~Escapable {
|
||||
let s: S
|
||||
@_lifetime(borrow self)
|
||||
func selfFunc() -> S { return s }
|
||||
@_lifetime(borrow `self`)
|
||||
func selfFunc2(`self`: S) -> S { return `self` }
|
||||
}
|
||||
|
||||
//--- interface.txt.expected
|
||||
|
||||
public struct S : ~Escapable {
|
||||
@@ -35,5 +43,16 @@ public struct S : ~Escapable {
|
||||
public func fooFunc(_ foo: inout S)
|
||||
@_lifetime(&bar)
|
||||
public func barFunc(_ bar: inout S) -> S
|
||||
@_lifetime(func: copy func)
|
||||
@_lifetime(`func`: copy `func`)
|
||||
public func funcFunc(func: inout S)
|
||||
|
||||
public struct T : ~Escapable {
|
||||
|
||||
internal let s: S
|
||||
|
||||
@_lifetime(borrow self)
|
||||
internal func selfFunc() -> S
|
||||
|
||||
@_lifetime(borrow `self`)
|
||||
internal func selfFunc2(self: S) -> S
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user