Commit Graph

4105 Commits

Author SHA1 Message Date
swift-ci
44ab03a90b Merge pull request #66871 from kavon/generics-error-noncopyable
Be more specific than "noncopyable type T can't be used with generics yet"
2023-06-26 18:32:26 -07:00
Doug Gregor
6d58bce230 Merge pull request #66928 from DougGregor/unify-call-isolation-checking 2023-06-26 18:21:47 -07:00
Kavon Farvardin
8072eef926 describe noncopyables in parameter packs 2023-06-26 16:55:06 -07:00
Kavon Farvardin
485bdc7918 describe more cases of noncopyable in a tuple; also improve existing message a bit. 2023-06-26 16:55:06 -07:00
Kavon Farvardin
c40985dfb3 describe how generic parameters implicitly require Copyable 2023-06-26 16:55:06 -07:00
Doug Gregor
d78a5edb99 Handle all isolation checking for function calls in one place
Isolation checking for calls had two separate implementation places:
one that looked at the declaration being called (for member
declarations) and one that worked on the actual call expression. Unify
on the latter implementation, which is more general and has access to
the specific call arguments. Improve diagnostics here somewher so we
don't regress in that area.

This refactoring shouldn't change the actual semantics, but it makes
upcoming semantic changes easier.
2023-06-26 13:39:56 -07:00
Xi Ge
0a3dadff90 Sema: temporarily downgrade backdeployed_opaque_result_not_supported to a warning
rdar://111334653
2023-06-26 10:05:33 -07:00
Kabir Oberai
c499dd22ee [Sema] Improve SerialExecutor diagnostics 2023-06-26 06:36:07 -04:00
Kavon Farvardin
66bf3c03fc describe illegal casts to existentials 2023-06-23 20:15:01 -07:00
Kavon Farvardin
e6312058ec add more specific versions of the noncopyable generics error diagnostic 2023-06-22 15:12:20 -07:00
Michael Gottesman
80bb497275 Merge pull request #66833 from gottesmm/pr-e19b18739384c4a73467c39d7034ec6efcb6f466
[move-only] Ban resilient noncopyable types.
2023-06-21 22:31:19 -07:00
Michael Gottesman
d0938a906f [move-only] Ban resilient noncopyable types.
One can still in resilient frameworks have noncopyable frozen types.

This means that one cannot make a noncopyable:

1. Full resilient public type.
2. @usableFromInline type.

NOTE: One can still use a frozen noncopyable type as a usableFromInline class
field. I validated in the attached tests that we get the correct code
generation.

I also eliminated a small bug in TypeCheckDeclPrimary where we weren't using a
requestified attr check and instead were checking directly.

rdar://111125845
2023-06-21 16:57:44 -07:00
swift-ci
7c3917c0d3 Merge pull request #66818 from kavon/noncopyable-and-raw-error
emit error when a noncopyable enum has a raw type
2023-06-21 13:56:05 -07:00
Kavon Farvardin
79332c19b0 emit error when a noncopyable enum has a raw type
previously I was allowing these because I thought there was
some representational difference if the enum is raw. it
turns out that a raw enum is only useful if you synthesize
conformance to RawRepresentable. since I disabled that
synthesis it's kind of silly to still allow the raw type
to be written at all.

rdar://110539937
2023-06-21 11:21:49 -07:00
Egor Zhdan
84a2f33424 Merge pull request #66749 from apple/egorzhdan/cxx-template-subst-crash
[cxx-interop] Avoid crashing when template substitution fails
2023-06-21 13:51:22 +01:00
Joshua Turcotti
b63a10698d Merge pull request #66640 from JTurcotti/protocol-variance
Super-level sendable checking for function parameters in overrides and conformances
2023-06-20 10:43:46 -07:00
Egor Zhdan
4a1afa9bd3 [cxx-interop] Avoid crashing when template substitution fails
This code used to crash the compiler:

    var s = std.string("hi")
    s.append("foo")

`append` in this case resolves to a templated C++ method that accepts `std::string_view`, while we tried passing a Swift String to it as a parameter.

rdar://107018724
2023-06-19 15:58:41 +01:00
Kavon Farvardin
36451efb55 require consume x for noncopyable pattern bindings since they're consuming
this was staged in as a warning initially but it was intended to be
an error if it is not written so that we can move to a world where
these pattern matches are done as a borrowing operation instead.

