Commit Graph

801 Commits

Author SHA1 Message Date
Allan Shortlidge
3a02629be4 Frontend: Make lazy typechecking a TC opt instead of a frontend action. 2023-08-28 08:28:56 -07:00
Zak Kent
d1c5b4a7ad [Parse] [Sema] Ensure lazy immediate mode only enabled when requested 2023-08-14 13:28:22 -07:00
Zak Kent
791cdea545 [Immediate] Lazy Parsing
Implement lazy parsing, allowing functions to be
parsed only when they are executed.
2023-08-14 13:28:22 -07:00
Artem Chikin
6ef79c4ba0 [Dependency Scanning] Specify Explicit Module output path to the scanner explicitly
Instead of the code querying the compiler's built-in Clang instance, refactor the
dependency scanner to explicitly keep track of module output path. It is still
set according to '-module-cache-path' as it has been prior to this change, but
now the scanner can use a different module cache for scanning PCMs, as specified
with '-clang-scanner-module-cache-path', without affecting module output path.

Resolves rdar://113222853
2023-08-10 11:11:05 -07:00
Artem Chikin
6d92157298 [Explicit Module Builds] Write '-clang-target' to serialized debugging options
Otherwise LLDB's ClangImporter instance will be instantiated against a
mismatching triple.
2023-08-08 10:12:12 -07:00
Steven Wu
b9fef33891 Merge pull request #67263 from cachemeifyoucan/eng/PR-explicit-module-interface-check
[ExplicitModule] Allow typecheck-module-from-interface using explicit module
2023-07-25 16:10:48 -07:00
Ben Barham
a5607cc82e Merge pull request #67352 from bnbarham/disable-new-validation-when-skipping
Skip new parser validation when skipping function bodies
2023-07-22 17:30:07 -07:00
Ben Barham
392f98cb65 Skip new parser validation when skipping function bodies
This would otherwise result in false positives, since if the old parser
skipping a body with errors would cause a verification failure.

Don't perform round trip validation either, since we'll presumbly still
hit parsing the full file when not skipping bodies - there's no point
running it twice.

Resolves rdar://111032175.
2023-07-21 15:53:20 -07:00
Steven Wu
43add116d2 [ExplicitModule] Allow typecheck-module-from-interface using explicit module
Allow `-typecheck-module-from-interface` using explicit module instead
of building implicit module.

This setups swift-frontend to accept explicit module build arguments and
loading explicit module during verifying. SwiftDriver needs to setup
correct arguments including the output path for swift module to fully
enable explicit module interface check.
2023-07-19 10:47:41 -07:00
Nate Chandler
8959d4ccb6 [Frontend] Added option to bypass resilience.
This functionality was added awhile back to support the debugger.
Provide a flag for use by other cliients.
2023-07-18 11:57:02 -07:00
Evan Wilde
250082df25 [NFC] Reformat all the LLVMs
Reformatting everything now that we have `llvm` namespaces. I've
separated this from the main commit to help manage merge-conflicts and
for making it a bit easier to read the mega-patch.
2023-06-27 09:03:52 -07:00
Evan Wilde
f3ff561c6f [NFC] add llvm namespace to Optional and None
This is phase-1 of switching from llvm::Optional to std::optional in the
next rebranch. llvm::Optional was removed from upstream LLVM, so we need
to migrate off rather soon. On Darwin, std::optional, and llvm::Optional
have the same layout, so we don't need to be as concerned about ABI
beyond the name mangling. `llvm::Optional` is only returned from one
function in
```
getStandardTypeSubst(StringRef TypeName,
                     bool allowConcurrencyManglings);
```
It's the return value, so it should not impact the mangling of the
function, and the layout is the same as `std::optional`, so it should be
mostly okay. This function doesn't appear to have users, and the ABI was
already broken 2 years ago for concurrency and no one seemed to notice
so this should be "okay".

I'm doing the migration incrementally so that folks working on main can
cherry-pick back to the release/5.9 branch. Once 5.9 is done and locked
away, then we can go through and finish the replacement. Since `None`
and `Optional` show up in contexts where they are not `llvm::None` and
`llvm::Optional`, I'm preparing the work now by going through and
removing the namespace unwrapping and making the `llvm` namespace
explicit. This should make it fairly mechanical to go through and
replace llvm::Optional with std::optional, and llvm::None with
std::nullopt. It's also a change that can be brought onto the
release/5.9 with minimal impact. This should be an NFC change.
2023-06-27 09:03:52 -07:00
Steven Wu
b78b569450 [CAS] Consolidate compile cache flags
Rename `-enable-cas` to `-compile-cache-job` to align with clang option
names and promote that to a new driver only flag.

