Commit Graph

1866 Commits

Author SHA1 Message Date
Doug Gregor
f91767cfa0 [Conformance checker] Capture potential matches for missing witnesses.
Rework the data structures we use in the conformance checker to talk
about missing witnesses, so they can capture the set of potential
matches. This will allow us to delay more diagnostics to later,
more uniformly.
2020-09-18 16:50:22 -07:00
Varun Gandhi
5e9bf1f7c6 [SIL] Store ClangTypeInfo in SILFunctionType.
This patch includes a large number of changes to make sure that:
1. When ExtInfo values are created, we store a ClangTypeInfo if applicable.
2. We reduce dependence on storing SIL representations in ASTExtInfo values.
3. Reduce places where we sloppily create ASTExtInfo values which should
   store a Clang type but don't. In certain places, this is unavoidable;
   see [NOTE: ExtInfo-Clang-type-invariant].

Ideally, we would check that the appropriate SILExtInfo does always store
a ClangTypeInfo. However, the presence of the HasClangFunctionTypes option
means that we would need to condition that assertion based on a dynamic check.
Plumbing the setting down to SILExtInfoBuilder's checkInvariants would be too
much work. So we weaken the check for now; we should strengthen it once we
"turn on" HasClangFunctionTypes and remove the dynamic feature switch.
2020-09-16 10:34:42 -07:00
Brent Royal-Gordon
cce0411000 [NFC] Add ASTContext::getModuleByIdentifier()
This is a reasonably common operation.
2020-09-10 19:08:29 -07:00
Brent Royal-Gordon
7bfeeebcb9 [NFC] Add helper to parse import paths in strings 2020-09-10 19:08:29 -07:00
Brent Royal-Gordon
cff4ddf13a [NFC] Adopt new ImportPath types and terminology
# Conflicts:
#	lib/IDE/CodeCompletion.cpp
2020-09-10 19:07:49 -07:00
swift-ci
400accb8ea Merge pull request #33871 from AnthonyLatsis/o-some 2020-09-10 15:43:21 -07:00
Anthony Latsis
1926cc7169 Optimize ASTContext::getOpenedArchetypeSignature
Avoid computing and caching a new signature for a plain protocol type when
when we can grab the protocol's own identical canonical generic signature
2020-09-10 23:05:13 +03:00
Holly Borla
3fd882cadf [NFC] Rename "storage wrapper var" to "projection var" or "projected value"
in property wrapper-related code.
2020-09-02 18:07:40 -07:00
Xi Ge
c403b140e1 ClangImporter: refactor ClangImporterOptions to be ASTContext-owned. NFC
We need ClangImporterOptions to be persistent for several scenarios: (1)
when creating a sub-ASTContext to build Swift modules from interfaces; and
(2) when creating a new Clang instance to invoke Clang dependencies scanner.

This change is NFC.
2020-09-01 14:04:22 -07:00
Doug Gregor
10fa19b2b5 Merge pull request #33674 from DougGregor/concurrency-objc-import-async
[Concurrency] Import Objective-C methods with completion handlers as async
2020-08-28 19:48:02 -07:00
Varun Gandhi
8df83150fb Merge pull request #33541 from varungandhi-apple/vg-clang-types-in-sil-setup
Setup code for Clang types in SIL.
2020-08-28 14:34:27 -07:00
Pavel Yaskevich
a6c3e6f543 Merge pull request #33658 from xedin/introduce-hole-type
[ConstraintSystem] Introduce a new type to represent a type hole
2020-08-28 10:40:15 -07:00
Doug Gregor
1e5d30f5ca [Concurrency] Import Objective-C methods with completion handlers as async
When a given Objective-C method has a completion handler parameter
with an appropriate signature, import that Objective-C method as
async. For example, consider the following CloudKit API:

    - (void)fetchShareParticipantWithUserRecordID:(CKRecordID
*)userRecordID
            completionHandler:(void (^)(CKShareParticipant * _Nullable shareParticipant, NSError * _Nullable error))completionHandler;

