Commit Graph

1451 Commits

Author SHA1 Message Date
Doug Gregor
0215216c00 Add "disable" counterpart to -enable-experimental-opened-existential-types 2022-02-18 11:22:57 -08:00
Doug Gregor
196a4d2e4b SwiftOnoneSupport creates different specializations with opened existentials
Implicitly disable implicit opening of existentials for SwiftOnoneSupport
because it generates different specializations.
2022-02-18 11:22:57 -08:00
Doug Gregor
1e1b3427c3 Experimental support for implicitly opening existential arguments.
When calling a generic function with an argument of existential type,
implicitly "open" the existential type into a concrete archetype, which
can then be bound to the generic type. This extends the implicit
opening that is performed when accessing a member of an existential
type from the "self" parameter to all parameters. For example:

    func unsafeFirst<C: Collection>(_ c: C) -> C.Element { c.first! }

    func g(c: any Collection) {
      unsafeFirst(c)   // currently an error
                       // with this change, succeeds and produces an 'Any'
    }

This avoids many common sources of errors of the form

    protocol 'P' as a type cannot conform to the protocol itself

which come from calling generic functions with an existential, and
allows another way "out" if one has an existention and needs to treat
it generically.

This feature is behind a frontend flag
`-enable-experimental-opened-existential-types`.
2022-02-18 11:22:56 -08:00
Karoy Lorentey
2966dce3d9 [IRGen] Allow configuring a panic function to call instead of trapping
Add a new frontend option (called `-trap-function <name>`, similar to Clang’s existing `-ftrap-function`) that specifies a function to call instead of trapping.

When the option is used, the compiler will emit a call to the specified function every time it would have otherwise emitted a trap instruction. The function must have no parameters and it must never return.

