Commit Graph

1278 Commits

Author SHA1 Message Date
Hamish Knight
a40f1abaff Introduce if/switch expressions
Introduce SingleValueStmtExpr, which allows the
embedding of a statement in an expression context.
This then allows us to parse and type-check `if`
and `switch` statements as expressions, gated
behind the `IfSwitchExpression` experimental
feature for now. In the future,
SingleValueStmtExpr could also be used for e.g
`do` expressions.

For now, only single expression branches are
supported for producing a value from an
`if`/`switch` expression, and each branch is
type-checked independently. A multi-statement
branch may only appear if it ends with a `throw`,
and it may not `break`, `continue`, or `return`.

The placement of `if`/`switch` expressions is also
currently limited by a syntactic use diagnostic.
Currently they're only allowed in bindings,
assignments, throws, and returns. But this could
be lifted in the future if desired.
2023-02-01 15:30:18 +00:00
Pavel Yaskevich
51b2481091 [AST] Expand TypeJoin expression to support joining over a type
(cherry picked from commit 4efc35a76c)
2023-02-01 15:13:58 +00:00
Alex Hoppen
4169f937d0 [AST] Fail an assertion when printing a TypeVariableType with an unknown originator 2023-02-01 10:29:06 +01:00
John McCall
d25a8aec8b Add explicit lowering for value packs and pack expansions.
- SILPackType carries whether the elements are stored directly
  in the pack, which we're not currently using in the lowering,
  but it's probably something we'll want in the final ABI.
  Having this also makes it clear that we're doing the right
  thing with substitution and element lowering.  I also toyed
  with making this a scalar type, which made it necessary in
  various places, although eventually I pulled back to the
  design where we always use packs as addresses.

- Pack boundaries are a core ABI concept, so the lowering has
  to wrap parameter pack expansions up as packs.  There are huge
  unimplemented holes here where the abstraction pattern will
  need to tell us how many elements to gather into the pack,
  but a naive approach is good enough to get things off the
  ground.

- Pack conventions are related to the existing parameter and
  result conventions, but they're different on enough grounds
  that they deserve to be separated.
2023-01-29 03:29:06 -05:00
Doug Gregor
6e3289d4d5 [Macros] Compute discriminators for freestanding macro expansions.
Introduce discriminators into freestanding macro expansion expressions
and declarations. Compute these discriminators alongside closure and
local-declaration discriminators, checking them in the AST verifier.
2023-01-25 22:03:38 -08:00
John McCall
0e3a9adc32 Add Builtin.PackIndex 2023-01-19 23:57:13 -05:00
Holly Borla
3f462f0f43 [Decl] Add MissingDecl to use for parser recovery. 2023-01-15 09:55:15 -08:00
John McCall
2afb336d79 Parse Pack{...} types in SIL mode
This is needed for general fidelity in SIL, since generic argument
lists are used for a lot of different things that aren't restricted
from containing multiple packs.  I haven't actually done the work to
use Pack structure to disambiguate the resolution of pack parameters,
but this is a good start.

We'll probably need something like this in source eventually, so
there's no reason to regret adding all the infrastructure for it.
2023-01-11 03:11:30 -05:00
Holly Borla
74bf2f3e7a [AST] Introduce a syntactic distinction betweek vararg type reprs and
pack expansion type reprs.

