2489 Commits

Author SHA1 Message Date
Kuba Mracek
25cad6fe8a Diagnose more invalid uses of @_section/@_used 2023-10-18 17:48:20 -07:00
Yuta Saito
bd898b0e7e [wasm] add @_extern(wasm) attribute support
This attribute instructs the compiler that this function declaration
should be "import"ed from host environment. It's equivalent of Clang's
`__attribute__((import_module("module"), import_name("field")))`
2023-10-10 22:42:08 +00:00
Karl Wagner
ab4f80ed95 [SE-0404] Allow protocols to be nested in non-generic contexts 2023-10-06 21:04:03 +02:00
Alex Hoppen
90506909d3 Merge pull request #68603 from ahoppen/ahoppen/storage-attribute-completion
[CodeCompletion] Completion for `@storageRestrictions` attribute
2023-10-02 10:17:43 -07:00
Doug Gregor
ef642098f2 [Typed throws] Parsing and AST representation for typed errors
Parse typed throw specifiers as `throws(X)` in every place where there
are effects specified, and record the resulting thrown error type in
the AST except the type system. This includes:
* `FunctionTypeRepr`, for the parsed representation of types
* `AbstractFunctionDecl`, for various function-like declarations
* `ClosureExpr`, for closures
* `ArrowExpr`, for parsing of types within expression context

This also introduces some serialization logic for the thrown error
type of function-like declarations, along with an API to extract the
thrown interface type from one of those declarations, although right
now it will either be `Error` or empty.
2023-09-29 10:51:51 -07:00
Rintaro Ishizaki
8dbde04c61 Merge pull request #68408 from rintaro/fetch-content
[CMake] Replace early swift-syntax with FetchContent
2023-09-28 11:22:10 -07:00
Alex Hoppen
17e6a25234 [Parse] Accumulate a parser status while parsing attributes 2023-09-27 09:33:38 -07:00
Alex Hoppen
ee85314e6f [CodeCompletion] Add completion for @storageRestrictions 2023-09-27 09:33:38 -07:00
Yuta Saito
ac440c336a [wasm] Accept multiple @_expose on a single function decl
But multiple @_expose with the same exposure kind are still invalid.
2023-09-26 14:13:43 +00:00
Yuta Saito
6d378a3ec3 [wasm] add @_expose(wasm) attribute support
This attribute instructs the compiler that this function declaration
should be "export"ed from this .wasm module. It's equivalent of Clang's
`__attribute__((export_name("name")))`
2023-09-26 14:13:33 +00:00
Kavon Farvardin
c01360d02e [Sema] reimplement ~C as an general inverse constraint 2023-09-20 09:34:06 -07:00
Ben Barham
041691184c [CMake] Replace early swift-syntax with FetchContent
Use FetchContent to include swift-syntax directly in swift. This can be
thought of as an `add_subdirectory` for a directory outside the root.

