Commit Graph

28 Commits

Author SHA1 Message Date
Allan Shortlidge
cad1ee75d5 AST: Optimize the layout of AvailabilityRange.
`AvailabilityRange` is now being used as a currency type in more of the
compiler, and some of those uses are in permanent `ASTContext` allocations. The
class wraps the `VersionRange` utility, which is itself a wrapper around
`llvm::VersionTuple` with some additional storage for representing sentinel
values. Even though the two sentinel values can be be represented with just a
single bit of additional storage on top of the 16 bytes required to represent
`VersionTuple`, because of alignment requirements the sentinel values end up
bloating the layout of `VersionRange` by many bytes.

To make `AvailabilityRange` and `VersionRange` more efficient to store, we can
instead reserve two unlikely `llvm::VersionTuple` bit patterns as the sentinel
values instead. The values chosen are the same ones LLVM uses to represent
version tuple tombstones and empty keys in a `DenseMap`.
2025-03-05 07:15:15 -08:00
Allan Shortlidge
3ea979f712 AST: Request-ify retrieval of SemanticAvailabilitySpec.
Introduced `SemanticAvailabilitySpecRequest` to retrieve the semantic spec for
an `AvailabilitySpec`. Add an `isInvalid` bit to `AvailabilitySpec` to track
whether the request failed. Unfortunately, there aren't any easily accessible
spare bits in the layout of `AvailabilitySpec` so it had to be a new field.
2025-03-04 17:46:18 -08:00
Allan Shortlidge
aaa0e0a7b3 AST/Parse: Parse custom availability domain specs in if #available(...).
Delay resolution of availability domain identifiers parsed in availability
specifications until type-checking. This allows custom domain specifications to
be written in `if #available` queries.
2025-02-27 23:07:55 -08:00
Allan Shortlidge
b0afd07e14 AST/Parse: Always delay AvailabilityDomain lookup to type-checking.
This will unblock parsing and type-checking availability queries that specify
custom availability domains, e.g.:

```
if #available(CustomDomain) {
  // Use declarations protected by @available(CustomDomain)
}
```
2025-02-26 21:46:14 -08:00
Allan Shortlidge
62c8e72f23 AST: Centralize AvailabilityDomain lookup.
Implement lookup of availability domains for identifiers on
`AvailabilityDomainOrIdentifier`. Add a bit to that type which represents
whether or not lookup has already been attempted. This allows both
`AvailableAttr` and `AvailabilitySpec` to share a common implementation of
domain lookup.
2025-02-25 22:00:31 -08:00
Allan Shortlidge
8ebf2aa7e6 AST: Add printing utilities for AvailabilityDomain and AvailabilitySpec. 2025-02-25 19:45:39 -08:00
Allan Shortlidge
c54825b4c3 AST: Use AvailabilityDomainOrIdentifier to store domains in AvailabilitySpec. 2025-02-25 09:02:47 -08:00
Allan Shortlidge
eb6506a1ad AST: Introduce SemanticAvailabilitySpec.
It wraps an type-checked `AvailabilitySpec`, which guarantees that the spec has
a valid `AvailabilityDomain` associated with it. This will unblock moving
AvailabilitySpec domain resolution from parsing to sema.
2025-02-23 10:53:06 -08:00
Allan Shortlidge
670084a9ac AST: Retire PlatformVersionConstraintAvailabilitySpec. 2025-02-12 22:46:58 -08:00
Allan Shortlidge
0722efe97e AST: Retire PlatformAgnosticVersionConstraintAvailabilitySpec. 2025-02-12 20:41:00 -08:00
Allan Shortlidge
6844cfe714 AST: Retire OtherPlatformAvailabilitySpec. 2025-02-12 19:39:30 -08:00
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
735000f24a AST: Flatten the representation of AvailabilitySpec.
Push all of the members up into the AvailabilitySpec superclass in preparation
for removing the subclasses.

NFC.
2025-02-11 22:12:22 -08:00
Allan Shortlidge
3142803d2f AST: Remove runtime version from AvailabilitySpec.
Instead of canonicalizing platform versions during parsing and storing two
versions, just canonicalize the parsed version on-demand when its requested.
2025-02-11 20:10:07 -08:00
Rintaro Ishizaki
c56dd2efca [ASTGen] Generate miscellaneous availability related nodes
* `@_specialize` with `availability:` arguments
* `@backDeployed` attributes
* `@_originallyDefinedIn` attributes
* `#available()` and `#unavailable()` statement conditions
2025-02-07 10:01:07 -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
Becca Royal-Gordon
59bb325e4b [NFC] Factor out ASTContext operator news
Many, many, many types in the Swift compiler are intended to only be allocated in the ASTContext. We have previously implemented this by writing several `operator new` and `operator delete` implementations into these types. Factor those out into a new base class instead.
2021-08-19 11:19:52 -07:00
Ankit Aggarwal
92d09f4e19 Extend @available to support PackageDescription
<rdar://problem/46548531> Extend @available to support PackageDescription

