Commit Graph

24025 Commits

Author SHA1 Message Date
Holly Borla
eb858d938e [ConstraintSystem] Use an explicit generic argument constraint for
UnresolvedSpecializeExpr.

The eager generic argument matching code in CSGen for unresolved
specializations was incorrect because it didn't account for parameter
packs. Fortunately, a constraint to delay explicit generic argument
matching already exists for macros. Use it here.
2023-06-14 18:24:58 -07:00
Holly Borla
35bd5099ab Merge pull request #66632 from hborla/pack-diagnostics
[Diagnostics] Suppress printing explicit pack types in the ASTPrinter instead of stripping `PackType` out of diagnostic arguments.
2023-06-14 16:10:58 -07:00
Rintaro Ishizaki
5791a2cb37 [Macros] Plugin search options group
'load-plugin-library', 'load-plugin-executable', '-plugin-path' and
'-external-plugin-path' should be searched in the order they are
specified in the arguments.

Previously, for example '-plugin-path' used to precede
'-external-plugin-path' regardless of the position in the arguments.
2023-06-14 15:46:39 -07:00
Becca Royal-Gordon
1532fb188c Merge pull request #66609 from beccadax/just-empty-protocol
Diagnose conformances on @objcImpl extensions
2023-06-14 14:12:13 -07:00
Holly Borla
e42667bde6 [Diagnostics] Suppress printing explicit pack types in the ASTPrinter instead of
stripping PackType out of diagnostic arguments.

There are places in the type printing code that assume the substitution for a
type parameter pack is always a pack, and violating that invariant will crash
the compiler. We also never want to print 'Pack{...}' in diagnostics anyway,
so the print option is a better approach and fixes a few existing tests that still
contained 'Pack{...}' in error messages.
2023-06-14 11:57:18 -07:00
Pavel Yaskevich
2b8a39724c Merge pull request #66513 from xedin/init-accessor-diagnostics
[Sema/SIL] Improve diagnostics related to init accessors
2023-06-14 09:57:08 -07:00
Becca Royal-Gordon
6758fdb518 Diagnose conformances on @objcImpl extensions
@objcImpl extensions aren’t allowed to declare new conformances; instead, they should either be declared in the header or in an ordinary extensions. (If they were permitted, they’d be ignored.)

Fixes rdar://110669366.
2023-06-13 17:21:44 -07:00
swift-ci
0d1095efa3 Merge pull request #66262 from beccadax/your-implementation-is-required
Support required inits in @objcImpl
2023-06-13 14:28:56 -07:00
Pavel Yaskevich
34c8cf60f1 [Sema/SILGen] InitAccessors: Memberwise initializers with init accessors should follow field order
Skip stored properties that are initialized via init accessors and
emit parameters/initializations in field order which allows us to
cover more use-cases.
2023-06-13 13:56:33 -07:00
Pavel Yaskevich
cffc3fd73d [Sema/SILGen] InitAccessors: Don't synthesize memberwise init if initializes intersect
If some property is initializable by one than one init accessor
let's not sythesize a memberwise initializer in that case because
it's ambiguous what is the best init accessor to use.
2023-06-13 12:40:41 -07:00
Pavel Yaskevich
4f59538eba [Sema] InitAccessors: Diagnose situations when memberwise init cannot be synthesized
If some of the properties with init accessors have out of order
accesses diagnose that while checking whether memberwise init
could be synthesized.
2023-06-13 10:58:50 -07:00
Pavel Yaskevich
ddcfe01ba5 [Sema/SILGen] InitAccessors: Emit intersecting init accessor calls in memberwise init
If init accessor initialize the same properties, let's emit them
in sequence and emit `destroy_addr` in-between to make sure that
there is no double initialization.
2023-06-13 10:58:50 -07:00
Pavel Yaskevich
db024d973e [CSDiagnostics] InitAccessors: Implement invalid member reference diagnostics within init accessors 2023-06-13 10:58:50 -07:00
Pavel Yaskevich
3c924be2a0 [CSFix] InitAccessors: Add a fix that tracks invalid member references within init accessors 2023-06-13 10:58:50 -07:00
Pavel Yaskevich
935142ff49 [ConstraintSystem] InitAccessors: Detect invalid references to members within init accessors
Only properties that are listed in 'initializes' and 'accesses'
attributes could be referenced within init accessor. Detect any
and all invalid member references in the solver.
2023-06-13 10:58:50 -07:00
Pavel Yaskevich
5613006944 [Sema] PreCheck: Diagnose standalone self within init accessors
'self' within init accessor could only be used to refer to
properties listed in `initializes` and `accesses` attributes.
2023-06-13 10:58:50 -07:00
Pavel Yaskevich
71432032d4 Merge pull request #66579 from xedin/allow-holes-in-diagnostic-mode-only
[ConstraintSystem] Allow generic parameters to bind to holes only in …
2023-06-13 10:58:23 -07:00
Hamish Knight
c6dd3ad839 [CS] Diagnose UnresolvedPatternExprs as part of constraint solving
Instead of diagnosing in CSApply, let's create a
fix and diagnose in the solver instead.
Additionally, make sure we assign ErrorTypes to
any VarDecls bound by the invalid pattern, which
fixes a crash.

