Commit Graph

30 Commits

Author SHA1 Message Date
Allan Shortlidge
4a7e76775a AST: Add llvm::raw_ostream conveniences for availability constructs.
Make it easier to debug availability by printing to output streams like
`llvm::errs()`.

NFC.
2025-07-17 18:59:01 -07:00
Anthony Latsis
dd78cd6dbe ASTBridging: Bridge swift::PlatformKind directly 2025-06-20 16:46:03 +01:00
Nate Chandler
2ec007d1a1 [NFC] AST: Add always available availability ctxt. 2025-04-17 09:23:23 -07:00
Allan Shortlidge
303f7d8452 AST: Build scopes for if #available queries on custom availability domains.
Resolves rdar://138441298 and rdar://138441307.
2025-04-01 09:03:41 -07:00
Allan Shortlidge
e943c4bffd AST: Build statement condition availability scopes using AvailabilityContext.
Preparation for building availability scopes for `if #available` statements
that query non-platform availability domains.
2025-04-01 07:46:46 -07:00
Allan Shortlidge
2dd544a73c AST/Sema: Sink AvailabilityContext for location queries from Sema to AST. 2025-03-15 23:47:29 -07:00
Allan Shortlidge
0462cfda11 AST: Teach AvailabilityContext to represent version-less availability.
This enables potential unavailability diagnostics to be emitted for decls that
are only available in version-less domains.
2025-03-06 22:29:50 -08:00
Allan Shortlidge
c6a5e6f745 AST: Reimplement AvailabilityContext storage using TrailingObjects.
This makes more efficient use of the permanent memory allocated for
`AvailabilityContext` representations and also fixes a leak that was introduced
in https://github.com/swiftlang/swift/pull/79718 where the small vector for
unavailable domain storage was not being cleaned up on `ASTContext`
deallocation.

Resolves rdar://145929932.
2025-03-03 18:29:34 -08:00
Allan Shortlidge
866db542a3 Gardening: Use const consistently for ASTContext parameters. 2025-03-02 14:45:50 -08:00
Allan Shortlidge
f34e135cfa AST: Add verification for AvailabilityContext. 2025-02-28 19:09:34 -08:00
Allan Shortlidge
9455a0fece AST: Track multiple unavailable domains in AvailabilityContext. 2025-02-28 19:09:34 -08:00
Allan Shortlidge
ddb5f23306 AST: Add AvailabilityContext::containsUnavailableDomain().
Replaces AvailabilityContext::getUnavailableDomain().
2025-02-06 09:50:07 -08:00
Allan Shortlidge
889bc3138d unittests: Add tests for AvailabilityContext. 2025-02-06 09:50:07 -08:00
Allan Shortlidge
fe138e014a AST: Track an unavailable domain instead of platform in AvailabilityContext.
Now that most of the compiler tracks availability in terms of
AvailabilityDomain, it's time to do so in AvailabilityContext as well. This
will ensure that the compiler accurately suppresses diagnostics about a decl
being unavailable in an arbitrary domain when the context of the use is already
unavailable in that domain.

With this change, most of the special-casing for the Embedded Swift availability
domain has been removed from the compiler, outside of parsing and interface
printing.
2025-01-22 06:40:11 -08:00
Allan Shortlidge
0b5d787a73 AST: Rename AvailabilityContext::PlatformInfo.
It's about to get updated to contain more than just platform-specific
availability context information.

NFC.
2025-01-21 11:44:28 -08:00
Allan Shortlidge
c615faacd7 AST: Rename AvailabilityContext's storage member.
NFC.
2025-01-21 11:44:27 -08:00
Doug Gregor
c043f1138b Drop the "allows unsafe" modeling as availability
With the move to unsafe effects, we no longer model `unsafe` as an
availability problem. Remove all of that supporting code.
2025-01-10 10:39:16 -08:00
Allan Shortlidge
d0f63a0753 AST: Split Availability.h into multiple headers.
Put AvailabilityRange into its own header with very few dependencies so that it
can be included freely in other headers that need to use it as a complete type.

NFC.
2025-01-03 18:36:04 -08:00
Doug Gregor
f33077a363 Ensure that @safe(unchecked) only applies to bodies (not declarations) 2024-12-13 13:31:21 -08:00
Doug Gregor
268d5ccbde Suppress strict safety diagnostics in @unsafe declarations
When a declaration is `@unsafe`, don't emit strict safety diagnostics
for uses of unsafe entities, constructs, or types within it. This
allows one to account for all unsafe behavior in a module using strict
memory safety by marking the appropriate declarations `@unsafe`.

Enhance the strict-safety diagnostics to suggest the addition of
`@unsafe` where it is needed to suppress them, with a Fix-It. Ensure
that all such diagnostics can be suppressed via `@unsafe` so it's
possible to get to the above state.

Also includes a drive-by bug fix where we weren't diagnosing unsafe
methods overriding safe ones in some cases.

Fixes rdar://139467327.
2024-12-12 21:22:41 -08:00
Allan Shortlidge
c3f8352d5c AST: Introduce AvailabilityContext::forDeploymentTarget(). 2024-11-19 17:19:51 -08:00
Allan Shortlidge
6bf0e628be AST: Rename AvailabilityContext::getDefault() to forInliningTarget().
Mirrors the factory methods on `AvailabilityRange`.
2024-11-19 17:19:51 -08:00
Allan Shortlidge
6ac729ea41 Sema: Allow calls to @_unavailableInEmbedded functions in compatible contexts.
Treat `@_unavailableInEmbedded` as if it were `@available(Embedded,
unavailable)` and apply platform compatibility logic in the availability
checker. Revert back to disallowing calls to universally unavailable functions
(`@available(*, unavailable)`) in all contexts.
2024-11-01 13:03:30 -07:00
Allan Shortlidge
7c75b26f1b Sema: Make suppression of availability checking for types more consistent.
Availability checking for types was only suppressed when the immediate context
for the use of the type was explicitly marked unavailable. Availability is
lexical so the checking should be suppressed in the entire scope instead.
2024-11-01 08:18:13 -07:00
Allan Shortlidge
bc30ecc438 Merge pull request #77166 from tshortli/copy-constructor-warning
AST: Fix a `-Wdeprecated-copy-with-user-provided-copy` warning
2024-10-22 16:24:21 -07:00
Allan Shortlidge
748dde5bfa AST: Fix a -Wdeprecated-copy-with-user-provided-copy warning. 2024-10-22 09:31:55 -07:00
Allan Shortlidge
536e666aba Sema: Introduce TypeChecker::availabilityAtLocation().
Implement a query that returns the `AvailabilityContext` for a given
`SourceLoc` and `DeclContext`. Re-implement the existing type checker query
that just returns an `AvailabilityRange` on top of the new query.
2024-10-22 08:39:30 -07:00
Allan Shortlidge
2ba37da7e7 AST: Refactor AvailabilityContext::PlatformInfo operations. 2024-10-22 08:39:29 -07:00
Allan Shortlidge
b346385544 AST: Refactor AvailabilityContext into a value type.
Make the pointer to uniqued storage an implementation detail of an
`AvailabilityContext` value. This way clients of `AvailabilityContext` don't
need to think about pointers and can have access to mutating operations on a
context when appropriate.
2024-10-21 15:16:08 -07:00
Allan Shortlidge
0730209302 AST: Move AvailabilityContext into its own header and cpp file. 2024-10-21 15:16:08 -07:00