Commit Graph

334 Commits

Author SHA1 Message Date
Holly Borla
70d998a1bb [Concurrency] Make OptionalIsolatedParameters a conditionally suppressible
language feature, and suppress it for `Clock.measure`.

This allows the _Concurrency swiftinterface file to continue building with
compilers that do not support `OptionalIsolatedParameters`. The feature
suppression drops the `isolated` keyword and replaces `#isolation` with
`nil`.
2024-03-12 22:56:16 -07:00
John McCall
fc538f32fb Allow declarations to opt in to suppressing @isolated(any). 2024-03-01 22:10:15 -05:00
John McCall
1437acdf22 Implement conditional feature suppression.
Our standard conception of suppressible features assumes we should
always suppress the feature if the compiler doesn't support it.
This presumes that there's no harm in suppressing the feature, and
that's a fine assumption for features that are just adding information
or suppressing new diagnostics.  Features that are semantically
relevant, maybe even ABI-breaking, are not a good fit for this,
and so instead of reprinting the decl with the feature suppressed,
we just have to hide the decl entirely.  The missing middle here
is that it's sometimes useful to be able to adopt a type change
to an existing declaration, and we'd like older compilers to be
able to use the older version of the declaration.  Making a type
change this way is, of course, only really acceptable for
@_alwaysEmitIntoClient declarations; but those represent quite a
few declarations that we'd like to be able to refine the types of.

Rather than trying to come up with heuristics based on
@_alwaysEmitIntoClient or other sources of information, this design
just requires the declaration to opt in with a new attribute,
@_allowFeatureSuppress.  When a declaration opts in to suppression
for a conditionally-suppressible feature, the printer uses the
suppression serially-print-with-downgraded-options approach;
otherwise it uses the print-only-if-feature-is-available approach.
2024-03-01 22:10:14 -05:00
Doug Gregor
c96a89b2f2 Introduce a suppressible feature for async sequences Failure type
Suppressing this feature doesn't disable the use of new syntax in the
normal way. Instead, it introduces `@rethrows` on the
AsyncIteratorProtocol and AsyncSequence protocols, so that older
compilers can still use the async sequences generated by newer
compilers and standard libraries.

Fixes the rest of rdar://123782658
2024-02-29 11:49:26 -08:00
Ben Barham
ef8825bfe6 Migrate llvm::Optional to std::optional
LLVM has removed llvm::Optional, move over to std::optional. Also
clang-format to fix up all the renamed #includes.
2024-02-21 11:20:06 -08:00
Rintaro Ishizaki
92e70ef80a [AST] Remove DeclAttrKind::Count
Introduce NumDeclAttrKinds for number of enum values. Use optional for
invalid attribute kind. This align with `TypeAttrKind`.
2024-02-02 09:36:49 -08:00
Rintaro Ishizaki
b839718351 [AST] Use scoped enum for attribute kinds
Align with other kind enum e.g. DeclKind.
2024-02-02 09:36:48 -08:00
Slava Pestov
45f31b4516 AST: Refactor ASTPrinter to use getRequirementsWithInverses() 2024-01-31 18:40:35 -05:00
John McCall
41cdfb04ad Introduce a proper TypeAttribute class hierarchy.
The old TypeAttributes reprsentation wasn't too bad for a small number of
simple attributes.  Unfortunately, the number of attributes has grown over
the years by quite a bit, which makes TypeAttributes fairly bulky even at
just a single SourceLoc per attribute.  The bigger problem is that we want
to carry more information than that on some of these attributes, which is
all super ad hoc and awkward.  And given that we want to do some things
for each attribute we see, like diagnosing unapplied attributes, the linear
data structure does require a fair amount of extra work.

I switched around the checking logic quite a bit in order to try to fit in
with the new representation better.  The most significant change here is the
change to how we handle implicit noescape, where now we're passing the
escaping attribute's presence down in the context instead of resetting the
context anytime we see any attributes at all.  This should be cleaner overall.

The source range changes around some of the @escaping checking is really a
sort of bugfix --- the existing code was really jumping from the @ sign
all the way past the autoclosure keyword in a way that I'm not sure always
works and is definitely a little unintentional-feeling.

I tried to make the parser logic more consistent around recognizing these
parameter specifiers; it seems better now, at least.
2024-01-28 22:30:26 -05:00
Kavon Farvardin
63b3e7624d [NCGenerics] fold InverseType into PCT
We already need to track the inverses separate from the members in a
ProtocolCompositionType, since inverses aren't real types. Thus, the
only purpose being served by InverseType is to be eliminated by
RequirementLowering when it appears in a conformance requirement.