The default build directory will be `_deps/swiftsyntax-subbuild/`, though
the modules and shared libraries will be built in `lib/swift/host` by
passing down `SWIFT_HOST_LIBRARIES_DEST_DIR` to avoid copying them as we
were doing previously.
2023-09-18 14:44:10 -07:00
Alex Hoppen
44a4d6998c Merge pull request #67111 from AnthonyLatsis/astgen-decls
ASTGen: An assortment of strides and improvements
2023-09-16 08:08:05 -07:00
Anthony Latsis
b6be6da277 ASTGen: Translate associated type declarations
Plus tweak `DefaultDefinitionTypeRequest` caching to support querying the
cached type when dumping. This fixes a crash where type computation is
triggered in the dumper before import resolution in `-dump-parse` mode.
2023-09-12 20:37:50 +03:00
Anthony Latsis
4b2cdedc48 ASTGen: Start diagnosing instances of an invalid syntax tree 2023-09-12 20:37:50 +03:00
Kuba Mracek
9a380212c1 [embedded] Add an interim attr to mark declarations as unavailable in embedded Swift
Implemented as custom parsing logic instead of a proper attribute because we want it to be rewritten at parse time (into nothing in regular Swift mode, and into unconditional unavailable attr in embedded Swift mode), no serialization, printing, etc.
2023-09-10 08:23:31 -07:00
Luciano Almeida
4c24384f5f [Parse] Remove initializes and accesses attr parse code 2023-08-22 20:55:30 -03:00
Hamish Knight
35a98f3828 [ASTGen] Allow querying of enabled features
For now this is using C interop, we ought to be
using C++ interop, but that's a much bigger
change.
2023-08-09 19:35:50 +01:00
Pavel Yaskevich
2a0651e8b0 [Frontend/NFC] SE-0400: Enable InitAccessors feature by default 2023-07-31 13:18:59 -07:00
Pavel Yaskevich
7777ed5b00 [Parser] NFC: Rename isAllowedInProtocolRequirement -> isAllowedWhenParsingLimitedSyntax 2023-07-28 13:53:03 -07:00
Pavel Yaskevich
1a9c2e63f5 [Parse] InitAccessors: Parse limited representation of init accessor in SIL context 2023-07-28 08:32:37 -07:00
Allan Shortlidge
48d5bd836e NFC: Fix unused variable warnings in ParseDecl.cpp. 2023-07-27 12:45:28 -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
Pavel Yaskevich
0bbf3403e4 [Parse] InitAccessors: Diagnose an attempt to use init accessor without a getter 2023-07-11 13:45:38 -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
Alex Hoppen
ed4dc1becd Change Optional -> llvm::Optional 2023-07-07 21:16:33 +02:00
Alex Hoppen
c385fe5e87 [CodeCompletion] Migrate PostfixExprParen to solver-based 2023-07-07 19:50:46 +02:00
Pavel Yaskevich
9992af593c [Parse] InitAccessors: Implement @storageRestrictions parsing, diagnostics and error recovery 2023-07-07 10:00:36 -07:00
Pavel Yaskevich
9719cd01ef [AST] InitAccessors: Introduce new @storageRestrictions(initializes:accesses:) attribute
This is the replacement for `initializes`, `accesses` attributes.
2023-07-07 10:00:35 -07:00
Doug Gregor
16bfd783f4 [Macros] When a macro defines a getter or setter, remove didSet/willSet
As with the initial value of a property that is converted from a stored
property to a computed property by an accessor macro, remove
didSet/willSet. It is the macro's responsibility to incorporate their
code or diagnose them.

Fixes rdar://111101833.
2023-07-05 19:37:21 -07:00
Doug Gregor
22158be449 [Macros] Diagnose when an accessor macro produces an accessor that already exists
We used to crash; now we diagnose and... don't crash.

Fixes rdar://111588129.
2023-07-05 16:27:25 -07:00
Doug Gregor
6fca08acf7 [Macros] Cope with local types and opaque result types in macros and expansions
Address a few related issues that affect local types and opaque result types within macros:
* Don't add local types or opaque types encountered while parsing the
arguments of a freestanding macro to the global list. When we do add
them, make sure we're adding them to the outermost source file so
they'll get seen later. This avoids trying to generate code for these
types, because they aren't supposed to be part of the program. Note
that a similar problem remains for arguments to attached macros, which
will need to be addressed with a more significant refactoring.
* When determining whether opaque types should be substituted within a
resilience domain, check the outermost source files rather than the exact
source file, otherwise we will end up with a mismatch in
argument-passing conventions.
* When delaying the type checking of functions that occur as part of a
macro expansion, make sure we record them in the outermost Swift source
file. Otherwise, we won't come back to them.

There is a common theme here of using AST state on the source file in
a manner that isn't ideal, and starts to break down with macros. In
these cases, we're relying on side effects from earlier phases
(parsing and type checking) to inform later phases, rather than
properly expressing the dependencies through requests.

Fixes rdar://110674997&110713264.
2023-07-03 15:09:54 -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
Kuba (Brecka) Mracek
d427696bf9 Allow @_silgen_name to be used on globals and add a @_silgen_name(raw: ...) version that skips mangling (#66540)
Attribute @_silgen_name is today only allowed to be used on functions, this change allows usage on globals as well. The motivation for that is to be able to "forward declare" globals just like it's today possible to do with functions (for the cases where it's not practical or convenient to use a bridging header).

