Commit Graph

4105 Commits

Author SHA1 Message Date
Slava Pestov
2fa344bf85 AST: Tweak some variadic generic diagnostics 2023-03-15 23:04:50 -04:00
Luciano Almeida
4d981e3c0b Merge pull request #63904 from LucianoPAlmeida/ambiguous-overload
[Sema] Diagnose function coercion ambiguity
2023-03-15 23:18:00 -03:00
Ellie Shin
584919e86f Merge pull request #64373 from apple/es-tests
Update package name input and access scope check
2023-03-15 10:45:04 -07:00
Kavon Farvardin
a8a44ebb17 Merge pull request #64106 from kavon/enable-moveonly-by-default
Enable moveonly / noncopyable types by default
2023-03-15 09:59:29 -07:00
Ellie Shin
0fe0d6d221 Allow Swift as a package name
Update AccessScope::isChildOf
Add more tests for package access level
Resolves rdar://106728606
2023-03-14 17:17:14 -07:00
Pavel Yaskevich
ed5984abe6 Merge pull request #64213 from xedin/rdar-104384604
[BuilderTransform] Verify that builder type has at least one accessible build{Partial}Block
2023-03-14 15:07:43 -07:00
Alex Lorenz
89083eebf4 Merge pull request #64343 from hyp/explicit-objc-unavail
[interop][SwiftToCxx] explicitly tell the user that @objc decls can't…
2023-03-14 06:06:18 -07:00
Kavon Farvardin
ea1e83b1d7 move noncopyable types out from behind the feature flag
Since these types depend on lexical borrow scopes (a SIL
option), we're now making that the requirement whenever
such types appear.
2023-03-13 22:39:31 -07:00
Alex Lorenz
9f86ff9072 [interop][SwiftToCxx] explicitly tell the user that @objc decls can't be yet exposed to C++ 2023-03-13 18:16:36 -07:00
Ellie Shin
1924376658 Merge pull request #64230 from apple/es-dbg
[AccessScope] Treat PackageUnit as enclosing scope of ModuleDecl
2023-03-13 17:00:45 -07:00
Luciano Almeida
63315ccce9 [Diagnostics] Adjust ExtraneousArgumentsFailure note diagnostic 2023-03-11 18:47:52 -03:00
Ellie Shin
671533fed2 Associate PackageUnit with ModuleDecl
* Weakly reference ModuleDecl from PackageUnit
* Add PackageUnit decl context getter and use it for a package AccessScope
* Return module decl referenced by PackageUnit in getModuleScopeContext and getParentModule
* Handle package acl in access scope checkers
* Remove AccessLimitKind
* Fix tests
Resolves rdar://104987295, rdar://105187216, rdar://104723918
2023-03-10 16:19:32 -08:00
Doug Gregor
ef7f707fcc Revert "Improve @objcImplementation member checking" 2023-03-10 12:00:33 -08:00
Alexis Laferrière
5f8338f8ef Merge pull request #64243 from xymus/access-level-import-note
[Sema] Improve the note on imports with an access-level when it causes an error
2023-03-09 13:05:28 -08:00
Alexis Laferrière
a26fbd2849 [Sema] Improve note on access-level downgrade from import
Using an access-level on an import downgrades imported decl from public
to the import's access-level. When we can identify which decl is
problematic, name it in the note displayed on the import. This should
help understanding the effect of the import's access level on the decl
causing an error further down in the source file.
2023-03-09 09:08:42 -08:00
Pavel Yaskevich
b0bd756a4a Merge pull request #64229 from AnthonyLatsis/dot-self-hack
Sema: Allow member type expressions rooted on non-identifier qualifiers to omit `.self` until Swift 6
2023-03-09 00:30:03 -08:00
Anthony Latsis
4d2b2f6fee Sema: Allow member type expressions rooted on non-identifier qualifiers to omit .self until Swift 6 2023-03-09 04:55:25 +03:00
Pavel Yaskevich
6b323f1663 [BuilderTransform] Verify that builder type has at least one accessible build{Partial}Block
Check accessibility of all build{Partial}Block overloads and
diagnose if none of them are as accessible as type, otherwise
swift interfaces could end up with invalid result builder
declarations when type is public and all builder methods are
internal.

