Commit Graph

1316 Commits

Author SHA1 Message Date
Allan Shortlidge
09f8622b1b AST: Simplify AvailabilitySpec subclasses further.
Remove methods that are specific to AvailabilitySpec subclasses and replace
them with methods on the superclass if necessary.

NFC.
2025-02-11 22:45:43 -08:00
Allan Shortlidge
6daea78ccf AST: Remove AvailabilitySpec.h include from Stmt.h.
Include it where it's actually used instead to improve compile times.
2025-02-11 20:03:01 -08:00
Tony Allevato
4e3e91e3b2 Merge pull request #79218 from allevato/json-ast-inherited
[ASTDumper] Write inherited types correctly.
2025-02-09 20:18:24 -08:00
Tony Allevato
5ff6286dd3 [ASTDumper] Write inherited types correctly.
ASTDumper was never updated to print extra conformance information,
like suppression, preconcurrency, etc. In default mode, we print it
as a comma-delimited list of source-like strings. In JSON mode, we
print objects containing flags.
2025-02-07 10:05:40 -08:00
Michael Gottesman
7e350bb4ce Revert "[concurrency] Add Concurrent/ConcurrentUnsafe and use it instead of ActorIsolation::Nonisolated."
This reverts commit 0cb64638d0.
2025-02-06 14:05:06 -08:00
Michael Gottesman
f05f08c2c0 Revert "[concurrency] Make ActorIsolation::Nonisolated -> CallerIsolationInheriting and delete CallerIsolationInheriting."
This reverts commit 543b1e6ca3.
2025-02-06 14:04:30 -08:00
Anton Korobeynikov
1e7a1d91fc Emit reabstraction thunks for implicit conversions between T.TangentType and Optional<T>.TangentType (#78076) 2025-02-05 20:57:52 -08:00
Rintaro Ishizaki
df2ada37df [ASTGen] Generate AvailableAttr
* Move `AvailabilitySpec` handling logic to AST, so they can be shared
  between libParse and ASTGen
* Requestify '-define-availability' arguments parsing and parse them
  with 'SwiftParser' according to the 'ParserASTGen' feature flag
* Implement 'AvailableAttr' generation in ASTGen
2025-02-04 23:40:01 -08:00
Tony Allevato
c5f0200680 Merge pull request #79059 from allevato/json-ast-followups
[ASTDumper] Some followups from the initial JSON PR and macro dumping improvements.
2025-02-04 01:13:46 -05:00
Michael Gottesman
543b1e6ca3 [concurrency] Make ActorIsolation::Nonisolated -> CallerIsolationInheriting and delete CallerIsolationInheriting. 2025-02-03 10:56:08 -08:00
Michael Gottesman
0cb64638d0 [concurrency] Add Concurrent/ConcurrentUnsafe and use it instead of ActorIsolation::Nonisolated.
This is just the first part of a larger transition.
2025-02-03 10:56:06 -08:00
Tony Allevato
0d9467e688 Hoist ASTDumpMemberLoading choice up to the frontend call sites. 2025-02-03 11:37:47 -05:00
Tony Allevato
237e79a467 Print the macro's concrete decl ref for any macro expansions.
This gives us the macro's USR, letting us match it up to its
declaration elsewhere.
2025-01-31 11:15:02 -05:00
Anthony Latsis
a84dfc8387 [Gardening] Fix some set but not used variables 2025-01-30 21:34:38 +00:00
Tony Allevato
9d3bcca73f Ensure that top-level macro expansions are in the JSON AST dump. 2025-01-30 12:18:21 -05:00
Tony Allevato
3804110db8 Change parseIfNeeded to an enum to control member loading behavior. 2025-01-30 09:10:15 -05:00
Tony Allevato
5fe10ce86a ASTDumper: Label "interface type" -> "interface_type". 2025-01-29 13:55:00 -05:00
Doug Gregor
9af4d6eb65 Merge pull request #78730 from DougGregor/safe-attr
Introduce the @safe attribute as described in the opt-in safety checking proposal
2025-01-24 19:42:52 -08:00
Tony Allevato
d2fd3479da Additional post-review fixes. 2025-01-24 14:11:20 -05:00
Doug Gregor
4395537fa0 Introduce the @safe attribute as described in the opt-in safety checking proposal 2025-01-23 07:47:17 -08:00
Tony Allevato
f249db3f85 Use cached evaluator results when looking up function types.
Also improve the output for thrown error destinations in
parsable modes.
2025-01-22 14:26:14 -05:00
Tony Allevato
8df48e52ff Address more reviewer feedback. 2025-01-22 14:26:14 -05:00
Tony Allevato
87cabb0f04 Print the buffer ID for non-main buffers and test via macro expansions. 2025-01-22 14:26:13 -05:00
Tony Allevato
a4c64b081d Address most of the simple review feedback. 2025-01-22 14:26:13 -05:00
Tony Allevato
52c009a2ec [AST] Improve JSON representation of various AST nodes. 2025-01-22 14:26:13 -05:00
Tony Allevato
a57fb4dfa9 [AST] Add minimal JSON support to ASTDumper.
This only takes the existing AST information and writes it as JSON
instead of S-expressions. Since many of these fields are stringified,
they're not ideal for the kind of analysis clients of the JSON format
would want to do. A future commit will update these values to use a
more structured representation.
2025-01-22 14:26:13 -05:00
Tony Allevato
d14f3c94fd [AST] NFC: Refactor format-specific printing into a "writer".
This makes the low-level `print*` methods in `PrintBase` simply
forward to the writer, which does the actual work. Right now,
there's only the abstract base class for the writer and the
default (S-expression-like) writer. A later commit will
introduce the JSON writer.

Also update the `printField*` methods to take `Label`s instead
of `StringRef`s.
2025-01-22 14:26:13 -05:00
Tony Allevato
80f713b489 [AST] NFC-ish: Improve printing of availability specs.
Availability specs are currently dumped by writing a pre-formatted
string directly to the output stream instead of using the structured
primitives in `PrintBase`. This needs to be fixed before we can
introduce the generalized writers.

The format here is meant to be the same as the format printed by
the original methods, but some colors may differ slightly when
dumping to the terminal.
2025-01-22 14:23:32 -05:00
Tony Allevato
8670ecf245 [AST] NFC: Refactor ASTDumper to use a "label" abstraction.
ASTDumper allows nodes/values to be printed without labels, which
works fine for the default output but won't work for JSON when every
value needs to have a valid key. To balance these needs, we create
a `Label` abstraction that can be created as either `always` or
`optional`. All the current labels are treated as `always`, and all
other values have had `optional` labels associated with them, which
won't be printed in the default AST dump.

This change also adds a `printList` function that replaces anywhere
that `for` loops with `printRec` calls in their bodies. This will
be used to provide the necessary array structuring for JSON output
later. (There are some places where `for` loops call `printFlag`
which will need to be dealt with later.)
2025-01-22 14:23:32 -05:00
Allan Shortlidge
52b89a8ee0 Merge pull request #78805 from tshortli/private-available-attr-fields
AST: Eliminate remaining direct access to AvailableAttr's fields
2025-01-22 03:41:30 -08:00
Becca Royal-Gordon
ebea19d7b9 Merge pull request #78697 from beccadax/rdar142693093
Work around Foundation NS_TYPED_ENUM bug
2025-01-22 00:57:41 -08:00
Allan Shortlidge
ba822d1e23 AST: Eliminate remaining direct access to AvailableAttr's fields.
Most of the compiler should use SemanticAvailableAttr instead. In contexts like
ASTDumper where a semantic attribute is unavailable use accessors on
AvailableAttr.

NFC.
2025-01-21 22:56:07 -08:00
Pavel Yaskevich
ca96a2b060 [AST] Define @execution(concurrent | caller) attribute on function declarations 2025-01-17 15:40:00 -08:00
Becca Royal-Gordon
992d9af8b7 [NFC] Indicate whether dumped types are imported 2025-01-16 15:33:58 -08:00
Alejandro Alonso
09d122af7c Merge pull request #76438 from Azoy/vector
[stdlib] Slab
2025-01-12 10:36:25 -08:00
Allan Shortlidge
393ad9872a Merge pull request #78541 from tshortli/available-attr-remodel
AST: Refactor `AvailableAttr` representation to use `AvailabilityDomain`
2025-01-11 02:39:27 -08:00
Allan Shortlidge
51aaacceb7 AST: Remove AvailableAttr::getPlatformAgnosticAvailability(). 2025-01-10 19:18:42 -08:00
Allan Shortlidge
8cd9319a3e AST: Improve ASTDumper output for AvailableAttr.
The platform field now indicates whether the attribute applies universally, to
a specific platform, to the Swift language, or to package descriptions.
Additionally the output now reflects whether or not the attribute specifies
unconditional deprecation or unavailabity or is `noasync`.
2025-01-10 18:43:12 -08:00
Doug Gregor
1b7707d2cc Remove the now-unused @safe(unchecked) 2025-01-10 10:39:16 -08:00
Doug Gregor
8bb5bbedbc Implement an unsafe expression to cover uses of unsafe constructs
Introduce an `unsafe` expression akin to `try` and `await` that notes
that there are unsafe constructs in the expression to the right-hand
side. Extend the effects checker to also check for unsafety along with
throwing and async operations. This will result in diagnostics like
the following:

    10 |   func sum() -> Int {
    11 |     withUnsafeBufferPointer { buffer in
    12 |       let value = buffer[0]
       |                   |     `- note: reference to unsafe subscript 'subscript(_:)'
       |                   |- warning: expression uses unsafe constructs but is not marked with 'unsafe'
       |                   `- note: reference to parameter 'buffer' involves unsafe type 'UnsafeBufferPointer<Int>'
    13 |       tryWithP(X())
    14 |       return fastAdd(buffer.baseAddress, buffer.count)

These will come with a Fix-It that inserts `unsafe` into the proper
place. There's also a warning that appears when `unsafe` doesn't cover
any unsafe code, making it easier to clean up extraneous `unsafe`.

This approach requires that `@unsafe` be present on any declaration
that involves unsafe constructs within its signature. Outside of the
signature, the `unsafe` expression is used to identify unsafe code.
2025-01-10 10:39:14 -08:00
Alejandro Alonso
b9487d132a Cache the value type of a generic param when cloning 2025-01-08 10:37:15 -08:00
Slava Pestov
2d17294d73 Merge pull request #78301 from slavapestov/remove-one-way-constraints
Sema: Remove ConstraintKind::OneWayBindParam and ConstraintKind::OneWayEqual
2025-01-05 10:38:14 -05:00
Joe Groff
5c4406b5e8 Add an @_addressableForDependencies type attribute.
This attribute makes it so that a parameter of the annotated type, as well as
any type structurally containing that type as a field, becomes passed as
if `@_addressable` if the return value of the function has a dependency on
the parameter. This allows nonescapable values to take interior pointers into
such types.
2025-01-02 21:33:51 -08:00
Michael Gottesman
5d4239af57 [concurrency] Add new isolation kind CallerIsolationInheriting.
Right now it is basically a version of nonisolated beyond a few simple cases
like constructors/destructors where we are pretty sure we want to not support
this.

This is part of my bringup strategy for changing nonisolated/unspecified to be
caller isolation inheriting.
2025-01-02 13:18:30 -08:00
Slava Pestov
74f8960bd8 Sema: Remove OneWayExpr and Builtin.one_way 2024-12-21 00:42:13 -08:00
Becca Royal-Gordon
08e2a4ddae Type check ABI decls
Sema now type-checks the alternate ABI-providing decls inside of @abi attributes.

Making this work—particularly, making redeclaration checking work—required making name lookup aware of ABI decls. Name lookup now evaluates both API-providing and ABI-providing declarations. In most cases, it will filter ABI-only decls out unless a specific flag is passed, in which case it will filter API-only decls out instead. Calls that simply retrieve a list of declarations, like `IterableDeclContext::getMembers()` and friends, typically only return API-providing decls; you have to access the ABI-providing ones through those.

As part of that work, I have also added some basic compiler interfaces for working with the API-providing and ABI-providing variants. `ABIRole` encodes whether a declaration provides only API, only ABI, or both, and `ABIRoleInfo` combines that with a pointer to the counterpart providing the other role (for a declaration that provides both, that’ll just be a pointer to `this`).

Decl checking of behavior specific to @abi will come in a future commit.

Note that this probably doesn’t properly exercise some of the new code (ASTScope::lookupEnclosingABIAttributeScope(), for instance); I expect that to happen only once we can rename types using an @abi attribute, since that will create distinguishable behavior differences when resolving TypeReprs in other @abi attributes.
2024-12-19 15:49:34 -08:00
Becca Royal-Gordon
94ff062edd Parse and serialize @abi attribute
This attribute will allow you to specify an alternate version of the declaration used for mangling. It will allow minor adjustments to be made to declarations so long as they’re still compatible at the calling convention level, such as refining isolation or sendability, renaming without breaking ABI, etc.

The attribute is behind the experimental feature flag `ABIAttribute`.
2024-12-19 15:48:54 -08:00
Becca Royal-Gordon
73377fe6b4 [NFC-ish] Fix some crashes from early Decl::dump()
Changes dump output used in one test; otherwise NFC.
2024-12-19 15:47:07 -08:00
Pavel Yaskevich
636525ebd9 Merge pull request #78171 from xedin/rdar-140300022
[TypeChecker/SILGen] Allow `any Sendable` to match `Any` while matching generic arguments
2024-12-17 20:24:34 -08:00
Doug Gregor
e260d65f71 Add @safe(unchecked) to allow unsafe code within a declaration.
Introduce an attribute to allow unsafe code within the annotated
declaration without presenting an unsafe interface to users. This is,
by its nature, and unsafe construct, and is used to document where
unsafe behavior is encapsulated in safe constructs.

There is an optional message that can be used as part of an audit
trail.
2024-12-13 11:36:40 -08:00