Commit Graph

3458 Commits

Author SHA1 Message Date
Hamish Knight
526dcfbe11 [AST] Factor out AccessorDecl::createParsed
Move the logic for splicing together the
accessor's parameter list out of the parser so
that ASTGen will be able to use it too.
2023-12-15 21:44:30 +00:00
Hamish Knight
b04d5d5abc [ASTGen] Better handle pattern binding entries
Generate all entries, and ensure we introduce a
PatternBindingInitializer context for non-local
cases. Also use this opportunity to cleanup
`PatternBindingDecl::create`.
2023-12-15 21:44:30 +00:00
Hamish Knight
f10365597d [AST] Use PatternBindingDecl::createImplicit in more places
And simplify the implementation of `create`.
2023-12-15 21:44:30 +00:00
Doug Gregor
ab5ab28010 Merge pull request #70454 from DougGregor/full-typed-throws-inference
[Typed throws] Implement thrown type inference for do..catch within closures
2023-12-14 16:09:33 -08:00
Kavon Farvardin
64226fbcba Merge pull request #70452 from kavon/fix-typelowering
[NCGenerics] fix type lowering
2023-12-14 11:38:55 -08:00
Kavon Farvardin
4657fa9d48 [NCGenerics] fix type lowering
TypeDecl::canBeNoncopyable is never going to be fully accurate. In this
instance, we were incorrectly treating some types like `S<T: ~Copyable>`
 as noncopyable, and thus non-trivial, despite them in some cases being
 Copyable.
2023-12-14 08:45:27 -08:00
Becca Royal-Gordon
e9672194b4 Merge pull request #69468 from beccadax/c-implementation
Make @objcImpl work with @_cdecl
2023-12-14 00:36:12 -08:00
Doug Gregor
e1be9c312b Eliminate the DeclContext from ExplicitCaughtTypeRequest
Correctly determining the DeclContext needed for an
ExplicitCaughtTypeRequest is tricky for a number of callers, and
mistakes here can easily lead to redundant computation of the caught
type, redundant diagnostics, etc.

Instead, put a `DeclContext` into `DoCatchStmt`, because that's the
only catch node that needs a `DeclContext` but does not have one.
2023-12-13 11:42:56 -08:00
Becca Royal-Gordon
5aa932fba4 Tweak syntax for VC++ support 2023-12-13 11:09:50 -08:00
Becca Royal-Gordon
6591d4ea82 [NFC] Add accessor for @_cdecl name
It also reads the C name out of imported C functions, which will be convenient for @cdecl @implementation.
2023-12-13 11:09:50 -08:00
Becca Royal-Gordon
8651af4325 Make @objcImpl work with @_cdecl
No real diagnostics yet, but we’re emitting mostly correct code.
2023-12-13 11:09:49 -08:00
Doug Gregor
2cf7b3a063 Merge pull request #70426 from DougGregor/catch-node-refinement
Tighten CatchNode from an AbstractClosureExpr to a ClosureExpr.
2023-12-13 02:32:21 -08:00
Doug Gregor
25faa002a4 Merge pull request #70397 from DougGregor/cleanup-caught-error-type
[Typed throws] Cleanups for the caught error type computation
2023-12-12 23:13:00 -08:00
Doug Gregor
05a4a822ba Tighten CatchNode from an AbstractClosureExpr to a ClosureExpr.
Only real closures can have thrown error types, so we can use the
tighter bound for closures and simplify various CatchNode operations.
2023-12-12 22:30:18 -08:00
Doug Gregor
3369e3349f [Typed throws] Handle explicitly-specified throws on do..catch in closures
Teach the constraint system to use the same primitives as elsewhere to
determine the type context for a `throw` statement and the caught
error type within a `do..catch` statement. This makes
explicitly-specified `throws` work on `do..catch` that occurs in
closures.

Cleans up some redundant computations for caught error types.
2023-12-12 00:06:17 -08:00
Doug Gregor
91df336a4d [Typed throws] Unify ThrownTypeRequest and DoCatchExplicitThrownTypeRequest
These two requests are effectively doing the same thing to two
different cases within CatchNode. Unify the requests into a single
request, ExplicitCaughtTypeRequest, which operates on a CatchNode.

This also moves the logic for closures with explicitly-specified throws
clauses into the same request, taking it out of the constraint system.
2023-12-12 00:06:17 -08:00
Michael Gottesman
f328e7893b [region-isolation] Add support for representing ApplyIsolationCrossing at the SIL level on apply, begin_apply, try_apply.
Some notes:

This is not emitted by SILGen. This is just intended to be used so I can write
SIL test cases for transfer non sendable. I did this by adding an
ActorIsolationCrossing field to all FullApplySites rather than adding it into
the type system on a callee. The reason that this makes sense from a modeling
perspective is that an actor isolation crossing is a caller concept since it is
describing a difference in between the caller's and callee's isolation. As a
bonus it makes this a less viral change.