With the experimental concurrency model, this would import as:

    func fetchShareParticipant(withUserRecordID userRecordID: CKRecord.ID) async throws -> CKShare.Participant?

The compiler will be responsible for turning the caller's continuation
into a block to pass along to the completion handler. When the error
parameter of the completion handler is non-null, the async call
will result in that error being thrown. Otherwise, the other arguments
passed to that completion handler will be returned as the result of
the async call.

async versions of methods are imported alongside their
completion-handler versions, to maintain source compatibility with
existing code that provides a completion handler.

Note that this only covers the Clang importer portion of this task.
2020-08-27 21:30:13 -07:00
Pavel Yaskevich
4847ec9a6b [AST/TypeChecker] Add more asserts to make sure types don't get into AST 2020-08-27 13:18:45 -07:00
Varun Gandhi
eead4ae8f0 [NFC] Remove unused function parameter. 2020-08-27 13:14:05 -07:00
Varun Gandhi
8da4d53d2c [NFC] Use ClangTypeInfo's implicit null state instead of an extra Optional. 2020-08-27 13:14:05 -07:00
Varun Gandhi
c890cdd1a3 [AST] Add functionality for computing Clang types for SIL functions. 2020-08-27 13:14:05 -07:00
Pavel Yaskevich
8f2e53c72d [AST] Make sure that hole types are always allocated in ConstraintSolver arena
Since `HoleType` directly as well as other types which could contain holes
are bound to a lifetime of constraint system that created them, we need to
make sure that such types are always allocated using `ConstraintSolver`
arena instead of a permanent one.
2020-08-26 22:18:02 -07:00
Pavel Yaskevich
78ea3de8e4 [AST] Introduce a new type to represent a type hole in constraint system
Instead of using `UnresolvedType` as a placeholder for a type hole,
let's switch over to a dedicated "rich" `HoleType` which is capable
of storing "originator" type - type variable or dependent member
type which couldn't be resolved.

This makes it easier for the solver to determine origins of
a hole which helps to diagnose certain problems better. It also
helps code completion to locate "expected type" of the context
even when it couldn't be completely resolved.
2020-08-26 16:55:39 -07:00
Nate Chandler
5d813f38ec Revert "[SIL] Add flag to SILFunctionType::Profile for async."
This reverts commit b8976a3ec5.
2020-08-25 13:50:16 -07:00
Nate Chandler
94b5f76654 Revert "[SIL] Add SILFunctionType flag for async."
This reverts commit 9b8828848d.
2020-08-25 13:37:26 -07:00
Xi Ge
29e655bac0 DependenciesScanner: implement protocol for batch module dependencies scan
This scanning mode allows swift-driver to query module dependencies in a batch
and in a more granular way. In short term, it could help solve a problem that
clang module dependencies may vary if target triple changes. In a longer term,
we could break a holistic dependencies graph into smaller pieces for better caching
and reusing.

This change doesn't include the implementation of using the specified scanner
arguments to set up Clang dependencies scanner. It will come in later commits.
2020-08-20 14:06:47 -07:00
Nate Chandler
b8976a3ec5 [SIL] Add flag to SILFunctionType::Profile for async.
Previously, the flag was omitted, causing function types which were
otherwise the same to have the same id, leading to caching woes.

Here, the issue is fixed by adding the boolean flag to the id, ensuring
that types which differ only in that flag are still understood to be
different.
2020-08-19 18:01:05 -07:00
Nate Chandler
9b8828848d [SIL] Add SILFunctionType flag for async. 2020-08-19 11:29:58 -07:00
Anthony Latsis
78a2460de1 [NFC] Remove TypeLoc::setInvalidType 2020-08-18 23:01:34 +03:00
Slava Pestov
5f26fa84bc AST: A class-constrained OpenedArchetypeType should have a layout constraint
This is now the case for archetypes instantiated from a generic
signature; let's establish this invariant for opened types as well.
2020-08-15 03:09:09 -04:00
Rintaro Ishizaki
1ab4a4742a [AST] Formalize getBodySourceRange() for fast completion
Fast completion replaces the body ('BraceStmt') of function decls with
other bodies parsed from different source buffers from the original
source buffer. That means the source range of the body and the location
of the function declaration itself might be in different buffers.

