Commit Graph

2322 Commits

Author SHA1 Message Date
Rintaro Ishizaki
d4db99ce9d [Parse] Remove unnecessary dependencies to Parser.h
C++ swift::Parser is going to be replaced with SwiftParser+ASTGen.
Direct dependencies to it should be removed. Before that, remove
unnecessary '#include "swift/Parse/Parser.h"' to clarify what actually
depends on 'swift::Parser'.

Split 'swift::parseDeclName()' et al. into the dedicated files.
2024-11-02 01:23:59 -07:00
Rintaro Ishizaki
1094ae03d5 [ASTGen] Disable ExportedSourceFile for macro expanded buffers 2024-10-31 09:53:34 -07:00
Allan Shortlidge
53413dd941 AST: Add an IsForEmbedded bit to AvailableAttr.
This bit is true for attributes written as `@_unavailableInEmbedded` in source.
2024-10-30 14:29:45 -07:00
Hamish Knight
499fe6dc48 Merge pull request #77072 from hamishknight/complete-options
[IDE] Pass LangOptions to `ide::isSourceInputComplete`
2024-10-30 20:17:47 +00:00
Slava Pestov
9d85221ae5 Parse: Save and restore InFreestandingMacroArgument when delayed parsing
Closures appearing in freestanding macro arguments don't have
discriminators assigned, since we don't actually emit them.

Similarly we skip recording opaque return types that appear in macro
arguments, since they don't get emitted.

However this logic didn't take delayed parsing into account, which must
save and restore the InFreestandingMacroArgument bit correctly.

As a result, if the freestanding macro argument contained a closure
which contained a local function with a declaration that has an
opaque return type, we would crash in serialization from attempting
to mangle an opaque return type nested inside of a closure without a
discriminator.

Fixes rdar://135445004
2024-10-24 17:19:50 -04:00
Nate Chandler
f797e19a29 [Parse] Updated protocol diagnostic to allow read.
With the `CoroutineAccessors` feature, `read` is allowed along with
`get` and `set`; alter the diagnostic that's issued when a disallowed
introducer is listed in the requirement list to indicate that `read` is
one of those which are valid, but only when the feature is enabled.
2024-10-22 18:03:03 -07:00
Nate Chandler
f2e3e8e857 [Sema] Permit read requirement.
Along with `get` and `set`, permit `read` to be required.  When a type
defines `read`, the read impl is that `read`.
2024-10-22 18:02:30 -07:00
Hamish Knight
81dc7d87ed [Parse] Remove TypeChecker and SIL options parameter from ParserUnit
Providing these is a bit of a layering violation,
the parser shouldn't care about these options (there
does seem to be one current use of `TypeCheckerOpts`
in the parser for designated operator types, but
that's a legacy feature that was never officially
supported).
2024-10-17 14:04:34 +01:00
Rintaro Ishizaki
cb6372a9c4 [ASTGen] Generate EditorPlaceholderExpr and 'do' expressions 2024-10-11 09:34:41 -07:00
Meghana Gupta
a3740ae557 Disallow target specification in SIL's @lifetime
SIL's @lifetime continues to be positional. Don't parse 'target:' in this case.
2024-10-08 15:39:37 -07:00
Meghana Gupta
271143405b Don't allow space between @lifetime and '(' 2024-10-08 15:21:39 -07:00
Meghana Gupta
b443ff76e4 [NFC] Use llvm::TrailingObjects to represent variable list of lifetime sources 2024-10-08 15:11:26 -07:00
Meghana Gupta
f591680c2a Update SIL printing of @lifetime
Lifetime dependencies in SIL tests continue to be represented as a type modifier on the target.

As before, they are represented as a LifetimeDependentTypeRepr in the AST.
2024-10-08 15:10:59 -07:00
Meghana Gupta
31c1dc7eb5 Add support for specifying target in @lifetime
@lifetime(target: source1, source2...) where target can be any
parameter or 'self'. We cannot have @lifetime attributes with duplicate targets.

Also, update the internal data structures. Previously LifetimeEntry stored
pairwise (target, source) dependencies. Now, LifetimeEntry will store an optional
target descriptor and an array of source descriptors.
2024-10-08 15:10:48 -07:00
Meghana Gupta
011b5bf10c Delete dependsOn support
Lifetime dependencies will now be represented with @lifetime attribute in the language.

dependsOn is a type modifier and was represented as a LifetimeDependentTypeRepr in the AST.

I am deleting dependsOn syntax parsing support and retaining LifetimeDependentTypeRepr support.

We may want to represent lifetime dependencies in a function type with a type attribute in the future.
If we use a decl attribute instead, then support for LifetimeDependentTypeRepr can be deleted.
2024-10-07 00:24:35 -07:00
Meghana Gupta
148155710f Merge pull request #76624 from meg-gupta/lifetimedepscoped
Add support for borrow lifetime dependence
2024-10-02 13:58:14 -07:00
Alexis Laferrière
edb0b925c8 Parser: Register all availability macro definition buffers before parsing
The availability macro definitions from the command line are copied into
source buffers for parsing. Let's register all of these buffers in one go,
before starting to parse any of them. Parsing triggers using `findBuffer`
services which sorts all buffers. The new logic should ensure this
sorting happens only once for availability macros.
2024-10-01 11:27:05 -07:00
Alexis Laferrière
ff803c6df1 Sema: Move the availability macros cache to the ASTContext
The availability macros definitions are parsed from the command line and
stored in a cache. The cache was in the Parser, which would have it be
computed for each file using availability macros. Let's move it to the
ASTContext instead where it can generally be computed once per invocation
and used across the module.

rdar://134797088
2024-10-01 09:07:56 -07:00
Nate Chandler
091368ba21 [CoroutineAccessors] Added read.
The name is a placeholder for the mutating single-yield coroutine
accessor.
2024-09-26 18:10:39 -07:00
Nate Chandler
98a2e6a7df [CoroutineAccessors] Added modify.
The name is a placeholder for the mutating single-yield coroutine
accessor.
2024-09-26 18:10:39 -07:00
Nate Chandler
6f6292705e [NFC] AST: Removed dead #define.
It was once used for materializeForSet.
2024-09-25 21:06:36 -07:00
Nate Chandler
6b89f1e62b [NFC] Parse: Contextualize accessor introducer.
To the routine that parses the introducer for an accessor whether it is
would be first accessor, pass whether it would be the first accessor;
from it, return whether the accessor is from an unavailable feature.
These both enable expected behavior when an experimental feature is
disabled: the former enables maintaining source compatibility with code
that uses the introducer name as a function name which is called with a
trailing closure as the first expression in an implicit getter.  The
latter enables suppressing duplicative diagnostics.
2024-09-25 21:06:36 -07:00
Meghana Gupta
34782b750e Parse scoped lifetime dependence kind within the @lifetime attribute 2024-09-20 21:50:51 -07:00
Doug Gregor
5b2520e379 Remove IfConfigDecl from the AST
The swift-syntax tree retains information about the parsed #if
regions. Drop it from the semantic AST.
2024-09-18 20:51:54 -07:00
Doug Gregor
d762dd53f8 Stop parsing into IfConfiDecl nodes in the C++ parser
When parsing #if...#endif regions, parse the active clause directly into
place in the AST without ever producing an IfConfigDecl instance.
2024-09-18 20:51:09 -07:00
Doug Gregor
49aa0e966f Ensure that SourceFiles always have a backing buffer in the SourceManager
The "buffer ID" in a SourceFile, which is used to find the source file's
contents in the SourceManager, has always been optional. However, the
effectively every SourceFile actually does have a buffer ID, and the
vast majority of accesses to this information dereference the optional
without checking.

Update the handful of call sites that provided `nullopt` as the buffer
ID to provide a proper buffer instead. These were mostly unit tests
and testing programs, with a few places that passed a never-empty
optional through to the SourceFile constructor.

Then, remove optionality from the representation and accessors. It is
now the case that every SourceFile has a buffer ID, simplying a bunch
of code.
2024-09-16 21:46:42 -07:00
Allan Shortlidge
02dbb96b94 AST: Rename AvailabilityContext to AvailabilityRange.
The generality of the `AvailabilityContext` name made it seem like it
encapsulates more than it does. Really it just augments `VersionRange` with
additional set algebra operations that are useful for availability
computations. The `AvailabilityContext` name should be reserved for something
pulls together more than just a single version.
2024-09-13 16:25:18 -07:00
Meghana Gupta
2b011b0a3a [NFC] Rename/reorg LifetimeDependence utils 2024-09-09 22:02:44 -07:00
Meghana Gupta
e61d87c01c Add support for parsing @lifetime attribute to specify lifetime dependencies on declarations 2024-09-09 22:02:42 -07:00
Alejandro Alonso
75c2cbf593 Implement value generics
Some requirement machine work

Rename requirement to Value

Rename more things to Value

Fix integer checking for requirement

some docs and parser changes

Minor fixes
2024-09-04 15:13:25 -07:00
Ian Anderson
2a597a7e46 [Sema] Don't clear ParsedUnrecognizedPlatformName when a recognized platform is parsed
The callers of parsePlatformVersionInList need to know if an unrecognized platform was parsed in the whole list. It can get cleared in the case of (unrecognized 1.0, *) but PlatformAndVersions will still be empty.
2024-08-28 11:05:51 -07:00
Ian Anderson
8eb583c04c Merge pull request #76073 from ian-twilightcoder/unknown-platform-attr
[Sema] Allow unrecognized platforms  in @backDeployed and @_originallyDefinedIn
2024-08-27 18:27:40 -07:00
Ian Anderson
eb11ad99a1 [Sema] Allow unrecognized platforms in @backDeployed and @_originallyDefinedIn
Don't emit attr_availability_need_platform_version for a @backDeployed or @_originallyDefinedIn that have a single unrecognized platform name.
2024-08-27 14:02:37 -07:00
Doug Gregor
c241e782e0 Use SwiftIfConfig to determine where to emit new parser diagnostics 2024-08-22 22:33:53 -07:00
Doug Gregor
fc5ba4c7d5 Revert "Use SwiftIfConfig to determine where to emit new parser diagnostics"
This reverts commit 1da2631c4e.
2024-08-22 09:22:20 -07:00
Doug Gregor
1da2631c4e Use SwiftIfConfig to determine where to emit new parser diagnostics 2024-08-17 22:48:18 -07:00
Hamish Knight
e65647c559 Merge pull request #75574 from jamieQ/missing-return-diagnostics
[AST][SILOptimizer]: unify missing return diagnostics in some cases
2024-08-09 16:23:47 +01:00
Jamie
6c676c9f22 [AST][SILOptimizer]: unify missing return diagnostics in some cases
Previously, missing return diagnostics for unreachable subscripts
differed from the treatment unreachable functions received, leading to
inconsistent diagnostic behavior. This change removes the responsibility
for handling the relevant diagnostics from the AST code, in favor of the
diagnostics implemented via the SIL optimizer. Additionally, where the
AST-generation code would previously have diagnosed a missing return for
an implicit empty getter, it will now admit as valid, deferring the
missing return diagnostics to the later SIL passes.
2024-08-07 08:14:11 -05:00
Mateus Rodrigues
ac57e61278 Merge branch 'main' into trailing-comma 2024-08-06 09:34:43 -03:00
Mateus Rodrigues
e3f4228e36 Remove macro role trailing comma support 2024-08-05 15:27:44 -03:00
Hamish Knight
a657f97c9b [Parse] Avoid skipping bodies with #sourceLocation
`#sourceLocation` requires setting and restoring
state in the parser, so we cannot skip any bodies
containing `#sourceLocation` tokens. Member skipping
was already doing this, extend it to function
body skipping too.
2024-07-30 16:56:00 +01:00
Hamish Knight
1bd2a9b18b [Parse] Allow skipping member bodies following #sourceLocation
If the bodies themselves don't have a
`#sourceLocation` in them, there should be no
harm in skipping; the parsed virtual files get
recorded on the SourceManager, so will be
accessible when doing delayed parsing. The
`InPoundLineEnvironment` flag will be inaccurate,
but that's only needed for the parsing of
`#sourceLocation` itself.
2024-07-30 16:56:00 +01:00
Alejandro Alonso
ca8c90ecc0 Support movesAsLike for the array variant of @_rawLayout 2024-07-28 10:29:57 -07:00
Mateus Rodrigues
b1ba769754 Minor changes for better clarity 2024-07-25 15:30:37 -03:00
Mateus Rodrigues
e0d416cdab Ungate accepted parts of SE439 2024-07-22 09:55:16 -03:00
Meghana Gupta
8137aed238 Rename LifetimeDependentReturnTypeRepr -> LifetimeDependentTypeRepr 2024-07-10 14:20:03 -07:00
Hamish Knight
ec597c82fa [Completion] Only complete @unchecked et al in inheritance clauses
Add a case for completing type attributes in
inheritance clause position, and limit the
completion of `@unchecked`, `@preconcurrency`, and
`@retroactive` to that case.
2024-07-03 11:41:58 +01:00
Michael Gottesman
34195ff213 Merge pull request #74610 from gottesmm/pr-324fd70c13e87a329334341aae4667f2d1be152c
[sending] Remove transferring.
2024-07-02 14:02:18 -07:00
Hamish Knight
ff09cad05d [Parse] Add fix-it for unknown isolation in @isolated
Currently `any` is the only supported kind, so we
can suggest that.

rdar://130287211
2024-07-02 12:01:13 +01:00
Xiaodi Wu
e1f537107f Merge branch 'main' into trailing-comma 2024-06-29 16:36:06 -04:00