Classic variadic parameters still use the postfix ellipsis syntax, and
pack expansion types now use a prefix 'repeat' keyword.
2023-01-07 09:50:11 -08:00
Anthony Latsis
1bb407ac8c [NFC] AST: Rename ComponentIdentTypeReprIdentTypeRepr 2023-01-07 07:15:36 +03:00
Anthony Latsis
746c7aff7d [NFC] AST: Rename CompoundIdentTypeReprMemberTypeRepr 2023-01-07 07:14:41 +03:00
Anthony Latsis
7be645e2de [NFC] Remove some uses of CompoundIdentTypeRepr::getComponents 2023-01-07 07:11:30 +03:00
Anthony Latsis
2113e175f5 [NFC] AST: Remove IdentTypeRepr::ComponentRange 2023-01-07 07:11:30 +03:00
Michael Gottesman
b95fe48a90 Merge pull request #62742 from gottesmm/pr-947919228bebf49e02eae5aedb1efee8038c2b4b
[borrow-expr] Add simple support for borrow-expr and wire it up to SILGenApply
2023-01-03 08:04:33 -08:00
Michael Gottesman
947919228b [borrow-expr] Add simple support for borrow-expr but don't wire it up to anything. 2022-12-21 14:36:43 -08:00
Pavel Yaskevich
7d54af84ea [AST] RuntimeMetadata: Add new initializer context to cover runtime attrs 2022-12-20 09:45:01 -08:00
Doug Gregor
2b79371e67 Force computation of discriminators when dumping for non-debugging purposes
Some testing mechanisms depend on having closure discriminators
pre-computed when dumping the AST. When not dumping to either the
standard error or debugger output streams, trigger computation of
closure discriminators prior to dumping them.
2022-12-19 15:45:44 -08:00
Doug Gregor
402ba1492f Set closure descriminators via a request.
Rather than set closure discriminators in both the parser (for explicit
closures) and then later as part of contextualizing closures (for
autoclosures), do so via a request that sets all of the discriminators
for a given context.
2022-12-19 15:23:45 -08:00
Holly Borla
f1fd9acb23 [AST] Add 'PackElementExpr' for explicit pack elements spelled with the 'each'
keyword.
2022-12-14 20:45:51 -08:00
Slava Pestov
57eeb1894d Merge pull request #62548 from slavapestov/irgen-pack-shape
IRGen: Preliminary support for working with pack shapes
2022-12-13 22:08:54 -05:00
Slava Pestov
f711df12f5 ASTDumper: print if GenericTypeParamType is a pack 2022-12-12 23:26:33 -05:00
Holly Borla
41298c2466 [AST] Introduce PackReferenceTypeRepr for pack references spelled with
a contextual 'each' keyword.
2022-12-10 16:16:04 -08:00
Pavel Yaskevich
6989cd086f [ASTDump] NFC: Remove double printing of pattern component 2022-11-18 11:29:50 -08:00
Doug Gregor
5ab6b72604 [Macros] Turn Macro into a declaration node.
Although the declaration of macros doesn't appear in Swift source code
that uses macros, they still operate as declarations within the
language. Rework `Macro` as `MacroDecl`, a generic value declaration,
which appropriate models its place in the language.

The vast majority of this change is in extending all of the various
switches on declaration kinds to account for macros.
2022-11-13 12:21:29 -08:00
Pavel Yaskevich
f5301fb9c8 [ASTDumper] Print type variables that appear in substitution maps 2022-11-08 16:43:27 -08:00
Robert Widmann
7944635f2e Merge pull request #61898 from CodaFi/i-write-syns-not-tragedies 2022-11-04 08:20:47 -07:00
Robert Widmann
2d07f382c5 Delete _InternalSwiftSyntaxParser And Its Build Infrastructure
This is the start of the removal of the C++ implementation of libSyntax
in favor of the new Swift Parser and Swift Syntax libraries. Now that
the Swift Parser has switched the SwiftSyntaxParser library over to
being a thin wrapper around the Swift Parser, there is no longer any
reason we need to retain any libSyntax infrastructure in the swift
compiler.

As a first step, delete the infrastructure that builds
lib_InternalSwiftSyntaxParser and convert any scripts that mention
it to instead mention the static mirror libraries. The --swiftsyntax
build-script flag has been retained and will now just execute the
SwiftSyntax and Swift Parser builds with the just-built tools.
2022-11-02 10:35:29 -07:00
Slava Pestov
44e6cb1d12 Merge pull request #61856 from slavapestov/remove-abstract-type-param-decl
Remove AbstractTypeParamDecl
2022-11-02 11:05:33 -04:00
Slava Pestov
36b3f0ee12 AST: Remove AbstractTypeParamDecl 2022-11-01 19:13:46 -04:00
Doug Gregor
0f9a70601a Parse and record top-level "items" rather than always forcing declarations.
In the Swift grammar, the top-level of a source file is a mix of three
different kinds of "items": declarations, statements, and expressions.
However, the existing parser forces all of these into declarations at
parse time, wrapping statements and expressions in TopLevelCodeDecls,
so the primary API for getting the top-level entities in source files
is based on getting declarations.

Start generalizing the representation by storing ASTNode instances at
the top level, rather than declaration pointers, updating many (but
not all!) uses of this API. The walk over declarations is a (cached)
filter to pick out all of the declarations. Existing parsed files are
unaffected (the parser still creates top-level code declarations), but
the new "macro expansion" source file kind skips creating top-level
code declarations so we get the pure parse tree. Additionally, some
generalized clients (like ASTScope lookup) will now look at the list
of items, so they'll be able to walk into statements and expressions
without the intervening TopLevelCodeDecl.

