Commit Graph

269 Commits

Author SHA1 Message Date
Slava Pestov
6363961e90 Split up a couple more tests into stable and pre-stable ABI deployment target versions 2019-05-21 17:30:13 -04:00
Slava Pestov
5d66bb810a Run stable ABI tests on all Apple platforms
A number of tests exercise features only available in Apple OSes that
shipped with Swift 5.0 in the OS; this includes the following versions:

- macOS 10.14.4
- iOS 12.2
- tvOS 12.2
- watchOS 5.2

Previously these tests were restricted to running on macOS only, with
an explicit -target x86_64-apple-macosx10.14.4. To get better test
coverage, add a new %target-stable-abi-triple substitution which
expands to a triple with the correct OS version on all Apple platforms.

On non-Apple platforms, this is the same as %target-variant-triple,
but for now any test that uses this exercises Apple platform features
anyway.

One caveat is that since iOS 12.2 does not have a 32-bit slice, we
have to skip any tests that use -target %target-stable-abi-triple
on this platform. A new swift_stable_abi feature flag can be tested
with 'REQUIRES: swift_stable_abi'. To get maximum test coverage,
I split off a 'stable_abi' version of a few tests that build with both
an old and new deployment target. This allows the old deployment
target case to still be tested on 32-bit iOS.
2019-05-16 17:02:06 -04:00
Slava Pestov
c954dfa6a9 Sema: Tweak test/decl/protocol/conforms/nscoding.swift a bit
Make sure we test on both an "old" and "new" deployment target.
2019-05-03 18:56:46 -04:00
Slava Pestov
04ac33dd2b Sema: Fix order dependency in @objc inference from witnessed protocol requirement
If we haven't validated the declaration yet, the 'witnesses @objc
requirement' check would immediately fail. Move the validateDecl()
call to matchWitness() to fix this.

Fixes <rdar://problem/49482328>, <https://bugs.swift.org/browse/SR-10257>.
2019-04-24 17:35:05 -04:00
kitasuke
543ddbceee Remove NSKeyedArchiver family support for decl attributes 2019-04-15 17:33:51 +09:00
Jordan Rose
33438bd0f8 Add a test for circular protocol inheritance through a typealias
We could do better on the diagnostics here, but it's not that
important.

https://bugs.swift.org/browse/SR-9224
2019-04-09 18:17:57 -07:00
Slava Pestov
0dba5626b2 Sema: Fix crashes in witness access control checking
This fixes a crash-on-invalid regression from the fix for
<rdar://problem/43824052>.
2019-02-22 14:03:39 -05:00
Harlan Haskins
62f9edf647 [Sema] Don't print __consuming when suggesting protocol requirement stubs 2018-12-18 11:26:37 -08:00
Slava Pestov
8c653332ef Sema: Fix failure to emit a diagnostic when a protocol witness is being validated already
Validating a declaration can trigger conformance checking. If the conformance checker
comes across the same declaration as a candidate witness, it would fail to emit a
diagnostic. As a result we would then go onto SILGen, which would crash while emitting
a witness table with a missing entry.

Fixes <rdar://problem/45151902>.
2018-12-07 20:44:59 -05:00
John McCall
49ba9c59d1 Allow Error to conform to itself.
Most of the foundation for this was laid in earlier patches.
2018-11-17 02:51:45 -05:00
Vinicius Vendramini
39d3963131 Fix broken tests
- Many tests got broken because of two things:
  - AST dump now outputs to stdout, but many tests expected stderr. This was a straightforward fix.
  - Many tests call swift with specific parameters; specifically, many call `swift frontend` directly. This makes them go through the compiler in unexpected ways, and specifically it makes them not have primary files, which breaks the new AST dump implementation. This commit adds the old implementation as a fallback for those cases, except it dumps to `stdout` to maintain some consistence.