Separately, this change also adds a @_silgen_name(raw: ...) syntax, which simply avoids mangling the name (by using the \01 name prefix that LLVM uses). The motivation for that is to be able to reference the "magic Darwin linker symbols" that can be used to look up section bounds (in the current dylib/module) -- those symbols don't use the underscore prefix in their mangled names.
2023-06-29 08:37:51 -07:00
Holly Borla
c867c7c917 [Macros] Allow extension macros to specify conformances in the attached
attribute.
2023-06-28 00:42:23 -07:00
Holly Borla
725374e0d8 [Macros] Implement attached extension macros. 2023-06-27 21:22:12 -07:00
Evan Wilde
250082df25 [NFC] Reformat all the LLVMs
Reformatting everything now that we have `llvm` namespaces. I've
separated this from the main commit to help manage merge-conflicts and
for making it a bit easier to read the mega-patch.
2023-06-27 09:03:52 -07:00
Evan Wilde
f3ff561c6f [NFC] add llvm namespace to Optional and None
This is phase-1 of switching from llvm::Optional to std::optional in the
next rebranch. llvm::Optional was removed from upstream LLVM, so we need
to migrate off rather soon. On Darwin, std::optional, and llvm::Optional
have the same layout, so we don't need to be as concerned about ABI
beyond the name mangling. `llvm::Optional` is only returned from one
function in
```
getStandardTypeSubst(StringRef TypeName,
                     bool allowConcurrencyManglings);
```
It's the return value, so it should not impact the mangling of the
function, and the layout is the same as `std::optional`, so it should be
mostly okay. This function doesn't appear to have users, and the ABI was
already broken 2 years ago for concurrency and no one seemed to notice
so this should be "okay".

I'm doing the migration incrementally so that folks working on main can
cherry-pick back to the release/5.9 branch. Once 5.9 is done and locked
away, then we can go through and finish the replacement. Since `None`
and `Optional` show up in contexts where they are not `llvm::None` and
`llvm::Optional`, I'm preparing the work now by going through and
removing the namespace unwrapping and making the `llvm` namespace
explicit. This should make it fairly mechanical to go through and
replace llvm::Optional with std::optional, and llvm::None with
std::nullopt. It's also a change that can be brought onto the
release/5.9 with minimal impact. This should be an NFC change.
2023-06-27 09:03:52 -07:00
Alex Hoppen
2ff585d6ff [SourceKit] Highlight consuming and borrowing as keywords 2023-06-08 10:59:42 -07:00
Pavel Yaskevich
0e61a75ef9 [Parser] InitAccessors: Properties in initializes/accesses should be separated by comma 2023-06-06 18:59:46 -07:00
Pavel Yaskevich
a090eb4e17 [Parse] InitAccessor: Reject init accessor declarations on subscripts 2023-06-06 18:59:13 -07:00
Pavel Yaskevich
f96e1d7a4e [Parse] InitAccessors: Validate that init accessor declaration context
Init accessors are only allowed on properties.
2023-06-06 18:59:13 -07:00
Holly Borla
404a5239c3 [Parser] Parse 'initializes' and 'accesses' attributes on init accessors. 2023-06-06 18:59:13 -07:00
Holly Borla
e5f75029de [AST] Add 'initializes' and 'accesses' attributes for init accessor
definite initialization dependencies.
2023-06-06 18:59:13 -07:00
Holly Borla
d35da6262b [AST] Add a 'newValue' parameter to init accessors. 2023-06-06 18:59:13 -07:00
Holly Borla
429f1908c7 [Parser] Parse init accessors when the experimental feature is enabled. 2023-06-06 18:57:31 -07:00
Holly Borla
684ef9c482 [AST] Add a new accessor kind for init accessors. 2023-06-06 18:57:31 -07:00
Rintaro Ishizaki
a61fa5a4c2 Merge pull request #66296 from rintaro/macros-freestandingexpansion
[Macros] Unify MacroExpansionDecl/MacroExpansionExpr expansion logic
2023-06-05 09:35:18 -07:00
Doug Gregor
c28598777b Merge pull request #66327 from DougGregor/local-types-in-macro-expansions 2023-06-05 02:02:35 -07:00
Doug Gregor
e964d1290f [Parser] Add local type declarations to the outermost enclosing source file
The parser is currently responsible for adding local type declarations
to a `SourceFile`, which IR generation later queries. However, IRGen
never sees the source files associated with macro expansion buffers,
so local types introduced there don't get recorded.

In time, this approach of using the parser to record semantic
information should be replaced with something more "pull" oriented.
For now, however, record local type declarations in the outermost
enclosing source file... so we see the ones produced by macro
expansions, too.

Fixes rdar://109370309.
2023-06-04 21:54:25 -07:00