Commit Graph

413 Commits

Author SHA1 Message Date
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
b50dfef51c Merge pull request #34808 from CodaFi/read-eval-fingerprint-loop
Add 'Fingerprint' Currency Type... And Serialize It!
2020-11-18 21:35:37 -08:00
Robert Widmann
d2a98f3b0f Address Review Comments 2020-11-18 17:12:09 -08:00
Robert Widmann
883902411b Migrate loadFingerprint onto ModuleDecl and Friends 2020-11-18 12:20:14 -08:00
Robert Widmann
27d29262b0 [NFC] Traffic in Fingerprints 2020-11-18 12:20:14 -08:00
Ben Barham
b07c06e839 [Serialization] Fix crashes when allowing compiler errors in modules 2020-11-18 12:35:21 +10:00
Robert Widmann
9f79fd5df1 Serialize Fingerprints in Swift Modules 2020-11-17 16:23:07 -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
Robert Widmann
d65ab096dd Correct Incremental Extension Test 2020-11-11 19:39:06 -08:00
Slava Pestov
b3dadc8973 AST: Use VarDecl::isInitExposedToClients() from DeclContext::getFragileFunctionKind()
getFragileFunctionKind() would report that all initializers in
non-resilient public types were inlinable, including static
properties.

This was later patched by VarDecl::isInitExposedToClients(),
which was checked in diagnoseInlinableDeclRefAccess().
However, the latter function only looked at the innermost
DeclContexts, not all parent contexts, so it would incorrectly
diagnose code with a nested DeclContext inside of a static
property initializer.

Fix this by changing getFragileFunctionKind() to call
isInitExposedToClients() and simplifying
diagnoseInlinableDeclRefAccess().

This commit also introduces a new isLayoutExposedToClients()
method, which is similar to isInitExposedToClients(), except
it also returns 'true' if the property does not have an
initializer (and in fact the latter is implemented in terms
of the former).
2020-10-22 01:11:39 -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
4b0d39c49d AST: Clean up and write better comments for source range assertions in addMember() 2020-10-08 16:17:11 -04:00
Slava Pestov
ee0d008178 Parse: Preserve source order when code completion adds delayed declarations 2020-10-07 23:28:29 -04:00
Robert Widmann
74765a8ba8 Remove Type Body Fingerprints Flags
This infrastructure has more than proven itself. Drop the code paths and tests supporting the status quo.
2020-10-01 13:09:00 -07: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
650a8b25da [AST] Rename EmittedMembersRequest -> SemanticMembersRequest. 2020-09-01 13:21:59 -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
Slava Pestov
769c4c1911 Sema: Fix some crashes with invalid nesting of extensions and protocols
Make sure we consistently use getParentForLookup() and not getParent()
when looking at generic DeclContexts. This is because an extension or
protocol that is nested inside of another generic context must never
inherit generic parameters from the parent context.

We already had this invariant enforced in some places, but now that we
do it more consistently we can fix more crashes of this kind.

Fixes <rdar://problem/58813746>, <https://bugs.swift.org/browse/SR-13004>.
2020-07-28 02:07:16 -04:00
Anthony Latsis
9fd1aa5d59 [NFC] Pre- increment and decrement where possible 2020-06-01 15:39:29 +03:00
Owen Voorhees
45bc578ae5 [SourceManager] Rename line and column APIs for clarity 2020-05-21 12:54:07 -05:00
Anthony Latsis
c337757964 [NFC] Sema: get rid of redundant DeclContext parameter to checkConformancesInContext 2020-05-20 02:38:24 +03:00
Anthony Latsis
55447e66aa Merge pull request #31645 from AnthonyLatsis/relocate-to-iterabledc
[NFC] AST: Relocate some conformance lookup client methods from DeclContext to IterableDeclContext
2020-05-18 22:25:08 +03:00
Anthony Latsis
edcf7640c0 [NFC] AST: Define and use IterableDeclContext::getAsGenericContext() 2020-05-08 03:15:07 +03:00
Slava Pestov
edb71db1c6 AST: Diagnose references to non-public declarations from default arguments of inlinable local functions
Part of <https://bugs.swift.org/browse/SR-12404>.
2020-05-04 15:38:46 -04:00
Anthony Latsis
74252028ca AST: Rename getFullName -> getName on ValueDecl & MissingMemberDecl 2020-04-23 05:16:55 +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
Dan Zheng
c834696bfa Add SynthesizedFileUnit.
`SynthesizedFileUnit` is a container for synthesized declarations. Currently, it
only supports module-level declarations.

