Commit Graph

43 Commits

Author SHA1 Message Date
Becca Royal-Gordon
da07ff577c [PrintAsClang] Warn about unstable decl order
PrintAsClang is supposed to emit declarations in the same order regardless of the compiler’s internal state, but we have repeatedly found that our current criteria are inadequate, resulting in non-functionality-affecting changes to generated header content. Add a diagnostic that’s emitted when this happens soliciting a bug report.

Since there *should* be no cases where the compiler fails to order declarations, this diagnostic is never actually emitted. Instead, we test this change by enabling `-verify` on nearly all PrintAsClang tests to make sure they are unaffected.

This did demonstrate a missing criterion that only mattered in C++ mode: extensions that varied only in their generic signature were not sorted stably. Add a sort criterion for this.
2025-02-14 21:41:36 -08:00
Anton Korobeynikov
581b13fe31 Ignore "noescape" bit for all @convention(c) function pointers 2022-04-20 10:34:45 +02:00
Saleem Abdulrasool
36c951d31e Revert "[DebugInfo] Ignore noescape bit for all @convention(c) pointers" 2022-04-19 18:09:23 -07:00
Anton Korobeynikov
07396c5de6 Ignore "noescape" bit for all @convention(c) function pointers 2022-04-18 22:43:57 +02:00
Slava Pestov
eef1428a2b PrintAsObjC: Support for blocks with __owned parameters 2019-12-02 18:41:27 -05:00
Michael Gottesman
f854547c55 [ownership] Enable ownership verification by default.
I also removed the -verify-sil-ownership flag in favor of a disable flag
-disable-sil-ownership-verifier. I used this on only two tests that still need
work to get them to pass with ownership, but whose problems are well understood,
small corner cases. I am going to fix them in follow on commits. I detail them
below:

1. SILOptimizer/definite_init_inout_super_init.swift. This is a test case where
DI is supposed to error. The only problem is that we crash before we error since
the code emitting by SILGen to trigger this error does not pass ownership
invariants. I have spoken with JoeG about this and he suggested that I fix this
earlier in the compiler. Since we do not run the ownership verifier without
asserts enabled, this should not affect compiler users. Given that it has
triggered DI errors previously I think it is safe to disable ownership here.

2. PrintAsObjC/extensions.swift. In this case, the signature generated by type
lowering for one of the thunks here uses an unsafe +0 return value instead of
doing an autorelease return. The ownership checker rightly flags this leak. This
is going to require either an AST level change or a change to TypeLowering. I
think it is safe to turn this off since it is such a corner case that it was
found by a test that has nothing to do with it.

