Commit Graph

4105 Commits

Author SHA1 Message Date
Yuta Saito
69479933df [c-interop] Rename @_extern to @extern
Now the feature is gated by experimental feature flag.
It's not shipped in any language release, so this rename should be fine.
2023-10-20 17:37:43 +00:00
Yuta Saito
03ed46aa74 [c-interop] Gate @_extern behind experimental feature flag 2023-10-20 17:04:36 +00:00
Yuta Saito
b62171a2c7 [c-interop] Relax C name validation as warning
And allow expert users to use potentially invalid symbols by specifying
it explicitly.
2023-10-20 15:34:09 +00:00
Yuta Saito
7767f6d272 [c-interop] Ban non-ASCII identifiers in @_extern(c) conservatively 2023-10-20 15:34:09 +00:00
Yuta Saito
a1b8687867 [c-interop] Reject @_silgen_name with @_extern
To avoid ambiguity at SIL level name since both tries to change the SIL
level name.
2023-10-20 15:34:09 +00:00
Yuta Saito
b27fd9a616 [c-interop] Add @_extern(c) attribute to declare C function in Swift 2023-10-20 15:34:08 +00:00
Alex Lorenz
5a2d1f4066 Merge pull request #69262 from hyp/eng/non-trivial-objc-disallow
[cxx-interop] disallow use of non-trivial C++ types in @objc declarat…
2023-10-19 09:24:52 -07:00
Alex Lorenz
c2e15d6472 [cxx-interop] disallow use of non-trivial C++ types in @objc declarations
Even though such types can technically be represented in C++, Swift's @objc support does not support them

rdar://114163485
2023-10-18 17:49:13 -07:00
Kuba Mracek
25cad6fe8a Diagnose more invalid uses of @_section/@_used 2023-10-18 17:48:20 -07:00
Kavon Farvardin
f76360c5b1 [Sema] "Noncopyable" means no Copyable conformance 2023-10-18 13:52:14 -07:00
Kavon Farvardin
d5f2d54ca7 [Sema] initial overhaul of isNoncopyable
This implementation has the function execute a request to scan the
inheritance clause of non-protocol nominals for a `~Copyable`. For
protocols, we look in the requirement signature.

This isn't our final state, as the GenericEnvironment needs to be
queried in general to determine of a Type is noncopyable. So for now
checking for a `~Copyable` only makes sense for Decls.
2023-10-18 13:45:50 -07:00
Kavon Farvardin
2cbb637813 [nfc] remove unused diagnostics 2023-10-18 13:45:50 -07:00
Andrew Trick
681a2b72e0 Merge pull request #69164 from atrick/nonescapable_attr
Add a temporary @_nonEscapable and @_hasUnsafeNonEscapableResult attribute
2023-10-17 21:39:10 -07:00
Andrew Trick
1f521cd7f1 Add -experimental-feature NonEscapableTypes 2023-10-17 12:45:00 -07:00
Angela Laar
22e79c27fb Merge pull request #69177 from angela-laar/prevent-sendable-attribute
[Concurrency] Disallow Sendable annotation on methods of non-Sendable types
2023-10-16 21:12:02 -07:00
Angela Laar
e779b05627 [Concurrency] Disallow Sendable annotation on methods of non-Sendable types 2023-10-16 14:21:58 -07:00
Rintaro Ishizaki
bdd4c005e5 [Macros] Diagnose how ExternalMacroDefinition request was failed
Return the failure reason as the result.
2023-10-12 16:08:48 -07:00
Pavel Yaskevich
898cde7a54 Merge pull request #68934 from dancamarotto/castmessage-whentypenotfound
Improve cast message when type not found
2023-10-12 13:39:28 -07:00
Yuta Saito
051bf4dd43 Merge pull request #69107 from kateinoigakukun/yt/extern-wasm-sym
[wasm] Add @_extern(wasm) attribute support
2023-10-12 09:29:13 -07:00
Alexis Laferrière
9ba500d4e4 Merge pull request #68967 from xymus/feature-0409
Sema: Lift flag requirement for access levels on imports now that SE-0409 has been accepted
2023-10-11 22:23:52 -07:00
Danilo Camarotto
6142a44996 making improvements requested in code review 2023-10-11 20:17:14 +01:00
Slava Pestov
e298fb5a04 Merge pull request #69116 from slavapestov/fix-apply-variadic-generic-args
Sema: Fix two bugs with type resolution of generic arguments
2023-10-11 15:00:07 -04:00
Danilo Camarotto
d68eb6b5eb Merge branch 'main' into castmessage-whentypenotfound 2023-10-11 18:58:51 +01:00
Slava Pestov
73c18fb668 Sema: Better distinguish scalar from variadic generic argument positions, and reject pack expansion types there
We used to disallow pack expansions in generic argument lists of
protocols, but allow them for all other nominal types. However,
we only actually checked that the pack expansions match up if
the type itself was variadic.

