Commit Graph

104 Commits

Author SHA1 Message Date
Robert Widmann
bfe23bba5b Define LookupOperatorRequest and Friends
Turn macro metaprogramming into template metaprogramming by defining a new kind of request that runs operator lookups.

This is the final piece of the puzzle for requestification of the current referenced name tracker system.
2020-03-20 15:50:12 -07:00
Fred Riss
259d78a350 Adapt to llvm.org StringRef API change 2020-03-13 19:08:22 +01:00
Brent Royal-Gordon
d0e957885f [NFC] Use CompoundDeclName for zero-arg names
Currently DeclName uses an inline representation for compound names with no argument labels. This is more compact, but it costs a spare bit that we need for other purposes. This commit switches over to representing this using a separate CompoundDeclName allocation with zero trailing argument labels instead.
2019-12-18 17:22:40 -08:00
Brent Royal-Gordon
6a8598a99c [NFC] Remove DeclNameRef staging calls 2019-12-11 00:55:18 -08:00
Brent Royal-Gordon
4b9a219d4f [NFC] Add DeclNameRef type to the compiler
This type wraps a DeclName, indicating that it is a reference to a declaration that exists somewhere else and it requires slightly “fuzzy” comparison (i.e. if it’s not compound, only the base names should be compared). DeclName::matchesRef() and MemberLookupTable::find() both now take a DeclNameRef instead of a DeclName.

This commit temporarily allows implicit conversion from DeclName; I’ll flip the switch on that in a later commit.
2019-12-11 00:45:08 -08:00
Brent Royal-Gordon
4c41794c9d [NFC] Add a spare bit to Identifier
So that DeclName can have a spare bit, allowing it to be used in places where we’re currently using PointerIntPair<Identifier, 1> or PointerUnion<Identifier, Whatever>.
2019-12-11 00:45:08 -08:00
Hamish Knight
633de0241b Add UnqualifiedLookupRequest
This request performs raw unqualified lookup,
and will be used to replace the UnqualifiedLookup
type.
2019-11-15 14:25:42 -08:00
Brent Royal-Gordon
99faa033fc [NFC] Standardize dump() methods in frontend
By convention, most structs and classes in the Swift compiler include a `dump()` method which prints debugging information. This method is meant to be called only from the debugger, but this means they’re often unused and may be eliminated from optimized binaries. On the other hand, some parts of the compiler call `dump()` methods directly despite them being intended as a pure debugging aid. clang supports attributes which can be used to avoid these problems, but they’re used very inconsistently across the compiler.

This commit adds `SWIFT_DEBUG_DUMP` and `SWIFT_DEBUG_DUMPER(<name>(<params>))` macros to declare `dump()` methods with the appropriate set of attributes and adopts this macro throughout the frontend. It does not pervasively adopt this macro in SILGen, SILOptimizer, or IRGen; these components use `dump()` methods in a different way where they’re frequently called from debugging code. Nor does it adopt it in runtime components like swiftRuntime and swiftReflection, because I’m a bit worried about size.

Despite the large number of files and lines affected, this change is NFC.
2019-10-31 18:37:42 -07:00
Brent Royal-Gordon
dee631bb31 [NFC] Explicitly control alignment of Identifiers
Identifier contains a pointer to character data, and we need to ensure that this pointer has enough spare bits in it for DeclBaseName and DeclName. This currently happens to be true because the StringMap used to intern Identifier pointers happens to place a 32-bit size field in the MapTableEntry object, but it would be better to explicitly force the alignment we want and assert that it’s correct.
2019-09-30 19:38:10 -07:00
Brent Royal-Gordon
0e8d600b8d [NFC] Make DeclName::dump() and ObjCSelector::dump() work
They were being stripped out of builds as dead code.
2019-08-30 13:38:17 -07:00
Pavel Yaskevich
b8c25db47e [ConstraintSystem] Add keypath subscript choice only if argument has an expected label
Currently only valid way to form keypath subscript is to use `keyPath:`
label in subscript invocation, so let's avoid adding keypath overload
choice to every subscript lookup and instead only add it when it could
potentially match.

