Commit Graph

4105 Commits

Author SHA1 Message Date
Alexis Laferrière
2ef019610c [Sema] Error on resilient importing publicly a non-resilient module
Importing a non-library-evolution enabled module from a
library-evolution enabled module will lead to generating a
swiftinterface that can't be rebuilt by a different compiler.
Make it a hard error when using access level imports, and keep it as a
warning for @_implementationOnly imports.
2023-02-27 19:31:52 -08:00
Alexis Laferrière
c6c96c4688 [Sema] Report inconsistent access level on import
When targeting Swift 5 and earlier, the default import is public. To
notify of a possible unintentional public import, raise errors on
default imports when other imports of the same target have an explicit
type.

This check isn't necessary in the tentative Swift 6 mode.
2023-02-27 19:31:52 -08:00
Alexis Laferrière
1afc6af739 Merge pull request #63912 from xymus/access-level-import-parsing
[Parser|Sema] Accept access level on imports with experimental flag
2023-02-27 09:27:26 -08:00
Alexis Laferrière
08895657cb [Parser] Intro parser support and flag for access level on imports 2023-02-25 09:47:19 -08:00
Luciano Almeida
22a18de1b1 [Sema] Improving integer literal as boolean diagnostic 2023-02-21 10:30:48 -03:00
Kavon Farvardin
197a97621f require an ownership specifier for noncopyable parameters
Per the current proposal, these are to be specified
explicitly, as they form an important part of the API.

Bonus: This commit includes a fix to make
`CompileTimeConstTypeRepr` a proper `isa<>` subtype of
`SpecifierTypeRepr`, since we forgot to add it to
that type's `classof` function.

resolves rdar://105480354
2023-02-16 22:08:13 -08:00
Alexis Laferrière
9a1a32cd9b Merge pull request #63639 from xymus/serial-precise-tag
[Serialization] Don't fail the precise tag check if only the last digit doesn't match
2023-02-14 09:31:31 -08:00
swift-ci
e800217716 Merge pull request #63564 from kavon/noncopyable-conformance-fixes
[move-only] fix conformance synthesis & conformances in extensions
2023-02-13 21:24:27 -08:00
Alexis Laferrière
a5ccbf3264 [Serialization] Only remark if the last digit mismatches in precise tag check
Weaken the precise tag check at loading swiftmodule to accept binary
modules build by a compiler with a tag where only the last digit is
different. We assume that the other digit in the version should ensure
compiler and stdlib compatibility. If the last digit doesn't match,
still raise a remark.

rdar://105158258
2023-02-13 14:28:10 -08:00
Rajveer
33bf9d2d0b [Sema] Align error messages for failure to infer generic parameter and opaque result type
Fixes #63291.
2023-02-11 11:36:16 +05:30
Kavon Farvardin
5b7eada4dd permit conformances in extensions of move-only types
previously we were blindly rejecting anything
that such extensions conformed to, but Sendable
is now allowed for move-only types.
2023-02-10 10:02:43 -08:00
Pavel Yaskevich
e2b22d9f62 [AST/Sema] Remove TypeWrapper feature functionality 2023-02-08 00:16:00 -08:00
swift-ci
e4510ea753 Merge pull request #63487 from kavon/no-conditional-cast-of-moveonly
prevent move-only types from being cast incorrectly
2023-02-07 19:30:36 -08:00
Kavon Farvardin
9a18422647 statically prevent runtime casts of move-only type
It appears that conditional casts require a check of the
type's metadata at runtime. There's no reason for us to
permit that at this time, since all such conditional
casts are going to fail, unless its the identity cast.

That is, a move-only type is currently only a subtype
of itself.