It is used by the SIL differentiation transform, which generates implicit struct
and enum declarations.
2020-04-07 18:29:26 -07:00
Robert Widmann
f13c76cf51 Add ModuleDecl Base Case To extractNearestSourceLoc
ModuleDecl is its own declaration context.
2020-04-03 14:52:21 -07:00
Robert Widmann
27b211c1f9 Lazy-load the eraser of @_typeEraser where possible
Type erasure requires a circular construction by its very nature:

@_typeEraser(AnyProto)
protocol Proto { /**/ }
public struct AnyProto : Proto {}

If we eagerly resolve AnyProto, the chain of resolution steps that
deserialization must make goes a little something like this:

Lookup(Proto)
    -> Deserialize(@_typeEraser(AnyProto))
    -> Lookup(AnyProto)
    -> DeserializeInheritedStuff(AnyProto)
    -> Lookup(Proto)

This cycle could be broken if the order of incremental inputs was
such that we had already cached the lookup of Proto.

Resolve this cycle in any case by suspending the deserialization of the
type eraser until the point it's demanded by adding
ResolveTypeEraserTypeRequest.

rdar://61270195
2020-04-03 14:52:21 -07:00
Robert Widmann
987cd55f50 [NFC] Drop llvm::Expected from Evaluation Points
A request is intended to be a pure function of its inputs. That function could, in theory, fail. In practice, there were basically no requests taking advantage of this ability - the few that were using it to explicitly detect cycles can just return reasonable defaults instead of forwarding the error on up the stack.

This is because cycles are checked by *the Evaluator*, and are unwound by the Evaluator.

Therefore, restore the idea that the evaluate functions are themselves pure, but keep the idea that *evaluation* of those requests may fail. This model enables the best of both worlds: we not only keep the evaluator flexible enough to handle future use cases like cancellation and diagnostic invalidation, but also request-based dependencies using the values computed at the evaluation points. These aforementioned use cases would use the llvm::Expected interface and the regular evaluation-point interface respectively.
2020-03-26 23:08:02 -07:00
Alexis Laferrière
c61cc6fe4e [AST] Add SPI information to public access scopes 2020-03-04 16:42:18 -08: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
Suyash Srijan
37b40203a7 [AST] Remove redundant 'return false' from 'hasValueSemantics()' 2019-10-15 01:35:46 +01:00
Suyash Srijan
6665e716c5 [AST] Use getExtendedProtocolDecl() to check for protocol extension and use getDeclaredInterfaceType() instead of getSelfTypeInContext() - both are cheaper 2019-10-15 01:35:46 +01: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
Robert Widmann
75670c1727 Merge pull request #27436 from CodaFi/signed-sealed-delivered
[NFC] Adopt TypeBase-isms for GenericSignature
2019-09-30 15:50:42 -07:00
Robert Widmann
5a8d0744c3 [NFC] Adopt TypeBase-isms for GenericSignature
Structurally prevent a number of common anti-patterns involving generic
signatures by separating the interface into GenericSignature and the
implementation into GenericSignatureBase.  In particular, this allows
the comparison operators to be deleted which forces callers to
canonicalize the signature or ask to compare pointers explicitly.
2019-09-30 14:04:36 -07:00
David Ungar
ea81fdc7d8 Merge pull request #27313 from davidungar/generic-request-or-extended-nominal-assertion
Fail early if getExtendedNominal is called before extension has been bound.
2019-09-30 08:37:33 -07:00
David Ungar
4bc4030338 Catch failures earlier caused by premature requests for extended nominal 2019-09-28 15:19:32 -07:00
Harlan Haskins
b904133c42 [Modules] Add flag to skip non-inlinable function bodies
This flag, currently staged in as `-experimental-skip-non-inlinable-function-bodies`, will cause the typechecker to skip typechecking bodies of functions that will not be serialized in the resulting `.swiftmodule`. This patch also includes a SIL verifier that ensures that we don’t accidentally include a body that we should have skipped.

There is still some work left to make sure the emitted .swiftmodule is exactly the same as what’s emitted without the flag, which is what’s causing the benchmark noise above. I’ll be committing follow-up patches to address those, but for now I’m going to land the implementation behind a flag.
2019-09-26 10:40:11 -07:00
Jordan Rose
8d7f1b7c5d [AST] Separate SourceFile from FileUnit.h
Like the last commit, SourceFile is used a lot by Parse and Sema, but
less so by the ClangImporter and (de)Serialization. Split it out to
cut down on recompilation times when something changes.

This commit does /not/ split the implementation of SourceFile out of
Module.cpp, which is where most of it lives. That might also be a
reasonable change, but the reason I was reluctant to is because a
number of SourceFile members correspond to the entry points in
ModuleDecl. Someone else can pick this up later if they decide it's a
good idea.

No functionality change.
2019-09-17 17:54:41 -07:00