Resolves: rdar://104384604
2023-03-08 12:46:50 -08:00
Michael Gottesman
92581020ec Merge pull request #64162 from gottesmm/pr-ca138b56e9896ca836369feed78694f40d116df3
[move-only] Ban @objc enum being marked as move only.
2023-03-07 13:54:41 -08:00
Holly Borla
74cc62735b [RequirementMachine] Diagnose same-element requirements.
The rewrite rules are not quite right yet for same-element requirements, so
let's ban them for now.
2023-03-06 21:32:30 -08:00
Michael Gottesman
faea5697a4 [move-only] Ban @objc enum being marked as move only.
rdar://106340608
2023-03-06 18:26:09 -08:00
Xi Ge
ffc998a0e7 Merge pull request #63668 from beccadax/checkmate
Improve @objcImplementation member checking
2023-03-06 08:21:59 -08:00
Richard Wei
833338f9ce [Macros] Top-level freestanding macros (#63553)
Allow freestanding macros to be used at top-level.
- Parse top-level `#…` as `MacroExpansionDecl` when we are not in scripting mode.
- Add macro expansion decls to the source lookup cache with name-driven lazy expansion. Not supporting arbitrary name yet.
- Experimental support for script mode and brace-level declaration macro expansions: When type-checking a `MacroExpansionExpr`, assign it a substitute `MacroExpansionDecl` if the macro reference resolves to a declaration macro. This doesn’t work quite fully yet and will be enabled in a future fix.
2023-03-06 07:15:20 -08:00
swift-ci
788f52bd1a Merge pull request #64124 from kavon/moveonly-no-effectful-accessor
disallow effectful getters for borrowed reads
2023-03-05 19:12:01 -08:00
Kavon Farvardin
2bf37b49cf disallow effectful getters for borrowed reads
This means properties returning noncopyable types or those
marked with `@_borrowed` can't have effects. The compiler
never accepted the latter correctly before.

The synthesized coroutine `read` calls the user-defined `get`,
but coroutines don't support `async` or `throws`.

resolves rdar://106260787
2023-03-05 16:40:49 -08:00
swift-ci
92a58e236f Merge pull request #64123 from kavon/moveonly-no-failable-init
disallow failable initializers for noncopyable types
2023-03-05 13:28:01 -08:00
Kavon Farvardin
971ce817be disallow failable initializers for noncopyable types
These initializers implicitly return an optional of the
nominal type, but we can't wrap move-only / noncopyable
types inside of optionals at the moment, because that
would permit copying.

resolves rdar://106120881
2023-03-05 10:49:45 -08:00
Holly Borla
4a319b2a4e [Macros] Diagnose default literal type overrides in macro expansions. 2023-03-04 15:31:25 -08:00
Holly Borla
cd62c6d513 [Macros] Fix a few issues with invalid macro expansion diagnostics, and add tests. 2023-03-04 15:31:25 -08:00
Holly Borla
c9a86ac4fa [Macros] Diagnose macro expansions containing invalid declarations, such as
new macro decls or value decls whose names are not covered by the macro.
2023-03-04 15:31:24 -08:00
Becca Royal-Gordon
7f688ef2c1 Refactor and expand @objcImpl checking
Create a checker for @_objcImplementation member implementations that considers all of a class’s interface and implementation decls at once. This allows us to handle several things better:

• Unimplemented requirements are now diagnosed

• Header members that can match several implementations, or implementations that could match several header members, are now diagnosed

• Tailored diagnostic when the implementation's Swift name matches the header's selector instead of its Swift name

• Recommends inserting `@objc(<selector>)` when a Swift name matches but the implicit ObjC name doesn't

• An `@objc(<selector>)` on one implementation can eliminate its requirement from being considered for other implementations, resolving ambiguities

This does unfortunately regress the diagnostics when a requirement is implemented in the wrong extension. Some sort of whole-module checking would be needed to address this problem.
2023-03-03 17:40:48 -08:00
Alexis Laferrière
2a7aa37cd5 Merge pull request #64074 from xymus/report-mismatching-module-version-to-stderr
[Serialization] Remark only on stderr when loading a mismatching swiftmodule
2023-03-03 15:14:37 -08:00
Alexis Laferrière
f4bb6dc9ec [Serialization] Remark on stderr when loading a mismatching swiftmodule
Swiftmodules built by a mismatching compiler are loaded if the mismatch
is only on the last digit of the compiler version. In such a case, write
a remark directly to stderr to avoid showing this error in IDE but keep
it for debugging purposes.

rdar://105881894
2023-03-03 10:46:27 -08:00
swift-ci
d0f88433da Merge pull request #63822 from kavon/resilient-noncopyable
Support resilient properties of move-only type
2023-03-03 01:24:37 -08:00
Holly Borla
6d2827b1b4 Merge pull request #64024 from hborla/single-element-tuple-substitution
[Sema] Eliminate single-element tuples after parameter pack substitution.
2023-03-02 23:01:12 -08:00
Alex Lorenz
ba34e4f4e7 Merge pull request #64046 from hyp/eng/cxx-interop-no-expose
[interop][SwiftToCxx] do not require @_expose when generating C++ interface for a Swift module
2023-03-02 20:55:31 -08:00
Holly Borla
ad3a385cd2 [Sema] Eliminate single-element tuples after parameter pack substitution. 2023-03-02 19:37:52 -08:00
Alex Lorenz
1d3797308d [interop][SwiftToCxx] do not expose functions / properties that throw without the experimental feature 2023-03-02 15:22:36 -08:00
Alexis Laferrière
fbac54546d Merge pull request #64014 from xymus/access-level-import
[Sema] Diagnose exportability of decls limited by a non-public import
2023-03-02 10:11:15 -08:00
Alexis Laferrière
75255d153c [Sema] Diagnose exportability of decls limited by a non-public import
Check the API of decls to ensure that imported types are only used in
decls with compatible access-level. For example, error on using a type
import as internal in a public function, but allow it in internal
functions and lower.

This change raises errors on wrongful use of types limited by an import
and offers a note pointing to the import that did limit the imported
type.
2023-03-01 18:35:41 -08:00
Joe Groff
ecceb02e2a Implement consume x operator with the accepted SE-0366 syntax.
Implement it as a contextual operator that only parses as an operator when
followed by an identifier.
2023-03-01 17:37:54 -08:00
Kavon Farvardin
796d247d26 re-allow non-final classes to have move-only members 2023-03-01 11:24:29 -08:00
Becca Royal-Gordon
e7c91b2236 Diagnose objcImpl members with wrong name 2023-03-01 09:00:43 -08:00
Becca Royal-Gordon
3212d2e60e Correct and improve objcImpl member matching
• `@objc` is now inferred on non-`final` members of @objcImplementation extensions
• Diagnostics now suggest adding `private` to ObjC helper members, not `@objc`, in line with currently proposed behavior
• Better diagnostic for members implemented in the wrong extension

Part of rdar://103150189.
2023-03-01 09:00:43 -08:00
Kavon Farvardin
404267d3e9 ensure forget cannot appear outside the type's module
We can't implement `forget` unless if we know all of the fields
in the type, so it cannot be resilient at all. We go further and
say that you can only `forget` from the same module, since that's
what the proposal currently states. If needed we can loosen that
in the future.
2023-02-28 21:15:17 -08:00
Kavon Farvardin
f41ed5926b implement the forget statement
Currently, this is staged in as `_forget`,
as part of SE-390. It can only be used on
`self` for a move-only type within a consuming
method or accessor. There are other rules, see
Sema for the details.

A `forget self` really just consumes self and
performs memberwise destruction of its data.
Thus, the current expansion of this statement
just reuses what we inject into the end of a
deinit.

Parsing of `forget` is "contextual".
By contextual I mean that we do lookahead to
the next token and see if it's identifier-like.
If so, then we parse it as the `forget` statement.
Otherwise, we parse it as though "forget" is an
identifier as part of some expression.

This way, we won't introduce a source break for
people who wrote code that calls a forget
function.

This should make it seamless to change it from
`_forget` to `forget` in the future.

resolves rdar://105795731
2023-02-28 21:15:17 -08:00
Alexis Laferrière
16baee3771 Merge pull request #63948 from xymus/access-level-import-context
[Sema] Context validation checks for access-level on imports
2023-02-28 17:15:54 -08:00
Alex Lorenz
e7ad1f4487 Merge pull request #63970 from hyp/eng/unsupported-generics-in-cxx
[interop][SwiftToCxx] diagnose when certain generic decls can not yet…
2023-02-28 16:10:53 -08:00
Alex Lorenz
8bce678200 [interop][SwiftToCxx] diagnose when certain generic decls can not yet be exposed to C++ 2023-02-28 09:17:31 -08:00
Alexis Laferrière
0a71a5c66b [Sema] Report conflicts between @_exported and non-public imports
@_exported can only be used on public imports, it's incompatible with
any other access level. This implementation doesn't take into account
Swift 6 mode.
2023-02-27 19:31:52 -08:00