rdar://43398898
2019-03-25 00:11:52 -07:00
Michael Gottesman
0dfaa19f9f [ownership] Rename enable-sil-ownership => verify-sil-ownership.
I have been meaning to do this change for a minute, but kept on putting it off.
This describes what is actually happening and is a better name for the option.
2019-03-18 01:31:44 -07:00
Michael Gottesman
15c03b7b0a Fix potential use-after-free in emitFuncToBlock exposed by enabling ownership verification on PrintAsObjC/blocks.swift.
If the block is guaranteed, we need to be sure to copy here. This can happen for
instance with arguments (where this was caught). I added a SILGen test that
exposes this failure since this is not an actual bug in PrintAsObjC.
2019-03-11 14:23:44 -07:00
Slava Pestov
5964c00091 Migrate PrintAsObjC tests to Swift 4
I didn't migrate test/PrintAsObjC/versioned.swift, because it
explicitly checks the Swift 3 projection of some APIs.
2018-06-26 16:57:04 -07:00
Slava Pestov
5d2752f7d2 Run tests with -swift-version 4 by default
Some test now fail, so add an explicit -swift-version 3.
2018-06-19 23:24:19 -07:00
Robert Widmann
e15e293eed Don't flatten input types in ObjC representation check
Arguments of tuple type are not representable in Objective-C but the
old check was looking specifically for them.
2018-06-12 15:13:13 -07:00
Dmitri Gribenko
984210aa53 tests: replace '// RUN: rm -rf' '// RUN: mkdir' pairs with '%empty-directory(...)'
These changes were made using a script.
2017-06-04 11:08:39 -07:00
Doug Gregor
80e9491fe3 Make Swift-3-inferred @objc explicit in test cases 2017-03-31 21:22:15 -07:00
Tim Bodeit
96c964ee0d [test/PrintAsObjc] Adjust existing test cases for SWIFT_WARN_UNUSED_RESULT 2016-12-10 01:48:49 +01:00
David Farler
b7d17b25ba Rename -parse flag to -typecheck
A parse-only option is needed for parse performance tracking and the
current option also includes semantic analysis.
2016-11-28 10:50:55 -08:00
Dmitri Gribenko
55864d10cb Tests: use 'mkdir -p' 2016-09-02 21:36:45 -07:00
Jacob Bandes-Storch
89d0d62bd6 [PrintAsObjC] print __attribute__((noescape)) in Obj-C headers (#4438)
https://bugs.swift.org/browse/SR-2406
2016-08-31 09:27:59 -07:00
Dmitri Gribenko
d175b3b66d Migrate FileCheck to %FileCheck in tests 2016-08-10 23:52:02 -07:00
Doug Gregor
b9363fe6bd [SE-0111] Enable SE-0111 by default. 2016-07-29 17:28:24 -07:00
Michael Ilseman
c37751ae96 [noescape by defaul] make noescape the default
This flips the switch to have @noescape be the default semantics for
function types in argument positions, for everything except property
setters. Property setters are naturally escaping, so they keep their
escaping-by-default behavior.

Adds contentual printing, and updates the test cases.

There is some further (non-source-breaking) work to be done for
SE-0103:

- We need the withoutActuallyEscaping function
- Improve diagnostics and QoI to at least @noescape's standards
- Deprecate / drop @noescape, right now we allow it
- Update internal code completion printing to be contextual
- Add more tests to explore tricky corner cases
- Small regressions in fixits in attr/attr_availability.swift
2016-07-29 13:49:08 -07:00
Chris Lattner
8c1c0bed8c update the last of the testsuite to have parens around function type parameters. 2016-05-06 21:07:08 -07:00
Manav Gabhawala
7928140f79 [SE-0046] Implements consistent function parameter labels by discarding extraneous parameter names and adding _ where necessary 2016-04-06 20:21:58 -04:00
Kevin Ballard
00ccc9ddc3 [PrintAsObjC] Print argument names for function/block types
Including the argument names helps code completion in Xcode.

Fixes SR-365.

Also fixes an issue where a property of a block/function type whose name
is a clang keyword would produce an invalid declaration, e.g.

    var `struct`: (Int -> Int)?

was printing as

    @property (nonatomic, copy, getter=struct, setter=setStruct:) NSInteger (^ _Nullable struct)(NSInteger)_;
2016-03-02 21:02:32 -08:00
Kevin Ballard
66369468aa Use new-style _Nullable keywords in obj-c header
Use the keywords `_Nullable`, `_Nonnull`, and `_Null_unspecified`
instead of the older compatibility forms `__nullable`, `__nonnull`, and
`__null_unspecified`.

Part of rdar://problem/23614638
2015-12-05 19:54:27 -08:00
Jordan Rose
bca4b12f60 [PrintAsObjC] Handle blocks whose parameters come from a typealias.
...instead of crashing.

rdar://problem/21974146

Swift SVN r30753
2015-07-29 04:06:17 +00:00
Ted Kremenek
f97f7b66b0 Fix up test case.
Swift SVN r28460
2015-05-12 06:36:26 +00:00
Ted Kremenek
42cccf07b2 Make CFunctionPointer, GeneratorOf, SequenceOf unavailable.
Implements rdar://problem/20477688

Swift SVN r28459
2015-05-12 06:28:02 +00:00
Joe Groff
ec47ebdd3a PrintAsObjC: Handle @convention(c) function types.
Swift SVN r27263
2015-04-13 23:13:14 +00:00
Dmitri Hrybenko
f43843f25c tests: use the new substitution for the mock SDK
This is required to correctly use the mock SDK when the SDK overlay is
built and tested separately.  (Otherwise, the mock SDK might not get
used, because the overlay SDK options would expand from the
%-substitution, appear first on the command line, and shadow the mock
SDK in the search path).

Swift SVN r25185
2015-02-11 18:57:29 +00:00
Graham Batty
83b4384fac Update test flags for linux failures and support.
Also removed the sdk 'feature' in favour of the more specific
objc_interop.

Swift SVN r24856
2015-01-30 21:31:48 +00:00
Doug Gregor
fe5fe16c46 PrintAsObjC: Start printing __null_unspecified where needed.
Fixes rdar://problem/19499467.

Swift SVN r24643
2015-01-22 19:26:21 +00:00
Dmitri Hrybenko
3b04d1b013 tests: reorganize tests so that they actually use the target platform
Most tests were using %swift or similar substitutions, which did not
include the target triple and SDK.  The driver was defaulting to the
host OS.  Thus, we could not run the tests when the standard library was
not built for OS X.

Swift SVN r24504
2015-01-19 06:52:49 +00:00
Dmitri Hrybenko
1eea220932 Use one module cache directory for all the lit tests to speed them up
Doing so is safe even though we have mock SDK.  The include paths for
modules with the same name in the real and mock SDKs are different, and
the module files will be distinct (because they will have a different
hash).

This reduces test runtime on OS X by 30% and brings it under a minute on
a 16-core machine.

This also uncovered some problems with some tests -- even when run for
iOS configurations, some tests would still run with macosx triple.  I
fixed the tests where I noticed this issue.

rdar://problem/19125022

Swift SVN r23683
2014-12-04 11:21:48 +00:00
Graham Batty
83f27a8af7 Revert "Mark tests that don't pass on linux as XFAIL."
This reverts commit 2711ca86de7bf6a7885ccea24219a48a590b1e95.

Swift SVN r23577
2014-11-24 17:42:13 +00:00
Graham Batty
198402dcfe Mark tests that don't pass on linux as XFAIL.
Swift SVN r23573
2014-11-24 17:40:37 +00:00
Doug Gregor
96bdf90fcc Stop printing __null_unspecified per rdar://problem/18383574.
Swift SVN r23510
2014-11-21 05:06:53 +00:00
Doug Gregor
96a9751372 PrintAsObjC: Print nullability type specifiers to capture optionality.
Part of rdar://problem/19005653. There is still some work to do to
produce pretty output here, but the current output is correct.

Swift SVN r23444
2014-11-19 21:08:23 +00:00
Jordan Rose
52f7cd48b0 [PrintAsObjC] Print ownership qualifiers on properties.
weak => 'weak', unless the type is a CF type. I'm not sure weak references to
        CF types work anyway, but until we have that cleared up this works.

unowned => 'assign'. In Objective-C, use of 'assign' for object properties is
           largely deprecated in favor of 'unsafe_unretained', but unowned
           properties behave more like a 'safe_unretained'. Since they don't
           auto-update like 'weak', though, this should hint to clients to
           be careful about lifetimes.

unowned(unsafe) => 'unsafe_unretained'

As before, Arrays, Dictionaries, and Strings are considered 'copy' properties;
blocks are now considered 'copy' properties as well.

All other types get their (implied)  default: 'strong' for objects, 'assign'
for primitives.

<rdar://problem/17346846>

Swift SVN r20112
2014-07-17 20:59:53 +00:00
Joe Groff
c4fbf674da PrintAsObjC: Handle CFunctionPointer.
Swift SVN r20048
2014-07-16 22:13:27 +00:00
Jordan Rose
b24e19b4f0 [PrintAsObjC] Handle unparenthesized closure input types.
<rdar://problem/17358809>

Swift SVN r19837
2014-07-10 23:57:26 +00:00
Jordan Rose
c90cd11aff [PrintAsObjC] Only include internal decls if we have a bridging header.
The upshot of this is that internal decls in an app target will be in the
generated header but internal decls in a framework target will not. This
is important since the generated header is part of a framework's public
interface. Users always have the option to add members via category to an
internal framework type they need to use from Objective-C, or to write the
@interface themselves if the entire type is missing. Only internal protocols
are left out by this.

The presence of the bridging header isn't a /perfect/ way to decide this,
but it's close enough. In an app target without a bridging header, it's
unlikely that there will be ObjC sources depending on the generated header.

Swift SVN r19763
2014-07-09 23:58:57 +00:00
Ted Kremenek
fad874708e Adjust test cases.
Swift SVN r17964
2014-05-12 22:01:52 +00:00
Jordan Rose
8b9dfb017a Move test/Swift2ObjC to test/PrintAsObjC to match the library name.
Swift SVN r13799
2014-02-12 01:19:12 +00:00