This among other things greatly helps diagnostics because sometimes
`keypath application` becomes the only choice even although it's
not really viable, which impedes member reference diagnostics.
2019-07-03 00:48:04 -07:00
Brent Royal-Gordon
31aeb64efa Make a .def file for ObjCSelectorFamily 2019-02-14 13:31:16 -08:00
Brent Royal-Gordon
5f94043ef6 [NFC] Move selector family logic to ObjCSelector
SILFunctionType has some logic which examines a selector and decides if it belongs to one of Objective-C’s special “method families”, like -alloc* and -copy*, which need to return a retained pointer instead of an autoreleased one. This change extracts most of that logic into SwiftAST as ObjCSelector::getSelectorFamily(), while leaving details specific to SIL’s use of it behind.
2019-02-13 18:40:25 -08:00
Saleem Abdulrasool
d281b98220 litter the tree with llvm_unreachable
This silences the instances of the warning from Visual Studio about not all
codepaths returning a value.  This makes the output more readable and less
likely to lose useful warnings.  NFC.
2018-09-13 15:26:14 -07:00
Alex Hoppen
dfad6f787f [Basic] Extract isEditorPlaceholder from Identifier to standalone function 2018-07-13 16:56:03 -07:00
Slava Pestov
30dae65226 AST: Add DeclBaseName::Kind::Constructor
Not used yet.
2018-03-16 00:25:54 -07:00
swift-ci
9972dcca76 Merge remote-tracking branch 'origin/master' into master-llvm-swift5-transition 2018-02-20 14:17:56 -08:00
Alex Blewitt
1eca59dcb4 [SR-7032] Fix compare for lhs and rhs 2018-02-20 11:56:05 +00:00
John McCall
a5d328690d PointerLikeTypeTraits is now a struct, not a class.
We compile with a pedantic warning that complains about these things,
and the massive flood of warnings is actually causing problems for the
build infrastructure.
2017-08-17 17:01:17 -04:00
Alex Hoppen
2eb36e41f5 Introduce special name for destructors
This name is not used yet
2017-07-28 10:46:50 +02:00
John McCall
e83b355446 Add functions to check whether a DeclName is a specific compound name.
Also add an Identifier::is(StringRef), which is slightly nicer to use
than 'ident.str() == string' without making it too easy to use this
instead of Identifier equality.
2017-07-21 23:37:29 -04:00
Alex Hoppen
f8c2692f79 Introduce special decl names
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.
2017-07-11 19:04:13 +02:00
Alex Hoppen
949968a182 Adjust printing to take into account special DeclNames
Print DeclBaseNames using a new userFacingStr() method to prepare for
DeclBaseNames that are not backed by Identifiers
2017-06-24 11:39:09 +02:00
Alex Hoppen
6f3b8ca60f Merge pull request #9978 from ahoppen/pdm-remove-implicit-conversion
Remove implicit conversion from DeclBaseName to Identifier
2017-06-17 16:02:51 +02:00
Jordan Rose
f0aca936c7 Allow '@objc(RuntimeName)' on classes with generic ancestry.
This is accomplished by recognizing this specific situation and
replacing the 'objc' attribute with a hidden '_objcRuntimeName'
attribute. This /only/ applies to classes that are themselves
non-generic (including any enclosing generic context) but that have
generic ancestry, and thus cannot be exposed directly to Objective-C.

This commit also eliminates '@NSKeyedArchiverClassName'. It was
decided that the distinction between '@NSKeyedArchiverClassName' and
'@objc' was too subtle to be worth explaining to developers, and that
any case where you'd use '@NSKeyedArchiverClassName' was already a
place where the ObjC name wasn't visible at compile time.

This commit does not update diagnostics to reflect this change; we're
going to change them anyway.

