Commit Graph

311 Commits

Author SHA1 Message Date
Doug Gregor
bbbc346768 [Macros] Treat MacroDecl as a local context, like functions are. 2022-11-28 18:33:10 -08:00
swift-ci
c6a647ae06 Merge remote-tracking branch 'origin/main' into rebranch 2022-11-13 20:33:41 -08:00
Doug Gregor
5ab6b72604 [Macros] Turn Macro into a declaration node.
Although the declaration of macros doesn't appear in Swift source code
that uses macros, they still operate as declarations within the
language. Rework `Macro` as `MacroDecl`, a generic value declaration,
which appropriate models its place in the language.

The vast majority of this change is in extending all of the various
switches on declaration kinds to account for macros.
2022-11-13 12:21:29 -08:00
Erik Eckstein
48befc4e32 AST: fix DeclContext's cast_convert_val
Replace it with `CastInfo`.
This fixes a build error with the new LLVM.
2022-11-04 20:44:18 +01:00
Becca Royal-Gordon
6143b8379f Generate IR for @_objcImpl stored properties
Only works for trivial types right now because features related to initialization and deinitialization are seriously busted.
2022-10-18 17:21:56 -07:00
Becca Royal-Gordon
3a2f12a099 Allow stored properties in @_objcImpls
Stored properties are only allowed in the extension implementing the class's main interface, not its categories. This also means banning `@objc final`, which is unenforceable anyway when ObjC subclasses are allowed, and therefore allowing `@objc let` and `@objc static` properties to be overridden if they're declared in objcImplementations.
2022-10-18 17:21:56 -07:00
Hamish Knight
cfd24354e1 [Sema] Fix missing operator diagnostic logic
Introduce a `getTopmostDeclarationDeclContext`
utility to ensure we ensure we don't visit a
`nullptr` DeclContext for an erroneous module
under `-experimental-allow-module-with-compiler-errors`.

Additionally, tweak the insertion location such
that we insert at the start of any attributes
present.

rdar://97267326
2022-07-28 12:55:53 +01:00
Allan Shortlidge
5f5cc9f00b Sema: Diagnose use of availability macros in conditional statements in @_backDeploy functions. Add a test verifying that expected diagnostics are emitted when referencing non-public declarations from a @_backDeploy function body.
Resolves rdar://90270100
2022-03-14 17:16:17 -07:00
Allan Shortlidge
25b59cb8bc AST: Emit @_backDeploy function bodies into .swiftinterface files.
Resolves rdar://88650341
2022-02-11 14:47:32 -08:00
Kavon Farvardin
6823744779 reimplement nonisolated initializing exprs for instance properties
It's possible to create an impossible set of constraints for
instance-member stored properties of a type. For example:

@MainActor func getStatus() -> Int { /* ... */ }
@PIDActor func genPID() -> ProcessID { /* ... */ }

class Process {
  @MainActor var status: Int = getStatus()
  @PIDActor var pid: ProcessID = genPID()

  init() {} // Problem: what is the isolation of this init?
}

We cannot satisfy the isolation of the initilizing expressions,
which demand that genStatus and genPID are run with isolation
from a non-async designated initializer, which is not possible.

This patch changes the isolation for those initializer expressions
for instance members, saying that the isolation is unspecified.

fixes rdar://84225474