Instead, we introduce separate type InverseRequirement just to keep
track of which inverses we encounter to facilitate cancelling-out
defaults and ensuring that the inverses are respected after running
the RequirementMachine.
2023-12-07 22:14:23 -08:00
Ellie Shin
9d716394b1 Add an interface mode getter/setter in PrintOptions and ModuleInterfaceOptions
Update args parsing
2023-11-13 13:48:07 -08:00
Ellie Shin
e5ca8e5c0b Allow loading package interface if in same package.
Add a new flag to enable package interface loading.
Use the last value of package-name in case of dupes.
Rename PrintInterfaceContentMode as InterfaceMode.
Update diagnostics.
Test package interface loading with various scenarios.
Test duplicate package-name.
2023-11-09 18:44:06 -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
Slava Pestov
5ce14265e4 Fix some random compiler warnings 2023-06-29 16:29:10 -04:00
Holly Borla
81a1f64811 [Macros] Allow @attached(extension) attributes to be suppressed in
module interfaces.
2023-06-28 14:53:16 -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
418471494b [Module printing] Don't print attached macros in generated interfaces
Macros are expanded as part of interface generation, so they shouldn't
also be printed into the Swift interface.

Fixes rdar://109378191.
2023-05-25 11:24:53 -07:00
Anthony Latsis
7f6d3bcd41 ASTPrinter: Turn on explicit any printing for everything and remove the option to disable it 2023-05-13 02:55:49 +03:00
Allan Shortlidge
ffaa1d5dbc Revert "[Macros] Treat FreestandingExpressionMacros as a suppressible feature"
This reverts commit b412c6c884.

Resolves rdar://108591384
2023-05-01 19:44:39 -07:00
Slava Pestov
df5d531dc6 ASTPrinter: Fix printing of pack requirements
Also remove the flag for printing 'each' and make it always on.
2023-04-19 13:04:51 -04:00
QuietMisdreavus
0d74959af6 don't print macro definitions in symbol graphs (#64732)
rdar://106862694
2023-03-29 17:04:00 -06:00
Alex Lorenz
259763c278 [interop] do not print inline C++ namespaces when printing module interface 2023-03-20 19:47:49 -07:00
Egor Zhdan
201a3b1076 Merge pull request #64287 from apple/egorzhdan/do-not-auto-complete-unsafe
[cxx-interop] Do not auto-complete unsafe underscored methods
2023-03-13 00:06:32 +00:00
Egor Zhdan
8326c84bfc [cxx-interop] Do not auto-complete unsafe underscored methods
e.g. `__beginUnsafe()` or `__endUnsafe()` which return iterators

rdar://103252957
2023-03-10 19:31:04 +00:00
Doug Gregor
b412c6c884 [Macros] Treat FreestandingExpressionMacros as a suppressible feature
When the feature isn't available, use the older `@expression` syntax to
work around limitations of older compilers.
2023-03-09 20:33:30 -08:00
Victoria Mitchell
d208dd9993 don't print the "not inherited" mark in SGF declarations
rdar://104917487
2023-02-02 14:53:03 -07:00
Artem Chikin
f85deb0008 [AST Printer] Add ability to print desugared arrays, dictionaries, optionals 2023-01-23 17:09:25 -08:00
John McCall
55b72d4eb7 Fix the pretty-printing of pack expansion types to match the current design 2023-01-11 03:11:30 -05:00
Alexis Laferrière
ab38752d33 [ModuleInterface] Ignore export_as in private swiftinterface
Introduce a new behavior when printing references to modules with an
`export_as` definition. Use the `export_as` name in the public swiftinterface
and the real module name in the private swiftinterface.

This has some limits but should still be an improvement over the current
behavior. First, the we use the `export_as` names only for references to clang
decls, not Swift decls with an underlying module defining an `export_as`.
Second, we always print the `export_as` name in the public swiftinterface,
even in the original swiftinterface file when the `export_as` target is likely
not know, so that generated swiftinterface is still broken.

This behavior is enabled by the flags `-enable-experimental-feature ModuleInterfaceExportAs`
or the `SWIFT_DEBUG_USE_EXPORTED_MODULE_NAME_IN_PUBLIC_ONLY` env var. We may
consider turning it on by default in the future.

rdar://98532918
2022-12-12 14:58:19 -08:00
Alexis Laferrière
888fe84013 Merge pull request #62073 from xymus/module-alias-disambiguate-more
[ModuleInterface] AliasModuleNames workaround support for indirect dependencies and missing imports
2022-11-17 10:33:56 -08:00
Alexis Laferrière
7ae02c02f5 [ModuleInterface] Always use the real name for modules not imported directly
In AliasModuleNames, avoid wrongfully printing aliased names for modules
that were not aliased. This can happen in the case of modules indirectly
imported via a reexport.