Finally, the `/test/Driver/filelists.swift` failed for unknown reasons. It seems its output now had some lines out of order, and fixing the order made the test pass. However, as the reasons why it failed are unknown, this fix might not have been a good idea. Corrections are welcome.
2018-11-14 13:38:01 -02:00
Greg Titus
d20fdf5f82 Merge pull request #19920 from gregomni/8757
[Sema][QoI] Call out missing conformances in protocol witness candidates.
2018-10-22 16:39:51 -07:00
gregomni
939de4fb4a Extend candidate missing conformance checking to other types of requirements so that we check superclass and same type requirements in the same way. 2018-10-19 10:02:30 -07:00
Greg Titus
4f8e3f3597 Merge pull request #19879 from gregomni/8757
[Sema] Omit protocol match diagnosis for constructors with differing names.
2018-10-16 09:36:16 -07:00
Greg Titus
7d0bdb112e Omit protocol match diagnosis for constructors with differing names. 2018-10-14 17:08:50 -07:00
gregomni
42a24ebb71 Use hasDynamicSelfType and add another test where the result type is complex and includes the non-dynamic self. 2018-10-11 13:31:56 -07:00
gregomni
679ac44f1f Add check for dynamic self in the witnessing type, and test. This would also fail to infer previously. 2018-10-09 07:04:07 -07:00
gregomni
eae1015072 Allow associated type inference for requirement returning dynamic Self when witness returns self type and isn't a class or is a final class. (Same as meeting the requirement.) 2018-10-07 09:24:54 -07:00
Slava Pestov
c3f02b14d3 Add test case for https://bugs.swift.org/browse/SR-1571 2018-10-05 16:56:46 -04:00
Pavel Yaskevich
63b802ca88 [AST/Printing] Don't omit empty labels in special names
This makes diagnostics more verbose and accurate, because
it's possible to distinguish how many parameters there are
based on the message itself.

Also there are multiple diagnostic messages in a format of
`<descriptive-kind> <decl-name> ...` that get printed as
e.g. `subscript 'subscript'` if empty labels are omitted.
2018-09-24 18:36:53 -07:00
Davide Italiano
ef46ec08fc [AST] Update tests now that we preserve sugar. 2018-09-18 09:23:02 -07:00
Mark Lacey
78d83e5703 Use %target-typecheck-verify-swift where possible. 2018-07-26 23:13:43 -07:00
Doug Gregor
6a8d3211aa [Type checker] Move ad-hoc isObjC/isDynamic checking to finalization.
Whenever we visit a declaration via the DeclChecker, add it to the
list of declarations to finalize. This makes sure that we can centralize
the notion of “finalize for SILGen” and that it will be called for
everything in the source file being processed.
2018-07-25 20:55:13 -07:00
Slava Pestov
31ab93b82c Remove Swift 3-specific tests 2018-07-02 21:14:22 -07:00
Slava Pestov
3701f745c4 Migrate various Sema tests to Swift 4 2018-06-25 01:02:20 -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
Mark Rowe
62eb12b652 Include source ranges for decls in the AST dump. 2018-05-17 10:50:19 -07:00
Ben Langmuir
f20586b3d8 Revert "Include source ranges for statements, declarations, and parameter lists in the AST dump" 2018-05-17 09:53:05 -07:00
Jordan Rose
cb6c8f0a8e Merge pull request #16473 from bdash/ast-dump-source-ranges
Include source ranges for statements, declarations, and parameter lists in the AST dump
2018-05-17 09:16:35 -07:00
Jordan Rose
6bd7e5e5b4 Make sure protocol witness errors don't leave the conformance context
That is, if there's a problem with a witness, and the witness comes
from a different extension from the conformance (or the original type,
when the conformance is on an extension), put the main diagnostic on
the conformance, with a note on the witness. This involves some
shuffling and rephrasing of existing diagnostics too.

There's a few reasons for this change:

- More context. It may not be obvious why a declaration in file
  A.swift needs to be marked 'public' if you can't see the conformance
  in B.swift.