rdar://110638279
2023-06-13 12:14:25 +01:00
Hamish Knight
762cd4d10e Merge pull request #66565 from hamishknight/connect-two 2023-06-13 08:45:53 +01:00
Pavel Yaskevich
cfbbb2807e [ConstraintSystem] Allow generic parameters to bind to holes only in diagnostic mode
If generic parameter gets opened during regular solving it cannot
be bound to a hole, that can only happen in diagnostic mode, so
let's not even try. Doing so also makes sure that there are no
inference side-effects related to holes because bindings are ranked
based on their attributes.
2023-06-12 16:29:59 -07:00
Allan Shortlidge
775b4a47c0 AST: Inherit access level of opaque type decls from naming decl.
When an `OpaqueTypeDecl` is constructed, the access level attributes of the
decl that names the opaque type were copied on to it. However, the
`@usableFromInline` attribute is not permitted on every decl, so it does not
get copied. This in turn causes access level computations for opaque types to
fail to take `@usableFromInline` into account and that results in the emitted
symbol getting the wrong linkage during IRGen. The fix is to make access level
computations take this quirk of opaque types into account directly (like they
already to for several other kinds of decls), instead of relying on copying of
attributes.

Resolves rdar://110544170
2023-06-12 12:05:25 -07:00
Hamish Knight
f18293bf7c [CS] Walk ExprPattern conjunction elements when finding type variables
Apply the same logic that we apply to other
conjunction elements, to make sure that e.g
property wrapper projected values work correctly.

rdar://110649179
2023-06-12 18:27:26 +01:00
Hamish Knight
1616e167b9 [CS] Walk into patterns when looking for closure referenced vars
Previously we would skip over ExprPatterns, but
we need to ensure that we walk them, as they may
have interesting variable references that the
closure needs to be connected to the type
variables for.

rdar://110617471
2023-06-12 18:27:24 +01:00
Holly Borla
393b4ceb95 [NameLookup] Move macro-related name lookup operations into the namelookup
namespace.

This moves the `isInMacroArgument` predicate and `lookupMacros` into `namelookup`.
ASTScope still encapsulates the scope tree and contains the operation to lookup
the enclosing macro scope, which then invokes a callback to determine whether a
potential macro scope is indeed a macro, because answering this question requires
name lookup.
2023-06-11 23:10:43 -07:00
Holly Borla
706411d2e6 [CodeCompletion] Plumb source locations through code completion name lookup. 2023-06-11 23:10:43 -07:00
Holly Borla
98249543cd [Macros] Ban freestanding and peer macro expansions that can produce arbitrary
names at global scope.