rdar://110908714
2023-06-16 17:18:44 -07:00
jturcotti
eb78da256c modify Sendable checking of overrides and protocol conformances. In the past, both the results and parameters of overriding (resp. conforming) functions were checked for Sendability. This is overly restrictive. For safety, the parameters of the overridden (resp. requiring) function should be checked for Sendability and the results of the overriding (resp. conforming) should be checked. This commit implements that change. 2023-06-16 13:39:08 -07:00
Allan Shortlidge
c8f4dabe02 Sema: Diagnose @backDeployed on functions with opaque result types.
The compiler does not yet implement support for back deploying opaque result
types.

Resolves rdar://110806234
2023-06-15 16:08:38 -07:00
Becca Royal-Gordon
1532fb188c Merge pull request #66609 from beccadax/just-empty-protocol
Diagnose conformances on @objcImpl extensions
2023-06-14 14:12:13 -07:00
Pavel Yaskevich
2b8a39724c Merge pull request #66513 from xedin/init-accessor-diagnostics
[Sema/SIL] Improve diagnostics related to init accessors
2023-06-14 09:57:08 -07:00
Becca Royal-Gordon
6758fdb518 Diagnose conformances on @objcImpl extensions
@objcImpl extensions aren’t allowed to declare new conformances; instead, they should either be declared in the header or in an ordinary extensions. (If they were permitted, they’d be ignored.)

Fixes rdar://110669366.
2023-06-13 17:21:44 -07:00
swift-ci
0d1095efa3 Merge pull request #66262 from beccadax/your-implementation-is-required
Support required inits in @objcImpl
2023-06-13 14:28:56 -07:00
Pavel Yaskevich
4f59538eba [Sema] InitAccessors: Diagnose situations when memberwise init cannot be synthesized
If some of the properties with init accessors have out of order
accesses diagnose that while checking whether memberwise init
could be synthesized.
2023-06-13 10:58:50 -07:00
Pavel Yaskevich
db024d973e [CSDiagnostics] InitAccessors: Implement invalid member reference diagnostics within init accessors 2023-06-13 10:58:50 -07:00
Pavel Yaskevich
5613006944 [Sema] PreCheck: Diagnose standalone self within init accessors
'self' within init accessor could only be used to refer to
properties listed in `initializes` and `accesses` attributes.
2023-06-13 10:58:50 -07:00
Holly Borla
fc24471ff7 Merge pull request #66532 from hborla/suppress-expansion-in-macro-argument
[Macros] Use source locations to determine whether to suppress macro expansions.
2023-06-12 11:18:25 -07:00
Alex Lorenz
d1c7688962 Merge pull request #66474 from hyp/cxx-error-always
[cxx-interop] compilations that do not enable C++ interoperability sh…
2023-06-12 09:01:51 -07:00
Holly Borla
98249543cd [Macros] Ban freestanding and peer macro expansions that can produce arbitrary
names at global scope.

Freestanding and peer macros applied at top-level scope cannot introduce
arbitrary names. Introducing arbitrary names means that any lookup
into this scope must expand the macro. This is a problem, because
resolving the macro can invoke type checking other declarations, e.g.
anything that the macro arguments depend on. If _anything_ the macro
depends on performs name unqualified name lookup, e.g. type resolution,
we'll get circularity errors. It's better to prevent this by banning
these macros at global scope if any of the macro candidates introduce
arbitrary names.
2023-06-11 23:10:41 -07:00
Doug Gregor
1209ef89ec Ensure that macros within init accessors are expanded early enough
Now that we've made accessor macro expansion more lazy, ensure that
when querying for init accessors (e.g., to build a memberwise
initializer), we also expand any accessor macros that might produce an
init accessor.

This is a partial step toward the real goal, which is that
`AbstractStorageDecl::getAccessor()` should lazily expand macros if
needed.

Update the Observable macro to document that it produces an `init`
accessor.
2023-06-11 08:48:43 -07:00
Doug Gregor
a72fb83034 Requestify AbstractStorageDecl::hasStorage().
The `hasStorage()` computation is used in many places to determine the
signatures of other declarations. It currently needs to expand accessor
macros, which causes a number of cyclic references. Provide a
simplified request to determine `hasStorage` without expanding or
resolving macros, breaking a common pattern of cycles when using
macros.

Fixes rdar://109668383.
2023-06-10 08:28:06 -07:00
Slava Pestov
743eefb01e Merge pull request #66498 from slavapestov/reword-diagnostics-in-current-context
Sema: Reword diagnostics to say 'without a type annotation' instead of 'without more context'
2023-06-10 11:15:20 -04:00
Doug Gregor
24e3fe08f9 Merge pull request #66509 from DougGregor/unambiguous-freestanding-macro-role
[Macros] Provide the freestanding macro role for expansion operations.
2023-06-09 21:28:49 -07:00
Alex Lorenz
ba8d4d7801 [cxx-interop] compilations that do not enable C++ interoperability should not be able to import modules that do enable C++ interoperability by default
A supplemental hidden frontend option allows advanced users to opt-out of this requirement.

