Commit Graph

2927 Commits

Author SHA1 Message Date
Doug Gregor
919da2c6c0 Enable emission of macro expansion buffers for diagnostics by default
This feature is too handy to leave off-by-default. Enable it by
default, but allow `-emit-macro-expansion-files no-diagnostics` to
disable it.
2023-01-30 18:16:20 -08:00
Doug Gregor
8871129896 [Macros] Add frontend flag to dump macro expansions for diagnostics.
Add frontend flag `-emit-macro-expansion-files diagnostics` to emit any
macro expansion buffers referenced by diagnostics into files in a
temporary directory. This makes debugging type-checking failures in
macro expansions far easier, because you can see them after the
compiler process has exited.
2023-01-30 18:05:53 -08:00
Holly Borla
f6f57a8099 [Macros] Rename "synthesized member macros" to "member macros". 2023-01-26 21:52:36 -08:00
Ben Barham
4380ee659a Merge pull request #63227 from bnbarham/optional-api-update
Update `llvm::Optional` API uses
2023-01-26 10:19:51 -08:00
Michael Gottesman
89176928ee Merge pull request #63213 from gottesmm/rdar103271138
[move-only] Implement borrow+struct_extract to restructure transform
2023-01-26 07:19:10 -08:00
Ben Barham
3ec878d918 Update llvm::Optional API uses
Use the std-equivalent names as the LLVM ones are now deprecated
(eventually `llvm::Optional` will disappear):
  - `getValue` -> `value`
  - `getValueOr` -> `value_or`
  - `hasValue` -> `has_value`

Follow up from ab1b343dad and
7d8bf37e5e with some missing cases.
2023-01-25 16:28:10 -08:00
Holly Borla
c707643396 Merge pull request #63059 from hborla/synthesized-member-macros
[Macros] Initial support for synthesized member macros.
2023-01-25 07:28:16 -08:00
Kavon Farvardin
9d65c9e81e enable move-only and move-only classes in production builds 2023-01-24 16:01:23 -08:00
Michael Gottesman
e2b5c03c77 [frozen-multi-map] Add the ability to "unfreeze" the multi-map so one can add incrementally more elements to the multi-map.
For those unfamiliar, this map is a vector of pairs that we stable sort by the
key when we "freeze" it so we can run map operations upon the keys. This allows
one to accumulate into the multi-map and then once one has finished
accumulating, perform these map operations.

While doing some work in the move checker, I thought I would need the ability to
incrementally update a multi-map by appending more entires. Due to the design,
supporting this is as simple as unfreezing the map. This results in one being no
longer able to run map operations without hitting an assert. When one freezes
again, the stable sort will put the new entries in the appropriate place in the
already sorted initial part of the array.

Turns out I didn't need this, but seemed useful, so I am upstreaming it.
2023-01-24 15:28:11 -08:00
swift-ci
ca1f3f7a54 Merge pull request #63179 from kavon/moveonly-structs-or-enums
Limit `@_moveOnly` to structs and enums
2023-01-24 07:05:24 -08:00
Kavon Farvardin
1356694043 experimentally allow move-only classes
A lot of existing regression tests rely on there
being some form of move-only classes, despite
them being something that will not be available
to users (and not complete).

This change introduces a `MoveOnlyClasses`
experimental feature so that those tests don't
need to be fully rewritten just yet. You need to
include `-enable-experimental-feature MoveOnlyClasses` along with
`-enable-experimental-move-only` to get move-only classes.
2023-01-23 22:33:27 -08:00
Alexis Laferrière
a0ee5c5312 Merge pull request #63116 from xymus/deser-safety-by-default
[Serialization] Enable deserialization safety by default
2023-01-23 17:18:48 -08:00
Holly Borla
8b9be30783 [Macros] Add a new macro role for synthesized member macros. 2023-01-22 21:19:21 -08:00
Doug Gregor
bdf1183757 [Diagnostics] Add a swift-syntax diagnostic style
The SwiftDiagnostics module within swift-syntax has a diagnostic
pretty-printer that does a nice rendering of the source code with
diagnostics placed inside gaps between the code lines.
Introduce another `-diagnostic-style` argument, `swift-syntax`,
to bridge from the pretty-printed C++ diagnostics over to the
swift-syntax diagnostics engine.
2023-01-21 23:09:56 -08:00
Doug Gregor
31a3d8e329 Introduce infrastructure to dump generated source buffers into temporary files 2023-01-19 21:30:22 -08:00
Alexis Laferrière
af70cc5464 [Serialization] Enable deserialization safety by default
rdar://99495048
2023-01-19 10:50:55 -08:00
Holly Borla
1b74d6cfcc [SourceManager] Distinguish between the various macro roles in
GeneratedSourceInfo::Kind.
2023-01-15 10:11:00 -08:00
Doug Gregor
91ee109c2f [Macros] Start expanding accessor macros attached to a storage declaration.
Accessor macros are attached macros (written with attribute syntax)
that can generate accessors for a property or subscript. Recognize
custom attributes that are accessor macros when written on a storage
declaration, and expand those macros.

