Граф коммитов

19333 Коммитов

Автор SHA1 Сообщение Дата
Ben Langmuir 2ea6c058d8 [index] Fix infinite loop while looking at superclasses
While checking for superclasses in isUnitTest, we need to handle
circular inheritance. For good measure, add tests for protocols as well.

The new API is designed to behave the same as walkInheritedProtocols
except that is walks over superclasses.

rdar://49434989
2019-03-29 16:58:35 -07:00
Doug Gregor 04e69a6014 [IRGen] Mangle Swift @objc(renamed) protocols as Objective-C in metadata.
When emitting metadata for a Swift-defined @objc protocol that has
provided a specific Objective-C name (e.g., via @objc(renamed)),
mangle such protocols using their Objective-C names so they can be
found at runtime.

Only do this for metadata, because doing it anywhere else would cause
an ABI break. Fixes rdar://problem/47877748.
2019-02-25 22:37:24 -08:00
Xi Ge bf038c2684 AST: TapExpr should return sub-expression's source locations if set.
Without source location, TapExpr could stop IDE from collecting parameters
while perform refactoring.

rdar://47835267
2019-02-08 10:44:46 -08:00
John McCall 03f97a6efc Remove some comments that are both unnecessary and invalid. 2019-02-07 13:21:52 -05:00
Xi Ge fc847a5c19 IDE: print underscored keywords for interface generation
Addressing @airspeedswift's code review feedback.
2019-02-06 16:06:24 -08:00
Xi Ge 2f32a12125 ASTPrinter: add an option to skip keywords with a prefix of underscore.
DocSupport will use set this flag to avoid printing __consuming, __owned, and
__shared.

rdar://47777848
2019-02-06 16:06:10 -08:00
Slava Pestov 3fc95a0dcf Reflection: Fix definition of swift_layout_kind to line up with Swift 4.2
Internally we have some code that dlopen()s different versions of the
reflection library, so the constants must match across supported
versions.

Fixes <rdar://problem/46830173>.
2019-02-06 15:56:46 -05:00
AnnaZaks d07c25ac16
Merge pull request #22400 from rjmccall/init-class-metadata-dependencies-runtime-5.0
[5.0] Add new runtime functions for handling dependencies when initializing class metadata
2019-02-05 23:40:46 -08:00
John McCall 37b0a546de Add new APIs for init/updateClassMetadata that can report dependencies. 2019-02-05 23:18:24 -05:00
Doug Gregor 1d705ca9dc [ABI] Fix metadata accessors for 32-bit remote AST/remote mirrors.
The use of sizeof(void*) in TargetStructMetadata and
TargetEnumMetadata's accessors is incorrect when (e.g.) reading
metadata from a 32-bit process in a 64-bit host. Use
sizeof(StoredPointer) instead to properly account for the runtime
pointer size.

Fixes rdar://problem/47305557.
2019-02-05 14:20:24 -08:00
Adrian Prantl 768ab4d948 Cache clang ASTFile information in swift::Module (NFC from the outside).
The loading of additional modules by Sema may trigger an out-of-date
PCM rebuild in the Clang module dependencies of the additional
module. A PCM rebuild causes the ModuleManager to unload previously
loaded ASTFiles. For this reason we must use the cached ASTFile
information here instead of the potentially dangling pointer to the
ASTFile that is stored in the clang::Module object.

This fixes a crash in IRGenDebugInfo when generation DIModule context
chains.

rdar://problem/47600180
2019-02-01 17:35:44 -08:00
AnnaZaks 29040d4cfc
Merge pull request #22254 from xedin/change-text-of-fallback-diag-5.0
[5.0][CSDiagnostics] NFC: Fallback diagnostic shouldn't ask for the project
2019-01-31 19:25:04 -08:00
Pavel Yaskevich c69d79cc1a [CSDiagnostics] NFC: Fallback diagnostic shouldn't ask for the project
(cherry picked from commit 52024681e0)
2019-01-30 17:38:38 -08:00
Erik Eckstein 3952423f51 SILOptimizer: fix a bug in the TempRValue optimization which causes a miscompile.
The problematic scenario is that a function receives an @in_guaranteed and @inout parameter where one is a copy of the other value. For example, when appending a container to itself.
In this case the optimization removed the copy_addr, resulting in passing the same stack location to both parameters.