Fixes https://github.com/apple/swift/issues/65833
Fixes https://github.com/apple/swift/issues/65832
2023-06-09 15:38:16 -07:00
Slava Pestov
1957bd6065 Sema: Reword diagnostics to say 'without a type annotation' instead of 'without more context' 2023-06-09 17:44:42 -04:00
swift-ci
4f8f262f13 Merge pull request #66504 from DougGregor/bad-macros-with-result-types
[Macros] Only freestanding expression macros can have a non-Void result type
2023-06-09 13:50:43 -07:00
Doug Gregor
c5ec3892aa Diagnose macros that have multiple freestanding macro roles.
Per SE-0397, a macro may only have a single freestanding macro role,
otherwise we would have an ambiguity in how a particular freestanding
macro would be expanded. Produce an error on such macro declarations.

Fixes rdar://110178899.
2023-06-09 13:40:11 -07:00
Alexis Laferrière
b18e7f14a8 Merge pull request #66227 from xymus/recovery-notes
[Serialization] Display contextual notes on deserialization errors and misconfigurations
2023-06-09 12:09:06 -07:00
Doug Gregor
759f52066e [Macros] Only freestanding expression macros can have a non-Void result type
Fixes rdar://108871352.
2023-06-09 10:40:28 -07:00
Alexis Laferrière
af88a6588a [Serialization] Be more specific irt which clang settings may cause a failure 2023-06-08 12:35:01 -07:00
Alexis Laferrière
9804075549 [Serialization] Show contextual notes on deserialization errors
This PR makes diagnostics on deserialization errors caused by project
configuration more helpful by providing contextual information on the
issue:

- Path to the modules involved (up to 4 modules): the loaded swiftmodule
with the broken outgoing reference, the path to the module where the
decl was expected, the path to the underlying clang module, and the path
to the module where the decl was found. This information should prevent
us from having to ask for a different log with `-Rmodule-loading`.
- Hint to delete the swiftmodule files when the module is
library-evolution enabled.
- Hint that clang settings affect clang modules involved in this
scenario.
- Pointing out when a decl moved between two modules with a similar name
(where one name is a prefix of the other). This is a common issue when
headers are shared between a clang framework's public and private
modules.
- Pointing out layering issues when an SDK module imports a local
module.
- Pointing out Swift language version mismatch which may lead to the
compiler viewing the same clang decls differently when they are modified
by APINotes files.
2023-06-08 09:24:11 -07:00
Alexis Laferrière
b1e0b89cf7 [Serialization] Invert order of diagnostics in forced recovery mode 2023-06-07 16:03:08 -07:00
Alexis Laferrière
2f03c952c3 [Serialization] ModularizationError keeps full objects
Preserve more information about the context of modularization errors by
replacing the module names with pointers to ModuleDecl and ModuleFile
objects.
2023-06-07 13:01:37 -07:00
Pavel Yaskevich
274a43b040 Merge pull request #66283 from xedin/init-accessors
[Parse/Sema/SIL] Implementation of init accessors feature (under a flag)
2023-06-07 08:16:35 -07:00
Pavel Yaskevich
22061e6621 [Sema] InitAccessors: Verify that a property never appears both in initializes(...) and accesses(...) 2023-06-06 18:59:46 -07:00
Pavel Yaskevich
d7f5419623 [AST] InitAccessors: Add initializes/accesses attribute location validation 2023-06-06 18:59:13 -07:00
Pavel Yaskevich
c1a00005f1 [AST] InitAccessors: Add a way to retrieve referenced property declarations
Add a special request that validates all of the property names
referenced by `initialized` and `accesses`, does the lookup and
returns underlying `VarDecl`s. This would also be used by DI.
2023-06-06 18:59:13 -07:00
Holly Borla
684ef9c482 [AST] Add a new accessor kind for init accessors. 2023-06-06 18:57:31 -07:00
Hamish Knight
0695917bbd [CS] Don't form conversion between switch subject and pattern
This is wrong because there's nowhere to put any
conversion that is introduced, meaning that we'll
likely crash in SILGen. Change the constraint to
equality, which matches what we do outside of the
constraint system.

rdar://107709341
2023-06-07 00:35:01 +01:00