Freestanding and peer macros applied at top-level scope cannot introduce
arbitrary names. Introducing arbitrary names means that any lookup
into this scope must expand the macro. This is a problem, because
resolving the macro can invoke type checking other declarations, e.g.
anything that the macro arguments depend on. If _anything_ the macro
depends on performs name unqualified name lookup, e.g. type resolution,
we'll get circularity errors. It's better to prevent this by banning
these macros at global scope if any of the macro candidates introduce
arbitrary names.
2023-06-11 23:10:41 -07:00
Holly Borla
db23cf5f32 [PreCheckExpr] Don't perform typo correction inside macro arguments. 2023-06-11 23:09:48 -07:00
Holly Borla
cd752cca22 [NameLookup] Plumb source location arguments through all name lookup APIs.
This source location will be used to determine whether to add a name lookup
option to exclude macro expansions when the name lookup request is constructed.
Currently, the source location argument is unused.
2023-06-11 23:09:47 -07:00
Holly Borla
2943064511 [Macros] Always exclude macro expansions in TypeChecker::lookupMacros. 2023-06-11 23:09:47 -07:00
Doug Gregor
5457290143 Eliminate "may have storage" hack in PatternBindingEntryRequest.
Remove an early iteration of cycle-breaking in `PatternBindingEntryRequest`
that has been subsumed by the lazy computation of
`AbstractStorageDecl::hasStorage()`. We can now directly use
`hasStorage()` here.
2023-06-11 08:52:37 -07:00
Doug Gregor
1209ef89ec Ensure that macros within init accessors are expanded early enough
Now that we've made accessor macro expansion more lazy, ensure that
when querying for init accessors (e.g., to build a memberwise
initializer), we also expand any accessor macros that might produce an
init accessor.

This is a partial step toward the real goal, which is that
`AbstractStorageDecl::getAccessor()` should lazily expand macros if
needed.

Update the Observable macro to document that it produces an `init`
accessor.
2023-06-11 08:48:43 -07:00
Doug Gregor
a72fb83034 Requestify AbstractStorageDecl::hasStorage().
The `hasStorage()` computation is used in many places to determine the
signatures of other declarations. It currently needs to expand accessor
macros, which causes a number of cyclic references. Provide a
simplified request to determine `hasStorage` without expanding or
resolving macros, breaking a common pattern of cycles when using
macros.

Fixes rdar://109668383.
2023-06-10 08:28:06 -07:00
Doug Gregor
f7de3a3590 [Macros] Downgrade "void return for non-expression macro" error in interfaces
This allows us to continue to accept Swift interface files created with
older versions of the Swift 5.9 compiler that emitted a spurious
`-> ()` on non-expression macro declarations.
2023-06-09 23:25:35 -07:00
Doug Gregor
c78afdc6d1 [Macros] Tighten restriction on non-expression macros not having return types
There is no reason to special-case `Void` to permit it. Rather, make
this a syntactic rule. Thanks to Alex Hoppen for the suggestion.
2023-06-09 23:25:26 -07:00
Doug Gregor
c5ec3892aa Diagnose macros that have multiple freestanding macro roles.
Per SE-0397, a macro may only have a single freestanding macro role,
otherwise we would have an ambiguity in how a particular freestanding
macro would be expanded. Produce an error on such macro declarations.

Fixes rdar://110178899.
2023-06-09 13:40:11 -07:00
Doug Gregor
3c04cff8dd [Macros] Provide the freestanding macro role for expansion operations.
The compiler knows (from a macro declaration) what freestanding macro
role a macro implementation is expected to implement. Pass that through
to the macro expansion code itself, rather than guessing based on the
protocol conformances of the implementation type. We already use this
approach with attached macros, so this is more of the same.