Previously, FuncDecl::getSourceRange() used to use the 'func' keyword decl
as the start loc and 'getBodySourceRange().End' as the end loc. This
breaks a SourceRange invariant where the start and end loc must be
in the same buffer.

This patch add a new function 'getOriginalBodySourceRange()' which
always return the source range of the original body of the function. And
use that from 'getSourceRange()' functions.

The orignal body source range is stored in a side table in ASTContext so
that normal compilation doesn't consume space for that extra info.
2020-08-11 17:08:27 -07:00
Matei Oprea
f971b349b4 [NFC] Refactor manual size calculations in memory allocation (#33256) 2020-08-03 22:02:31 -07:00
Varun Gandhi
270b5dc7a6 Merge pull request #33118 from varungandhi-apple/vg-builder-pattern-ExtInfo
Refactor ExtInfo to use the builder pattern for construction.
2020-08-03 10:30:05 -07:00
Varun Gandhi
f219e58ada [NFC] Refactor ExtInfo to use a builder-pattern based API.
Since the two ExtInfos share a common ClangTypeInfo, and C++ doesn't let us
forward declare nested classes, we need to hoist out AnyFunctionType::ExtInfo
and SILFunctionType::ExtInfo to the top-level.

We also add some convenience APIs on (AST|SIL)ExtInfo for frequently used
withXYZ methods. Note that all non-default construction still goes through the
builder's build() method.

We do not add any checks for invariants here; those will be added later.
2020-07-31 13:55:55 -07:00
Slava Pestov
94c6bff65d AST: Replace some calls to getDeclaredType() with getDeclaredInterfaceType() 2020-07-31 13:39:01 -04:00
Varun Gandhi
aee1151d76 [NFC] Remove unused parameter to ASTContext::getClangFunctionType. 2020-07-30 21:46:38 -07:00
eeckstein
5fffeb81fb Merge pull request #33128 from eeckstein/string-optimization
SIL optimizer: Add a new string optimization
2020-07-28 10:17:28 +02:00
Varun Gandhi
aeda622298 [NFC] Rename ExtInfo::Uncommon to ExtInfo::ClangTypeInfo.
The previous name was poorly chosen (by me). Time to fix that.
2020-07-27 13:40:32 -07:00
Erik Eckstein
7f684b62e2 SIL optimizer: Add a new string optimization.
Optimizes String operations with constant operands.

Specifically:
  * Replaces x.append(y) with x = y if x is empty.
  * Removes x.append("")
  * Replaces x.append(y) with x = x + y if x and y are constant strings.
  * Replaces _typeName(T.self) with a constant string if T is statically known.

With this optimization it's possible to constant fold string interpolations, like "the \(Int.self) type" -> "the Int type"

This new pass runs on high-level SIL, where semantic calls are still in place.

rdar://problem/65642843
2020-07-27 21:32:56 +02:00
Varun Gandhi
1ddf4ff790 [Gardening] Use consistent style for referencing notes. 2020-07-25 23:36:17 -07:00
Xi Ge
84dd4db0b1 Dependencies Scanner: report compiled Swift module paths if they are available
For the explicit module mode, swift-driver uses -compile-module-from-interface to
generate modules from interfaces found by the dependency scanner. However, we don't
need to build the binary module if up-to-date modules are available, either adjacent
to the interface file or in the prebuilt module cache directory. This patch teaches
dependencies scanner to report these ready-to-use binary modules.
2020-07-01 11:54:15 -07:00
Robert Widmann
057097a6c3 [NFC] Hide LoadedModules From Clients of ASTContext
There's no reason clients need to be able to access this data directly.
It obscures where module loading is actually happening, and makes it too
easy to accidentally register a module with the wrong identifier in the
context.

Hide the registration operations behind opaque accessors.
2020-06-16 15:09:19 -07:00
Dan Zheng
d3b6b89de6 [AutoDiff] Support multiple differentiability result indices in SIL. (#32206)
`DifferentiableFunctionInst` now stores result indices.
`SILAutoDiffIndices` now stores result indices instead of a source index.

`@differentiable` SIL function types may now have multiple differentiability
result indices and `@noDerivative` resutls.

`@differentiable` AST function types do not have `@noDerivative` results (yet),
so this functionality is not exposed to users.

Resolves TF-689 and TF-1256.

Infrastructural support for TF-983: supporting differentiation of `apply`
instructions with multiple active semantic results.
2020-06-05 16:25:17 -07:00
Robert Widmann
1d0065d136 Merge pull request #32145 from CodaFi/port-of-call
[NFC] Miscellaneous Cleanups To Clang Module Loading
2020-06-03 00:11:53 -07:00
Robert Widmann
e7f38db235 [NFC] Have Evaluator's Constructor Read LangOptions
It's a touch cleaner to do this than passing around a pile of bools.
2020-06-02 09:51:04 -07:00
Anthony Latsis
9fd1aa5d59 [NFC] Pre- increment and decrement where possible 2020-06-01 15:39:29 +03:00
Hamish Knight
046f17f519 [AST] Move the empty module assertion
Start asserting in `ModuleDecl::getFiles`
that the module is either non-empty or has
failed to load. This ensures that module
loading doesn't attempt to query the module's
files until the ModuleFile has been installed.
2020-05-28 12:09:11 -07:00
Hamish Knight
bc618a9763 [ClangImporter] Avoid calling into ObjCSelector lookup
The ClangImporter currently calls into
`ObjCSelector`'s `lookupDirect` in a couple of
places, stashing the selector in a DenseMap to try
and avoid re-entrancy problems.

However this will become a problem once
`ObjCSelector`'s `lookupDirect` is both
requestified and starts pulling in members from
the main module, so migrate the ClangImporter off
calling it.

Fortunately most of its uses only care about decls
with associated Clang nodes. For those cases, we
can use the existing member table, making sure to
populate it with any method we import.

In one case, the ClangImporter needs to check to
see if there's a deserialized Swift method with a
matching selector. Instead of calling through to
`lookupDirect`, let's just query the Swift module
loaders directly.
2020-05-21 09:19:02 -07:00
Robert Widmann
afe8f2b63f Drop TypeCheckerDebugConsumer 2020-05-18 22:49:55 -07:00
Anthony Latsis
44a92a926c [NFC] GenericSignatureImpl: Spell conformsToProtocol & getConformsTo in terms of requirements 2020-05-14 22:51:44 +03:00
Xi Ge
3952fd5bf7 ModuleInterface: refactor compiler instance configuration to a standalone delegate class. NFC
Module interface builder used to maintain a separate compiler instance for
building Swift modules. The configuration of this compiler instance is also
useful for dependencies scanner because it needs to emit front-end compiler invocation
for building Swift modules explicitly.

This patch refactor the configuration out to a delegate class, and the
delegate class is also used by the dependency scanner.
2020-05-12 16:19:27 -07:00
Joe Groff
c5863ac0f3 SILOptimizer: Constant fold the _kvcKeyPathString of literal key paths.
Eliminate the intermediate key path object when a literal key path is passed to a function that
just wants its KVC string to pass down to an ObjC API.
2020-05-07 13:33:01 -07:00
Robert Widmann
ad003502db Merge pull request #31568 from CodaFi/this-is-a-private-party
Initial Infrastructure for "Private Intransitive" Dependencies
2020-05-05 16:13:08 -07:00
Robert Widmann
b06211eac4 Initial plumbing for private dependencies
Add a mode bit to the dependency collector that respects the frontend flag in the previous commit.

Notably, we now write over the dependency files at the end of the compiler pipeline when this flag is on so that dependency from SILGen and IRGen are properly written to disk.
2020-05-05 13:48:25 -07:00