Fix this by repurposing Context::ProtocolGenericArgument into
Context::ScalarGenericArgument, and using that when the type does
not have a parameter pack.

Context::GenericArgument is now Context::VariadicGenericArgument,
and we only use it if the type has a parameter pack, in which case
we use the PackMatcher, so any pack expansions in the wrong place
are caught there.

Fixes rdar://116716014 and https://github.com/apple/swift/issues/69088.
2023-10-11 10:39:26 -04:00
Slava Pestov
67308e6894 Sema: Fix crash-on-invalid with incorrect use of variadic generic type
Applying generic arguments to a variadic generic type uses the
PackMatcher to build a mapping between generic parameters and
arguments.

The PackMatcher is symmetric, so there was an unexpected failure
mode that wasn't handled: if the variadic generic type had some
non-pack parameters, but the argument list was a single pack
expansion type, the match would succeed, grouping all of the
generic parameters into a single match.

This is non-sensical, so we need to explicitly check for this
case and diagnose it. This requires a new diagnostic, since
otherwise the general diagnostic we emit for variadic generic
type mismatches doesn't make sense, since it's complaining
about there being too few generic parameters.

Fixes rdar://116713961 / https://github.com/apple/swift/issues/69012.
2023-10-11 10:39:26 -04:00
Holly Borla
fad02e3737 Merge pull request #69089 from hborla/diagnose-invalid-declaration-macros
[Macros] Diagnose attached and freestanding declaration macros that produce something other than a declaration.
2023-10-10 15:44:00 -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
Alexis Laferrière
cbe5c3828e [Sema] Lift flag requirement for access level on imports 2023-10-10 09:09:22 -07:00
Danilo Camarotto
7eac14b783 changing diagnostics err to use ValueDecl and created note 2023-10-10 10:39:49 +01:00
Hamish Knight
042ccdda01 Merge pull request #68344 from hamishknight/do-it 2023-10-10 10:26:12 +01:00
Holly Borla
1f07cbae2a [Macros] Diagnose attached and freestanding declaration macros that produce
something other than a declaration.

The validation code already diagnosed all sorts of invalid declarations, but
it was ignoring AST nodes that aren't declarations at all.
2023-10-09 22:50:12 -07:00
Slava Pestov
f321dd3321 Merge pull request #66247 from karwa/nested-protocols
Allow protocols to be nested in non-generic contexts
2023-10-08 12:00:46 -04:00
Danilo Camarotto
2d61c56a21 Merge branch 'main' into castmessage-whentypenotfound 2023-10-07 16:15:20 +01:00
Karl Wagner
ab4f80ed95 [SE-0404] Allow protocols to be nested in non-generic contexts 2023-10-06 21:04:03 +02:00
Hamish Knight
33f94bc874 Introduce do expressions 2023-10-06 11:17:48 +01:00
Doug Gregor
4b3d2f47d9 [Typed throws] Handle function conversions involving different thrown errors
Teach the constraint solver about the subtyping rule that permits
converting one function type to another when the effective thrown error
type of one is a subtype of the effective thrown error type of the
other, using `any Error` for untyped throws and `Never` for
non-throwing.

With minor other fixes, this allows us to use typed throws for generic
functions that carry a typed error from their arguments through to
themselves, which is in effect a typed `rethrows`:

