Skip to content

Introduce special decl names #9989

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

Merged
merged 2 commits into from
Jul 11, 2017

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented May 30, 2017

After a long way we're finally here: The PR to introduce special names for subscripts and fix SR-2575.

Special DeclNames represent names that do not have an identifier in the surface language. This implies serializing the information about whether a name is special together with its identifier (if it is not special) in both the module file and the swift lookup table.

@ahoppen ahoppen requested a review from jrose-apple May 30, 2017 21:04
@ahoppen
Copy link
Member Author

ahoppen commented May 30, 2017

@swift-ci please test

@ahoppen ahoppen force-pushed the introduce-special-declnames branch from 8105cb6 to 3d1f716 Compare May 31, 2017 14:22
@ahoppen
Copy link
Member Author

ahoppen commented May 31, 2017

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Jenkins build - Swift Test OS X Platform
Git Commit - 8105cb6ddff4d68cf255525ecd410d4fedb2964d
Test requested by - @ahoppen

@swift-ci
Copy link
Contributor

Build failed
Jenkins build - Swift Test Linux Platform
Git Commit - 8105cb6ddff4d68cf255525ecd410d4fedb2964d
Test requested by - @ahoppen

Copy link
Contributor

@jrose-apple jrose-apple left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking pretty good—all the comments are small. I think you could have split this out a little more (a big chunk of the Serialization and ClangImporter changes don't depend on special names existing yet), but it's all right.

We do still have one issue for down the road, which is that there's no syntax for #selector(getter:NSDictionary.subscript), which would refer to a property named "subscript". Maybe we'll have to go with something like #selector(getter:NSDictionary[])

appendIdentifier(decl->getBaseName().getIdentifier().str());
// FIXME: Should a mangled subscript name contain the string "subscript"?
switch (decl->getBaseName().getKind()) {
case DeclBaseName::Kind::Normal:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: Swift/LLVM style doesn't indent case labels.

@@ -45,6 +45,102 @@ class TypedefNameDecl;

namespace swift {

/// A name from a SwiftLookupTable that has not been deserialized into a
/// DeclBaseName yet
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: missing period.

}

/// Return a string representation of the name that can be used for sorting
StringRef sortStr() const {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: I think this should be private for now. This partially comes from me still not being a fan of using the "str" abbreviation with any kind of description.

(also, missing period again)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was meant to be in sync with DeclBaseName, so I'll change the name to userFacingName. Shall we still make it private or keep it public then?

@@ -400,8 +400,7 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
}

SmallVector<char, 64> Buf;
// TODO: Handle special names
StringRef Name = (VD->getBaseName().getIdentifier().str() +
StringRef Name = (VD->getBaseName().userFacingName() +
Twine(Kind)).toStringRef(Buf);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adrian-prantl, this is the no-functionality-change implementation, and I think it does make sense to land that first, but it's worth considering whether this makes sense to begin with. Subscripts can be overloaded.

switch (P.Tok.getKind()) {
case tok::kw_subscript:
P.consumeToken();
FullName.push_back(DeclBaseName::createSubscript());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gottesmm or @swiftix, is this correct behavior for finding "subscript" in a textual SIL dotted path? Or is that expected to be treated as a regular identifier? Or can it just not come up?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gottesmm @swiftix Just a friendly ping as the question above still stands

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if it answers the question but maybe I'll just comment on what's going on here:

Previously, subscripts were backed by the identifier "subscript" so no distinction between properties named "subscript" and proper subscripts was necessary. Now we need distinguish between the two. As per #6848 (comment) I decided to represent a property named "subscript" as "`subscript`" in a SIL dotted path while plain "subscript" (without the backticks) still refers to a proper subscript.

So what I'm doing here is checking if a component in a SIL dotted path is the keyword subscript in order to translate it to a special DeclBaseName for subscripts. If "subscript" is spelled in backticks, the token kind will be "backtick", the default branch is taken and parseSILIdentifier will parse "`subscript`" as an identifier named "subscript", producing a dotted path that refers to a property named "subscript".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jckarter says this solution sounds good.

@@ -85,16 +85,21 @@ namespace {
using offset_type = unsigned;

hash_value_type ComputeHash(key_type_ref key) {
assert(!key.empty());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep this assertion in the Normal branch; it's caught bugs before. :-)

IdentifiersToWrite.push_back(ident.getIdentifier());
return id;
switch (ident.getKind()) {
case DeclBaseName::Kind::Normal: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: indented switch again.

@@ -1138,6 +1138,7 @@ void SwiftLangSupport::getDocInfo(llvm::MemoryBuffer *InputBuf,
if (Error)
Consumer.failed("Error occurred");
return;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spurious change?

@@ -1,4 +1,4 @@
// RUN: not --crash %target-swift-frontend %s -typecheck
// RUN: not %target-swift-frontend %s -typecheck
// REQUIRES: asserts
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: No more "REQUIRES: asserts" needed.

@@ -0,0 +1,16 @@
// RUN: %target-run-simple-swift | %FileCheck %s
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: test/Sema isn't supposed to have execution tests. Please move this to test/Interpreter (which has a number of non-interpreter execution tests at the moment) and add "REQUIRES: executable_test".

@ahoppen ahoppen force-pushed the introduce-special-declnames branch 2 times, most recently from 6ff4737 to 710dd93 Compare June 30, 2017 16:44
@ahoppen
Copy link
Member Author

ahoppen commented Jun 30, 2017

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Jenkins build - Swift Test Linux Platform
Git Commit - 3d1f71627f63b90c293e213c1f258a49b6652e78
Test requested by - @ahoppen

@swift-ci
Copy link
Contributor

Build failed
Jenkins build - Swift Test OS X Platform
Git Commit - 3d1f71627f63b90c293e213c1f258a49b6652e78
Test requested by - @ahoppen

@ahoppen ahoppen force-pushed the introduce-special-declnames branch from 710dd93 to ded6aed Compare July 6, 2017 11:37
@ahoppen
Copy link
Member Author

ahoppen commented Jul 6, 2017

Resolved merge conflicts

@swift-ci Please test

@swift-ci
Copy link
Contributor

swift-ci commented Jul 6, 2017

Build failed
Jenkins build - Swift Test OS X Platform
Git Commit - 710dd93a332ae1512a91171408fc06a8400c2afd
Test requested by - @ahoppen

@swift-ci
Copy link
Contributor

swift-ci commented Jul 6, 2017

Build failed
Jenkins build - Swift Test Linux Platform
Git Commit - 710dd93a332ae1512a91171408fc06a8400c2afd
Test requested by - @ahoppen

@ahoppen
Copy link
Member Author

ahoppen commented Jul 7, 2017

@jrose-apple I've addressed all the comments in your last review and the PR is ready from my side. Could you review the changes if you've got time?

Copy link
Contributor

@jrose-apple jrose-apple left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some small comments on this last version, but other than these this looks good to me! No need to wait for me after fixing this round.

@@ -206,15 +208,45 @@ namespace swift {

/// Wrapper that may either be an Identifier or a special name
/// (e.g. for subscripts)
///
/// The raw values of this enum are used in serialization by both
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment should no longer be necessary, right? (Also, it belongs on the enum, not the class!)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still using them for serialisation in ClangImporter but you said that they don't need to be stable for that, correct?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, that's correct.

@@ -90,7 +90,6 @@ IDENTIFIER(simd)
IDENTIFIER(some)
IDENTIFIER(storage)
IDENTIFIER(stringValue)
IDENTIFIER(subscript)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

@@ -540,8 +540,15 @@ void ASTMangler::appendDeclName(const ValueDecl *decl) {
break;
}
} else if (decl->hasName()) {
// TODO: Handle special names
appendIdentifier(decl->getBaseName().getIdentifier().str());
// FIXME: Should a mangled subscript name contain the string "subscript"?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something @eeckstein may have an opinion on, but can be changed in a follow-up commit.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to start a thread about that once the changes have been landed


// CHECK-LABEL: sil_vtable SubscriptAsFunction {
// CHECK-NOT: #SubscriptAsFunction.subscript
// CHECK: #SubscriptAsFunction.`subscript`!1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a SIL parser test for this too, even if just a basic one.

out << key.getIdentifier().str();
endian::Writer<little> writer(out);
switch (key.getKind()) {
case DeclBaseName::Kind::Normal:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: LLVM style does not indent switch cases.

ahoppen added 2 commits July 11, 2017 19:04
Special DeclNames represent names that do not have an identifier in the
surface language. This implies serializing the information about whether
a name is special together with its identifier (if it is not special)
in both the module file and the swift lookup table.
@ahoppen ahoppen force-pushed the introduce-special-declnames branch from ded6aed to 2dd670b Compare July 11, 2017 17:04
@ahoppen
Copy link
Member Author

ahoppen commented Jul 11, 2017

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Jenkins build - Swift Test Linux Platform
Git Commit - ded6aed0ee0d5d09a30f7e9ad627f764925a388e
Test requested by - @ahoppen

@swift-ci
Copy link
Contributor

Build failed
Jenkins build - Swift Test OS X Platform
Git Commit - ded6aed0ee0d5d09a30f7e9ad627f764925a388e
Test requested by - @ahoppen

@ahoppen ahoppen merged commit ec6fc4d into swiftlang:master Jul 11, 2017
@ahoppen ahoppen deleted the introduce-special-declnames branch July 12, 2017 14:12
jckarter added a commit to jckarter/swift that referenced this pull request Jul 20, 2017
…iptExprs.

Interactions with the rest of the type checker cause use of functions named `subscript` with backtick-quotes to become ambiguous. This is more fully and robustly solved in master by swiftlang#9989, but that's too invasive a change for 4.0, and we need a spot fix to prevent source compatibility regressions such as SR-5513.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants