Commit Graph

4105 Commits

Author SHA1 Message Date
Ben Barham
ebe3a00ad7 Merge pull request #67885 from bnbarham/improve-macro-diag
[Diagnostics] Reduce missing external macro diagnostic
2023-08-11 17:53:27 -07:00
Ben Barham
10a5ead2e0 [Diagnostics] Reduce missing external macro diagnostic
This is a very large diagnostic, where the second half is mostly aimed
at macro authors rather than clients. Cut it down to the base
diagnostic.

Resolves rdar://113646544.
2023-08-11 09:47:04 -07:00
Allan Shortlidge
be2d4d8ffd Revert "Revert "Sema: temporarily downgrade backdeployed_opaque_result_not_supported to a warning""
This reverts commit e3453ca32a.
2023-08-11 09:38:38 -07:00
Slava Pestov
59bdf6630c Sema: Move tuple conformance diagnostic to TypeCheckDeclPrimary.cpp 2023-08-09 17:42:25 -04:00
Alex Lorenz
97c25ae854 [interop][SwiftToCxx] nested types are not yet supported so do not emit references to them 2023-08-02 13:03:05 -07:00
Ben Barham
7e8a33097e Merge pull request #67488 from bnbarham/better-note-locations
[Diagnostics] Improve diagnostics involving macros
2023-07-26 17:48:02 -07:00
Michael Gottesman
2a1d9199a3 [sema] Ban user created read/set accessor that produce noncopyable types.
The reason why we are doing this is that this combination of read/set forces the
compiler to emit a copy if we want to emit a modify operation.

The reason why we are forced to emit such a copy is that:

1. _read provides a guaranteed value in memory
2. performing a modify requires an owned value in memory.

This together implies that the only way we can do this is to copy from the _read
into temporary memory. But we have a noncopyable type so we can't do this.

rdar://112915525
2023-07-26 12:53:43 -07:00
Allan Shortlidge
86265881c3 Merge pull request #67528 from tshortli/revert-66930
Sema: Resume diagnosing `@backDeployed` on functions with opaque result types as errors
2023-07-26 09:15:50 -07:00
Joe Groff
705e317c3f Merge pull request #67425 from jckarter/raw-storage
[WIP] Raw storage and locks/atomics prototype
2023-07-26 08:49:02 -07:00
Allan Shortlidge
e3453ca32a Revert "Sema: temporarily downgrade backdeployed_opaque_result_not_supported to a warning"
This reverts commit 0a3dadff90.
2023-07-25 21:13:31 -07:00
Ben Barham
9691060418 [Diagnostics] Add declaration name to macro_attached_to_invalid_decl
This could also use `%kind` for the declaration kind, but that ends up
being "extension of struct" instead of just "extension", which seems
slightly worse.
2023-07-25 16:03:52 -07:00
Joe Groff
aee071bf4e Introduce an experimental @_rawLayout attribute.
This attribute can be attached to a noncopyable struct to specify that its
storage is raw, meaning the type definition is (with some limitations)
able to do as it pleases with the storage. This provides a basis for
implementing types for things like atomics, locks, and data structures
that use inline storage to store conditionally-initialized values.
The example in `test/Prototypes/UnfairLock.swift` demonstrates the use
of a raw layout type to wrap Darwin's `os_unfair_lock` APIs, allowing
a lock value to be stored inside of classes or other types without
needing a separate allocation, and using the borrow model to enforce
safe access to lock-guarded storage.
2023-07-24 14:28:19 -07:00
swift-ci
7741409f8e Merge pull request #67075 from beccadax/kinder-diagnostics
Improve DiagnosticEngine's handling of ValueDecl arguments
2023-07-20 18:26:14 -07:00
Becca Royal-Gordon
fe6753485f [NFC] Adopt new diagnostic features across Sema 2023-07-20 15:23:47 -07:00
Holly Borla
f76783d619 Merge pull request #67405 from hborla/enable-extension-macros
[Macros] Remove the `ExtensionMacros` experimental feature flag.
2023-07-19 17:59:21 -07:00
Becca Royal-Gordon
9c6b3bb6ff Adopt %kind in diag::objc_overriding_objc_decl
Slightly alters wording of a diagnostic.
2023-07-19 13:08:13 -07:00
Becca Royal-Gordon
325ab9118e [NFC] Adopt new features in availability diagnostics
Allows the removal of a helper function.
2023-07-19 13:08:12 -07:00
Becca Royal-Gordon
1d6b041e58 Reword @objcImpl diagnostics to avoid “an”
…and also adopt new DiagnosticEngine features.
2023-07-19 13:08:12 -07:00
Becca Royal-Gordon
fca140211d Adopt warnUntilSwiftVersion for diag::witness_not_usable_from_inline_warn
This changes the wording of some diagnostics in Swift 4.2 and Swift 4 modes.
2023-07-19 13:08:12 -07:00
Becca Royal-Gordon
b4855aee1f Adopt ValueDecl in autodiff diagnostics 2023-07-19 13:08:12 -07:00
Becca Royal-Gordon
025728f568 Adopt ValueDecl for invalid redeclaration errors
Causes slight changes to notes on certain `init`s.
2023-07-19 13:08:12 -07:00
Becca Royal-Gordon
09e20776cb Remove diag::descriptive_decl_declared_here
It was used in one place to handle accessors, which happily is no longer necessary.
2023-07-19 13:08:12 -07:00
Becca Royal-Gordon
1b81c3de7b [NFC] Adopt ValueDecl * for decl_declared_here 2023-07-19 13:08:12 -07:00
Becca Royal-Gordon
fc2c66f674 [NFC] Adopt %kind for Sema ValueDecl diagnostics 2023-07-19 13:08:11 -07:00
Becca Royal-Gordon
84592b8f8e Adopt %kind in Sendable checking diagnostic
Causes minor changes in diagnostic text.
2023-07-19 13:06:51 -07:00
Becca Royal-Gordon
3732c75e97 Adopt %kind for certain access control diagnostics
These particular changes slightly alter some diagnostics.
2023-07-19 13:06:51 -07:00
Becca Royal-Gordon
1318bf5bf5 [NFC] Begin adopting new diagnostics features 2023-07-19 13:06:51 -07:00
Holly Borla
9ac257baa1 [Macros] Diagnose conformance macros as being replaced by extension macros. 2023-07-19 10:02:12 -07:00
Alex Lorenz
3748b0ff1c Merge pull request #65129 from hyp/eng/no-evo-cxx
[interop] Prohibit use of C++ APIs in public interfaces that opt-in i…
2023-07-19 08:10:23 -07:00
Holly Borla
769fc5d2c5 Merge pull request #67383 from hborla/diagnose-undocumented-conformances
[Macros] Diagnose undocumented conformances in extension macro expansions.
2023-07-18 22:39:22 -07:00
Holly Borla
3c24932138 [Macros] Diagnose undocumented conformances in extension macro expansions. 2023-07-18 18:06:51 -07:00
Holly Borla
c55d0e2e44 Merge pull request #67106 from hborla/validate-extension-macros
[Macros] Add missing macro validation.
2023-07-14 07:53:43 -07:00
Holly Borla
04ea8b0a67 [Macros] Diagnose macros attached to declarations they cannot apply to. 2023-07-13 17:07:24 -07:00
Allan Shortlidge
e973ff941f Merge pull request #67225 from tshortli/allow-usable-from-inline-access-in-default-args
Sema: Allow default arguments to access `@usableFromInline` decls
2023-07-12 20:40:24 -07:00
Xi Ge
45b5b4c13e Merge pull request #67269 from apple/block-list-note
ModuleLoader: emit a note when encountering a blocklisted module interface
2023-07-12 16:55:39 -07:00
Konrad `ktoso` Malawski
2044cb78cf Merge pull request #66934 from kabiroberai/main 2023-07-13 06:53:23 +09:00
Xi Ge
b697d40fb6 ModuleLoader: emit a note when encountering a blocklisted module interface 2023-07-12 13:53:36 -07:00
Allan Shortlidge
496d29c47f AST: Remove FragileFunctionKind.allowUsableFromInline.
It was effectively always true after allowing default argument expressions to
reference `@usableFromInline` decls.
2023-07-12 12:47:06 -07:00
Pavel Yaskevich
4760b95282 Merge pull request #67183 from xedin/convert-effects-into-storageRestrictions
[AST/Sema] Implement @storageRestrictions attribute
2023-07-11 11:57:14 -07:00
Michael Gottesman
f2bfa1cbac [reference-bindings] Add Sema checks for inout reference bindings to make sure we can only attach to lvalues
rdar://112029192
2023-07-10 12:47:46 -07:00
Pavel Yaskevich
9992af593c [Parse] InitAccessors: Implement @storageRestrictions parsing, diagnostics and error recovery 2023-07-07 10:00:36 -07:00
Anton Korobeynikov
eb82df6bc6 [AutoDiff] Support differentiable functions with multiple semantic results (#66873)
Add support for differentiable functions having multiple semantic results

Co-authored-by: Brad Larson <larson@sunsetlakesoftware.com>
2023-07-06 16:31:39 -07:00
Alexis Laferrière
fabb345624 [Sema] Warn on uses of @_implementationOnly imports without library-evolution
@_implementationOnly was designed for use from resilient modules only,
using it from non-resilient modules in unsupported. This change adds a
warning about it.

If anyone hits this warning, they should either enable library-evolution
or consider adopting the new `internal import` when it is available as
it handles this scenario properly.

What leads to a crash: an @_implementationOnly import fully hides the
dependency from indirect clients. This can lead to the compiler being
unaware of some internal details of a non-resilient module when building
a client against it. In turn this may lead to run time crashes from
miscompilation.

In general one could still use @_implementationOnly in a non-resilient
modules as long as it's referenced only from function bodies. However,
references from even non-public properties does lead to important memory
layout information being hidden from clients of the module.

rdar://78129903
2023-07-05 16:20:42 -07:00
Kabir Oberai
4f523807c9 feedback 2023-07-05 00:10:40 -04:00
Doug Gregor
8df508c453 Merge pull request #67105 from DougGregor/freestanding-macro-global-scope-in-scripts 2023-07-04 12:17:47 -07:00
Doug Gregor
939376b61e [Macros] Enable freestanding macros at module scope in script mode
Eliminate the error message

    error: global freestanding macros not yet supported in script mode

by implementing name lookup, type checking, and code emission for
freestanding macros. The key problem here is that, in script mode,
it is ambiguous whether a use of a freestanding macro is an expression
or a declaration. We parse as an expression (as we do within a
function body), which then gets wrapped in a top-level code
declaration.

Teach various parts of the compiler to look through a top-level code
declaration wrapping a macro expansion expression that is for a
declaration or code-item macro, e.g., by recording these for global
name lookup and treating their expansions as "auxiliary" declarations.

Fixes rdar://109699501.
2023-07-03 21:00:51 -07:00
Holly Borla
0bd898eb12 [Macros] Allow extension macros to suppress conformances that are already
stated in the original source.

If an extension macro can introduce protocol conformances, macro expansion
will check which of those protocols already have a stated conformance in the
original source. The protocols that don't will be passed as arguments to
extension macro expansion, indicating to the macro that it should only add
conformances to those protocols.
2023-06-30 16:01:15 -07:00
Holly Borla
7a46466b65 Merge pull request #66967 from hborla/extension-macro
[Macros] Generalize `conformance` macros as `extension` macros
2023-06-29 08:57:04 -07:00
Holly Borla
095542ae96 [Macros] Ban extension macros attached to local types. 2023-06-27 21:42:43 -07:00
Becca Royal-Gordon
a8fbad3551 Match @objcImpl members’ foreign error conventions
ClangImporter can import some methods as throwing that `@objc` cannot generate. For instance, an imported Objective-C method with an error out parameter in an unconventional position can still be imported as throwing no matter its selector, but `@objc` can only generate an error out parameter in an unconventional position if the matching selector part consists of the word `error` or (for the first part) ends with `Error`. Detect and diagnose these situations.

Note that the tests do not cover all of the new diagnostics because some of these conditions (like the `Void` parameter) cause selector mismatches and others (like the owned error parameter) are representable in the compiler but cannot currently be imported. I have chosen to add these diagnostics anyway in case there is a corner case that I haven’t discovered.

Fixes rdar://110100071.
2023-06-27 16:08:49 -07:00