rdar://problem/32414557
2017-06-05 17:32:25 -07:00
Alex Hoppen
930ffdacff Remove implicit conversion from DeclBaseName to Identifier
This conversion just existed to aid migration from Identifier to
DeclBaseName and is no longer needed. It will technically not even be
correct once special names are introduced.
2017-05-31 16:02:00 +02:00
Jordan Rose
c0ccdb1626 Change getBaseName to return DeclBaseName instead of Identifier (#9968)
This changes `getBaseName()` on `DeclName` to return a `DeclBaseName`
instead of an `Identifier`. All places that will continue to be
expecting an `Identifier` are changed to call `getBaseIdentifier` which
will later assert that the `DeclName` is actually backed by an
identifier and not a special name.

For transitional purposes, a conversion operator from `DeclBaseName` to
`Identifier` has been added that will be removed again once migration
to DeclBaseName has been completed in other parts of the compiler.

Unify approach to printing declaration names

Printing a declaration's name using `<<` and `getBaseName()` is be
independent of the return type of `getBaseName()` which will change in
the future from `Identifier` to `DeclBaseName`
2017-05-28 17:55:03 -07:00
Alex Hoppen
e068bc39e6 Add a couple of helper methods to DeclBaseName (#9319) 2017-05-28 17:24:58 -07:00
Alex Hoppen
4f0ab96626 Change the backing base name type of DeclName to DeclBaseName
The new DeclBaseName type will later be able to hold either normal
identifiers (as they exist now) or special names that don't have an
identifier (like subscripts)
2017-03-10 21:44:17 +00:00
Xi Ge
143c5a5d82 Address @jrose-apple's code review comments (#7474) 2017-02-14 18:41:21 -08:00
Xi Ge
055da1fbfb [SourceKit] Teach name translation request to translate Swift names to ObjC ones (by using PrintAsObjC). (#7449) 2017-02-14 14:25:52 -08:00
Jordan Rose
c011aa04fd Pull PointerLikeTypeTraits<DeclName> up to Identifier.h
No functionality change.
2017-01-10 16:43:40 -08:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Alex Hoppen
64aaacb309 [AST] Bugfix in ordering of DeclNames 2016-12-15 08:43:01 +01:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
Doug Gregor
8802d6d52a Improve diagnostics for selector collisions with @objc optional requirements.
When an optional requirement of an @objc protocol has a selector that
collides with an entity that has a different *Swift* name but produces
an Objective-C method with the same selector, we have an existing
diagnostic complaining about the conflict. In such cases, make a few
suggestions (with Fix-Its) to improve the experience:

* Change Swift name to match the requirement, adding or modifying the
  @objc as appropriate.
* Add "@nonobjc" to silence the diagnostic, explicitly opting out of
  matching an @objc requirement.

This is intended to help with migration of Swift 2 code into Swift
3. The Swift 2 code will produce selectors that match Objective-C
methods in the protocol from Swift names that don't match; this helps
fix up those Swift names so that we now match.

Fixes the rest of rdar://problem/25159872. In some sense, it's a
stop-gap for more detailed checking of near-misses for optional
requirements, but it's not clear how wide-reaching such changes would
be.
2016-04-19 10:22:23 -07:00
Greg Parker
125a146365 Revert "[Sema] Improve diagnostics for witness mismatches against @objc protocols." and "Improve diagnostics for selector collisions with @objc optional requirements."
This reverts commits 46269299cd
and 27279866ad
and c826a408dd.

The changes broke test bots, including
https://ci.swift.org/job/oss-swift-package-osx/1348/
2016-04-19 05:52:33 -07:00
Doug Gregor
27279866ad Improve diagnostics for selector collisions with @objc optional requirements.
When an optional requirement of an @objc protocol has a selector that
collides with an entity that has a different *Swift* name but produces
an Objective-C method with the same selector, we have an existing
diagnostic complaining about the conflict. In such cases, make a few
suggestions (with Fix-Its) to improve the experience:

* Change Swift name to match the requirement, adding or modifying the
  @objc as appropriate.
* Add "@nonobjc" to silence the diagnostic, explicitly opting out of
  matching an @objc requirement.

This is intended to help with migration of Swift 2 code into Swift
3. The Swift 2 code will produce selectors that match Objective-C
methods in the protocol from Swift names that don't match; this helps
fix up those Swift names so that we now match.

Fixes the rest of rdar://problem/25159872. In some sense, it's a
stop-gap for more detailed checking of near-misses for optional
requirements, but it's not clear how wide-reaching such changes would
be.
2016-04-18 17:08:06 -07:00
Dmitri Gribenko
023eaa6aa8 Merge pull request #1926 from danra/patch-1
Add missing period in end of comment (NFC)
2016-03-29 17:19:19 -07:00
danra
03862bc3ed Finish comment (NFC) 2016-03-30 00:35:19 +03:00
Dan Raviv
201873b729 Prettier operator!= DRY 2016-03-29 23:40:16 +03:00
Chris Lattner
de436b148d Merge pull request #1885 from danra/identifier_opaque_ptr
Fix getAsOpaquePointer method const-correctness
2016-03-26 19:40:41 -07:00
Ted Kremenek
338d8ead31 Merge pull request #1880 from danra/patch-1
Assert on calling getLength() on empty Identifier
2016-03-26 11:01:25 -07:00
Ted Kremenek
dc1106b999 Merge pull request #1884 from danra/identifier_notequals_dry
operator!= DRY
2016-03-26 11:01:02 -07:00
Dan Raviv
5124ff1bb6 Fix getAsOpaquePointer method const-correctness
In order for the method to be const, it should cast its Pointer member to a const void* and return it as such, not as a void*. This wasn't caught before due to using a C-style cast which stripped away the member's constness implicitly.
2016-03-26 20:04:14 +03:00
Dan Raviv
e7b9844b23 operator!= DRY 2016-03-26 19:50:15 +03:00
danra
0dce9f1352 Use nullptr instead of 0 for null pointer value 2016-03-26 18:19:46 +02:00
danra
e2851a9626 Assert on calling getLength() on empty Identifier
Calling ::strlen on nullptr is not allowed, but getLength() does not such check. We should either check for nullptr and return 0, or just assert assuming that calling getLength() on an empty Identifier is not intended and indicates a bug. Here the second approach was selected.
2016-03-26 18:17:37 +02:00
Dmitri Gribenko
8b86dac8c1 Revert "[gardening] Fix typo: "nul-terminated" → "null-terminated"" 2016-02-13 15:27:53 -08:00
Peter Friese
888d0f3fa6 [gardening] Fix typo: "nul-terminated" → "null-terminated" 2016-02-11 11:03:38 +00:00