- Better locations for imported declarations. If you're checking a
  conformance in a source file but the witness came from an imported
  module, it's better to put the diagnostic on the part you have
  control over. (This is especially true in Xcode, which can't display
  diagnostics on imported declarations in the source editor.)

- Plays better with batch mode. Without this change, you can have
  diagnostics being reported in file A.swift that are tied to a
  conformance declared in file B.swift. Of course the contents of
  A.swift also affect the diagnostic, but compiling A.swift on its
  own wouldn't produce the diagnostic, and so putting it there is
  problematic.

The change does in some cases make for a worse user experience,
though; if you just want to apply the changes and move on, the main
diagnostic isn't in the "right place". It's the note that has the info
and possible fix-it. It's also a slightly more complicated
implementation.
2018-05-10 19:31:12 -07:00
Jordan Rose
545b12fa9f Convert backticks to single-quotes in Sema diagnostics
Let's be consistent!
2018-05-09 21:59:39 -07:00
Mark Rowe
28af6959b8 Include source ranges for decls in the AST dump. 2018-05-09 11:15:35 -07:00
David Zarzycki
995dec5d82 [Sema] Error if ObjC interop is needed when disabled 2018-05-07 14:43:04 -04:00
Huon Wilson
2e5799e26b [Sema] Diagnose redundant conditional conformances more specifically.
We don't allow things like

    extension Type: P where Param: P {}
    extension Type: P where Param: Q {}

or

    extension Type: P where Param == Int {}
    extension Type: P where Param == Float {}

or

    extension Type: P where Param: P {}
    extension Type: P where Param == SomethingThatIsntP {}

and the default error message "redundant conformance" message doesn't convey
this very well.

Fixes rdar://problem/36262409.
2018-04-27 11:50:17 +10:00
Slava Pestov
510f842488 AST: Workaround for same-type constraints getting dropped from requirement environment
The fix for <https://bugs.swift.org/browse/SR-617> introduced
a new kind of requirement environment where 'Self' remains a
generic parameter, but receives a class constraint, instead of
becoming fully concrete.

As before, we would form the synthetic signature by taking
the generic signature of the requirement, and substituting it
the new 'Self' type.

However, whereas previously the 'Self' type was always concrete
and any DependentMemberTypes in the requirement's signature
would become concrete type references, with a class-constrained
'Self' the DependentMemberTypes remain.

Apparently, the GSB cannot handle DependentMemberTypes where
the base is class-constrained.

Work around this by ensuring that we add a conformance constraint
for the 'Self' parameter to the protocol in question, which
allows the DependentMemberTypes to be correctly resolves once
the conformance is made concrete by a superclass constraint.

The FIXME comment being removed here references crashes which
no longer seem to reproduce, so I'm assuming some underlying
GSB issues got fixed and the FIXME is clearly no longer necessary.

However, I still consider this fix somewhat unsatisfying, because
it is not clear if there's some deeper flaw in how the GSB
models superclass constraints. It might resurface again in the
future.

Fixes <rdar://problem/39419121>, <https://bugs.swift.org/browse/SR-7428>.
2018-04-16 22:22:52 -07:00
Slava Pestov
08e4e7c990 Add test for https://bugs.swift.org/browse/SR-7422 2018-04-13 13:33:23 -07:00
Devin Coughlin
da6d078ff9 [Tests] Remove dependence on specific deployment target versions (#15819)
Generalize several tests so they are not locked to specific deployment target
versions.
2018-04-09 14:10:32 -07:00
Slava Pestov
a5579d1cff AST: Plug a hole in access control checking
A protocol extension of a private protocol can define internal
or public members. We should not be able to find these members
from another file or module if an internal or public type
conforms to the protocol.

Fixes <rdar://problem/21380336>.
2018-04-05 23:24:48 -07:00
Doug Gregor
e82e7ee908 [Type checker] Use BoundNameAliasType for all typealiases.
Rather than relying on the NameAliasType we get by default for references
to non-generic typealiases, use BoundNameAliasType consistently to handle
references to typealiases that are formed by the type checker.
2018-03-25 21:35:16 -07:00
Doug Gregor
790625ab5b Allow a witness's noescape parameter to match a requirement's escaping parameter
Extend protocol conformance checking to allow a requirement with an
escaping parameter (of function type) to be satisfied by a witness
with a corresponding non-escaping parameter. This limited form of
covariance was already supported by SILGen and is needed to address
the source-compatibility "regression" introduced by inferring escaping
function types for associated type witnesses. It's also obviously a
good idea :)