This introduces a new private availability kind "_PackageDescription" to
allow availability testing by an arbitary version that can be passed
using a new command-line flag "-swiftpm-manifest-version". The semantics
are exactly same as Swift version specific availability. In longer term,
it maybe possible to remove this enhancement once there is
a language-level availability support for 3rd party libraries.

Motivation:

Swift packages are configured using a Package.swift manifest file. The
manifest file uses a library called PackageDescription, which contains
various settings that can be configured for a package. The new additions
in the PackageDescription APIs are gated behind a "tools version" that
every manifest must declare. This means, packages don't automatically
get access to the new APIs. They need to update their declared tools
version in order to use the new API. This is basically similar to the
minimum deployment target version we have for our OSes.

This gating is important for allowing packages to maintain backwards
compatibility. SwiftPM currently checks for API usages at runtime in
order to implement this gating. This works reasonably well but can lead
to a poor experience with features like code-completion and module
interface generation in IDEs and editors (that use sourcekit-lsp) as
SwiftPM has no control over these features.
2018-12-08 09:38:40 +05:30
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
Graydon Hoare
66f2027f62 s/Version/PlatformVersion/ to availability specs, add LanguageVersion. 2016-10-12 11:20:42 -07:00
practicalswift
8efa5f587e [gardening] Remove "-*- C++ -*-" tag from .cpp files
Emacs assumes .h files are C files by default which is why the
tag "-*- C++ -*-" is needed.

.cpp files do not have this problem.
2016-01-23 12:09:32 +01:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
Devin Coughlin
37088d4fb9 Parse: Update parsing of #available(...) to no longer user >= version comparison
Change the syntax of availability queries from #available(iOS >= 8.0, OSX >= 10.10, *) to

This change reflects the fact that now that we spell the query '#available()' rather than
'#os()', the specification is about availability of the APIs introduced in a particular OS
release rather than an explicit range of OS versions on which the developer expects the
code to run.

There is a Fix-It to remove '>=' to ease adopting the new syntax.

Swift SVN r28025
2015-05-01 05:34:10 +00:00
Devin Coughlin
a3c4a8cd50 Add '*' wildcard to #os()
On platforms that are not explicitly mentioned in the #os() guard, this new '*'
availability check generates a version comparison against the minimum deployment target.

This construct, based on feedback from API review, is designed to ease porting
to new platforms. Because new platforms typically branch from
existing platforms, the wildcard allows an API availability check to do the "right"
thing (executing the guarded branch accessing newer APIs) on the new platform without
requiring a modification to every availability guard in the program.

So, if the programmer writes:

  if #os(OSX >= 10.10, *) {
  . . .
  }

and then ports the code to iOS, the body will execute.

We still do compile-time availability checking with '*', so the compiler will
emit errors for references to potentially unavailable symbols in the body when compiled
for iOS.

We require a '*' clause on all #os() guards to force developers to
"future proof" their availability checks against the introduction of new a platform.

Swift SVN r26988
2015-04-04 21:03:20 +00:00
Dmitri Hrybenko
8fdd6aca87 Fix warnings about falling off the end of a function without a return
Swift SVN r22317
2014-09-27 23:34:22 +00:00
Devin Coughlin
5a9ccc5ab2 Add ASTDumper support for AvailabilityQueryExpr
This patch also moves some static utility methods involving PlatformKind out of Attr.h and into PlatformKind.h.


Swift SVN r21896
2014-09-12 00:13:48 +00:00
Devin Coughlin
ab563d6ef1 Add availability query expression (#os(...))to the AST
This commit adds a new expression (AvailabilityQueryExpr) and a single kind of
specification for when a block of code or function is available
(VersionConstraintAvailabilitySpec). We may add more kinds of specifications
in the future. At the moment, the AvailabilityQueryExpr allows only a
single platform to be queried; I will add support for multiple platforms
in a later commit.

This commit contains just the added AST nodes; no parsing, type checking, etc.
I’ve added assert(false && “Unimplemented”) for places where support for
AvailabilityQueryExpr will need to be added later.



Swift SVN r21760
2014-09-06 02:11:02 +00:00