rdar://problem/47632890
2019-01-30 17:03:19 -08:00
AnnaZaks c19dfb5008
Merge pull request #22219 from xedin/rdar-38885760-5.0
[5.0][TypeChecker] Always emit a fallback error if type-check failed witho
2019-01-30 16:44:09 -08:00
Karoy Lorentey f86388cf9e [5.0][Sema] Add dedicated fix-it for NSObject.hashValue overrides (#22173)
* [Sema] Add dedicated fix-it for NSObject.hashValue overrides

NSObject.hashValue used to be declared `@objc open` by historical accident. This has been corrected to `@nonobjc public` in Swift 5’s SDK overlays, to catch accidental overrides. (These never did work correctly, and shouldn’t have been allowed.)

Help migration by adding a dedicated error message for NSObject.hashValue overrides, with a nice fix-it.

rdar://problem/45674813
(cherry picked from commit df8eba480e)

* [test] Test new fix-it for NSObject.hashValue overrides

(cherry picked from commit 6af814d76c)
2019-01-29 21:12:05 -08:00
Pavel Yaskevich 8227182490 [TypeChecker] Add Builtin operation to trigger/test fallback diagnostic
(cherry picked from commit 64fa0ee729)
2019-01-29 10:49:22 -08:00
Jordan Rose 354e956138 Merge pull request #22188 from jrose-apple/open-your-heart
Don't fix access of an 'open' override in a 'public' extension

rdar://problem/47557376&28493971
(cherry picked from commit de93ba0992)
2019-01-29 10:49:08 -08:00
Pavel Yaskevich 094a781fb2 [TypeChecker] Always emit a fallback error if type-check failed without producing one
Sometimes constraint solver fails without producing any diagnostics,
it could happen during different phases e.g. pre-check, constraint
generation, or even while attempting to apply solution. Such behavior
leads to crashes down the line in AST Verifier or SILGen which are
hard to diagnose.

Let's guard against that by tracking if solver produced any diagnostics
upon its failure and if no errors were or are scheduled to be produced,
let's produce a fallback fatal error pointing at affected expression.

Resolves: rdar://problem/38885760
(cherry picked from commit 35202ab5b0)
2019-01-29 10:49:05 -08:00
Saleem Abdulrasool 13fc7bedb7 Remote: use the qualified name for `NodePointer`
Use the qualified name for the `NodePointer`.  The unqualified name
causes ambiguity when building on Windows.  This repairs the Windows
build.
2019-01-28 11:15:07 -08:00
Bob Wilson 0d2be92411
Merge pull request #21914 from linux-on-ibm-z/swift5.0-s390x-tupleSize-fix
Fix test case regressions on s390x arch
2019-01-28 10:16:14 -08:00
Doug Gregor c4139d611e [Remote AST] Use anonymous context descriptor mangled names for private types.
When an anonymous context descriptor provides a mangled name, use that
mangled name to provide the private declaration name for its child context.
This allows us to resolve private type names correctly when the corresponding
anonymous context has its mangled name.

Fixes rdar://problem/38231646.

(cherry picked from commit 61d14ed3d7)
2019-01-25 15:28:53 -08:00
Doug Gregor 8dd64be723 [ABI] Optionally emit mangled names into anonymous context metadata.
When -enable-anonymous-context-mangled-names is provided, emit mangled
names as part of the metadata of an anonymous context. This will allow
us to match textual mangled names to the metadata.

This is a backward-compatible ABI extension. Part of rdar://problem/38231646/.

(cherry picked from commit 0c88b88322)
2019-01-25 15:28:52 -08:00
Mike Ash 8358df8ef8 [REPL] When using the default resource directory, prefer loading Swift dylibs from /usr/lib/swift.
rdar://problem/46355503
2019-01-25 13:26:32 -05:00
Slava Pestov 2460aa787c AST: Cache ProtocolDecl::getInheritedProtocols()
Fixes <rdar://problem/47371754>.
2019-01-18 16:42:21 -05:00
Slava Pestov 407e818d10 AST: Cache SuperclassDeclRequest
This fixes a significant build time regression since 4.2.

Fixes <rdar://problem/47305605>.
2019-01-16 15:13:01 -05:00
rposts abcdac2971 Fix test case regressions on s390x arch 2019-01-16 09:38:56 -05:00
AnnaZaks 3ef4a2d1a0
Merge pull request #21849 from jrose-apple/5.0-collocating-convenience-initializers
[5.0] Restore initializing entry points for @objc convenience initializers
2019-01-15 10:30:02 -08:00
eeckstein a466ecea12
Merge pull request #21844 from eeckstein/fix-erase-apply-5.0
[5.0] SILCombine: fix a miscompile caused by dead-apply elimination
2019-01-14 16:19:33 -08:00
Jordan Rose be55564947 Restore initializing entry points for @objc convenience initializers (#21815)
This undoes some of Joe's work in 8665342 to add a guarantee: if an
@objc convenience initializer only calls other @objc initializers that
eventually call a designated initializer, it won't result in an extra
allocation. While Objective-C /allows/ returning a different object
from an initializer than the allocation you were given, doing so
doesn't play well with some very hairy implementation details of
compiled nib files (or NSCoding archives with cyclic references in
general).

This guarantee only applies to
(1) calling `self.init`
(2) where the delegated-to initializer is @objc
because convenience initializers must do dynamic dispatch when they
delegate, and Swift only stores allocating entry points for
initializers in a class's vtable. To dynamically find an initializing
entry point, ObjC dispatch must be used instead.

(It's worth noting that this patch does NOT check that the calling
initializer is a convenience initializer when deciding whether to use
ObjC dispatch for `self.init`. If we ever add peer delegation to
designated initializers, which is totally a valid feature, that should
use static dispatch and therefore should not go through objc_msgSend.)

This change doesn't /always/ result in fewer allocations; if the
delegated-to initializer ends up returning a different object after
all, the original allocation was wasted. Objective-C has the same
problem (one of the reasons why factory methods exist for things like
NSNumber and NSArray).

We do still get most of the benefits of Joe's original change. In
particular, vtables only ever contain allocating initializer entry
points, never the initializing ones, and never /both/ (which was a
thing that could happen with 'required' before).

rdar://problem/46823518
(cherry picked from commit 425c190086)
2019-01-14 15:43:07 -08:00
eeckstein cedfa64534
Merge pull request #21683 from atrick/5.0-fix-align-mask
Force manual allocation (via Unsafe*Pointer) to use >= 16 alignment.
2019-01-14 12:57:45 -08:00
Bob Wilson cd91b2bfb0
Merge pull request #21551 from compnerd/gen-x
[5.0] Remove check for including Runtime due to CmakeConfig.h dependencies
2019-01-14 10:28:45 -08:00
Erik Eckstein 1d70bc9065 SILCombine: fix a miscompile caused by dead-apply elimination
SILCombine ended up moving a strong_release past a dealloc_ref.
fixes https://bugs.swift.org/browse/SR-9627
rdar://problem/47153896
2019-01-14 10:00:12 -08:00
Andrew Trick e6b628b08f Reduce compile time for large strongly connected call graphs.
Improves SwiftSyntax release build speed by 4x.

Limit the size of the sets tracked by inter procedural
AccessedStorageAnalysis. There is a lot of leeway in this limit since
"normal" code doesn't come close to hitting it and SwiftSyntax compile
time isn't noticeably affected until 10x this limit.

This change also avoids reanalyzing function bodies once results have
bottomed out and avoids copying sets in the common case.

Fixes <rdar://problem/46905624> Release build time regression, a lot of time spent on AccessEnforcementOpts::run().

This is just a band aid. The fundamental problem is really:
<rdar://problem/47195282> Recomputing BottomUpIPAnalysis takes most of
the SwiftSyntax compile time.

SwiftSyntax compile time is still at least an order of magnitude
longer than it should be.

(cherry picked from commit 5b424694c5)
2019-01-11 14:57:09 -08:00
AnnaZaks cf150270fd
Merge pull request #21776 from jckarter/keypath-selector-instantiation-fn-5.0
[5.0] KeyPaths: Don't relative-reference selector refs.
2019-01-10 19:34:38 -08:00
Joe Groff 31100c1ce5 KeyPaths: Don't relative-reference selector refs.
ld64 doesn't like this. Instead, generate a stub function to grab the instantiated selector. Fixes rdar://problem/47184763.
2019-01-10 14:56:31 -08:00
Xi Ge 3583dea135 [Parser] Expose a flag to allow users explicitly disable delayed parsing. NFC
Discussed with @dcci, this patch is necessary to fix an lldb test failure. rdar://38396444
2019-01-10 11:49:17 -08:00
Jordan Rose 6925f866be Special-case diagnostic for when you just need `@unknown default` (#21695)
This is a new feature of Swift 5 mode, so it deserves at least a
little bit of explanation right in the diagnostic. If you have an
otherwise-fully-covered switch but can't assume the enum is frozen,
you'll now get this message:

    switch covers known cases, but 'MusicGenre' may have additional
    unknown values

Furthermore, if the enum comes from a system header, it looks like
this:

    switch covers known cases, but 'NSMusicGenre' may have additional
    unknown values, possibly added in future versions

...to further suggest the idea that even though your switch is covered
/now/, it might not handle everything in the /future/. This extra bit
is limited to system headers to avoid showing up on C enums defined in
your own project, for which it sounds silly. (The main message is
still valid though, since you can cram whatever you want into a C
enum, and people use this pattern to implement "private cases".)

rdar://problem/39367045
(cherry picked from commit 4a8f81db2b)
2019-01-08 08:48:09 -08:00
Andrew Trick 4dd1a1131b Force manual allocation (via Unsafe*Pointer) to use >= 16 alignment.
This fixes the Windows platform, where the aligned allocation path is
not malloc-compatible. It won't have any observable difference on
Darwin or Linux, aside from manually allocated memory on Linux now
being consistently 16-byte aligned (heap objects will still be 8-byte
aligned on Linux).

It is unfortunate that we can't guarantee Swift-allocated memory via
Unsafe*Pointer is malloc compatible on Windows. It would have been
nice for that to be a cross platform guarantee since it's normal to
allocate in C and deallocate in Swift or vice-versa. Now we have to
tell devs to always use _aligned_malloc/_aligned_free when
transitioning between Swift/C if they expect their code to work on
Windows.

Even though this fix isn't required today on Darwin/Linux, it makes
good sense to guarantee that the allocation/deallocation paths are
consistent.

This is done by specifying a constant that stdlib can use to round up
alignment, _swift_MinAllocationAlignment. The runtime asserts that
this constant is greater than MALLOC_ALIGN_MASK for all platforms. If
a user specifies alignment less than _swift_MinAllocationAlignment
(during manual allocation), then the stdlib rounds up to
_swift_MinAllocationAlignment, forcing the runtime to perform
"aligned" allocation. This way, the user does not need to provide the
identical alignment value again when deallocating the memory.

Alternatives are:

1. Require users of Unsafe*Pointer to specify the same alignment
   during deallocation. This is obviously madness.

2. Introduce new runtime entry points:
   swift_alignedAlloc/swift_alignedDealloc, introduce corresponding
   new builtins, and have Unsafe*Pointer always call those. This would
   make the run API a little more obvious but would introduce
   complexity all over the place and doesn't have any other
   significant benefit. Less than 16-byte alignment of manually
   allocated buffers on Linux is a non-goal.

(cherry picked from commit 0b5fa792e1)
2019-01-07 12:01:25 -08:00
Rintaro Ishizaki 7f57ad9952 [Parse] Eliminate backtracking in collection expression parsing
Parsing collection literal expression used to take exponential time
depending on the nesting level of the first element.

Stop using 'parseList()' because using it complicates libSyntax parsing.

rdar://problem/45221238 / https://bugs.swift.org/browse/SR-9220
rdar://problem/38913395 / https://bugs.swift.org/browse/SR-7283
(cherry picked from commit 22652f9e88)
2019-01-08 02:42:00 +09:00
Doug Gregor 95d75b51de [Runtime] Minor future-proofing for demangling bound generic ObjC classes. 2019-01-03 11:21:18 -08:00
Doug Gregor bd4ccb84aa [Runtime] Correctly match demangle tree for generic Objective-C classes.
When we encounter the demangle tree for a bound generic class type, look
through the "Type" node of the child tree before checking whether we
have an Objective-C class name. If we do have an Objective-C class name,
there is no way to preserve the generic arguments, so we ignore them and
return the (non-generic) class type.

Fixes rdar://problem/47028102.
2019-01-03 11:21:17 -08:00
Karoy Lorentey c22c0b82d1 [5.0][Sema] Emit a deprecation warning if a Hashable type only implements hashValue (#21445)
* [Sema] Emit a deprecation warning when hashValue is provided by hash(into:) isn’t

SE-206 deprecated hashValue as a protocol requirement. We should gently encourage people to migrate to hash(into:), for its more secure, easier and faster hashing.

Emit a compiler warning whenever hashValue has an explicit implementation, but hash(into:) doesn’t.

(cherry picked from commit e0495a7e0b)

* [stdlib] Document that `hashValue` is deprecated

(cherry picked from commit 1485404532)

* [test] Test new deprecation warning for hashValue implementations

(cherry picked from commit cb3cff55f9)

* Doc fix

Co-Authored-By: lorentey <klorentey@apple.com>
(cherry picked from commit 646849ee64)

* [test] StdlibUnittest: Add missing hash(into:) implementations

(cherry picked from commit 8e77a2655a)

* [test] Modernize hashing throughout the test suite

(cherry picked from commit 666a22feff)
2019-01-02 12:14:31 -08:00
Nathan Lanza 6b3dbf29ef Remove check for including Runtime due to CmakeConfig.h dependencies
Various files include Runtime/Config.h which depends on
Runtime/CMakeConfig.h and thus this check does not work.
2018-12-26 09:40:09 -08:00
AnnaZaks 5cfc2e7ba9
Merge pull request #21505 from DougGregor/dynamic-replacement-ambiguity-5.0
[5.0] [Type checker] Basic ambiguity resolution + diagnostics for dynamic replacement
2018-12-22 13:42:58 -08:00
Doug Gregor 0588b6dbff [Type checker] Basic ambiguity resolution + diagnostics for dynamic replacement.
We weren't doing much validation when dynamically replacing storage
declarations, and has an assert() that should be an error. Clean up this
area a bit, dealing with simple ambiguities (i.e., there are two
properties or subscripts with different type signatures; pick the
matching one) and reporting an error when there is a true ambiguity.

Fixes rdar://problem/46737657.

(cherry picked from commit 5d968621d7)
2018-12-21 13:18:01 -08:00
Andrew Trick 02939d1664 Fix SILCombine metatype cast optimization to avoid extending lifetimes.
This cannot be correctly done as a SILCombine because it must create
new instructions at a previous location. Move the optimization into
CastOptimizer. Insert the new metatype instructions in the correct
spot. And manually do the replaceAllUsesWith and eraseInstruction
steps.

Fixes <rdar://problem/46746188> crash in swift_getObjCClassFromObject.

(cherry picked from commit 65c95dd840)
2018-12-21 11:25:27 -08:00
AnnaZaks c86283e416
Merge pull request #21482 from CodaFi/the-not-so-logical-song
[5.0][SR-8272] Drop the last remnants of LogicValue
2018-12-21 11:17:03 -08:00
Robert Widmann 1ea4fcae2d [SR-8272] Drop the last remnants of LogicValue
Removes the _getBuiltinLogicValue intrinsic in favor of an open-coded
struct_extract in SIL.  This removes Sema's last non-literal use of builtin
integer types and unblocks a bunch of cleanup.

This patch would be NFC, but it improves line information for conditional expression codegen.
2018-12-20 23:38:13 -05:00
Jordan Rose a0a2ad43d9 Merge pull request #21450 from jrose-apple/conditionally-retro
[ABI] [Mangling] Only look for retroactive conformances in conditional reqs

rdar://problem/46735592
2018-12-20 18:04:09 -08:00