Fixes rdar://problem/35297911.
2018-03-20 13:02:49 -07:00
Doug Gregor
f24c2eb94c [Associated type inference] Infer escaping function types, not noescape ones.
When inferring an associated type witness by matching a function signature,
adjust non-escaping function types to escaping function types, because only
escaping function types could be written as explicit witnesses and
non-escaping function types are not permitted outside of function
parameters.

Addresses the first part of rdar://problem/35297911, eliminating the
type-soundness issue.
2018-03-20 13:02:49 -07:00
Michael Gottesman
c1bc576cdc Revert "[Associated type inference] Infer escaping function types, not noescape ones."
This reverts commit 60e8de7b65.
2018-03-19 18:54:24 -07:00
Michael Gottesman
2c0d406749 Revert "Allow a witness's noescape parameter to match a requirement's escaping parameter"
This reverts commit 44e230b91a.
2018-03-19 18:54:24 -07:00
Doug Gregor
44e230b91a Allow a witness's noescape parameter to match a requirement's escaping parameter
Extend protocol conformance checking to allow a requirement with an
escaping parameter (of function type) to be satisfied by a witness
with a corresponding non-escaping parameter. This limited form of
covariance was already supported by SILGen and is needed to address
the source-compatibility "regression" introduced by inferring escaping
function types for associated type witnesses. It's also obviously a
good idea :)

Fixes rdar://problem/35297911.
2018-03-19 15:29:32 -07:00
Doug Gregor
60e8de7b65 [Associated type inference] Infer escaping function types, not noescape ones.
When inferring an associated type witness by matching a function signature,
adjust non-escaping function types to escaping function types, because only
escaping function types could be written as explicit witnesses and
non-escaping function types are not permitted outside of function
parameters.

Addresses the first part of rdar://problem/35297911, eliminating the
type-soundness issue.
2018-03-19 14:38:40 -07:00
Saleem Abdulrasool
b67d5f0cf7 test: convert rm -rf && mkdir -p into %empty-directory
This converts the instances of the pattern for which we have a proper
substitution in lit.  This will make it easier to replace it
appropriately with Windows equivalents.
2018-03-06 14:30:54 -08:00
Erik Eckstein
2a7c9587ad NSArchive support: don't eagerly create class metadata for nested classes.
This is not required anymore to be able to unarchive such classes (before the first object of the class is instantiated).

rdar://problem/37568342
2018-02-16 15:36:52 -08:00
Doug Gregor
9b2c462709 [Conformance checking] Factor out associated type inference.
Move associated type inference into its own class, to make this
code easier to understand/maintain/improve. Minor diagnostics changes
because we're properly passing uninference associated type declarations
to the "group" checker.
2017-12-09 23:05:24 -08:00
Slava Pestov
4e8bdcd716 Sema: Type aliases with an unbound generic type cannot witness associated type requirements
We allow definitions like this:

struct G<T> {}
typealias A = G

As a shorthand for

typealias A<T> = G<T>

A typealias like this cannot satisfy an associated type requirement
for the same reason that a generic typealias cannot satisfy an
associated type requirement, which was already handled.

Previously this would crash in the type checker or in IRGen.

This fixes a weird regression in a fixed compiler crasher from the
next patch.
2017-11-04 23:40:23 -07:00
Slava Pestov
398f76d12b Sema: Check AnyObject constraint on associated type witnesses
Fixes <https://bugs.swift.org/browse/SR-6109>, <rdar://problem/34911213>.
2017-10-31 19:35:31 -07:00