Commit Graph

937 Commits

Author SHA1 Message Date
Hamish Knight
364eba482d [AST] Use CustomAttr's DeclContext for ResolveMacroRequest
Remove the DeclContext parameter from ResolveMacroRequest, we can now
retrieve the DeclContext either from the CustomAttr or macro expansion
expr/decl directly.
2025-10-16 11:21:54 +01:00
Hamish Knight
73710e3eef [AST] Introduce Decl::addAttribute
Introduce a convenience entrypoint that also calls `attachToDecl` on
the attribute, and migrate all existing uses of `getAttrs().add` onto
it.
2025-10-16 11:21:54 +01:00
Max Desiatov
e7aac5df12 for expressions scaffolding, making constraints work 2025-10-07 11:16:54 +01:00
swift-ci
7b8b46694b Merge remote-tracking branch 'origin/main' into rebranch 2025-09-18 06:36:53 -07:00
Slava Pestov
90bfc1676d Sema: Remove some unreachable code from CSApply
I believe these code paths could only be reached by re-typechecking
invalid code in the old CSDiag implementation.
2025-09-17 16:11:53 +01:00
swift-ci
fdc5b2bc73 Merge remote-tracking branch 'origin/main' into rebranch 2025-08-14 19:55:30 -07:00
Mykola Pokhylets
89f8f8b9bf Wrap only changes related to the closure frontend logic 2025-08-02 20:24:46 +02:00
Mykola Pokhylets
ae48446716 Wrap SE-0481 into an upcoming feature until source incompatibilities are resolved 2025-08-02 20:24:21 +02:00
swift-ci
3998a187f9 Merge remote-tracking branch 'origin/main' into rebranch 2025-07-30 09:36:41 -07:00
Anthony Latsis
fec049e5e4 Address llvm::PointerUnion::{is,get} deprecations
These were deprecated in
https://github.com/llvm/llvm-project/pull/122623.
2025-07-29 18:37:48 +01:00
Anthony Latsis
c1d794364b Adjust code after changes to llvm::TrailingObjects API
See:
- https://github.com/llvm/llvm-project/pull/138970
- https://github.com/llvm/llvm-project/pull/144930
2025-07-19 01:48:18 +01:00
Slava Pestov
4d977535ff Merge pull request #82011 from slavapestov/clang-importer-assert
AST: Add assertion to BuiltinLiteralExpr::setBuiltinInitializer()
2025-06-06 02:50:57 -04:00
Slava Pestov
d7d5641487 AST: Add assertion to BuiltinLiteralExpr::setBuiltinInitializer()
I just spent way too long debugging an issue where a null pointer
was passed here, and SILGen crashed much later.
2025-06-04 23:51:46 -04:00
Mykola Pokhylets
de3a87c0ab Merge branch 'main' into mpokhylets/weak-let 2025-05-23 17:26:49 +02:00
Hamish Knight
edca7c85ad Adopt ABORT throughout the compiler
Convert a bunch of places where we're dumping to stderr and calling
`abort` over to using `ABORT` such that the message gets printed to
the pretty stack trace. This ensures it gets picked up by
CrashReporter.
2025-05-19 20:55:01 +01:00
Mykola Pokhylets
3e0de8672a Removed the feature and made changes unconditional 2025-05-15 10:52:09 +02:00
Mykola Pokhylets
49b706a811 Added experimental feature to allow weak let and immutable weak captures 2025-05-15 10:26:26 +02:00
Alejandro Alonso
ae355007fc Store TypeRepr in TypeValueExpr 2025-04-14 15:33:08 -07:00
Alejandro Alonso
b3f3dd79cf Handle dynamically accessing the static member from type(of:) 2025-04-14 15:32:46 -07:00
Hamish Knight
d958c0e080 [AST] Introduce Expr::isAlwaysLeftFolded
Use this to query for `try`-like expressions when it comes to binary
operator folding.
2025-04-02 12:29:45 +01:00
Holly Borla
be670da373 Merge pull request #79980 from hborla/closure-body-macro
[Macros] Implement support for function body macros on closures.
2025-03-21 06:19:36 -07:00
Amritpan Kaur
978a5215d5 [Expr/AST] Add apply component to handle resolved method arguments. 2025-03-19 08:56:03 -07:00
Amritpan Kaur
0c614e09d1 [Expr/AST] Add unresolvedApply component to handle method arguments. 2025-03-19 08:56:03 -07:00
Amritpan Kaur
2583da94b2 [NFC] Generalize subscript index handling. 2025-03-19 08:53:18 -07:00
Holly Borla
31d4f661fc [Macros] Support function body macros on closures. 2025-03-18 20:50:47 -07:00
Erik Eckstein
d225c47d25 AST: rename OpenArchetypeType -> ExistentialArchetypeType
NFC
2025-03-11 20:21:46 +01:00
Hamish Knight
714c862d37 Merge pull request #79631 from hamishknight/up-to-spec
[AST] Look through specializations in `getDirectCallee`
2025-02-26 18:58:48 +00:00
Hamish Knight
96ae3fdb11 [AST] Look through specializations in getDirectCallee
This results in better recovery and fixes an assertion failure in
cases where we're attempting to diagnose a failure with the call.