Few other additions to driver flag for caching behaviors:
* `-compile-cache-remarks`: now cache hit/miss remarks are guarded behind
  this flag
* `-compile-cache-skip`: skip replaying from the cache. Useful as a
  debugging tool to do the compilation using CAS inputs even the output
  is a hit from the cache.
2023-06-26 10:34:27 -07:00
Steven Wu
2b7d38dc16 [CAS] Improve swift cas options
Using the same CASOption from clang to communicate CAS configurations so
it is easier to exchange CAS configuration between them.
2023-06-26 10:34:26 -07:00
Rintaro Ishizaki
706985df82 [Macros] Update plugin search options serialization
Previously plugin search options were serialized for each option kind.
Instead serialize them in the order specified.
2023-06-15 17:32:59 -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
Steven Wu
b1f99b8e93 [CAS] swift dependency scanning using CAS for compiler caching (#66366)
Teach swift dependency scanner to use CAS to capture the full dependencies for a build and construct build commands with immutable inputs from CAS.

This allows swift compilation caching using CAS.
2023-06-12 10:55:53 -07:00
Alex Lorenz
ba8d4d7801 [cxx-interop] compilations that do not enable C++ interoperability should not be able to import modules that do enable C++ interoperability by default
A supplemental hidden frontend option allows advanced users to opt-out of this requirement.

Fixes https://github.com/apple/swift/issues/65833
Fixes https://github.com/apple/swift/issues/65832
2023-06-09 15:38:16 -07:00
Alexis Laferrière
7abb4c38e2 [Serialization] Fix serializing CompilerPluginExecutablePaths values
rdar://110068048
2023-06-02 14:18:03 -07:00
Hamish Knight
58d6694783 Requestify ExportedSourceFile parsing
Avoid parsing the syntax tree up-front, and instead
only parse it when required, which happens when either:

1. ASTGen parsing is enabled (currently disabled
   by default)
2. Round trip checking is enabled for a primary
   file (enabled by default in a debug build,
   except when dep scanning or doing an IDE
   operation)
3. We need to evaluate a macro in that file

This change therefore means that we now no longer
need to parse the syntax tree for secondary files
by default unless we specifically need to evaluate
a macro in them (e.g if we need to lookup a member
on a decl with an attached macro). And the same
for primaries in release builds.

rdar://109283847
2023-05-22 14:55:19 +01:00
Steven Wu
add598762c Merge pull request #65985 from cachemeifyoucan/eng/PR-109411245
[ObjcHeader] Fix objc header generation when pch is explicited passed
2023-05-18 10:30:44 -07:00
Steven Wu
16e4cfae76 [ObjcHeader] Fix objc header generation when pch is explicited passed
When swift-frontend is explicitly passed the pch file as bridging header
on command-line through `-import-objc-header`, it needs to print the
original source file name if needed to the generated objc header.

rdar://109411245
2023-05-17 14:15:55 -07:00
Alex Lorenz
b17ade9391 [cxx-interop] implicitly imported CxxShim module should not force client modules to enable C++ interoperability
Fixes https://github.com/apple/swift/issues/65831
2023-05-15 10:10:56 -07:00
Steven Wu
e5c3b3f1d9 Merge pull request #65423 from cachemeifyoucan/eng/PR-cached-diagnostics-processor
[CAS] Add caching diagnostic processor
2023-05-09 12:25:57 -07:00
Alexis Laferrière
421042ec7c Merge pull request #65370 from xymus/serial-macro-paths
[Macros] Serialize plugin search paths for LLDB use
2023-05-02 09:20:16 -07:00
Rintaro Ishizaki
3ef6087d32 [Macros] Serialize plugin search paths for LLDB use
rdar://107030743
2023-05-01 14:04:39 -07:00
Ellie Shin
e9f847d414 Merge pull request #65336 from apple/es-private
Print package-name in .private.swiftinterface only for better abstraction
2023-04-27 20:07:12 -07:00
Steven Wu
d3891a86ba [CAS] Add caching diagnostic processor
Add a CachedDiagnosticsProcessor that is a DiagConsumer can capture all
the diagnostics during a compilation, serialized them into CAS with a
format that can be replayed without re-compiling.
2023-04-27 13:36:49 -07:00
Rintaro Ishizaki
a551c01d6a [Macros] Track plugin dependencies
* Factor out ASTContext plugin loading to newly introduced 'PluginLoader'
* Insert 'DependencyTracker' to 'PluginLoader'
* Add dependencies right before loading the plugins

rdar://104938481
2023-04-25 10:50:32 -07:00
Steven Wu
8cbf83f903 Mirror outputs into CAS using CASOutputBackend
When `-enable-cas` option is used, mirror the output into CAS so it can
be fetched from CAS with the cache key in the future.
2023-04-24 13:57:47 -07:00
Steven Wu
c7d66b8845 Teach swift to compute cache key for compiler outputs
Teach swift how to serialize its input into CAS to create a cache key
for compiler outputs. To compute the cache key for the output, it first
needs to compute a base-key for the compiler invocation. The base key is
computed from: swift compiler version and the command-line arguments for
the invocation.

Each compiler output from swift will gets its own key. The key for the
output is computed from: the base key for the compiler invocation + the
primary input for the output + the output type.
2023-04-24 13:55:38 -07:00
Ellie Shin
b081404daa Print package-name in .private.swiftinterface only for better abstraction
Resolves rdar://107638447
2023-04-20 17:45:22 -07:00
Steven Wu
e2c494179d [CAS] Integrate CAS into swift compiler
Teach swift compiler about CAS to allow compiler caching in the future.
1) Add flags to initiate CAS inside swift-frontend
2) Teach swift to compile using a CAS file system.
2023-04-17 13:18:09 -07:00
Steven Wu
09b8af86fb Virtualize swift compiler outputs (#63206)
Using a virutal output backend to capture all the outputs from
swift-frontend invocation. This allows redirecting and/or mirroring
compiler outputs to multiple location using different OutputBackend.

As an example usage for the virtual outputs, teach swift compiler to
check its output determinism by running the compiler invocation
twice and compare the hash of all its outputs.

Virtual output will be used to enable caching in the future.
2023-04-05 23:34:37 +08:00
Artem Chikin
cc34ba00e2 [Dependency Scanning] Disable Swift Parser ASTGen during dependency scan
On both input moduel source-files and interface files.
This currently yields dramatic scanning performance improvements at no cost - we do not require an AST during scan.
2023-03-31 15:49:54 -07:00
Matt Jacobson
31e26a92ec frontend: enable shouldImportConcurrencyByDefault() on FreeBSD
Match OpenBSD and honor the SWIFT_IMPLICIT_CONCURRENCY_IMPORT build setting.
2023-03-15 04:28:28 -04:00
Nuri Amari
86c5698780 Implement importing of forward declared objc protocols and interfaces
This modifies the ClangImporter to introduce an opaque placeholder
representation for forward declared Objective-C interfaces and
protocols when imported into Swift.

In the compiler, the new functionality is hidden behind a frontend
flag -enable-import-objc-forward-declarations, and is on by default
for language mode >6.

The feature is disabled entirely in LLDB expression evaluation / Swift
REPL, regardless of language version.
2023-03-07 16:00:16 -08:00
Alastair Houghton
44783e72c6 [Frontend] Add support for implicit import of _Backtracing
Once the API has gone through Swift Evolution, we will want to implicitly
import the _Backtracing module.  Add code to do that, but set it to off
by default for now.

rdar://105394140
2023-03-04 08:00:06 +00:00
Alexis Laferrière
cceafcf4ee [Frontend] Move the package name option from frontend to LangOptions 2023-03-03 11:42:59 -08:00
Ben Barham
6269643b4d [Index] Prevent re-indexing system modules repeatedly
If a module was first read using the adjacent swiftmodule and then
reloaded using the swiftinterface, we would do an up to date check on
the adjacent module but write out the unit using the swiftinterface.
This would cause the same modules to be indexed repeatedly for the first
invocation using a new SDK. On the next run we would instead raad the
swiftmodule from the cache and thus the out of date check would match
up.

The impact of this varies depending on the size of the module graph in
the initial compilation and the number of jobs started at the same time.
Each SDK dependency is re-indexed *and* reloaded, which is a drain on
both CPU and memory. Thus, if many jobs are initially started and
they're all going down this path, it can cause the system to run out of
memory very quickly.

Resolves rdar://103119964.
2023-02-09 11:49:13 -08:00
Artem Chikin
c1599fede4 Add -swift-module-file frontend flag for explicit Swift module dependencies 2023-02-07 11:29:09 -07:00
Richard Wei
4480d89536 [Macros] Emit plugin dependencies to loaded module trace. (#63367)
Emit plugins loaded with `-load-plugin-library` to loaded module trace.

Resolves rdar://102212316.
2023-02-03 09:16:14 +08:00
Alexis Laferrière
39fb1c5f55 [ModuleInterface] Intro export-as for Swift modules
Introduce a new flag `-export-as` to specify a name used to identify the
target module in swiftinterfaces. This provides an analoguous feature
for Swift module as Clang's `export_as` feature.

In practice it should be used when a lower level module `MyKitCore` is
desired to be shown publicly as a downstream module `MyKit`. This should
be used in conjunction with `@_exported import MyKitCore` from `MyKit`
that allows clients to refer to all services as being part of `MyKit`,
while the new `-export-as MyKit` from `MyKitCore` will ensure that the
clients swiftinterfaces also use the `MyKit` name for all services.

In the current implementation, the export-as name is used in the
module's clients and not in the declarer's swiftinterface (e.g.
`MyKitCore`'s swiftinterface still uses the `MyKitCore` module name).
This way the module swiftinterface can be verified. In the future, we
may want a similar behavior for other modules in between `MyKitCore` and
`MyKit` as verifying a swiftinterface referencing `MyKit` without it
being imported would fail.

rdar://103888618
2023-01-26 14:27:31 -08:00
Tony Allevato
dda1cda4df Allow Clang modules to be listed in the explicit module map.
This lets users of `-explicit-swift-module-map-file` use a single mapping
for all module dependencies, regardless of whether they're Swift or Clang
modules, instead of manually splitting them among this file and command
line flags.
2023-01-25 16:38:34 -08:00
Artem Chikin
6fd013aa67 Add an implicit dependency on the '_SwiftConcurrencyShims' library
Whenever concurrency mode is enabled in compilation. This avoids instead ad-hoc requests to load this module in SILGen.
2023-01-13 11:20:35 -08:00
Alexis Laferrière
d1343c86fb [Frontend] Intro flags to control deserialization safety
Deserialization safety remains off by default at the moment.
2023-01-06 12:02:47 -08:00
Ellie Shin
72ee150982 Add -package-name flag
De/serialize package name in module binary
Resoles rdar://103531218, rdar://103531208
2022-12-19 14:33:44 -08:00
Alex Hoppen
fe2ae72ad2 [IDE] Rename CodeCompletion to IDEInspection in cases where the code path no longer exclusively applies to code completion
The code completio infrastructure is also being used for cursor info now, so it should no longer be called code completion.

rdar://103251187
2022-12-13 11:41:05 +01:00
Artem Chikin
990b95e9d8 [Dependency Scanning] Key into a global (shared) dependency scanning cache via context hash
Introduces a concept of a dependency scanning action context hash, which is used to select an instance of a global dependency scanning cache which gets re-used across dependency scanning actions.
2022-12-06 08:26:28 -08:00
Nate Chandler
e9e93c1590 [Opaque Values] Address-lower TypeLowerings.
When opaque values are enabled, TypeConverter associates to an
address-only type an OpaqueValueTypeLowering.  That lowering stores a
single lowered SIL type, and its value category is "object".  So long as
the module has not yet been address-lowered, that type has the
appropriate value category.  After the module has been address-lowered,
however, that type has the wrong value category: the type is
address-only, and in an address-lowered module, its lowered type's value
category must be "address".

Code that obtains a lowered type expects the value category to reflect
the state of the module.  So somewhere, it's necessary to fixup that
single lowered type's value category.

One option would be to update all code that uses lowered types.  That
would require many changes across the codebase and all new code that
used lowered types would need to account for this.

Another option would be to update some popular conveniences that call
through to TypeConverter, for example those on SILFunction, and ensure
that all code used those conveniences.  Even if this were done
completely, it would be easy enough for new code to be added which
didn't use the conveniences.

A third option would be to update TypeLowering::getLoweredType to take
in the context necessary to determine whether the stored SILType should
be fixed up.  That would require each callsite to be changed and
potentially to carry around more context than it already had in order to
be able to pass it along.

A fourth option would be to make TypeConverter aware of the
address-loweredness, and to update its state at the end of
AddressLowering.

Updating TypeConverter's state would entail updating all cached
OpaqueValueTypeLowering instances at the end of the AddressLowering
pass.  Additionally, when TypeConverter produces new
OpaqueValueTypeLowerings, they would need to have the "address" value
category from creation.

Of all the options, the last is least invasive and least error-prone, so
it is taken here.
2022-12-01 14:18:17 -08:00