```swift
func mapArray<T, U, E: Error>(_ array: [T], body: (T) throws(E) -> U)
throws(E) -> [U] {
  var resultArray: [U] = .init()
  for value in array {
    resultArray.append(try body(value))
  }
  return resultArray
}
```
2023-10-05 11:55:05 -07:00
Holly Borla
f7a8bc2e04 Merge pull request #68794 from hborla/isolated-initializer-expressions
[Concurrency] Allow default arguments to require actor isolation.
2023-10-04 20:10:43 -07:00
Danilo Camarotto
439ae8051f changing message and fixing tests 2023-10-05 02:14:13 +01:00
Alexis Laferrière
5ad504e5c1 Merge pull request #68954 from xymus/report-non-public-extensions
Sema: Report public extensions using non-publicly imported types
2023-10-04 14:44:21 -07:00
Holly Borla
88b2332ba0 [Concurrency] Handle nested decl contexts while computing the required isolation
for a default argument, and improve diagnostics for conflicting isolation.
2023-10-04 13:12:11 -07:00
Holly Borla
95a7107872 [Concurrency] Allow default arguments to require actor isolation.
Type checking a default argument expression will compute the required
actor isolation for evaluating that argument value synchronously. Actor
isolation checking is deferred to the caller; it is an error to use a
default argument from across isolation domains.

Currently gated behind -enable-experimental-feature IsolatedDefaultArguments.
2023-10-04 13:12:11 -07:00
Alexis Laferrière
a63687059c [Sema] Report public extensions to non-publicly imported types
Access levels on extensions are special. Let's make sure we report
public extensions referencing non-public imported types using the
preexisting general exportability checks.

Record and remark on the use of the import at the same time.
2023-10-03 15:18:39 -07:00
Joe Groff
b4f536927a Disable destructuring initializations in struct let stored properties.
This looks like it was never properly implemented, since when we generate the
memberwise initializer for the struct in SILGen, it incorrectly tries to apply
the entire initializer expression to each variable binding in the pattern,
rather than destructuring the result and pattern-matching it to the variables.
Since it never worked it doesn't look like anyone is using this, so let's
put up an error saying it's unsupported until we can implement it properly.
Add `StructLetDestructuring` as an experimental feature flag so that tests around
the feature for things like module interface printing can still work.
2023-10-03 13:24:39 -07:00
Danilo Camarotto
1e03ecc0c0 Merge branch 'main' into castmessage-whentypenotfound 2023-10-03 15:51:17 +01:00
Danilo Camarotto
a1e8d29fa9 implementing changes and fixing unit tests 2023-10-03 15:37:03 +01:00
swift-ci
c1df6db3f0 Merge pull request #68881 from apple/prefix-smashing
Diagnose possible enum common-prefix mistakes
2023-10-02 21:48:14 -07:00
Becca Royal-Gordon
78127ce5ee Diagnose possible enum common-prefix mistakes
Clang Importer strips prefixes from enum and option set case names. The logic to do this computes a common prefix from the type name and all non-deprecated case names (to oversimplify), which means that adding, removing, or changing one case can change the prefix that is removed from *all* cases. This typically causes the prefix to become shorter, meaning that additional words are prepended to each existing case name.

Existing diagnostics make it look like the case has disappeared, when in fact it still exists under a different name. A little more information may help developers to figure out what happened.

Add a tailored diagnostic for this scenario which kicks in when (a) a missing member is diagnosed, (b) the base is an imported enum or option set’s metatype, and (c) an enum case or static property exists which has the name we attempted to look up as a suffix.

Fixes rdar://116251319.
2023-10-02 16:50:54 -07:00
Doug Gregor
581b9d8a95 Merge pull request #68629 from DougGregor/typed-throws
Typed throws
2023-09-30 11:18:41 -07:00
Alexis Laferrière
e820854784 Merge pull request #68831 from xymus/report-superfluously-public-imports
Sema: warn on imports that are too public and remark source of entities in API
2023-09-29 20:15:56 -07:00
Doug Gregor
31b8811167 [Typed throws] Perform access control and availability checking on thrown errors 2023-09-29 10:51:54 -07:00