rdar://89125883
2022-02-17 23:19:08 -08:00
Holly Borla
c2594d1338 [FrontendOptions] Remove the -enable-explicit-existential-types flag. 2022-02-17 17:54:59 -08:00
Doug Gregor
27056a0ed7 Enable SE-0341 "Opaque Parameter Declarations" by default.
This proposal has been accepted, so enable it by default and update
some diagnostics to stop implying that this feature cannot be used.
2022-02-17 13:57:45 -08:00
Anthony Latsis
ceb123b5e9 AssociatedTypeInference: Add -dump-type-witness-systems flag to enable debug output 2022-02-16 00:56:08 +03:00
Slava Pestov
e2e088e082 RequirementMachine: Remove merged associated types from completion 2022-02-07 18:57:45 -05:00
Slava Pestov
0060592b85 RequirementMachine: Add concrete nesting depth check
Configured with -requirement-machine-max-concrete-nesting= frontend flag.
2022-02-07 08:20:59 -05:00
Slava Pestov
634ca55764 RequirementMachine: Rework completion limits a bit
- Rename StepLimit to MaxRuleCount, DepthLimit to MaxRuleLength
- Rename command line flags to -requirement-machine-max-rule-{count,length}=
- Check limits outside of PropertyMap::buildPropertyMap()
- Simplify the logic in RequirementMachine::computeCompletion()
2022-02-07 08:20:59 -05:00
Nuri Amari
fda0b8053d Merge pull request #40903 from NuriAmari/default-diagnostics
Enable lazy ClangImporter diagnostics by default
2022-02-04 11:42:47 -05:00
Slava Pestov
aa67c8bf8a Parametrized => parameterized 2022-02-03 13:27:24 -05:00
Robert Widmann
f5b4092a32 Merge pull request #41172 from CodaFi/special-sauce 2022-02-03 09:19:07 -08:00
Kuba (Brecka) Mracek
ee7e04822c Add a -reflection-metadata-for-debugger-only flag that emits reflection metadata but does not link them from runtime data structures (#40853) 2022-02-03 05:53:31 -08:00
Robert Widmann
25ab410896 Implement (Sugared) Bound Generic Extensions
A scoped-down version of #39307. Implement extension of bound generic types. The important bit here is in TypeCheckGeneric where we now use the underlying type of a typealias and its associated nominal type decl when we're generating substitutions for the extended type.

Put this behind a new experimental flag

-enable-experimental-bound-generic-extensions

Resolves SR-4875
Resolves rdar://17434633
2022-02-02 17:05:23 -08:00
Kuba (Brecka) Mracek
17c5d6f0de Add a flag to disable compile-time preallocated instantiation caches (for type metadata and protocol conformances) (#41148) 2022-02-02 12:06:16 -08:00
Nuri Amari
7ec861fbd9 Enable lazy ClangImporter diagnostics by default
Replace the existing `-enable-experimental-clang-importer-diagnostics`
flag with an opt-out version entitled `-disable-experimentalc-clang-importer-diagnostics`.
Enable the beviour previously hidden behind the old flag by default.
2022-02-01 18:43:49 -05:00
Pofat
96231e2d5f Support -file-compilation-dir (#40735)
This PR adds a new flag -file-compilation-dir, which does the same thing as -ffile-compilation-dir in Clang.

swiftc -g -ffile-compilation-dir=. path/to/foo.swift gives us identical debug info paths regardless of what location we compiled the file from. It's useful to debug correctly using object files built on different machines in different locations.
There's also a long-existed TODO comment.

Resolves SR-5694
2022-01-27 20:56:10 -08:00
Doug Gregor
11a027714d Add frontend flag -enable-experimental-opaque-parameters 2022-01-26 14:47:12 -08:00
Slava Pestov
327a508648 Frontend: Add -enable-parametrized-protocol-types flag 2022-01-25 22:02:59 -05:00
Evan Wilde
794d0e0b9a Merge pull request #40832 from etcwilde/ewilde/async-top-level
A first pass at concurrency in top-level code
2022-01-21 13:24:51 -08:00
Richard Wei
59ad670c0c Merge pull request #40799 from rxwei/pairwise-buildblock
[ResultBuilders] `buildBlock(combining:into:)` for pairwise combination.
2022-01-19 17:11:38 -08:00
Richard Wei
b6e679f22c [ResultBuilders] buildBlock(combining:into:) for pairwise combination.
Allow a user-defined `buildBlock(combining:into:)` to combine subexpressions in a block pairwise top to bottom. To use `buildBlock(_combining:into:)`, the user also needs to provide a unary `buildBlock(_:)` as a base case. The feature is being gated under frontend flag `-enable-experimental-pairwise-build-block`.

This will enable use cases in `RegexBuilder` in experimental declarative string processing, where we need to concatenate tuples and conditionally skip captureless regexes.  For example:

```swift
let regex = Regex {
  "a" // Regex<Substring>
  OneOrMore("b").capture() // Regex<(Substring, Substring)>
  "c" // Regex<Substring>
  Optionally("d".capture()) // Regex<(Substring, Substring?)>
} // Regex<Tuple3<Substring, Substring, Substring?>>
let result = "abc".firstMatch(of: regex)
// MatchResult<(Substring, Substring, Substring?)>
```

In this example, patterns `"a"` and `"c"` have no captures, so we need to skip them. However with the existing result builder `buildBlock()` feature that builds a block wholesale from all subexpressions, we had to generate `2^arity` overloads accounting for any occurrences of captureless regexes. There are also other complexities such as having to drop-first from the tuple to obtain the capture type. Though these features could in theory be supported via variadic generics, we feel that allowing result builders to pairwise combine subexpressions in a block is a much simpler and potentially more useful approach.

With `buildBlock(_combining:into:)`, the regex builders can be defined as the following, assuming we have variadic generics:

```swift
enum RegexBuilder {
  static func buildBlock() -> Regex<Substring>
  static func buildBlock<Match>(_ x: Regex<Match>) -> Regex<Match>
  static func buildBlock<
    ExistingWholeMatch, NewWholeMatch, ExistingCaptures..., NewCaptures...
  >(
    _combining next: Regex<(NewWholeMatch, NewCaptures...)>,
    into combined: Regex<(ExistingWholeMatch,  ExistingCaptures...)>
  ) -> Regex<Substring, ExistingCaptures..., NewCaptures...>
}
```

Before we have variadic generics, we can define overloads of `buildBlock(_combining:into:)` for up to a certain arity. These overloads will be much fewer than `2^arity`.
2022-01-18 05:14:08 -08:00
Slava Pestov
3a92d2fc53 AST: Remove legacy GSB-based GenericSignature query implementation 2022-01-12 12:33:34 -05:00
Evan Wilde
130f5caf48 Add experimental-async-top-level flag
Protect this feature behind a feature flag until it's ready for
prime-time.
2022-01-11 11:04:43 -08:00
Nuri Amari
130f2de7fd Improve ClangImporter failure diagnostics
This patch introduces new diagnostics to the ClangImporter to help
explain why certain C, Objective-C or C++ declarations fail to import
into Swift. This patch includes new diagnostics for the following entities:

- C functions
- C struct fields
- Macros
- Objective-C properties
- Objective-C methods

In particular, notes are attached to indicate when any of the above
entities fail to import as a result of refering an incomplete (only
forward declared) type.

The new diangostics are hidden behind two new flags, -enable-experimental-clang-importer-diagnostics
and -enable-experimental-eager-clang-module-diagnostics. The first flag emits diagnostics lazily,
while the second eagerly imports all declarations visible from loaded Clang modules. The first
flag is intended for day to day swiftc use, the second for module linting or debugging the importer.
2022-01-02 12:43:59 -05:00
Alex Hoppen
669e3f34a6 Merge pull request #40155 from ahoppen/pr/improve-module-search-path-lookup
[Serialization] Improve module loading performance
2021-12-20 18:09:17 +01:00
nate-chandler
e31c155f78 Merge pull request #40555 from nate-chandler/copy_propagation/rename-disabled-flags
Clarified copy-prop/lexical-lifetime flags.
2021-12-16 15:28:26 -08:00
Nate Chandler
08bd7c5c99 Replaced -disable-copy-prop with multi-var.
Replaced the -disable-copy-propagation flag with
-enable-copy-propagation=false where the latter is a new multi-var
-enable-copy-propagation= which can take one of three values:
- true
- requested-passes-only
- false
2021-12-15 21:36:53 -08:00
Nate Chandler
e881e2accd Base LexicalLifetimes dflt on SILOpts::CopyProp.
Previously, the default value for SILOptions::LexicalLifetimes was based
on a copy propagation behavior (which can then be overridden by the
flags for lexical lifetimems) only when the copy propagation was
explicitly specified.  Instead, set base the default value for this
option (SILOptions::LexicalLifetimes) on the effective copy propagation
behavior (i.e. SILOptions::CopyPropagation) regardless of whether an
explicit behavior has been specified.

Doing so will ensure that the desired behavior occurs as the default
behavior for copy-propagation changes, but for now this change is NFC.
2021-12-15 21:36:46 -08:00
Slava Pestov
c1384f36a8 SIL: Add -disable-subst-sil-function-types flag to work around type lowering bugs 2021-12-15 12:14:34 -05:00
nate-chandler
660929dff5 Merge pull request #40539 from nate-chandler/copy_propagation/rename-options
[NFC] Tweaked SILOptions fields for copy propagation.
2021-12-14 07:56:04 -08:00
Alex Hoppen
fe7878ecce [Serialization] Improve module loading performance
When looking for a Swift module on disk, we were scanning all module search paths if they contain the module we are searching for. In a setup where each module is contained in its own framework search path, this scaled quadratically with the number of modules being imported. E.g. a setup with 100 modules being imported form 100 module search paths could cause on the order of 10,000 checks of `FileSystem::exists`. While these checks are fairly fast (~10µs), they add up to ~100ms.

To improve this, perform a first scan of all module search paths and list the files they contain. From this, create a lookup map that maps filenames to the search paths they can be found in. E.g. for
```
searchPath1/
  Module1.framework

searchPath2/
  Module1.framework
  Module2.swiftmodule
```
we create the following lookup table
```
Module1.framework -> [searchPath1, searchPath2]
Module2.swiftmodule -> [searchPath2]
```
2021-12-14 12:44:13 +01:00
swift-ci
36d6a34bec Merge pull request #40535 from nate-chandler/lexical_lifetimes/allow-flags-compatible-with-move-only-to-be-passed 2021-12-13 18:02:07 -08:00
Nate Chandler
59ae5180ba [NFC] Used SILOption field for copy propagation.
Replaced the quad-state (of state which one was illegal) of two booleans
(EnableCopyPropagation and DisableCopyPropagation) with an enum.
2021-12-13 17:44:28 -08:00
Nate Chandler
868ae0e259 Error on bad copy propagation flag combo.
Diagnose passing both -enable-copy-propagation and
-disable-copy-propagation.
2021-12-13 17:44:24 -08:00
Nate Chandler
0cee5b227e Fixed flag checking for lexical borrow scopes.
Previously the following pairs were prohibited incorrectly:
- -enable-lexical-borrow-scopes=true, -enable-experimental-move-only
- -enable-lexical-lifetimes=true, -enable-experimental-move-only
and the following pairs were allowed incorrectly:
- -enable-lexical-borrow-scopes=false, -enable-experimental-move-only
- -enable-lexical-lifetimes=false, -enable-experimental-move-only
Here, that's fixed.  The first two pairs are allowed and the second two
pairs prohibited.
2021-12-13 14:55:01 -08:00
nate-chandler
68f5d8d7ca Merge pull request #40519 from nate-chandler/lexical_lifetimes/disable-with-copy-propagation
Disable lexical-lifetimes with copy-propagation.
2021-12-12 20:28:49 -08:00
Ellie Shin
2ab97edd6a Merge pull request #40494 from apple/es-complete
[Module Aliasing] Add module aliasing option to swift-ide-test
Add module aliasing handling in code complete
Resolves rdar://86294338
2021-12-10 22:36:50 -08:00
Nate Chandler
08a3d3c367 Disable lexical-lifetimes with copy-propagation.
If -disable-copy-propagation is passed, just emit lexical diagnostic
markers but do not enable lexical lifetimes.
2021-12-10 18:36:35 -08:00
Nate Chandler
1464c1b1ff [NFC] Renamed LexicalLifetimesOption cases.
The cases' new names more accurately reflect what behavior occurs when
SILOptions::LexicalLifetimes is assigned that case.
2021-12-10 18:36:28 -08:00
Ellie Shin
4ad3a551b4 Exit early args are invalid
Add batch-code-compelte test
2021-12-10 17:14:18 -08:00
Ellie Shin
b5b285e54e Reuse compute module aliases function
Update tests
2021-12-10 16:06:18 -08:00
Holly Borla
69be7b17fc Merge pull request #40282 from hborla/existential-any
[SE-0335] Introduce existential `any`
2021-12-10 08:56:03 -08:00
Ellie Shin
1e5160b809 Update comments 2021-12-10 00:48:26 -08:00
Ellie Shin
93132b8ce3 Add module aliasing option to swift-ide-test
Add module aliasing handling in code complete
Resolves rdar://86294338
2021-12-09 15:36:55 -08:00
Slava Pestov
75ade66b21 Merge pull request #40459 from slavapestov/rqm-disabled-merged-types
RequirementMachine: Add flags to enable and disable merged associated types
2021-12-09 16:45:56 -05:00
Holly Borla
7cdda6dc80 [FrontendOptions] Add a frontend flag -enable-explicit-existential-types
to enable the 'any' keyword.
2021-12-09 09:26:12 -08:00
Nate Chandler
ea42e2f334 Enabling copy propagation enables lexical lifetimes.
The effect of passing -enable-copy-propagation is both to enable the
CopyPropagation pass to shorten object lifetimes and also to enable
lexical lifetimes to ensure that object lifetimes aren't shortened while
a variable is still in scope and used.

Add a new flag, -enable-lexical-borrow-scopes=true to override
-enable-copy-propagation's effect (setting it to ::ExperimentalLate) on
SILOptions::LexicalLifetimes that sets it to ::Early even in the face of
-enable-copy-propagation.  The old flag -disable-lexical-lifetimes is
renamed to -enable-lexical-borrow-scopes=false but continues to set that
option to ::Off even when -enable-copy-propagation is passed.
2021-12-08 19:13:21 -08:00
Slava Pestov
c1339240cd RequirementMachine: Add flags to enable and disable merged associated types
On by default, no change from current behavior. I'm going to try turning
this off (and hopefully ripping it out entirely) once I fix a few bugs.
2021-12-08 21:32:42 -05:00