The first attempt to do this was in
https://github.com/apple/swift/pull/40652
But, I implemented that as a hard source break, since the isolation
was changed in a way that an error diagnostic would be emitted.
This commit reimplements the change more gently, as a warning for
Swift 5 users.
2022-01-19 13:01:22 -08:00
Evan Wilde
cce3e8a7f5 Merge pull request #40149 from etcwilde/ewilde/concurrency/underscored-unavailablefromasync
Add `_unavailableFromAsync` attribute
2021-12-06 12:38:53 -08:00
zoecarver
f3b7a40f1e [nfc][cxx-interop] Mark lazy member loading complete only after members are loaded. 2021-11-30 11:54:58 -08:00
Evan Wilde
46d84bef4d Add 'isAsyncContext' to DeclContext
Querying the context for whether it is an async context is the easiest
way to detect if the context is async. Many decl contexts can be checked
at any point, but AbstractClosureExpr contexts must have been
typechecked. If this is called on an AbstractClosureExpr before the
types have been assigned, it may either crash or do bad things.
2021-11-30 11:11:34 -08:00
Becca Royal-Gordon
59bb325e4b [NFC] Factor out ASTContext operator news
Many, many, many types in the Swift compiler are intended to only be allocated in the ASTContext. We have previously implemented this by writing several `operator new` and `operator delete` implementations into these types. Factor those out into a new base class instead.
2021-08-19 11:19:52 -07:00
Slava Pestov
a250688a50 AST: Use availability to disambiguate multiple overlapping conformances
If a conformance is found in an imported module as well as the current module,
and one of the two conformances is conditionally unavailable on the current
deployment target, pick the one that is always available.

Fixes <rdar://problem/78633800>.
2021-06-07 00:45:59 -04:00
Doug Gregor
9579390024 [SE-0304] Rename ConcurrentValue to Sendable 2021-03-18 22:48:20 -07:00
Doug Gregor
b5e4b085aa Infer ConcurrentValue conformances for structs and enums.
When a struct or enum has only ConcurrentValue-conforming instance
data, infer conformance to ConcurrentValue.
2021-03-02 00:23:33 -08:00
Doug Gregor
01d4440fb9 Funnel all "get local conformances" queries through a request.
LookupAllConformancesInContextRequest caches the results of performing
lookup of all of the conformances ascribed to a given iterable
declaration context. However, it was only used in a small number of
places, with most clients using a different API
(`getLocalConformances()`) that does not provide
caching, cycle detection, or dependency tracking.

Sink LookupAllConformancesInContextRequest lower in the stack, and
reimplement `getLocalConformances()` on top of it. This ensures that
all of the various queries go through the cached request and get the
benefits of the request-evaluator infrastructure.
2021-03-01 22:05:24 -08:00
Doug Gregor
c4e265e280 [Type checker] Add "all members" request.
Introduce an "all members" request to compute all of the members of a
given iterable declaration context in stable order. This builds on ABI
members so that it will also include, e.g., type aliases synthesized
for associated types.
2021-01-20 12:56:32 -08:00
Doug Gregor
a8f7f0d4e5 [AST] Rename "semantic members" to "ABI members".
The "semantic members" query produces the list of members that can
affect the ABI, e.g., of classes. It does not produce the complete
list of members suitable for semantic queries.
2021-01-20 12:56:31 -08:00
Robert Widmann
27d29262b0 [NFC] Traffic in Fingerprints 2020-11-18 12:20:14 -08:00
Robert Widmann
cdd54f1a51 Unconditionally Record Type Body Fingerprints
We used to disable these for extensions, which meant changes to
extensions would pessimistically cause every decl in the file to be
considered dirty.
2020-11-11 19:48:04 -08:00
Slava Pestov
85d24953de Sema: Teach ExportContext to compute whether we're inside an unavailable declaration 2020-10-20 23:39:11 -04:00
Arnold Schwaighofer
b994bf3191 Add support for _specialize(exported: true, ...)
This attribute allows to define a pre-specialized entry point of a
generic function in a library.

The following definition provides a pre-specialized entry point for
`genericFunc(_:)` for the parameter type `Int` that clients of the
library can call.

```
@_specialize(exported: true, where T == Int)
public func genericFunc<T>(_ t: T) { ... }
```

Pre-specializations of internal `@inlinable` functions are allowed.

```
@usableFromInline
internal struct GenericThing<T> {
  @_specialize(exported: true, where T == Int)
  @inlinable
  internal func genericMethod(_ t: T) {
  }
}
```

There is syntax to pre-specialize a method from a different module.

```
import ModuleDefiningGenericFunc

@_specialize(exported: true, target: genericFunc(_:), where T == Double)
func prespecialize_genericFunc(_ t: T) { fatalError("dont call") }

```

