Commit Graph

2410 Commits

Author SHA1 Message Date
Holly Borla
d09ea98ba6 [GenericEnvironment] Add helper methods to map pack interface types to
element archetypes, and element interface types to pack archetypes.
2022-10-26 00:04:56 -07:00
Holly Borla
1ab9f8f7c6 [AST] Add helper methods to GenericTypeParamType for converting a given type
parameter to and from a pack type parameter.
2022-10-26 00:04:56 -07:00
Holly Borla
25eb9efc60 Merge pull request #61678 from hborla/pack-expansion-expression-checking
[Sema] Implement basic type checking for pack expansion expressions.
2022-10-25 08:07:59 -07:00
Holly Borla
7354ad30c3 [ConstraintSystem] Use opened element types for opaque values in pack expansions. 2022-10-24 18:11:00 -07:00
Doug Gregor
6cd0327655 Merge pull request #61691 from DougGregor/macros-expand-and-type-check 2022-10-24 05:47:57 -07:00
Holly Borla
596edde3ef [CSApply] Implement coerceToType for pack expansion expressions. 2022-10-23 22:44:22 -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
Doug Gregor
f04fd94465 [Macros] Separate out the expansion of macros into its own source file.
Once we've expanded a macro, create a new source buffer containing
the expanded macro contents.
2022-10-23 14:53:11 -07:00
Holly Borla
dab3b64c99 [ConstraintSystem] Implement basic type checking for pack expressions.
During prechecking, postfix '...' expressions are rewritten to pack
expansion expressions if the operand contains pack references. References
to packs are replaced with opaque values, and the pack expansion stores
the opaque value bindings to decl refs.
2022-10-22 13:41:48 -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
Doug Gregor
9979bb0e0a [Macros] Pass evaluated macro source back into the C++ part of the compiler.
Use this to print out the rewritten macro, for now.
2022-10-21 06:41:06 -07:00
Doug Gregor
636e6d1524 [Macros] "Expand" builtin macros for magic literals.
Introduce an experimental option `BuiltinMacros` that takes the magic
literals (`#file`, `#line`, `#function`, etc.) after type checking and
processes the original source for the expression using the build
syntactic macro system in the swift-syntax library. At present, the
result of expansion is printed to standard output, but it's enough to
verify that we're able to find the corresponding syntax node based on
the C++ AST.
2022-10-21 06:41:05 -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
Slava Pestov
5a9e43e657 AST: Re-implement transformWithPosition()'s handling of pack expansions with new utilities 2022-10-16 21:37:25 -04:00
Slava Pestov
ee8f45c41b Sema: More useful 'unhandled coercion' assertion 2022-10-16 21:37:25 -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
464e54aa02 Merge pull request #61523 from hborla/pack-expansion-expr
[AST] Add the skeleton for `PackExpansionExpr`.
2022-10-10 11:22:05 -07:00
Joe Groff
7a0e642596 Merge pull request #61374 from jckarter/single-closure-for-dynamic-metatype-static-partial-applications
Sema: Use capture list to represent dynamic metatype bases for partial applications.
2022-10-10 09:52:14 -07:00
Holly Borla
19688cc2b1 [AST] Add the skeleton for PackExpansionExpr. 2022-10-07 20:13:18 -07:00
Pavel Yaskevich
e696b759c3 [CSGen/CSApply] Use targets to handle boolean conditions
Remove adhoc constraint generation and solution application
logic from `CK_Boolean` handling and use `SolutionApplicationTarget`
instead.
2022-10-05 10:12:49 -07:00
Pavel Yaskevich
cfdcdf9f03 [CSApply] Remove extraneous setExprTypes from pattern binding conditions
All the types are going to be introduced to the AST by `rewriteTarget`.
2022-10-04 22:01:34 -07:00
Pavel Yaskevich
7bcd8ff203 [Sema] TypeWrappers: Replace self. with _storage. for immutable properties
Immutable properties cannot be re-assigned and don't have setters
which means that we cannot use `assign_by_wrapper` instruction to
handle `let` properties, but we can use a direct reference to
`_storage` property instead when immutable property appears as an
assignment destination and let read references go through a getter
still.
2022-10-04 13:24:46 -07:00
Allan Shortlidge
f810eb0818 Merge pull request #61316 from tshortli/accept-has-symbol-in-closures
Sema: Accept `if #_hasSymbol()` conditions in closure contexts
2022-09-30 09:02:35 -07:00
Anthony Latsis
18156d1177 Merge pull request #61347 from AnthonyLatsis/migrate-compiler-to-gh-issues
Gardening: Migrate compiler sources to GitHub issues
2022-09-30 10:48:52 +03:00
Joe Groff
a7e4e61ce2 Sema: Use capture list to represent dynamic metatype bases for partial applications. 2022-09-29 15:04:21 -07:00
Anthony Latsis
2843e0c871 Gardening: Migrate compiler sources to GitHub issues 2022-09-29 23:58:55 +03:00
Allan Shortlidge
8729801eb4 Sema: Store an 'invalid' bit in PoundHasSymbolInfo to avoid repeated if #_hasSymbol diagnostics. 2022-09-29 11:47:30 -07:00
Allan Shortlidge
034e53ad20 Sema: Accept if #_hasSymbol() conditions in closure contexts.
Resolves rdar://100129165
2022-09-29 10:55:08 -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
Joe Groff
d4b690cfd3 Merge pull request #61302 from jckarter/single-closure-for-all-static-partial-applications
Sema: Form all static member partial applications with one closure
2022-09-26 19:52:20 -07:00
Joe Groff
cef7ecc122 Sema: Form all static member partial applications with one closure.
There was a special case here to type-check `T.init` as a single closure
`{ args.. in T.init(args..) }`, but really, we can do that for any static
member applied to a static metatype base, including operators.