This is very much a work in progress, and the result of the expansion
isn't yet parsed or wired into the AST.
2023-01-13 10:12:25 -08:00
Max Desiatov
7ccb605386 Basic/type_traits: use __is_identifier for some feature checks (#62993)
* Basic/type_traits: use `__is_identifier` for some feature checks

When building on Alpine with Musl `__has_feature(is_trivially_constructible)` does not work, even though `__is_trivially_constructible` is defined and `__has_trivial_constructor` is deprecated. Same for `__is_trivially_destructible` and `__has_trivial_destructor` respectively.

* Basic/type_traits: use `__has_feature` or `__has_keyword`

That potentially makes these checks more future-proof in case more edge cases are introduced on different platforms.
2023-01-12 22:08:06 +00:00
Alexis Laferrière
4507307b35 Merge pull request #62982 from xymus/deser-safety-step2
[Serialization] Misc prep for the deserialization safety feature
2023-01-12 13:42:28 -08:00
Max Desiatov
fe373aa971 Basic/type_traits: use __has_feature or __has_keyword
That potentially makes these checks more future-proof in case more edge cases are introduced on different platforms.
2023-01-12 16:30:58 +00:00
Max Desiatov
2be8bdd5ed Basic/type_traits: use __is_identifier for some feature checks
When building on Alpine with Musl `__has_feature(is_trivially_constructible)` does not work, even though `__is_trivially_constructible` is defined and `__has_trivial_constructor` is deprecated. Same for `__is_trivially_destructible` and `__has_trivial_destructor` respectively.
2023-01-12 15:37:01 +00:00
Alexis Laferrière
faeb226ac5 [Serialization] Update doc on EnableDeserializationRecovery
Integrate reviewer's comment in a previous PR.
2023-01-11 15:14:30 -08:00
Doug Gregor
9e76023546 Add BuiltinCreateTaskGroupWithFlags feature and use it to guard the builtin 2023-01-11 13:47:28 -08:00
Michael Gottesman
b81fc00305 [frozen-multi-map] Add the ability to iterate through the internal storage of the map once we have been frozen.
The intention is that this can be used once we are no longer accumulating into
the multi-map.
2023-01-08 14:04:21 -08:00
Michael Gottesman
3bac57d9ac Merge pull request #62907 from gottesmm/pruned-liveness-fixes
[pruned-liveness] Make some small fixes that only are exposed when working with multi-bit code
2023-01-08 00:06:29 -08:00
Saleem Abdulrasool
9a7555cd70 Merge pull request #62868 from apple/maxd/has-trivial-constructor
include/swift/Basic: fix deprecation warnings
2023-01-07 08:49:33 -08:00
Alexis Laferrière
4e69160b92 Merge pull request #62886 from xymus/deser-safety-infra
[Serialization] Prepare the infrastructure for the deserialization safety feature
2023-01-06 21:08:24 -08:00
Michael Gottesman
4981527e2d [frozen-multi-map] Add the ability to determine if all values of all keys have been deleted from the mult-map.
This is useful to validate that a multi-map has been completely consumed as one
erases values from it.
2023-01-06 20:57:39 -08:00
Michael Gottesman
5bd2725c23 [basic] Add an operator<<(llvm::raw_ostream &os, const SmallBitVector &) implementation.
For some reason LLVM doesn't provide this. I have written a few versions of this
in the Swift codebase. Makes sense to factor it out before I make another one.
2023-01-06 20:57:39 -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
Doug Gregor
514a05297e Drop the original buffer ID from GeneratedSourceInfo.
Nobody is using it, and this information is recoverable from the original
source range.
2023-01-06 11:17:29 -08:00
Doug Gregor
5c217bd17c Add source buffers pretty-printed for diagnostics to serialized diagnostics
When emitting a diagnostic that references a declaration that does not
itself have a source location (e.g., because it was synthesized or
deserialized), the diagnostics engine pretty-prints the declaration
into a buffer so it can provide caret diagnostics pointing to that
declaration.

Start marking those buffers as "generated source buffers", so that we
emit their contents into serialized diagnostics files. This will allow
tools that make use of serialized diagnostics to also show caret
information.
2023-01-06 11:17:29 -08:00
Max Desiatov
e5ab9b4ab0 include/swift/Basic: fix deprecation warnings
These are deprecation warnings
```
include/swift/Basic/type_traits.h:49:29: warning: builtin __has_trivial_constructor is deprecated; use __is_trivially_constructible instead [-Wdeprecated-builtins]
  static const bool value = __has_trivial_constructor(T);
                            ^
include/swift/Basic/type_traits.h:61:29: warning: builtin __has_trivial_destructor is deprecated; use __is_trivially_destructible instead [-Wdeprecated-builtins]
  static const bool value = __has_trivial_destructor(T);
                            ^
2 warnings generated.
```
2023-01-05 16:47:36 +00:00
swift-ci
5e59444588 Merge pull request #62835 from DougGregor/macros-experimental-in-prod
Allow the "macros" experimental feature to be enabled in production compilers
2023-01-04 13:50:48 -08:00
Joe Groff
3ffbc45329 Merge pull request #62743 from jckarter/mangler-structural-opaque-type-issues
Mangler: Fix substitution ordering when mangling opaque return types.
2023-01-04 10:50:58 -08:00
Doug Gregor
74a5b6adbd Allow the "macros" experimental feature to be enabled in production compilers
Now that we have a macro in the standard library, we need production
compilers to be able to build the standard library.

Fixes rdar://103868067.
2023-01-04 08:33:21 -08:00
Joe Groff
6263956225 Mangler: Fix substitution ordering when mangling opaque return types.
When a declaration has a structural opaque return type like:

  func foo() -> Bar<some P>

then to mangle that return type `Bar<some P>`, we have to mangle the `some P`
part by referencing its defining declaration `foo()`, which in turn includes
its return type `Bar<some P>` again (this time using a special mangling for
`some P` that prevents infinite recursion). Since we mangle `Bar<some P>`
once as part of mangling the declaration, and we register substitutions for
bound generic types when they're complete, we end up registering the
substitution for `Bar<some P>` twice, once as the return type of the
declaration name, and again as the actual type. This would be fine, except
that the mangler doesn't check for key collisions, and it picks
substitution indexes based on the number of entries in its hash map, so
the duplicated substitution ends up corrupting the substitution sequence,
causing the mangler to produce an invalid mangled name.

Fixing that exposes us to another problem in the remangler: the AST
mangler keys substitutions by type identity, but the remangler
uses the value of the demangled nodes to recognize substitutions.
The mangling for `Bar<current declaration's opaque return type>` can
appear multiple times in a demangled tree, but referring to different
declarations' opaque return types, and the remangler would reconstruct
an incorrect mangled name when this happens. To avoid this, change the
way the demangler represents `OpaqueReturnType` nodes so that they
contain a backreference to the declaration they represent, so that
substitutions involving different declarations' opaque return types
don't get confused.
2023-01-03 09:33:07 -08:00
Doug Gregor
0c5436211c Merge pull request #62768 from DougGregor/macro-omnibus 2023-01-03 07:13:16 -08:00
Doug Gregor
0407610162 [Macros] Don't parse the macro expansion buffer twice.
Each macro expansion buffer was getting parsed twice: once by
ParseSourceFileRequest (which is used by unqualified name lookup) and
once to parse the expression when type-checking the expanded macro.
This meant that the same code had two ASTs. Hilarity ensures.

Stop directly invoking the parser on macro-expanded code. Instead, go
through ParseSourceFileRequest *as is always the right way*, and dig
out the expression we want.
2023-01-02 21:22:04 -08:00
Pavel Yaskevich
529269946d [AST] Drop ResultBuilderASTTransform feature flag 2022-12-21 12:18:02 -08:00
Pavel Yaskevich
697dfbae96 [TypeChecker] Enable result builder AST transform by default 2022-12-21 10:31:30 -08:00
Robert Widmann
3d3611356c Merge pull request #62675 from valeriyvan/SuccessorMap-missing-return
Fix bug missing return in operator=
2022-12-20 11:14:23 -07:00
Erik Eckstein
21d39ba524 use the new llvm::Optional API
fixes warnings in rebranch
2022-12-19 14:04:43 +01:00
Valeriy Van
e5d772d824 Fix bug missing return in operator= 2022-12-19 13:37:15 +02:00
Doug Gregor
33589de62f Experimentally emit diagnostics from the new Swift parser
Introduce the experimental feature `ParserDiagnostics`, which emits
diagnostics from the new Swift parser *first* for a source file. If
that produces any errors, we suppress any diagnostics emitted from the
C++ parser.
2022-12-15 21:24:44 -08:00
Doug Gregor
f467ef4d37 [Source manager] Start tracking generated-source info in the source manager
Establish the relationship for generated sources, whether for macro
expansions or (via a small stretch) replacing function bodies with
other bodies, in the source manager itself. This makes the information
available for diagnostic rendering, and unifies a little bit of the
representation, although it isn't used for much yet.
2022-12-14 23:02:27 -08:00
Alexis Laferrière
276281ded8 Merge pull request #62476 from xymus/module-interface-export-as
[ModuleInterface] Ignore export_as in private swiftinterface
2022-12-13 09:12:44 -08:00
Alex Hoppen
58aaa4f111 Merge pull request #62522 from ahoppen/ahoppen/rename-completion
[IDE] Rename CodeCompletion to IDEInspection in cases where the code path no longer exclusively applies to code completion
2022-12-13 16:40:28 +01:00
Ben Rimmington
620ba334fb [SE-0368] StaticBigInt: support older compilers (#62541) 2022-12-13 11:15:48 +00:00