Commit Graph

2062 Commits

Author SHA1 Message Date
Slava Pestov
c2f1193ae3 Merge pull request #67952 from slavapestov/tuple-conformance-tbd-etc
A pile of mostly unrelated one-liners
2023-08-18 15:31:26 -04:00
Slava Pestov
eadffd3c6c AST: Don't look at PatternBindingDecl in usesBuiltinType()
Type-checking patterns is not fully requestified, so the
ASTPrinter should not assume this has been filled in.

It appears sufficient to just visit the associated VarDecl,
as we do already.
2023-08-18 12:12:50 -04:00
zachary0kent
802e63a778 Merge pull request #67973 from zachary0kent/lazy-immediate-globals
[Immediate] JIT'ing Globals
2023-08-18 08:53:18 -07:00
Alexis Laferrière
be3492152e Merge pull request #67970 from xymus/spi-only-printer
[AST] Update source module correction logic to support @_spiOnly imports
2023-08-17 09:05:39 -07:00
zachary0kent
25f078adb5 Merge branch 'main' into lazy-immediate 2023-08-16 19:45:27 -07:00
Alexis Laferrière
011222da16 [AST] Fix source module correction logic to support @_spiOnly imports
This logic may override the module considered as the source of a decl to
ensure that only visible modules are printed in the swiftinterface. This
change updates it to consider @_spiOnly imported modules from the local
module as visible when printing the private swiftinterface only.