Also fix SILGen's function conversion peephole so it looks through
`as (T...) -> U` coercions that don't involve bridging.
2022-09-26 14:19:56 -07:00
Joe Groff
6463d96df0 Sema: Use AutoClosureExpr again in KeyPathExpr-as-function expansion
Remove the preallocated closure discriminator from KeyPathExpr and go back
to expanding them using an AutoClosureExpr inside of a CaptureListExpr now
that that's supported. This allows the discriminator to be assigned during
type checking without disturbing the indexing of explicit closure literals.
2022-09-23 10:26:18 -07:00
Joe Groff
a6a486c60b Merge pull request #61253 from jckarter/key-path-literal-as-function-ast-optimization-2
Sema: Simplify AST representation of key path literals as functions. [take 2]
2022-09-22 15:59:41 -07:00
Joe Groff
c6b6787f74 Sema: Simplify AST representation of key path literals as functions.
Previously, we would turn a key path literal like `\.foo` in function type
context into a double-wrapped closure like this:

```
  foo(\.x) // before type checking
  foo({ $kp$ in { $0[$kp$] } }(\.x)) // after type checking
```

in order to preserve the evaluation semantics of the key path literal. This
works but leads to some awkward raw SIL generated out of SILGen which misses
out on various SILGen peepholes and requires a fair number of passes to clean
up. The semantics can still be preserved with a single layer of closure, by
using a capture list:

```
  foo({[$kp$ = \.x] in $0[$kp$] }) // after type checking
```

which generates better natural code out of SILGen, and is also (IMO) easier
to understand on human inspection.

Changing the AST representation did lead to a change in code generation that
interfered with the efficacy of CapturePropagation of key path literals; for
key path literals used as nonescaping closures, a mark_dependence of the
nonescaping function value on the key path was left behind, leaving the key
path object alive. The dependence is severed by the specialization done in
the pass, so update the pass to eliminate the dependence.

Compared to the previous patch, this version removes the attempt to have
the type-checked function expression carry the noescape-ness of its context,
and allows for coerceToType to introduce a function conversion instead, since
that FunctionConversionExpr is apparently load-bearing for default argument
generators.
2022-09-22 12:00:22 -07:00
Artem Chikin
b8c1b4b3d0 Revert "Sema: Simplify AST representation of key path literals as functions." 2022-09-22 09:54:22 -07:00
Joe Groff
ddd154b637 Merge pull request #61213 from jckarter/key-path-literal-as-function-ast-optimization
Sema: Simplify AST representation of key path literals as functions.
2022-09-21 14:12:17 -07:00
Joe Groff
57553878f8 Sema: Simplify AST representation of key path literals as functions.
Previously, we would turn a key path literal like `\.foo` in function type
context into a double-wrapped closure like this:

  foo(\.x) // before type checking
  foo({ $kp$ in { $0[$kp$] } }(\.x)) // after type checking

in order to preserve the evaluation semantics of the key path literal. This
works but leads to some awkward raw SIL generated out of SILGen which misses
out on various SILGen peepholes and requires a fair number of passes to clean
up. The semantics can still be preserved with a single layer of closure, by
using a capture list:

  foo({[$kp$ = \.x] in $0[$kp$] }) // after type checking

which generates better natural code out of SILGen, and is also (IMO) easier
to understand on human inspection.

Changing the AST representation did lead to a change in code generation that
interfered with the efficacy of CapturePropagation of key path literals; for
key path literals used as nonescaping closures, a mark_dependence of the
nonescaping function value on the key path was left behind, leaving the key
path object alive. The dependence is severed by the specialization done in
the pass, so update the pass to eliminate the dependence.
2022-09-21 09:40:30 -07:00
Pavel Yaskevich
ad5fdf75ae Merge pull request #61066 from LucianoPAlmeida/diagnose-operator-crash
[Sema] Add param indicate diagnose or not in lookupPrecedenceGroupForInfixOperator
2022-09-14 15:33:10 -07:00
Luciano Almeida
2b5054f2be [Sema] Add param indicate diagnose or not in lookupPrecedenceGroupForInfixOperator 2022-09-13 21:43:43 -03:00
Hamish Knight
4716f61fba [AST] Introduce explicit actions for ASTWalker
Replace the use of bool and pointer returns for
`walkToXXXPre`/`walkToXXXPost`, and instead use
explicit actions such as `Action::Continue(E)`,
`Action::SkipChildren(E)`, and `Action::Stop()`.
There are also conditional variants, e.g
`Action::SkipChildrenIf`, `Action::VisitChildrenIf`,
and `Action::StopIf`.

There is still more work that can be done here, in
particular:

- SourceEntityWalker still needs to be migrated.
- Some uses of `return false` in pre-visitation
methods can likely now be replaced by
`Action::Stop`.
- We still use bool and pointer returns internally
within the ASTWalker traversal, which could likely
be improved.

But I'm leaving those as future work for now as
this patch is already large enough.
2022-09-13 10:35:29 +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
Luciano Almeida
7300fb5836 [Sema] Improve diagnostic for closure return contextual mismatch 2022-09-04 22:28:49 -03:00
Slava Pestov
8345088bdf Merge pull request #60738 from slavapestov/open-existential-in-self-super-init
Sema: Fix existential opening for arguments to self.init/super.init delegation
2022-08-31 11:21:44 -04:00