rdar://102262019
2022-11-16 10:40:55 -08:00
Ben Barham
46d12f8b51 [InterfaceGen] Print @discardableResult in generated interfaces
Resolves rdar://58805969.
2022-11-11 18:15:35 -08:00
Alexis Laferrière
66586b5f63 [ModuleInterface] Print alias for module names in swiftinterface files
Ambiguities are introduced in generated swiftinterfaces when a type
shares a name with a module (i.e. XCTest). This workaround uses the
module-alias feature to avoid these ambiguities. Writing module
references with a distinguishable prefix should allow normal
type-checking to avoid the usual ambiguities.

We should still aim for a proper fully-qualified named syntax, but this
may help in the mean time.

rdar://101969500
2022-11-04 12:30:33 -07:00
Dario Rexin
210c68d8aa [SILOptimizer] Add prespecialization for arbitray reference types (#58846)
* [SILOptimizer] Add prespecialization for arbitray reference types

* Fix benchmark Package.swift

* Move SimpleArray to utils

* Fix multiple indirect result case

* Remove leftover code from previous attempt

* Fix test after rebase

* Move code to compute type replacements to SpecializedFunction

* Fix ownership when OSSA is enabled

* Fixes after rebase

* Changes after rebasing

* Add feature flag for layout pre-specialization

* Fix pre_specialize-macos.swift

* Add compiler flag to benchmark build

* Fix benchmark SwiftPM flags
2022-09-22 16:29:01 -07:00
Holly Borla
8713d78704 [PrintOptions] Print explicit 'any' in SIL. 2022-08-18 01:15:12 -04:00
Xi Ge
e46b5f5966 ABIChecker: for decls with @_originallyDefinedIn, use original module names in ABI descriptors
rdar://93615410
2022-06-03 22:41:43 -07:00
Holly Borla
38dfb99031 [ASTPrinter] Put desugaring constraints for existential types behind a
PrintOptions flag that is only enabled for interface printing.
2022-05-23 22:15:17 -07:00
Allan Shortlidge
f27005b8d0 ModuleInterface: When printing synthesized extensions, we need to be sure to guard them with required features if applicable. Not doing so can result in broken interfaces that do not typecheck because, for instance, a conformance can refer to a nominal type that is only declared when certain features are enabled.
Also, fix a typo where `#elsif` was printed into interfaces instead of `#elseif`.

Resolves rdar://91509673
2022-04-12 17:53:59 -07:00
Evan Wilde
aa51bdf17a Add noasync availability kind to available attr
This patch adds the `noasync` availability kind to `@available`. The
spelling is `@available(*, noasync)`.
2022-03-22 15:12:51 -07:00
Holly Borla
12459cff80 [Diagnostics] Print 'any' in diagnostic arguments. 2022-03-05 14:26:45 -08:00
Slava Pestov
20ccd05120 AST: Support new primary associated type syntax in the ASTPrinter 2022-03-03 10:15:12 -05:00
Ben Barham
ab85807f06 Merge pull request #41136 from louisdh/refactoring-codable
[Refactoring] Add Codable refactoring action
2022-02-03 19:34:08 -08:00
Louis D'hauwe
5d36507a2f [Refactoring] Add Codable refactoring action
Inserts the synthesized implementation.
As part of this, fix some ASTPrinter bugs.

rdar://87904700
2022-02-02 14:14:23 -08:00
Slava Pestov
e4973158d8 AST: -debug-generic-signatures protocol-qualifies DependentMemberTypes 2022-01-19 22:36:15 -05:00
Holly Borla
3021071af4 [ASTPrinter] Add an option that controls whether existential types
are printed with the `any` keyword.

For now, printing `any` is off by default in order to turn on explicit
existential types with minimal changes to the test suite. The option
will also allow control over how existential types are printed in
Swift interfaces.
2022-01-13 19:30:44 -08:00
Louis D'hauwe
9da37466ea [ASTPrinter] More expression printing 2022-01-11 14:24:17 -08:00
Louis D'hauwe
a89ea380a9 [ASTPrinter] Print expressions
Add new `-print-ast-decl` frontend option for only printing declarations,
to match existing behavior.
Some tests want to print the AST, but don't care about expressions.

The existing `-print-ast` option now prints function bodies and expressions.
Not all expressions are printed yet, but most common ones are.
2022-01-11 14:24:16 -08:00
Robert Widmann
0182414382 Eliminate Superfluous Trivial Copy Constructors
These force an implicit copy-assignment operator to be generated which is a deprecated behavior in modern C++.
2021-12-13 12:25:30 -08:00
Becca Royal-Gordon
8007d70659 Print Sendable conformances for clang types 2021-11-19 11:34:01 -08:00
Saleem Abdulrasool
4d44953691 Revert "Support __available__((swift_attr("@Sendable")))" 2021-11-19 07:40:24 -08:00