Specially marked extensions allow for pre-specialization of internal
methods accross module boundries (respecting `@inlinable` and
`@usableFromInline`).

```
import ModuleDefiningGenericThing
public struct Something {}

@_specializeExtension
extension GenericThing {
  @_specialize(exported: true, target: genericMethod(_:), where T == Something)
  func prespecialize_genericMethod(_ t: T) { fatalError("dont call") }
}
```

rdar://64993425
2020-10-12 09:19:29 -07:00
Slava Pestov
ee0d008178 Parse: Preserve source order when code completion adds delayed declarations 2020-10-07 23:28:29 -04:00
Slava Pestov
f718a4cdd2 AST: Remove IterableDeclContext::getMemberCount() 2020-09-23 01:26:06 -04:00
Robert Widmann
934f994b46 Remove DeclContext::isCascadingContextForLookup 2020-09-21 10:37:41 -06:00
Doug Gregor
ccca4fd25d [AST] Add IterableDeclContext::getParsedMembers().
Provide an accessor for retrieving the parsed members, generalizing
`ParseMembersRequest` so it can provide the parsed members for
deserialized/synthesized declarations as well. This is the counterpart
to the recently-generalized `getSemanticMembers()`; together, these
should suffice for most (all?) clients of `getMembers()`.
2020-09-01 13:58:30 -07:00
Doug Gregor
ae4fbb6716 [AST] Generalize and rename ClassDecl::getEmittedMembers()
Generalize `ClassDecl::getEmittedMembers()` to operate on an
`IterableDeclContext`, so that it can be for other nominal types,
extensions, etc. Rename to `getSemanticMembers()` to indicate that
these are all of the members that are semantically part of that
context.

Clean up the implementation slightly so it only forces type checking
for the conformances within that particular context (using
`getLocalConformances()`) and doesn't need to list out each of the
protocols it cares about.
2020-09-01 13:01:10 -07:00
Hamish Knight
9e2cdf49b3 Merge pull request #31506 from hamishknight/hello-operator 2020-05-23 09:48:21 -07:00
Anthony Latsis
c337757964 [NFC] Sema: get rid of redundant DeclContext parameter to checkConformancesInContext 2020-05-20 02:38:24 +03:00
Hamish Knight
cc062ee2bb Fix precedencegroup and operator decl lookup
Re-implement operator and precedencegroup decl
lookup to use `namelookup::getAllImports` and
existing decl shadowing logic. This allows us to
find operator decls through `@_exported` imports,
prefer operator decls defined in the same module
over imported decls, and fixes a couple of other
subtle issues.

Because this new implementation is technically
source breaking, as we can find multiple results
where we used to only find one result, it's placed
behind the new Frontend flag
`-enable-new-operator-lookup` (with the aim of
enabling it by default when we get a new language
mode).

However the new logic will always be used if the
result is unambiguous. This means that e.g
`@_exported` operators will be instantly available
as long as there's only one candidate. If multiple
candidates are found, we fall back to the old
logic.

Resolves SR-12132.
Resolves rdar://59198796.
2020-05-18 14:33:43 -07:00
Anthony Latsis
bfe25fabeb [NFC] AST: Relocate getLocalConformances to IterableDeclContext 2020-05-08 17:43:09 +03:00
Anthony Latsis
b3af1a03f1 [NFC] AST: Relocate takeConformanceDiagnostics & getLocalProtocols to IterableDeclContext 2020-05-08 03:15:15 +03:00
Anthony Latsis
edcf7640c0 [NFC] AST: Define and use IterableDeclContext::getAsGenericContext() 2020-05-08 03:15:07 +03:00
Slava Pestov
e2349bdf67 AST: Move TypeChecker::getFragileFunctionKind() to a method on DeclContext
We had some duplicated logic between getResilienceExpansion() and
getFragileFunctionKind(). Clean this up by moving the latter into
AST, and re-implementing the former in terms of the latter.

