-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Initial language support for lifetime dependence #71069
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
Initial language support for lifetime dependence #71069
Conversation
Swift Parser changes and support for lifetime dependence in initializers and function types are pending. |
@swift-ci test |
@swift-ci test windows platform |
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.
Value(Identifier name) : Named({name}) {} | ||
Value(unsigned index) : Ordered({index}) {} | ||
Value() {} | ||
} value; |
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.
Instead of doing this could we take advantage of inline bit fields here? We'll get a NamedSpecifier, OrderedSpecifier or SelfSpecifier sublcasses and share trailing storage to store name/id similar to #70998?
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.
Can I do this as a follow on commit ?
static inline llvm::StringRef getOwnershipSpelling(ValueOwnership ownership) { | ||
switch (ownership) { | ||
case ValueOwnership::Default: | ||
return ""; |
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.
Should this be something more concrete i.e. "default"?
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.
Leaving the spelling as is, because it matched both swift and sil.
The diagnostics on valid dependence vs. ownership specifiers looks great to me. Please also disallow a As discussed, we should
But those can be follow-up PRs. |
c9220e6
to
d7b974d
Compare
@swift-ci smoke test |
lib/Sema/TypeCheckDecl.cpp
Outdated
if (returnTypeRepr) { | ||
if (auto *lifetimeDependentRepr = | ||
dyn_cast<LifetimeDependentReturnTypeRepr>(returnTypeRepr)) { | ||
lifetimeDependenceInfo = validateLifetimeDependenceInfo( |
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.
This should probably be in a separate request evaluator request
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.
can I do that in a follow up PR ?
You might want to consider landing some of these changes right away, to avoid merge conflicts. |
(Assuming the existing tests still pass) |
7f2ec44
to
abdade5
Compare
@swift-ci smoke 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.
Parser changes look good. Nothing serious.
break; | ||
} | ||
// consume the lifetime dependence kind | ||
consumeToken(); |
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.
Not remembering the location of kind token makes getStartLoc()
incorrect, but I don't think it's serious for now. applyAttributesToType()
changes the order of specifiers anyway. We should fix them, but not necessary in this PR.
Also, representing single _copy(x, y)
as separate LifetimeDependenceSpecifier
make it impossible to restore the textual representation of the specifier (when printing), but I think that's also not serious for now.
|
||
void LifetimeDependentReturnTypeRepr::printImpl( | ||
ASTPrinter &Printer, const PrintOptions &Opts) const { | ||
printTypeRepr(getBase(), Printer, Opts); |
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 assume you're going to implement printing specifiers in followups.
()) | ||
|
||
ERROR(expected_rparen_after_lifetime_dependence, PointsToFirstBadToken, | ||
"expected ')' after param list in lifetime dependence specifier", ()) |
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.
"expected ')' after param list in lifetime dependence specifier", ()) | |
"expected ')' after parameter list in lifetime dependence specifier", ()) |
Also: I don’ t think we have a test case for this diagnostic.
func use(_ x: borrowing BufferView) {} | ||
|
||
func deriveMultiView1(_ x: borrowing BufferView, _ y: borrowing BufferView) -> _borrow(x, y) BufferView { | ||
if (Int.random(in: 1..<100) % 2 == 0) { |
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.
Nitpick: The parentheses aren’t needed in Swift.
return BufferView(y.ptr) | ||
} | ||
|
||
func deriveMultiView2(_ x: borrowing BufferView, _ y: borrowing BufferView) -> _borrow(x) _borrow(y) BufferView { |
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.
Is it intentional that it’s allowed to specify _borrow
twice? I think we should error here and only allow _borrow(x, y)
.
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.
abdade5
to
1894b11
Compare
@swift-ci smoke test |
@swift-ci smoke test Linux |
@swift-ci test Linux platform |
…llowup Follow up for C++ parser changes in #71069
No description provided.