Eliminates a crash and improves diagnostics when the freestanding macro
role and its implementation are out of sync, fixing rdar://110418969.
2023-06-09 12:59:56 -07:00
Doug Gregor
759f52066e [Macros] Only freestanding expression macros can have a non-Void result type
Fixes rdar://108871352.
2023-06-09 10:40:28 -07:00
Pavel Yaskevich
9d418b4608 Merge pull request #66463 from xedin/init-accessor-memberwise-default
[Sema] InitAccessors: Don't synthesize default memberwise arg for ini…
2023-06-08 17:21:55 -07:00
Pavel Yaskevich
8c54d3d560 [Sema] InitAccessors: Don't synthesize default memberwise arg for init accessor initializations
Default arguments for `init accessors` are not fully supported
at the moment, so we shouldn't attempt to synthesize them in
Sema just to crash during linking.
2023-06-08 12:13:55 -07:00
Max Desiatov
3ba40af174 [NFC] TypeCheckDeclPrimary.cpp: remove unused isGenericType
This change fixes a warning encountered when compiling this file:

```
swift/lib/Sema/TypeCheckDeclPrimary.cpp:475:8: warning: unused variable 'isGenericType' [-Wunused-variable]
  bool isGenericType = isa<NominalTypeDecl>(decl);
```
2023-06-08 17:22:27 +01:00
Rintaro Ishizaki
c3d1304345 [SourceKit] Add request to expand macros syntactically
Expand macros in the specified source file syntactically (without any
module imports, nor typechecking).

Request would look like:
```
{
  key.compilerargs: [...]
  key.sourcefile: <file name>
  key.sourcetext: <source text> (optional)
  key.expansions: [<expansion specifier>...]
}
```
`key.compilerargs` are used for getting plugins search paths. If
`key.sourcetext` is not specified, it's loaded from the file system.
Each `<expansion sepecifier>` is
```
{
  key.offset: <offset>
  key.modulename: <plugin module name>
  key.typename: <macro typename>
  key.macro_roles: [<macro role UID>...]
}
```
Clients have to provide the module and type names because that's
semantic.

Response is a `CategorizedEdits` just like (semantic) "ExpandMacro"
refactoring. But without `key.buffer_name`. Nested expnasions are not
supported at this point.
2023-06-07 14:26:40 -07:00
Pavel Yaskevich
274a43b040 Merge pull request #66283 from xedin/init-accessors
[Parse/Sema/SIL] Implementation of init accessors feature (under a flag)
2023-06-07 08:16:35 -07:00
Doug Gregor
5ea559435d Merge pull request #66387 from DougGregor/silgen-freestanding-local-vars 2023-06-07 06:49:23 -07:00
swift-ci
c74fd074c6 Merge pull request #64280 from hamishknight/platypus
[CS] Allow ExprPatterns to be type-checked in the solver
2023-06-06 20:21:45 -07:00
Pavel Yaskevich
ad95e911a8 [Sema/SIL] InitAccessors: Incorporate init accessors into memberwise initializers
Properties with init accessors are used in place of properties they
are supposed to initialize in order of stored properties.
2023-06-06 18:59:46 -07:00
Pavel Yaskevich
22061e6621 [Sema] InitAccessors: Verify that a property never appears both in initializes(...) and accesses(...) 2023-06-06 18:59:46 -07:00
Pavel Yaskevich
fb15b6f2e5 [Sema] InitAccessors: Mark properties with init accessor as computed 2023-06-06 18:59:46 -07:00
Pavel Yaskevich
69269e6943 [Sema] InitAccessors: Mark init accesor as mutating "self" only for value types 2023-06-06 18:59:13 -07:00
Pavel Yaskevich
4a4bf3bd77 [Sema] InitAccessors/NFC: Add tests for invalid references in initializes/accesses attributes 2023-06-06 18:59:13 -07:00
Pavel Yaskevich
d7f5419623 [AST] InitAccessors: Add initializes/accesses attribute location validation 2023-06-06 18:59:13 -07:00