This also fixes a crash in at least one case where these two
implementations had previously diverged.

Fixes <rdar://problem/60605117>.
2020-04-16 14:09:04 -04:00
Robert Widmann
a9e11e3130 [NFC] Separate Taking Redundant Conformance Diagnostics From The Lookup Table 2020-03-24 12:40:11 -07:00
David Ungar
72032493f9 Fix and test for extension body 2020-02-29 23:19:09 -08:00
Brent Royal-Gordon
f8df2f66fd Add mechanism for per-SourceFile overlays
When a “separately imported overlay” is added to a SourceFile, two things happen:

1. The direct import of the underlying module is removed from getImports*() by default. It is only visible if the caller passes ImportFilterKind:: ShadowedBySeparateOverlay. This means that non-module-scoped lookups will search _OverlayModule before searching its re-export UnderlyingModule, allowing it to shadow underlying declarations.

2. When you ask for lookupInModule() to look in the underlying module in that source file, it looks in the overlays instead. This means that UnderlyingModule.foo() can find declarations in _OverlayModule.
2020-02-18 11:07:12 -08:00
David Ungar
8f4fd061f9 Use Optional for fingerprint 2020-01-27 15:14:46 -08:00
David Ungar
d61f6f2f66 Changes to support per-type-body fingerprints. 2020-01-27 15:14:46 -08:00
Robert Widmann
e626cfb378 Remove lazy member loading re-entrancy guards
Effectively revert #28907. The request evaluator will also catch re-entrancy here, and those cycles can be broken with NameLookupFlags::IgnoreNewExtensions.
2020-01-25 11:04:53 -08:00
Brent Royal-Gordon
9a57554bdf [NFC] DeclNameRef-ify qualified and unqualified lookup 2019-12-11 00:55:17 -08:00
Hamish Knight
256c129506 [NameLookup] Add AnyObjectLookupRequest 2019-11-22 12:59:27 -08:00
Robert Widmann
56a713f179 Remove LazyResolver! 2019-11-05 14:43:12 -08:00
Brent Royal-Gordon
99faa033fc [NFC] Standardize dump() methods in frontend
By convention, most structs and classes in the Swift compiler include a `dump()` method which prints debugging information. This method is meant to be called only from the debugger, but this means they’re often unused and may be eliminated from optimized binaries. On the other hand, some parts of the compiler call `dump()` methods directly despite them being intended as a pure debugging aid. clang supports attributes which can be used to avoid these problems, but they’re used very inconsistently across the compiler.

This commit adds `SWIFT_DEBUG_DUMP` and `SWIFT_DEBUG_DUMPER(<name>(<params>))` macros to declare `dump()` methods with the appropriate set of attributes and adopts this macro throughout the frontend. It does not pervasively adopt this macro in SILGen, SILOptimizer, or IRGen; these components use `dump()` methods in a different way where they’re frequently called from debugging code. Nor does it adopt it in runtime components like swiftRuntime and swiftReflection, because I’m a bit worried about size.

Despite the large number of files and lines affected, this change is NFC.
2019-10-31 18:37:42 -07:00
Suyash Srijan
6ca121dd2a [Typechecker] Do not incorrectly mark explicitly mutating methods as non-mutatingif we're in a class-constrained protocol extension 2019-10-15 01:35:46 +01:00
Suyash Srijan
70d77e9fe2 Revert "Revert "Merge pull request #27057 from theblixguy/unrevert/SR-11298""
This reverts commit 7725818275.
2019-10-15 01:35:46 +01:00
Jordan Rose
7725818275 Revert "Merge pull request #27057 from theblixguy/unrevert/SR-11298"
This reverts commit c99facb48b, reversing
changes made to 9a24013228.

rdar://problem/56165420
2019-10-10 14:29:52 -07:00
Jordan Rose
a1ea211f22 Add llvm::iterator_range to LLVM.h
If we're going to get rid of swift::IteratorRange, let's make
llvm::iterator_range easy to use.

No functionality change.
2019-10-08 15:24:06 -07:00