Over time, I'd like to phase out `getTopLevelDecls()` entirely,
relying on the new `getTopLevelItems()` for parsed content. We can
introduce TopLevelCodeDecls more lazily for semantic walks.
2022-11-01 08:04:15 -07:00
Becca Royal-Gordon
e79aefa39f Merge pull request #61782 from beccadax/at-implementation-2
Allow overrides in @_objcImplementation extensions
2022-10-28 11:57:48 -07:00
Doug Gregor
d6d2318dc9 [Macros] Handle macro expansion for function-like macros. 2022-10-27 17:15:30 -07:00
Becca Royal-Gordon
75965d0588 Exclude overrides from being member impls
Without this change, an `@_objcImplementation` cannot override parent class methods, because the special access control behavior breaks the access control checks for overrides.
2022-10-27 17:00:43 -07:00
Doug Gregor
6cd0327655 Merge pull request #61691 from DougGregor/macros-expand-and-type-check 2022-10-24 05:47:57 -07:00
Doug Gregor
414ef860a6 [Macros] Type-check and use the result of macro-expanding an expression macro.
Once we have expanded an expression macro, parse and type-check the
result given a priori knowledge of the expanded type. Then, create an
implicit macro-expansion expression to capture the result of the
rewrite.
2022-10-23 15:36:17 -07:00
Slava Pestov
9dfb6ea067 Merge pull request #61675 from slavapestov/element-generic-environment
AST: Opened element generic environments
2022-10-22 00:58:26 -04:00
Slava Pestov
68514b10b5 AST: Introduce ElementArchetypeType 2022-10-21 21:55:35 -04:00
Richard Wei
56e7cce809 [Macros] Parse MacroExpansionExpr and MacroExpansionDecl
Introduce `MacroExpansionExpr` and `MacroExpansionDecl` and plumb it through. Parse them in roughly the same way we parse `ObjectLiteralExpr`.

The syntax is gated under `-enable-experimental-feature Macros`.
2022-10-21 01:50:35 -07:00
Slava Pestov
da8ae1d36d Sema: Remove PackExpr 2022-10-16 21:37:25 -04:00
Slava Pestov
b3c16ea2b4 AST: Tweak printing of PackType and PackExpansionType 2022-10-16 21:37:24 -04:00
Holly Borla
9bb837a241 [AST] Rename SequenceArchetype to PackArchetype. 2022-10-10 16:25:26 -07:00
Holly Borla
67fb143f0e [AST] Remove ReifyPackExpr. 2022-10-10 16:25:26 -07:00
Holly Borla
19688cc2b1 [AST] Add the skeleton for PackExpansionExpr. 2022-10-07 20:13:18 -07:00
Holly Borla
38a2c8218b [Requirement] Rename RequirementKind::SameCount to SameShape. 2022-10-06 20:48:40 -07:00
Hamish Knight
bca941b152 [AST] NFC: Rename IfExpr -> TernaryExpr
This matches what we call it in SwiftSyntax, and
is just generally clearer.
2022-09-28 10:33:31 +01:00
Allan Shortlidge
06595f6597 Merge pull request #60852 from tshortli/parse-has-symbol
AST: Parse `#_hasSymbol`
2022-09-12 09:32:52 -07:00
Slava Pestov
c1b8690401 AST: Introduce special Builtin.TheTupleType singleton 2022-09-10 00:26:42 -04:00
Allan Shortlidge
f5f1d3c028 AST: Parse #_hasSymbol
Introduce the compiler directive `#_hasSymbol` which will be used to detect whether weakly linked symbols are present at runtime. It is intended for use in combination with `@_weakLinked import` or `-weak-link-at-target`.

```
if #_hasSymbol(foo(_:)) {
  foo(42)
}
```

Parsing only; SILGen is coming in a later commit.

Resolves rdar://99342017
2022-09-08 17:15:29 -07:00
Slava Pestov
79ed990728 AST: Replace TupleTypeRepr's ellipsis with PackExpansionTypeRepr 2022-09-07 12:35:54 -04:00
Slava Pestov
db4b4c9fa2 AST: Introduce PackExpansionTypeRepr 2022-09-07 12:35:53 -04:00