rdar://103325332
2023-08-16 16:40:57 -07:00
Pavel Yaskevich
b21e8426a0 [AST] NFC: Remove @runtimeMetadata related code 2023-08-15 12:16:40 -07:00
Zak Kent
289b812a14 [Immediate] Add frontend option for lazy compilation 2023-08-14 13:28:22 -07:00
Allan Shortlidge
7c0a9cc92e Merge pull request #67636 from tshortli/enum-unavailable-element-derived-equatable-hashable
Sema: Fix unavailable enum element cases in derived hashable/equatable impls
2023-08-01 16:22:28 -07:00
Pavel Yaskevich
bb135181bd Merge pull request #67625 from xedin/enable-init-accessors-feature
[Frontend/NFC] SE-0400: Enable `InitAccessors` feature by default
2023-08-01 15:54:43 -07:00
Allan Shortlidge
8079d9cf45 AST: Fix whitespace for switch statements under -print-ast.
No test changes because the tests for `-print-ast` don't match whitespace.
2023-07-31 21:27:46 -07:00
Alex Lorenz
0eed1a944c [cxx-interop] correctly add and lookup enumerators added to enums that correspond to namespaces
Fixes https://github.com/apple/swift/issues/67604
2023-07-31 18:57:50 -07:00
Pavel Yaskevich
2a0651e8b0 [Frontend/NFC] SE-0400: Enable InitAccessors feature by default 2023-07-31 13:18:59 -07:00
Pavel Yaskevich
a22bd2741e Merge pull request #67593 from xedin/textual-sil-assign_or_init
[SIL] InitAccessors: Support `assign_or_init` in textual SIL
2023-07-31 09:11:44 -07:00
Joshua Turcotti
2eade1d1b5 Merge pull request #67511 from JTurcotti/tweaks
[SendNonSendable] Assorted Bugfixes and Tweaks
2023-07-28 09:24:36 -07:00
Pavel Yaskevich
1ece483119 [AST] ASTPrinter: Print init accessor for SIL 2023-07-28 08:32:37 -07:00
jturcotti
bb2f3c011e rename DeferredSendableChecking pass to SendNonSendable pass, handle more instructions such as try_apply and begin_apply, and fix bugs 2023-07-27 16:45:29 -07:00
Joe Groff
aee071bf4e Introduce an experimental @_rawLayout attribute.
This attribute can be attached to a noncopyable struct to specify that its
storage is raw, meaning the type definition is (with some limitations)
able to do as it pleases with the storage. This provides a basis for
implementing types for things like atomics, locks, and data structures
that use inline storage to store conditionally-initialized values.
The example in `test/Prototypes/UnfairLock.swift` demonstrates the use
of a raw layout type to wrap Darwin's `os_unfair_lock` APIs, allowing
a lock value to be stored inside of classes or other types without
needing a separate allocation, and using the borrow model to enforce
safe access to lock-guarded storage.
2023-07-24 14:28:19 -07:00
Zoe Carver
7db5fe11ad Merge pull request #67296 from zoecarver/only-methods-on-self-contained-types-are-unsafe
[cxx-interop] Only mark projections of self-contained types as unsafe.
2023-07-19 14:18:46 -07:00
Doug Gregor
f03ad115a2 [SE-0401] Rename DisableActorInferenceFromPropertyWrapperUsage to DisableOutwardActorInference 2023-07-18 23:49:58 -07:00
John McCall
a934f1f66c Merge pull request #67368 from rjmccall/unimplementable-variadic-reabstraction
Diagnose attempts to reabstract variadic functions in unimplementable ways
2023-07-18 21:28:59 -04:00
zoecarver
2115f7aaf8 [cxx-interop] Add NewCxxMethodSafetyHeuristics feature and guard swift compiler sources changes on it. 2023-07-18 17:42:34 -07:00
Anders Bertelrud
d6e0ca3544 [PlaygroundTransform] Add experimental feature PlaygroundExtendedCallbacks to pass more info in callbacks (#67215)
* Add experimental feature `PlaygroundExtendedCallbacks` which passes more information in `-playground` callbacks

Adds the experimental feature `PlaygroundExtendedCallbacks` which (when `-playground` is also passed) causes the playground transform to use alternate forms of the result-value, scope-entry, and scope-exit callbacks that include the module name and file path of the source file.

The previous callbacks included integers for the module number and file number, but this was cumbersome to use because it required the caller to create source symbols with magical names formed from the module name and file path that the playground transform knew how to look up.

The extended callbacks in the experimental feature instead pass these strings as string literals. This is an experimental feature because of the need to measure the performance impact, and because of the need to provide an option to control which set of callbacks to use so that existing clients of the playground transform can opt into it when ready. It's also likely that we'll want to pass more information in the extended callbacks, such as an indication of the kind of result is being logged (e.g. a loop iteration variable vs a return statement vs a variable assignment). So this should be considered the first of a series of experimental improvements that will then be pitched as an actual, non-experimental v2.0 of the playground transform callback API. Because of the nature of how the playground transform is used, it's much easier to iterate on the functionality in the form of an experimental feature rather than using only desktop debug builds of the Swift compiler.

Changes:
- define a new experimental feature called `PlaygroundExtendedCallbacks`
- modify the playground transform step in sema to pass the module name and file name literals when the experimental feature is set
- add a unit test for the extended callbacks

There is no change in behaviour when `PlaygroundExtendedCallbacks` is not enabled.

rdar://109911742

Co-authored-by: Brent Shank <bshank@apple.com>
2023-07-18 11:55:26 -07:00
John McCall
1a7d44a11d Diagnose attempts to reabstract variadic function types in unimplementable ways. 2023-07-18 13:22:35 -04:00
Slava Pestov
29415df860 ASTPrinter: Fix logic to determine if a requirement needs 'repeat' prefix 2023-07-12 12:34:37 -04:00
jturcotti
aa9f1a3584 add an experimental feature DeferSendableChecking to defer the sendable checking of some sites. For now, only diagnostics corresponding to non-sendable arguments passed to calls with unsatisfied isolation are deferred. A SIL pass SendNonSendable is added to emit the deferred diagnostics, and ApplyExpr is appropriately enriched to make that deferral possible. 2023-07-03 09:52:11 -07:00
Slava Pestov
8afff61699 AST: Replace TypeArrayView<GenericTypeParamType> with ArrayRef<GenericTypeParamType *>
This basically undoes 3da6fe9c0d, which in hindsight was wrong.

There were no other usages of TypeArrayView anywhere else except for
GenericSignature::getGenericParams(), and it was almost never what
you want, so callers had to convert back and forth to an ArrayRef.
Remove it.
2023-06-29 19:23:44 -04:00
Holly Borla
7a46466b65 Merge pull request #66967 from hborla/extension-macro
[Macros] Generalize `conformance` macros as `extension` macros
2023-06-29 08:57:04 -07:00
Doug Gregor
e240ec5eb4 Merge pull request #66991 from DougGregor/experimental-feature-strict-concurrency 2023-06-28 15:07:59 -07:00
Holly Borla
81a1f64811 [Macros] Allow @attached(extension) attributes to be suppressed in
module interfaces.
2023-06-28 14:53:16 -07:00
Gwynne Raskind
5ab86d969c Add StrictConcurrency as an always-enabled experimental feature
Upcoming and experimental features are supported via command-line flags
and also in the SwiftPM manifest. Introduce it as an experimental
feature so that it can be enabled via SwiftPM without having to resort
to unsafe flags.

The `StrictConcurrency` experimental feature can also provide a
strictness level in the same manner as `-strict-concurrency`, e.g.,
`StrictConcurrency=targeted`. If the level is not provided, it'll be
`complete`.

Note that we do not introduce this as an "upcoming" feature, because
upcoming features should be in their final "Swift 6" form before
becoming available. We are still tuning the checking for concurrency.
2023-06-28 12:06:17 -07:00
Michael Gottesman
bd90e310e1 Merge pull request #66952 from gottesmm/pr-87fcc78991b465d8a15454dc76b66d6f347ddff0
[move-only] Emit an error if we /ever/ partially consume a noncopyable type.
2023-06-28 01:00:40 -07:00
Holly Borla
725374e0d8 [Macros] Implement attached extension macros. 2023-06-27 21:22:12 -07:00
Doug Gregor
7bc5e93251 Merge branch 'main' into disable-property-wrapper-based-isolation 2023-06-27 15:15:14 -07:00
Michael Gottesman
3dde9df468 [move-only] Emit an error if we /ever/ partially consume a noncopyable type.
The reason why I am doing this is that this was not part of the original
evolution proposal (it was called an extension) and after some discussion it was
realized that partial consumption would benefit from discussion on the forums.

rdar://111353459
2023-06-27 13:52:49 -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
Michael Gottesman
d0938a906f [move-only] Ban resilient noncopyable types.
One can still in resilient frameworks have noncopyable frozen types.

This means that one cannot make a noncopyable:

1. Full resilient public type.
2. @usableFromInline type.

NOTE: One can still use a frozen noncopyable type as a usableFromInline class
field. I validated in the attached tests that we get the correct code
generation.

I also eliminated a small bug in TypeCheckDeclPrimary where we weren't using a
requestified attr check and instead were checking directly.

rdar://111125845
2023-06-21 16:57:44 -07:00
Holly Borla
e42667bde6 [Diagnostics] Suppress printing explicit pack types in the ASTPrinter instead of
stripping PackType out of diagnostic arguments.

There are places in the type printing code that assume the substitution for a
type parameter pack is always a pack, and violating that invariant will crash
the compiler. We also never want to print 'Pack{...}' in diagnostics anyway,
so the print option is a better approach and fixes a few existing tests that still
contained 'Pack{...}' in error messages.
2023-06-14 11:57:18 -07:00
Doug Gregor
7fb1ba9798 [AST printer] Stop printing -> () types on all macro declarations. 2023-06-09 23:25:34 -07:00
Holly Borla
684ef9c482 [AST] Add a new accessor kind for init accessors. 2023-06-06 18:57:31 -07:00
Holly Borla
3dc470f5f4 [Features] Add an experimental feature flag for init accessors. 2023-06-06 18:57:31 -07:00
Slava Pestov
05daaae0fd ASTPrinter: Tweak PackExpansionType printing 2023-06-06 14:18:37 -04:00
Slava Pestov
e476b220b6 Merge pull request #66250 from slavapestov/variadic-generics-feature
Basic: Remove VariadicGenerics feature
2023-06-01 12:51:18 -04:00
Slava Pestov
ef466ca9d0 Basic: Remove VariadicGenerics feature 2023-05-31 23:41:23 -04:00
Sophia Poirier
93864f6c15 [Variadic Generics] drop requirement of .element for tuple expansion rdar://107160966 2023-05-30 11:37:55 -04:00
Kuba (Brecka) Mracek
2d5f33e2e3 Add @_used and @_section attributes for global variables and top-level functions (#65901)
* Add @_used and @_section attributes for global variables and top-level functions

This adds:
- @_used attribute that flags as a global variable or a top-level function as
  "do not dead-strip" via llvm.used, roughly the equivalent of
  __attribute__((used)) in C/C++.
- @_section("...") attribute that places a global variable or a top-level
  function into a section with that name, roughly the equivalent of
  __attribute__((section("..."))) in C/C++.
2023-05-26 14:02:32 -07:00
Slava Pestov
b2bc2c72ec AST: Introduce PackElementType 2023-05-25 11:17:30 -04:00
Doug Gregor
dba94bdbd4 [ASTGen] Add experimental feature to use ASTGen in lieu of parsing types
Introduce a new experimental feature `ASTGenTypes` that uses ASTGen to
translate the Swift syntax tree (produced by the new Swift parser)
into C++ `TypeRepr` nodes instead of having the C++ parser create the
nodes.

The approach here is to intercept the C++ parser's `parseType`
operation to find the Swift syntax node at the given position (where
the lexer currently is) and have ASTGen translate that into the
corresponding C++ AST node. Then, we spin the lexer forward to the
token immediately following the end of the syntax node and continue
parsing.
2023-05-22 21:39:59 -07:00
Michael Gottesman
fd25cf379a Rename MoveExpr -> ConsumeExpr to reflect the final name.
NFC.
2023-05-17 22:42:42 -07:00
Michael Gottesman
e6f1691122 [copy-operator] Add support for the copy operator in preparation for making consuming and borrowing no implicit copy.
Some notes:

1. I implemented this as a contextual keyword that can only apply directly to
lvalues. This ensures that we can still call functions called copy, define
variables named copy, etc. I added tests for both the c++ and swift-syntax based
parsers to validate this. So there shouldn't be any source breaks.

2. I did a little bit of type checker work to ensure that we do not treat
copy_expr's result as an lvalue. Otherwise, one could call mutating functions on
it or assign to it, which we do not want since the result of copy_value is

3. As expected, by creating a specific expr, I was able to have much greater
control of the SILGen codegen and thus eliminate extraneous copies and other
weirdness than if we used a function and had to go through SILGenApply.

rdar://101862423
2023-05-17 22:42:42 -07:00