For simplicity, I made it so that the isolation is represented as an optional
modifier on the instructions:

  apply [callee_isolation=XXXX] [caller_isolation=XXXX]

where XXXX is a printed representation of the actor isolation.

When neither callee or caller isolation is specified then the
ApplyIsolationCrossing is std::nullopt. If only one is specified, we make the
other one ActorIsolation::Unspecified.

This required me to move ActorIsolationCrossing from AST/Expr.h ->
AST/ActorIsolation.h to work around compilation issues... Arguably that is where
it should exist anyways so it made sense.

rdar://118521597
2023-12-11 19:27:27 -06:00
Holly Borla
e4436bac7e Merge pull request #70348 from hborla/cxx-generic-subscript
[cxx-interop] Allow imported subscript to have generic parameters.
2023-12-10 13:51:25 -08:00
Kavon Farvardin
a4a6c69e97 Merge pull request #70277 from kavon/inverse-escapable
[NCGenerics] add `~Escapable`
2023-12-10 05:42:24 -08:00
Kavon Farvardin
e99ce1cc5d [NCGenerics] add ~Escapable
Basic implementation of `~Escapable` in the type system.

rdar://119216918
2023-12-10 01:25:43 -08:00
Holly Borla
450e59c797 [cxx-interop] Allow imported subscript to have generic parameters. 2023-12-08 21:26:11 -08:00
Zhiyu Zhu/朱智语
5767e8f6d1 [Macros] Support module-qualified attached macro lookup (#69457)
Allow attached macro expansion syntax to have a module qualifier, `@Foo.Bar`.

rdar: //108621205
2023-12-08 15:57:51 -08:00
Hamish Knight
5e7854f46b [AST] Remove static loc and spelling kind from AccessorDecl
The spelling kind was only ever set to
`StaticSpellingKind::None`, and the static location
was never used for anything (and should be queried
on the storage anyway). This doesn't affect the
computation of `isStatic` since `IsStaticRequest`
already takes the static-ness from the storage for
accessors.
2023-12-08 17:59:44 +00:00
Sima Nerush
b6d0afba1f Merge pull request #67594 from simanerush/simanerush/pack-iteration-impl
[SE-0408] Enable Pack Iteration
2023-12-07 17:09:48 -08:00
Meghana Gupta
9a4bb7337a Merge pull request #70263 from meg-gupta/resultdependson
Add support for _resultDependsOn
2023-12-06 22:12:23 -08:00
Doug Gregor
12cb8becc6 Merge pull request #70283 from DougGregor/typed-try-force-and-opt 2023-12-06 21:26:50 -08:00
Meghana Gupta
b6326f5f24 Add initial support for _resultDependsOn
These attributes are used to establish lifetime dependence between
argument and the result.

Add them under NonEscapableTypes experimental feature
2023-12-06 16:38:38 -08:00
Doug Gregor
49b05cec84 [Typed throws] Make try? and try! into catch nodes
Both `try?` and `try!` are catch nodes, because they catch an error
thrown in their subexpression and handle it. Introduce an ASTScope for
all `try/try?/try1` expressions so we can find them, and model them as
catch nodes.

Fixes rdar://119216455.
2023-12-06 15:00:58 -08:00
Doug Gregor
fbd5cb42cd Merge pull request #70247 from DougGregor/body-macro-as-brace-stmt
Macro expansion refactoring for preamble and body macros
2023-12-05 21:47:05 -08:00
Meghana Gupta
6442e914a0 Merge pull request #70244 from meg-gupta/removeselfaccesskind
Remove SelfAccessKind::ResultDependsOnSelf
2023-12-05 18:30:32 -08:00
Doug Gregor
dd80cf79e6 [Macros] Parse body macro expansion as a single brace statement
Now that the macro expansion machinery is wrapping the contents of a
body macro in curly braces, parse it as a single brace statement. This
has the advantage of giving us real locations for `{` and `}` rather
than synthesizing them, and simplifies the implementation of macro
body expansion somewhat.
2023-12-05 13:55:50 -08:00
Sima Nerush
5832181077 Sema 2023-12-03 21:51:22 -08:00
Doug Gregor
cfe2b3c87d [Typed throws] Implement support for do throws(...) syntax
During the review of SE-0413, typed throws, the notion of a `do throws`
syntax for `do..catch` blocks came up. Implement that syntax and
semantics, as a way to explicitly specify the type of error that is
thrown from the `do` body in `do..catch` statement.
2023-12-02 07:37:47 -08:00
Robert Widmann
db28fc8adb Merge pull request #70100 from CodaFi/cereal-milk
Don't Serialize Declarations with `package` Access
2023-12-01 13:48:21 -07:00
Doug Gregor
5405f1a8e6 Merge pull request #70128 from DougGregor/preamble-macros-introducing-names
Allow preamble macros to introduce declarations with documented names
2023-11-30 18:39:37 -08:00
Doug Gregor
1c158b5ac4 Allow preamble macros to introduce declarations with documented names
Preamble macros introduce code at the beginning of a function body.
Allow them to introduce declarations as well, so long as the macro
declaration properly declares the names it introduces. This allows all
sorts of exciting macros that introduce (e.g.) new local variables
that one can use.
2023-11-30 11:30:12 -08:00
Kavon Farvardin
81ea9981c8 Merge pull request #69842 from kavon/ncgenerics-stdlib-building
[NCGenerics] more work towards getting the stdlib building
2023-11-29 17:31:45 -08:00
Robert Widmann
a987ba48d0 Don't Serialize Declarations with package Access
This accidentally started happening when I adjusted getEffectiveAccess to return `Public` for `Package` declarations in #69709. As a result, the optimizer thought it had more opportunities to go after declarations that used to be opaque. Unfortunately, this resulted in a miscompile as the devirtualizer was able to look through now-serialized package (static) functions. In one specific instance, the optimizer created direct calls to hidden accessors instead of going through the dispatch thunk.
2023-11-29 14:09:48 -07:00
Meghana Gupta
fd588ab509 Remove SelfAccessKind::ResultDependsOnSelf 2023-11-29 12:11:57 -08:00
Doug Gregor
36a2dcd927 Implement function body macros
Function body macros allow one to introduce a function body for a
particular function, either providing a body for a function that
doesn't have one, or wholesale replacing the body of a function that
was written with a new one.
2023-11-27 17:04:55 -08:00
Alex Hoppen
6ac7915dae Merge pull request #70013 from ahoppen/ahoppen/remove-leaveclosurebodiesunchecked
[Sema] Remove `LeaveClosureBodiesUnchecked`
2023-11-27 14:03:18 -08:00
Holly Borla
bd61b66754 Merge pull request #69974 from hborla/isolated-default-value-fixes
[SE-0411] Fixes for isolated default values.
2023-11-27 12:51:27 -08:00
Doug Gregor
19d578e72f Fix preprocessor metaprogramming for experimental attached macro roles 2023-11-26 23:03:10 -08:00
Doug Gregor
236418dbf8 Make the "typechecked function body" request more central and resilient
The "typechecked function body" request was defined to type-check a
function body that is known to be present, and not skipped, and would
assert these conditions, requiring its users to check whether a body
was expected. Often, this means that callers would use `getBody()`
instead, which retrieves the underlying value in whatever form it
happens to be, and assume it has been mutated appropriately.

Make the "typechecked function body" request, triggered by
`getTypecheckedBody()`, more resilient and central. A `NULL` result is
now acceptable, signifying that there is no body. Clients will need to
tolerate NULL results.

* When there is no body but should be one, produce an appropriate
error.
* When there shouldn't be a body but is, produce an appropriate error
* Handle skipping of function bodies here, rather than elsewhere.

Over time, we should move clients off of `getBody` and `hasBody`
entirely, and toward `getTypecheckedBody` or some yet-to-be-introduced
forms like `getBodyAsWritten` for the pre-typechecked body.
2023-11-26 09:09:29 -08:00
Doug Gregor
6fa556b35d Preprocessor metaprogramming for mangling of macros
Yet more preprocessor metaprogramming to eliminate per-macro-role boilerplate
in the compiler. This time, focused on mangling, demangling, and remangling
of the accessor macro roles.
2023-11-25 10:20:33 -08:00
Doug Gregor
737ef9b0cd Fix macro role metaprogramming for experimental attached macros 2023-11-25 10:20:31 -08:00
Alex Hoppen
b603a5e9a0 [Sema] Remove LeaveClosureBodiesUnchecked
This shouldn’t be needed anymore since we migrated code completion to be solver-based.

rdar://91403086
2023-11-23 11:41:29 -08:00
Holly Borla
e9750bc4e5 [Concurrency] Diagnose default values whose isolation differs from the corresponding
stored property.
2023-11-16 23:56:08 -05:00
Allan Shortlidge
84098f9fb1 Sema: Always mark initializers of lazy vars as subsumed.
Previously, the initializer expressions of lazy vars would only be marked as
subsumed when the getter body for the var was synthesized. This didn't work
with `-experimental-lazy-typechecking` since accessor synthesis was not
guaranteed to happen. Consequently, SILGen would emit the initializer even
though it was already subsumed and then assert/crash since the init had also
not been checked and contextualized. Now lazy var inits are marked subsumed in
the request creating storage.

Resolves rdar://118421753
2023-11-16 18:01:54 -08:00
Allan Shortlidge
8d7cf970a5 AST: Refactor pattern binding initializer expression state representation.
As a follow up to https://github.com/apple/swift/pull/69841, clarify the
possible states that initializer expression of a pattern can be in. The
possible states are not checked, checked, and "checked and contextualized"
(which is the new state that was introduced and requestified in the previous
PR). This refactoring encodes the states more explicitly and renames a few
compiler APIs to better align with the new naming. NFC.
2023-11-16 10:06:47 -08:00