So for now, `is`, `as?`, `as!` casts from or to a
move-only type are now an error. The `as` casts
are permitted only if the two move-only types are
equal.
2023-02-07 16:51:46 -07:00
Richard Wei
01e4c8df26 [Macros] Use name lookup for lazy declaration macro expansion (#63411)
- Use the name lookup table instead of adding members from a macro expansion to the parent decl context.
- Require declaration macros to specify introduced names and used the declared names to guide macro expansions lazily.
2023-02-07 11:24:42 +08:00
Michael Gottesman
ef5903f14e Merge pull request #63443 from gottesmm/pr-1c9625a7ee5b17755b835a7ff4aa7d4d7f6a04d6
[move-only] For now ban non-final classes from containing move only stored fields.
2023-02-06 15:01:00 -08:00
Michael Gottesman
3c976e9d79 [move-only] For now ban non-final classes from containing move only stored fields.
Just closing this hole for now until we have enough time to implement this the
correct way.
2023-02-05 13:08:44 -08:00
Michael Gottesman
c29abfb596 Merge pull request #63430 from gottesmm/pr-5d989a63a1de483a30457a09002cfa58c29fe7f8
[move-only] Ban move only enums from being indirect or having indirect fields.
2023-02-04 18:14:40 -08:00
Michael Gottesman
6f13f867e7 [move-only] Ban move only enums from being indirect or having indirect fields.
Banning it for now to close a hole in the model. We just want to implement it at
a later point in time.
2023-02-04 11:22:08 -08:00
Hamish Knight
c87b1b8bef Merge pull request #63022 from hamishknight/express-yourself 2023-02-03 16:40:09 +00:00
Allan Shortlidge
8fde58f6ca Merge pull request #63357 from tshortli/se0376-rename-backdeploy
[SE-0376] Rename `@_backDeploy(before:)` to `@backDeployed(before:)`
2023-02-02 12:36:53 -08:00
Kavon Farvardin
ab130883a3 Initial ban of move-only types from being used generically
Since values of generic type are currently assumed to always
support copying, we need to prevent move-only types from
being substituted for generic type parameters.

This approach leans on a `_Copyable` marker protocol to which
all generic type parameters implicitly must conform.

A few other changes in this initial implementation:

- Now every concrete type that can conform to Copyable will do so. This fixes issues with conforming to a protocol that requires Copyable.
- Narrowly ban writing a concrete type `[T]` when `T` is move-only.
2023-02-01 23:38:28 -08:00
Allan Shortlidge
d2524a6de8 AST: Implement parsing support for the accepted spelling of @backDeployed for SE-0376.
For source compatibility `@_backDeploy` continues to be accepted as a spelling.

rdar://102792909
2023-02-01 22:04:33 -08:00
Michael Gottesman
aad66806ab Merge pull request #63342 from gottesmm/pr-be1c0e09106b26c3a14caa3e66d52a889dc36491
[move-only] Teach the borrow to destructure transform how to handle consuming/non-consuming uses on the same instruction.
2023-02-01 21:43:05 -08:00
John McCall
ea107ae025 Merge pull request #63324 from rjmccall/element-archetype-printing
Fix printing and implement parsing of opened element archetypes in SIL
2023-02-01 18:59:54 -05:00
Michael Gottesman
43b90e8590 [noimplicitcopy] Error if a noimplicitcopy vardecl or paramdecl is of move only type.
rdar://104934156
2023-02-01 15:19:17 -08:00
Pavel Yaskevich
7a81eb3810 Merge pull request #63274 from xedin/runtime-metadata-impl-alignment
[AST/Sema] RuntimeMetadata: Align implementation with proposal
2023-02-01 12:37:24 -08:00
Hamish Knight
0d55f45d95 [Sema] Error on redundant try/awaits for if/switch expressions
Look through `try`/`await` markers when looking for
out of place if/switch expressions, and customize
the effect checking diagnostic such that we error
that `try`/`await` are redundant on `if`/`switch`
expressions.
2023-02-01 15:30:19 +00:00
Hamish Knight
a40f1abaff Introduce if/switch expressions
Introduce SingleValueStmtExpr, which allows the
embedding of a statement in an expression context.
This then allows us to parse and type-check `if`
and `switch` statements as expressions, gated
behind the `IfSwitchExpression` experimental
feature for now. In the future,
SingleValueStmtExpr could also be used for e.g
`do` expressions.

For now, only single expression branches are
supported for producing a value from an
`if`/`switch` expression, and each branch is
type-checked independently. A multi-statement
branch may only appear if it ends with a `throw`,
and it may not `break`, `continue`, or `return`.

The placement of `if`/`switch` expressions is also
currently limited by a syntactic use diagnostic.
Currently they're only allowed in bindings,
assignments, throws, and returns. But this could
be lifted in the future if desired.
2023-02-01 15:30:18 +00:00
John McCall
c491d25d06 Fix printing and implement parsing of opened element archetypes in SIL
Also, fix a couple places that were checking for opened existentials
to check for any local archetype.
2023-01-31 19:54:31 -05:00
John McCall
5dd6c4ee5f [NFC] Pass SIL-specific type resolution state abstractly into Sema
This is in preparation for parsing pack element archetypes.
2023-01-31 19:54:31 -05:00
Pavel Yaskevich
67b74a0633 [Sema] RuntimeMetadata: Diagnose missing explicit reflection metadata attributes
Diagnose situations where a sub-class or a protocol do not have all
of the reflection metadata attributes required by a superclass.

Resolves: rdar://103990788
2023-01-30 14:14:47 -08:00
Sophia Poirier
7016679fa5 Merge pull request #63208 from sophiapoirier/require-pack-reference-within-pack-expansion
[Variadic Generics] require pack ident type within a pack expansion t…
2023-01-30 12:43:09 -08:00
Pavel Yaskevich
ec3534b9a5 [Sema] RuntimeMetadata: Make reflection metadata attribute a conformance requirement
If conforming type doesn't declare required set of reflection metadata
attributes (based on the protocol declaration) fail conformance via
extension.
2023-01-30 10:11:28 -08:00
Pavel Yaskevich
ffd5d9661e [AST] RuntimeMetadata: Reject attributes with custom arguments on protocol declarations 2023-01-30 10:11:28 -08:00
Pavel Yaskevich
42694d867c [AST] RuntimeMetadata: Allow use of reflection metadata attrs on unavailable extensions
This is just a way to opt-out a type from use of the attribute,
there is no code generation for such cases because the attribute
could never be reached.
2023-01-30 10:11:21 -08:00
Anthony Latsis
792a9cf7c0 [DiagnosticsQoI] Sema: Use 'underlying' instead of 'concrete' in opaque result type diagnostic 2023-01-28 20:51:40 +03:00
Sophia Poirier
0e99f9c6e5 [Variadic Generics] require pack ident type within a pack expansion to form a pack reference 2023-01-27 13:17:12 -08:00
Doug Gregor
5a9a654adb Adopt @freestanding(expression) for all @expression macros 2023-01-25 17:07:38 -08:00
Kavon Farvardin
fef04f5534 allow @_moveOnly only on structs or enums
Per the existing proposal, we're not supporting
move-only reference types right now.
2023-01-23 16:51:37 -08:00
Allan Shortlidge
5b942eb18b SILGen/Sema: Add @_backDeploy support for constructors.
Resolves rdar://94436652
2023-01-21 18:04:54 -08:00
Ellie Shin
bf8f9a896a Add missing package acl in diags 2023-01-20 00:44:56 -08:00
Ellie Shin
37af51dc4c Merge branch 'main' into es-pkg-acl 2023-01-19 16:18:17 -08:00
Ellie Shin
c2acf61784 Add package to diags 2023-01-19 16:16:35 -08:00
Anton Korobeynikov
0763e4b98c Diagnose differentiable functions returning Void w/o inout arguments. (#63080)
Such functions are not differentiable and therefore should be rejected.
Fixes #62923,  fixes #58095
2023-01-18 13:57:51 -08:00
Luciano Almeida
f441e271a8 Merge pull request #62924 from LucianoPAlmeida/opaque-diags
[Diagnostics] Improving diagnostics for inference of opaque result concrete type
2023-01-18 08:38:26 -03:00
Luciano Almeida
5a84f4c96f Merge pull request #62796 from LucianoPAlmeida/actor-mismatch-diag
[Diagnostics][Sema] Improving global actor function mismatch diagnostic
2023-01-14 09:16:07 -03:00
Luciano Almeida
e513d23c0b [Sema] Improving global actor function mismatch diagnostic 2023-01-13 20:47:23 -03:00
Richard Wei
f17b7c48bf [Macros] Freestanding declaration macros
Add support for freestanding declaration macros.

- Parse `@declaration` attribute.
- Type check and expand `MacroExpansionDecl`.

Known issues:
- Generic macros are not yet handled.
- Expansion does not work when the parent decl context is `BraceStmt`. Need to parse freestanding declaration macro expansions in `BraceStmt` as `MacroExpansionDecl`, and add expanded decls to name lookup.
2023-01-10 19:09:11 -08:00
Luciano Almeida
c6ea1f6611 [Diagnostics] Improving diagnostics for inference of opaque result concrete type 2023-01-09 09:41:54 -03:00