Commit Graph

2489 Commits

Author SHA1 Message Date
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
swift-ci
a66951aa3d Merge pull request #60521 from kavon/preconcurrency-var-access
Add missing function conversion for member access to preconcurrency vardecl.
2022-08-30 00:58:49 -07:00
Kavon Farvardin
6c24bc57cb [AST][SILGen] model ABI-safe casts of LValues
We needed a way to describe an ABI-safe cast of an address
representing an LValue to implement `@preconcurrency` and
its injection of casts during accesses of members.

This new AST node, `ABISafeConversionExpr` models what is
essentially an `unchecked_addr_cast` in SIL when accessing
the LVAlue.

As of now I simply implemented it and the verification of
the node for the concurrency needs to ensure that it's not
misused by accident. If it finds use outside of that,
feel free to update the verifier.
2022-08-29 20:58:26 -07:00
Kavon Farvardin
e70fbbc738 [ConstraintSystem] correct the @preconcurrency adjustment of var references
We intended to introduce AST conversions that strip concurrency
attributes off of types associated with `@preconcurrency` decls.
But for VarDecl references, we stripped it too early, leading to
things like a MemberVarDecl that doesn't have `@Sendable` in its
result type, but the VarDecl it refers to does have it.

That caused crashes in SIL where types didn't match up. This patch
fixes things by delaying the stripping until the right point.

resolves rdar://98018067
2022-08-29 20:58:25 -07:00
Pavel Yaskevich
932c6b40c5 [ConstraintSystem] Don't use special locator for value-to-value conversions related to contextual type
Previously locator for value-to-value conversion would just drop
all the contextual information if the conversion occurred while
converting expression to a contextual type. This is incorrect for
i.e. `return` statements and other targets because because they
are solved separately and using the same locator would result in
a clash when solutions are merged.
2022-08-25 14:33:03 -07:00
Pavel Yaskevich
b23f1c23e9 [CSApply] Adjust contextual locator of single expression closure before coercion
Contextual conversion constraint is placed on `result of closure body`
and solution application logic should match that.
2022-08-25 14:32:13 -07:00
Slava Pestov
40c2678e38 Sema: Fix existential opening for arguments to self.init/super.init delegation
Fixes rdar://problem/98404682.
2022-08-24 00:24:55 -04:00
Pavel Yaskevich
b02e16de07 Merge pull request #60568 from xedin/rdar-98577451
[CSApply] Attempt value-to-opaque-result abstraction only after canon…
2022-08-16 09:47:42 -07:00
Pavel Yaskevich
b4949a0b2c [CSApply] Attempt value-to-opaque-result abstraction only after canonicalization
`ExprRewriter::coerceToType` should canonicalize contextual type before
attempting to use it for value abstraction, because sugared type could
have typealias references that hide their underlying opaque result types.

Resolves: rdar://98577451
2022-08-15 21:30:17 -07:00
Pavel Yaskevich
7bcb8d4a93 Merge pull request #60541 from xedin/fix-opened-type-printing
[ConstraintSystem] NFC: Check whether opened type has a binding befor…
2022-08-15 09:27:55 -07:00
Hamish Knight
76931677a8 Merge pull request #60438 from hamishknight/factor-in-factor-out 2022-08-13 17:21:37 +01:00
Pavel Yaskevich
389cfe7f65 [ConstraintSystem] NFC: Check whether opened type has a binding before printing
In some circumstances opened type might not have a fixed binding.
A good example could be dependent sub-component produced for
result builder transformed code (connected via one-way constraints),
in such a case `OpenedTypes` would have outer generic parameters
but they might not be bound yet, so they have to be printed as
type variables.
2022-08-12 17:29:29 -07:00
Pavel Yaskevich
42135e27c4 Merge pull request #60387 from amritpan/improve-solution-printing
[ConstraintSystem] Improve solution printing in the type inference algorithm debug output
2022-08-10 09:03:29 -07:00
Amritpan Kaur
2786f24b67 [TypeCheckConstraints.cpp] Remove printing of any empty constraint choice headings and fix minor spacing issues. 2022-08-09 14:09:39 -07:00
Hamish Knight
6b9bcf3935 [AST] Change DotSyntaxCallExpr to take an Argument base
This allows us to more easily propagate inout
information to it, which will become a necessity
once InOutExpr is removed.
2022-08-08 15:11:00 +01:00
Pavel Yaskevich
5ee5a22cf1 [TypeChecker] NFC: Add a dedicated method to get outermost attached wrapper
The outermost wrapper is the one at index `0` in the wrapper list
but it's easy for humans to make a reverse assumption since outermost
is the back of the list. Let's add a dedicated method to reduce error
probability of the property wrapper APIs.
2022-08-04 17:30:02 -07:00
Pavel Yaskevich
3e65a7cab0 Merge pull request #60065 from xedin/result-builder-ast-transform-under-flag
[TypeChecker] Implement result builder transform via AST modification under a flag
2022-08-02 16:22:01 -07:00
Pavel Yaskevich
432ce1cf4e [ConstraintSystem] Allow placeholder vars to have initializer and nested holes
Initializers of such variables are going to be type-checked post factum,
when the type of the variable itself has been determined by the solver.
2022-08-02 11:41:40 -07:00
Pavel Yaskevich
a6421fc94e [CSClosure] Declarations prefixed with $ can act as inferrable placeholders
If the type for such declaration could be completely inferred it
would be used during solution application. This is used to infer
types for result builder components.
2022-08-02 11:41:40 -07:00
Pavel Yaskevich
65aeb4ad89 [CSSolver] Add support for TypeJoinExpr 2022-08-02 11:41:35 -07:00
Hamish Knight
9da53193da [AST] Remove ParameterTypeFlags from ParenType and TupleType
The last clients that relied on stashing parameter
type flags on these types are now gone.
2022-08-02 13:56:32 +01:00
Hamish Knight
77b00821aa [CS] Remove an obsolete bit of logic
SILGen shouldn't care whether or not a self
parameter is wrapped in a paren with ownership.
2022-08-02 13:56:32 +01:00