Commit Graph

921 Commits

Author SHA1 Message Date
Doug Gregor
200f2340d9 [Macros] Be deliberate about walking macro arguments vs. expansions
Provide ASTWalker with a customization point to specify whether to
check macro arguments (which are type checked but never emitted), the
macro expansion (which is the result of applying the macro and is
actually emitted into the source), or both. Provide answers for the
~115 different ASTWalker visitors throughout the code base.

Fixes rdar://104042945, which concerns checking of effects in
macro arguments---which we shouldn't do.
2023-02-28 17:48:23 -08:00
Anthony Latsis
107ae6d589 Merge pull request #63784 from AnthonyLatsis/sugar-type-members-4
PreCheckExpr: Recognize non-identifier type qualifiers in type expressions
2023-02-23 21:19:43 +03:00
Anthony Latsis
00d09b118b AST: Allow passing arbitrary parent TypeRepr to TypeExpr::createForMemberDecl 2023-02-22 21:32:11 +03:00
Slava Pestov
e0c341d0ac AST: Rename PackReferenceTypeRepr => PackElementTypeRepr 2023-02-15 22:37:07 -05:00
Hamish Knight
c87b1b8bef Merge pull request #63022 from hamishknight/express-yourself 2023-02-03 16:40:09 +00:00
Hamish Knight
0d55f45d95 [Sema] Error on redundant try/awaits for if/switch expressions
Look through `try`/`await` markers when looking for
out of place if/switch expressions, and customize
the effect checking diagnostic such that we error
that `try`/`await` are redundant on `if`/`switch`
expressions.
2023-02-01 15:30:19 +00:00
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
2d1588a9d2 [CSClosure] Allocate temporary type-join and opaque value exprs in solver arena
(cherry picked from commit f3df7ab31b)
2023-02-01 15:13:58 +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
Holly Borla
7c50f95e1b [Macros] Use MacroExpansionExpr when resolving attached and freestanding macros. 2023-01-31 09:27:06 -08:00
Doug Gregor
4e50e29f3d Merge pull request #63233 from DougGregor/macros-mangle-buffer-names
[Macros] Mangle the names of macro expansion buffers
2023-01-26 06:57:15 -08:00
Pavel Yaskevich
7e0f02ac40 Merge pull request #62724 from valeriyvan/Formatting
Add check against NULL before dereferencing pointer
2023-01-26 00:24:47 -08:00
Doug Gregor
4ae434eaa1 [Macros] Add a mangling for macro expansions
These aren't ABI, but are useful to provide consistent names to refer
to macro expansions, e.g., in buffer names.
2023-01-25 22:45:14 -08:00
Doug Gregor
72ddbebc08 [Macros] Assign macro expansion discriminators more lazily.
This is a punt. They'll be unique, and they'll be per-context, but
they'll be lazy and therefore not stable.
2023-01-25 22:03:38 -08: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
Doug Gregor
08c5553ac3 Merge pull request #62911 from DougGregor/parent-source-file-in-generated-buffers
Teach DeclContext::getParentSourceFile() to return the innermost source file
2023-01-08 21:56:51 -08:00
Doug Gregor
dfa3ed910d Teach DeclContext::getParentSourceFile() to return the innermost source file
With macro expansions, and really any code generation that produces
proper source locations, the parent source file of a declaration
context will be a generated source file rather than the source file
near the top of the declaration-context stack. Adjust the
implementation of `getParentSourceFile()` to return that innermost
source file by doing location-based lookup.
2023-01-08 11:40:02 -08:00
Holly Borla
89fa17d74c [Parser] Replace postfix ellipsis with a prefix 'repeat' keyword for pack
expansion expressions, and create them in the parser instead of during
pre-checking in the constraint system.
2023-01-07 09:49:14 -08:00
Holly Borla
ab4ec2b6cb [AST] Remove trailing pack elements from PackExpansionExpr.
This wasn't used, and callers can instead use getExpandedPacks, which
also includes TypeReprs.
2023-01-07 09:49:14 -08:00
Anthony Latsis
1bb407ac8c [NFC] AST: Rename ComponentIdentTypeReprIdentTypeRepr 2023-01-07 07:15:36 +03:00
Anthony Latsis
ad5d55c36e [NFC] AST: Rename IdentTypeReprDeclRefTypeRepr 2023-01-07 07:14:44 +03:00
Anthony Latsis
746c7aff7d [NFC] AST: Rename CompoundIdentTypeReprMemberTypeRepr 2023-01-07 07:14:41 +03:00
Anthony Latsis
0c3a72d4d7 [NFC] CompoundIdentTypeRepr: Supplant getComponents with getBaseComponent & getMemberComponents
Also store the base component separately as an arbitrary `TypeRepr`.
2023-01-07 07:11:30 +03:00
Anthony Latsis
2113e175f5 [NFC] AST: Remove IdentTypeRepr::ComponentRange 2023-01-07 07:11:30 +03:00
Anthony Latsis
8935acdd5b [NFC] AST: Remove IdentTypeRepr::create 2023-01-07 07:11:29 +03:00
Valeriy Van
694c99883f Remove AbstractClosureExpr::hasBody() not needed anymore as suggested in review 2023-01-04 12:38:10 +02:00
eeckstein
bc2bb5bf7a Merge pull request #62771 from eeckstein/debug-info
Some small debug-info fixes
2023-01-04 11:24:39 +01: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
Erik Eckstein
8dbbfabea5 AST: add debug locations for generated IntegerLiteralExprs 2023-01-02 13:52:21 +01: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
Holly Borla
42ede18fb0 Merge pull request #62713 from hborla/open-pack-element-type-repr
[ConstraintSystem] Enable pack element type reprs in expressions.
2022-12-21 10:48:42 -05:00
Holly Borla
b977adfbdb [AST] Add a helper method to PackExpansionExpr that gathers all packs
that are expanded within the pattern.
2022-12-20 22:32:29 -05:00
Doug Gregor
c951497f9c Fall-back assignment of closure discriminators in ill-formed code
There are some cases of severely malformed code where we cannot compute
closure discriminators appropriate. Introduce a fallback to use the
unstable global numbering of discriminators in this case.
2022-12-19 15:52:42 -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
42020792c6 [Sema] Represent pack element references in pack expansion patterns as
PackElementExpr.
2022-12-14 20:45:52 -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
Doug Gregor
b29fcb4e58 [Macros] Parse macro declarations fully, and treat them as normal declarations 2022-11-28 18:32:43 -08:00
Doug Gregor
787af41765 [Macros] Parse generic arguments in macro expansions. 2022-11-17 16:46:43 -08:00
Robert Widmann
91c262bcb7 Move TokenKinds.def.gyb to AST 2022-11-16 13:38:25 -08:00
Pavel Yaskevich
70072a07ba Merge pull request #62122 from LucianoPAlmeida/fix-literal-dictionary-int
[Sema] printConstExprValue should consider negative signal when print number literals
2022-11-16 08:59:23 -08:00
Doug Gregor
9b10b0bde2 [Macros] Add pretty stack traces for macro expansions. 2022-11-15 15:00:52 -08:00
Luciano Almeida
4fb0e1c1f1 [Sema] printConstExprValue should consider negative signal when print number literals 2022-11-15 18:50:26 -03:00
Holly Borla
7354ad30c3 [ConstraintSystem] Use opened element types for opaque values in pack expansions. 2022-10-24 18:11:00 -07:00
Holly Borla
7f43001682 [AST] Store opaque value bindings in PackExpansionExpr. 2022-10-22 13:41:48 -07: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
fff224e2e7 Sema: Fix opening an existential argument to a 'try self.init()' delegation
Fixes rdar://problem/101098777.
2022-10-18 12:10:24 -04:00
Slava Pestov
da8ae1d36d Sema: Remove PackExpr 2022-10-16 21:37:25 -04: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
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