rdar://145593552
2025-02-26 10:02:55 +00:00
Alejandro Alonso
15c32e117b Directly store GTPD in TypeValueExpr 2025-02-25 14:11:55 -08:00
Rintaro Ishizaki
0ced6e06b4 [ASTGen] Generate CaptureListExpr
Move the capture list entry construction logic to
CaptureListEntry::createParsed() so that ASTGen can use it.
2025-02-16 05:22:46 -08:00
Doug Gregor
eab7c6aa29 Disable the crash in non-asserts builds when closures don't have a discriminator
We found another case where we aren't getting a closure discriminator,
so disable this again in non-asserts builds while we investigate.
Tracked by rdar://143590572.
2025-02-14 13:34:19 -08:00
Doug Gregor
ede7bfe1e8 Merge pull request #78554 from DougGregor/unsafe-effect 2025-01-10 23:51:29 -08:00
Doug Gregor
4ed008cf06 Assign fallback discriminators within top-level closures.
Fixes rdar://142425569.
2025-01-10 15:05:01 -08:00
Doug Gregor
8bb5bbedbc Implement an unsafe expression to cover uses of unsafe constructs
Introduce an `unsafe` expression akin to `try` and `await` that notes
that there are unsafe constructs in the expression to the right-hand
side. Extend the effects checker to also check for unsafety along with
throwing and async operations. This will result in diagnostics like
the following:

    10 |   func sum() -> Int {
    11 |     withUnsafeBufferPointer { buffer in
    12 |       let value = buffer[0]
       |                   |     `- note: reference to unsafe subscript 'subscript(_:)'
       |                   |- warning: expression uses unsafe constructs but is not marked with 'unsafe'
       |                   `- note: reference to parameter 'buffer' involves unsafe type 'UnsafeBufferPointer<Int>'
    13 |       tryWithP(X())
    14 |       return fastAdd(buffer.baseAddress, buffer.count)

These will come with a Fix-It that inserts `unsafe` into the proper
place. There's also a warning that appears when `unsafe` doesn't cover
any unsafe code, making it easier to clean up extraneous `unsafe`.

This approach requires that `@unsafe` be present on any declaration
that involves unsafe constructs within its signature. Outside of the
signature, the `unsafe` expression is used to identify unsafe code.
2025-01-10 10:39:14 -08:00
Slava Pestov
74f8960bd8 Sema: Remove OneWayExpr and Builtin.one_way 2024-12-21 00:42:13 -08:00
Pavel Yaskevich
1a5f00b205 [AST] Add a new implicit conversion to model unsafe casts
`UnsafeCastExpr` - A special kind of conversion that performs an unsafe
bitcast from one type to the other.

Note that this is an unsafe operation and type-checker is allowed to
use this only in a limited number of cases like: `any Sendable` -> `Any`
conversions in some positions, covariant conversions of function and
function result types.
2024-12-11 11:40:28 -08:00
Hamish Knight
c4efa0d5f0 [AST] Factor out Expr::getNameLoc
There are a bunch of AST nodes that can have
associated DeclNameLocs, make sure we cover them
all. I don't think this makes a difference for
`unwrapPropertyWrapperParameterTypes` since the
extra cases should be invalid, but for cursor info
it ensures we handle UnresolvedMemberExprs.
2024-12-05 15:55:19 +00:00
Hamish Knight
73fb36f371 [AST] Split out "is compound" bit on FunctionRefInfo
FunctionRefKind was originally designed to represent
the handling needed for argument labels on function
references, in which the unapplied and compound cases
are effectively the same. However it has since been
adopted in a bunch of other places where the
spelling of the function reference is entirely
orthogonal to the application level.

Split out the application level from the
"is compound" bit. Should be NFC. I've left some
FIXMEs for non-NFC changes that I'll address in a
follow-up.
2024-12-02 14:11:33 +00:00
Hamish Knight
a4d51419ba [AST] NFC: Rename FunctionRefKind -> FunctionRefInfo 2024-12-02 14:11:32 +00:00
Doug Gregor
1769ae9113 Only create ErrorExpr when the CallerSideDefaultArgExprRequest is cyclic
Right now, we're creating a bunch of throwaway ErrorExpr nodes in the AST.
2024-11-13 21:19:40 -08:00
Hamish Knight
9d4a78678a [Sema] Add logic to diagnose regex feature availability
Add the necessary compiler-side logic to allow
the regex parsing library to hand back a set of
features for a regex literal, which can then be
diagnosed by ExprAvailabilityWalker if the
availability context isn't sufficient. No tests
as this only adds the necessary infrastructure,
we don't yet hand back the features from the regex
parsing library.
2024-10-28 17:09:47 +00:00
Hamish Knight
7c3f965578 Merge pull request #76979 from hamishknight/regex-request
Requestify regex pattern parsing
2024-10-12 19:19:09 +01:00
Hamish Knight
6a435960b7 Requestify regex pattern parsing
Instead of doing the pattern parsing in both the
C++ parser and ASTGen, factor out the parsing into
a request that returns the pattern to emit, regex
type, and version. This can then be lazily run
during type-checking.
2024-10-11 19:25:58 +01:00
Anthony Latsis
41adfec8da [NFC] AST, Sema: Move TypeChecker::findReturnStatements into AnyFunctionRef
Also rename it to `getExplicitReturnStmts` for clarity and have it
take a `SmallVector` out parameter instead as a small optimization and
to discourage use of this new method as an alternative to
`AnyFunctionRef::bodyHasExplicitReturnStmt`.
2024-10-11 03:57:43 +03:00
Anthony Latsis
c7ea672463 [NFC] AST, Sema: Internalize BraceHasReturnRequest evaluation in AnyFunctionRef method 2024-10-11 03:44:43 +03:00
Doug Gregor
05e8140c6d Provide macro module name in MacroExpansionExpr creation
This properly passes the module name through from attached macros to
the freestanding macro that are used under-the-hood for type checking.
2024-09-16 16:44:17 -07:00
Hamish Knight
3367d8b3d1 [Sema] Remove workaround from TypeExpr::createForSpecializedDecl
This no longer seems to be necessary now that we
eagerly open UnboundGenericTypes in
`resolveTypeReferenceInExpression`.
2024-09-13 11:30:06 +01:00
Alejandro Alonso
0df42e9841 Lower UDRE to TypeValue if it references a value generic 2024-09-04 15:13:29 -07:00
Alejandro Alonso
75c2cbf593 Implement value generics
Some requirement machine work

Rename requirement to Value

Rename more things to Value

Fix integer checking for requirement

some docs and parser changes

Minor fixes
2024-09-04 15:13:25 -07:00
Tim Kientzle
1098054291 Merge branch 'main' into tbkka-assertions2 2024-06-18 17:52:00 -07:00