Commit Graph

1745 Commits

Author SHA1 Message Date
Anders Bertelrud
a363603c14 [Playgrounds] Add a new -playground-option flag to control which transforms to apply (#69355)
Generalize the existing `-playground-high-performance` flag into a set of options that control various aspects of the "playground transformation" in Sema.

This commit adds the first two of those controllable parts of the transform, matching what the existing flag already controls (scope entry/exit and function arguments), but in an extensible way. The intent is for this to be a scalable way to control a larger set of upcoming options.

So instead of a single flag, we represent the playground transform options as a set of well-defined choices, with a new `-playground-option` flag to individually enable or disable those options (when prefixed with "No", the corresponding option is instead disabled). Enabling an already-enabled option or disabling an already-disabled option is a no-op.

For compatibility, the existing `-playground-high-performance` flag causes "expensive" transforms to be disabled, as before. We can also leave it as a useful shorthand to include or exclude new options even in the future, based on their cost. There is a comment on the old function indicating that new code should use the more general form, but it remains for clients like LLDB until they can switch over.

The machinery for implementing the playground options is similar to how `Features.def` works, with a new `PlaygroundOptions.def` that defines the supported playground transform options.  Each playground definition specifies the name and description, as well as whether the option is enabled by default, and whether it's also enabled in the "high performance" case.

Adding a new option in the future only requires adding it to `PlaygroundOptions.def`, deciding whether it should be on or off by default, deciding whether it should also be on or off in `-playground-high-performance` mode, and checking for its presence from the appropriate places in `PlaygroundTransform.cpp`.

Note that this is intended to control the types of user-visible results that the invoker of the compiler wants, from an externally detectable standpoint. Other flags, such as whether or not to use the extended form of the callbacks, remain as experimental features, since those deal with the mechanics and not the desired observed behavior.

rdar://109911673
2023-11-15 13:02:34 -08:00
Ellie Shin
e8d43434db Merge pull request #69733 from apple/es-pkg-intf
Introduce a package interface
2023-11-15 03:53:49 -08:00
Doug Gregor
b53026d8d4 [Macros] Macro-metaprogram macro roles
Introduce X-macros for the various macro roles, and use them to
macro-metaprogram a lot of boilerplate involved with introducing new
macro roles.
2023-11-13 22:37:54 -08:00
Ellie Shin
aba3b6c24e Introduce a package interface.
It has an extension .package.swiftinterface and contains package decls
as well as SPIs and public/inlinable decls. When a module is loaded
from interface, it now looks up the package-name in the interface
and checks if the importer is in the same package. If so, it uses
that package interface found to load the module. If not, uses the existing
logic to load modules.

Resolves rdar://104617854
2023-11-08 14:56:20 -08:00
Hamish Knight
e2b8d98edc [Basic] Abstract BridgedOStream
Define using the wrapper macro.
2023-10-31 11:06:41 +00:00
Hamish Knight
2a6d93f505 [Basic] Improve API of BridgedArrayRef + BridgedData
Remove the default constructor footgun present with
the struct implementations, and sprinkle some
`SWIFT_NAME` and bridging utilities to make them
nicer to work with.
2023-10-30 23:49:59 +00:00
Hamish Knight
e0f57f84f0 [AST] Cleanup ASTBridging + BasicBridging
Sort AST node bridging functions into Expr, Stmt,
Decl, and TypeRepr, and tweak the headers to use
`MARK`.
2023-10-30 23:49:59 +00:00
Hamish Knight
6afde8a6d2 Remove CBasicBridging and CASTBridging
Merge with BasicBridging and ASTBridging
respectively. The changes here should be pretty
uncontroversial, I tried to keep it to just moving
code about.
2023-10-30 23:49:56 +00:00
Hamish Knight
ce23252a3f [Basic] Improve some bridging APIs
Improve APIs for BridgedStringRef,
BridgedOwnedString, and BridgedSourceLoc.
2023-10-30 23:49:53 +00:00
Evan Wilde
312bd47f4c Merge remote-tracking branch 'main' into 'rebranch' 2023-10-16 23:00:12 -07:00
Rintaro Ishizaki
37a637447f Merge pull request #69027 from rintaro/macro-resolveerror-rdar115571427
[Macros] Improve macro plugin loading macro definition resolution diagnostics
2023-10-16 17:35:48 -07:00
Steven Wu
6c3097657a [Caching] Change swift cache key computation
Update swift cache key computation mechanism from one cache key per
output, to one cache key per primary input file (for all outputs that
associated with that input).

The new schema allows fewer cache lookups while still preserving most of
the flexibility for batch mode and incremental mode.
2023-10-13 09:15:22 -07:00
Rintaro Ishizaki
bdd4c005e5 [Macros] Diagnose how ExternalMacroDefinition request was failed
Return the failure reason as the result.
2023-10-12 16:08:48 -07:00
swift-ci
bb57981112 Merge remote-tracking branch 'origin/main' into rebranch 2023-10-09 22:55:17 -07:00
Evan Wilde
24d0db249b Merge remote-tracking branch 'main' into 'rebranch'
Conflicts:
  CMakeLists.txt
    Take new BRIDGING_MODE

  SwiftCompilerSources/Sources/SIL/GlobalVariable.swift
    Take new
2023-10-09 17:21:23 -07:00
Alejandro Alonso
234410f2fe Change to _hasAtomicBitWidth 2023-10-09 14:05:45 -07:00
Erik Eckstein
2dbd6cc56b SwiftCompilerSources: rework bridging
Introduce two modes of bridging:
* inline mode: this is basically how it worked so far. Using full C++ interop which allows bridging functions to be inlined.
* pure mode: bridging functions are not inlined but compiled in a cpp file. This allows to reduce the C++ interop requirements to a minimum. No std/llvm/swift headers are imported.

This change requires a major refactoring of bridging sources. The implementation of bridging functions go to two separate files: SILBridgingImpl.h and OptimizerBridgingImpl.h.
Depending on the mode, those files are either included in the corresponding header files (inline mode), or included in the c++ file (pure mode).

The mode can be selected with the BRIDGING_MODE cmake variable. By default it is set to the inline mode (= existing behavior). The pure mode is only selected in certain configurations to work around C++ interop issues:
* In debug builds, to workaround a problem with LLDB's `po` command (rdar://115770255).
* On windows to workaround a build problem.
2023-10-09 09:52:52 +02:00
swift-ci
09ebb5b740 Merge remote-tracking branch 'origin/main' into rebranch 2023-10-05 21:15:35 -07:00
Doug Gregor
0814849f2c Merge pull request #68982 from DougGregor/faster-find-buffer-containing-loc-docfix 2023-10-05 21:01:10 -07:00
swift-ci
4a749b3e3d Merge remote-tracking branch 'origin/main' into rebranch 2023-10-05 16:59:34 -07:00
Allan Shortlidge
e01f23496a Merge pull request #68994 from tshortli/api-extract-supplementary-output
TBDGen: Introduce option to emit API descriptor as supplementary output
2023-10-05 16:45:51 -07:00
swift-ci
e767ad1bec Merge remote-tracking branch 'origin/main' into rebranch 2023-10-05 14:33:21 -07:00
Rintaro Ishizaki
37f5b43dd4 Merge pull request #68710 from rintaro/macros-darwin-swift
[ASTGen] Use standard headers in bridging interface
2023-10-05 14:27:14 -07:00
Allan Shortlidge
e1f2e25ed5 Frontend: Introduce -emit-api-descriptor flag.
An "API descriptor" file is JSON describing the externally accessible symbols
of a module and metadata associated with those symbols like availability and
SPI status. This output was previously only generated by the
`swift-api-extract` alias of `swift-frontend`, which is desgined to take an
already built module as input. Post-processing a built module to extract this
information is inefficient because the module and the module's dependencies
need to be deserialized in order to visit the entire AST. We can generate this
output more efficiently as a supplementary output of the -emit-module job that
originally produced the module (since the AST is already available in-memory).
The -emit-api-descriptor flag can be used to request this output.

This change lays the groundwork by introducing frontend flags. Follow up
changes are needed to make API descriptor emission during -emit-module
functional.

Part of rdar://110916764.
2023-10-05 11:40:53 -07:00
swift-ci
bfc9e47753 Merge remote-tracking branch 'origin/main' into rebranch 2023-10-05 07:16:16 -07:00
Doug Gregor
2e289f0b12 Merge pull request #68971 from DougGregor/faster-find-buffer-containing-loc
[Source manager] Improve the performance of findBufferContainingLocInternal
2023-10-05 07:02:33 -07:00
Doug Gregor
e9e958b09e Finish thought in a comment 2023-10-05 05:13:38 -07:00
Rintaro Ishizaki
7ac5d65479 [ASTGen] Use standard headers
For whatever reason, using standard headers in modules imported from
Swift code (i.e. depending on Darwin overlay) is no longer an issue.

rdar://115438609
2023-10-04 15:12:17 -07:00
Doug Gregor
f36d2d3978 [Source manager] Improve the performance of findBufferContainingLocInternal()
This function was performing a linear scan through the set of known
buffers to find the buffer containing a given source location. This
linear scan can show up in hot loops, and the number of buffers in a
program is increasing due to macros, so this has become a performance
problem.

Replace the linear scan with a logarithmic lookup into a sorted vector
of the buffer IDs, with a one-element most-recently-used cache so that
repeated lookups in the same buffer require constant time.

This mirrors what we already do with source files in a module.
Unfortunately, we cannot reuse that code because there is no link from
buffers to source files. We should look to consolidate this in the
future.

Fixes rdar://116184248.
2023-10-04 14:37:34 -07:00
swift-ci
556272e95f Merge remote-tracking branch 'origin/main' into rebranch 2023-10-02 21:54:26 -07:00
swift-ci
c1df6db3f0 Merge pull request #68881 from apple/prefix-smashing
Diagnose possible enum common-prefix mistakes
2023-10-02 21:48:14 -07:00
Becca Royal-Gordon
78127ce5ee Diagnose possible enum common-prefix mistakes
Clang Importer strips prefixes from enum and option set case names. The logic to do this computes a common prefix from the type name and all non-deprecated case names (to oversimplify), which means that adding, removing, or changing one case can change the prefix that is removed from *all* cases. This typically causes the prefix to become shorter, meaning that additional words are prepended to each existing case name.

Existing diagnostics make it look like the case has disappeared, when in fact it still exists under a different name. A little more information may help developers to figure out what happened.

Add a tailored diagnostic for this scenario which kicks in when (a) a missing member is diagnosed, (b) the base is an imported enum or option set’s metatype, and (c) an enum case or static property exists which has the name we attempted to look up as a suffix.

Fixes rdar://116251319.
2023-10-02 16:50:54 -07:00
swift-ci
1b2f485222 Merge remote-tracking branch 'origin/main' into rebranch 2023-09-30 12:53:10 -07:00
Alejandro Alonso
f58aa07d41 Merge pull request #68536 from Azoy/maxAtomicInlineWidth
[AST] Add #if _atomicBitWidth as a valid compilation conditional
2023-09-30 12:34:17 -07:00
Alejandro Alonso
a3f4361280 Add _atomicBitWidth compilation conditional
fix warning
2023-09-29 14:43:34 -07:00
swift-ci
17a5d30d54 Merge remote-tracking branch 'origin/main' into rebranch 2023-09-15 16:14:15 -07:00
Hamish Knight
febb019a86 Avoid storing a SourceManager on JSONFixitWriter
Switch to storing the necessary edit information
instead.
2023-09-15 18:27:49 +01:00
swift-ci
5fefff41f6 Merge remote-tracking branch 'origin/main' into rebranch 2023-09-11 07:14:12 -07:00
Pavel Yaskevich
bbe531c4ac [Basic] MaxMallocUsage statistic should cover all zones
Also for some reason passing `malloc_default_zone()` no longer
works, statistics return `0` use.
2023-09-08 16:25:36 -07:00
swift-ci
56aa4e6933 Merge remote-tracking branch 'origin/main' into rebranch 2023-09-04 08:14:39 -07:00
Saleem Abdulrasool
219f6eadeb Update Program.cpp 2023-09-03 18:53:24 -07:00
Saleem Abdulrasool
06ad3a75b6 AST,Basic: update support for process execution on Windows
Implement process launching on Windows to support macros.  Prefer to use
the LLVM types wherever possible.  The pipes are converted into file
descriptors as the types are internal to the process.  This allows us to
have similar paths on both sides and avoid having to drag in `Windows.h`
for the definition of `HANDLE`.  This is the core missing functionality
for Windows to support macros.
2023-09-03 10:45:03 -07:00
swift-ci
6da5bed7fb Merge remote-tracking branch 'origin/main' into rebranch 2023-08-05 18:36:02 -07:00
Tony Allevato
300a952ede Replace u8 string literal prefixes with SWIFT_UTF8 macro.
In C++20, `u8` literals create values of type `char8_t` instead of
`char`, and these can't be implicitly converted. This macro
mitigates the difference and allows the same code to compile under
C++14/17 modes and C++20, preserving the `char` type while ensuring
that the text is interpreted as UTF-8.
2023-08-04 16:41:36 -04:00
swift-ci
1969199a8e Merge remote-tracking branch 'origin/main' into rebranch 2023-07-26 23:13:08 -07:00
Alex Lorenz
d7b62b3c40 [cxx-interop] add 'upcoming-swift' compat version
This version will be used to gate new source breaking changes for C++ interoperability
2023-07-25 16:19:58 -07:00
Evan Wilde
f3cd71d2d1 [NFC] updating StringRef API
`StringRef::endswith_insensitive` and
`StringRef::startswith_insensitive` is deprecated and being replaced
with `StringRef::ends_with_insensitive` and
`StringRef::starts_with_insensitive` respectively.
2023-07-25 12:28:28 -07:00
Evan Wilde
2c216e08eb Add new OS platforms
LLVM added UEFI and LiteOS platforms. We don't currently support them,
so we should crash on the unsupported OS for now to avoid accidents
later.
2023-07-17 10:55:57 -07:00
Evan Wilde
26a974e772 [NFC] Headers headers headers!
Including headers that were being transitively included from LLVM
before. Also pointing them at the new locations for some of them.
2023-07-17 10:55:55 -07:00
Evan Wilde
4b5d25935d [NFC] Adding a few missing llvm namespaces
I missed a few LLVM optional and llvm None usages. Fixing those now.
2023-07-17 10:53:42 -07:00