Commit Graph

779 Commits

Author SHA1 Message Date
Anton Korobeynikov
797f500286 Add basic boilerplate for AST coroutines and yields 2025-11-12 21:02:25 -08:00
Anthony Latsis
bda6edb85c AST: Rename GenericContext::isGeneric to hasGenericParamList
`isGeneric` is a misleading name because this method checks for the
existence of a `GenericParamList`, which is not implied by genericity.
2025-11-11 15:55:16 +00:00
Doug Gregor
0ac8a83051 Use correct IR name for AutoDiff mangling 2025-10-29 19:35:57 -07:00
Hamish Knight
169096c233 [AST] Rename mangleDeclAsUSR -> mangleDeclWithPrefix
This is used by other things that don't necessarily want an IDE
USR.
2025-10-23 09:11:17 +01:00
Hamish Knight
a1e1656ed5 [AST] Remove respectOriginallyDefinedIn parameter from mangleAnyDecl
This was always set to `true` except for USR mangling, where we already
have it set to `false` for IDE USRs. The other clients were:

- AutoDiff, which is just using the resulting string as a dictionary
key, so don't seem to have any preference.
- The ClangImporter, which always overrides `@_originallyDefinedIn`
anyway.
2025-10-23 09:11:17 +01:00
Hamish Knight
b607ec7a2f [AST] Introduce ASTMangler::forUSR
Rather than setting the USR-specific bits for each USR entrypoint
into the mangler just expose a convenience constructor for USR
generation that sets them.
2025-10-23 09:11:17 +01:00
Hamish Knight
401eafa9f1 [AST] NFC: Move getABIDecl onto ASTMangler 2025-10-23 09:11:17 +01:00
Meghana Gupta
06eb315612 Update mangling for borrow and mutate accessors 2025-10-20 09:05:36 -07:00
Michael Gottesman
2fa3908e94 [concurrency] Add a new type Builtin.ImplicitActor.
This is currently not wired up to anything. I am going to wire it up in
subsequent commits.

The reason why we are introducing this new Builtin type is to represent that we
are going to start stealing bits from the protocol witness table pointer of the
Optional<any Actor> that this type is bitwise compatible with. The type will
ensure that this value is only used in places where we know that it will be
properly masked out giving us certainty that this value will not be used in any
manner without it first being bit cleared and transformed back to Optional<any
Actor>.
2025-10-16 10:51:13 -07:00
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
Erik Eckstein
ea6e3c9b4d ASTMangler: make sure to mangle canonical replacement types of substitution maps
When mangling types, it's expected that the type is canonical. Except if mangling for debug info.
Fixes a crash.
2025-10-06 09:47:41 +02:00
Hamish Knight
954b08cae5 [AST] Remove UnresolvedType
We have now removed all uses of this type.
2025-10-03 09:50:42 +01:00
Meghana Gupta
c764244df0 Merge pull request #84180 from meg-gupta/borrowandmutatepr
Add preliminary support for borrow accessors
2025-09-15 10:01:15 -07:00
Egor Zhdan
5dc2817913 Merge pull request #83874 from egorzhdan/egorzhdan/redecl-context-assertion
[cxx-interop] Fix an assertion for `extern "C"` blocks
2025-09-09 23:11:39 +01:00
Meghana Gupta
1cff471c57 Introduce ResultConvention::Guaranteed and ResultConvention::GuaranteedAddress
ResultConvention::Guaranteed will be used by borrow accessors when the storage type can be returned by value.

ResultConvention::GuaranteedAddress will be used by mutate accessors and borrow accessors when the storage type
cannot be returned by value.
2025-09-09 14:45:40 -07:00
Meghana Gupta
28c4595735 Add mangling support for borrow/mutate accessors 2025-09-09 14:30:34 -07:00
Ahmed Elrefaey
1bc96857a8 Merge pull request #82464 from a7medev/feat/full-documentation-in-code-completion
[IDE] Add full documentation to code completion result
2025-09-04 10:06:21 +01:00
Janat Baig
798c0f51a4 Merge branch 'main' into temp-branch 2025-08-23 11:11:04 -04:00
Egor Zhdan
2409e33928 [cxx-interop] Fix an assertion for extern "C" blocks
rdar://158896622 / resolves https://github.com/swiftlang/swift/issues/83861
2025-08-22 17:51:38 +01:00
Pavel Yaskevich
53ef38e31b [AST] NFC: Rename function type isolation NonisolatedCaller to NonisolatedNonsending
This reduces the number of ways we refer to caller isolated async
functions and matches the name to the attribute spelling.
2025-08-05 17:22:10 -07:00
JanBaig
0dbbc8ece0 [SIL] SILDeclRef Mangling Added 2025-07-31 22:18:00 -04: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
2920ea84d1 Address llvm::(Mutable)ArrayRef ctor deprecations
See:
- https://github.com/llvm/llvm-project/pull/146113
- https://github.com/llvm/llvm-project/pull/146011
2025-07-21 12:36:53 +01:00
QuietMisdreavus
1948907eb3 use RespectOriginallyDefinedIn when mangling extension contexts (#82348)
Resolves rdar://152598492

Consider the following Swift, adapted from a real-world framework:

```swift
@available(macOS 10.8, *)
@_originallyDefinedIn(module: "another", macOS 11.0)
public struct SimpleStruct {}

@available(macOS 12.0, iOS 13.0, *)
public extension SimpleStruct {
    struct InnerStruct {}
}
```

In this scenario, `SimpleStruct` was originally in a module called
`another`, but was migrated to this module around the time of macOS
11.0. Since then, the module was ported to iOS and gained a nested type
`SimpleStruct.InnerStruct`. When mangling USRs for this nested type, the
result differs depending on whether we're targeting macOS or iOS.
They're mostly the same, but the macOS build yields a USR with an `AAE`
infix, designating that the `InnerStruct` was defined in an extension
from a module with the name of the base module. On iOS, this infix does
not exist.

The reason this is happening is because of the implementation of
`getAlternateModuleName` checking the availability spec in the
`@_originallyDefinedIn` attribute against the currently active target.
If the target matches the spec, then the alternate module name is
reported, otherwise the real module name is. Since the iOS build reports
the real module name, the mangling code doesn't bother including the
extension-context infix, instead just opting to include the parent
type's name and moving on.

This PR routes around this issue by passing the
`RespectOriginallyDefinedIn` variable to the
`ExtensionDecl::isInSameDefiningModule` method, and using that to skip
the alternate module name entirely. It also sets
`RespectOriginallyDefinedIn` to `false` in more places when mangling
USRs, but i'm not 100% confident that it was all necessary. The goal was
to make USRs more consistent across platforms, regardless of the
surrounding context.
2025-06-30 12:57:12 -06:00
Slava Pestov
9033198674 ASTDemangler: Round-trip @isolated @sil_implicit_leading_param parameter attributes
We sometimes mangle SILFunctionTypes when generating debug info
for reabstraction thunks, and these can have various exotic
parameter and result attributes. Two recent additions were
never plumbed through the mangler, causing assertion failures
when emitting debug info.

Fixes rdar://153730847.
2025-06-27 10:56:12 -04:00
Gabor Horvath
059051cf69 [cxx-interop] Fix crash in ASTMangler triggered by UsingShadowDecls
We did not handle this declaration kind. This PR introduces makes sure
we mangle it the same way we do for the target declaration.

Fixes #82108.
2025-06-10 15:50:54 +01:00
Alex Hoppen
ff483fe092 Merge pull request #81941 from ahoppen/dont-verify-mangle
[Indexing] Don't verify mangling of USRs
2025-06-06 08:36:28 +02:00
Alex Hoppen
563f971c1e [Indexing] Don't verify mangling of USRs
Verifying USR mangling adds ~30% overhead to indexing times. Since an incorrect USR mangling doesn't result in a correctness issue at the same level as a miscompile, save those 30% in non-assert builds.
2025-06-04 20:45:33 +02:00
Pavel Yaskevich
aabfebec03 [AST] Add new declaration - using
Initially this declaration is going to be used to determine
per-file default actor isolation i.e. `using @MainActor` and
`using nonisolated` but it could be extended to support other
file-global settings in the future.
2025-05-30 00:39:06 -07: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
Alejandro Alonso
9e24563bb7 Merge pull request #81365 from Azoy/my-existentials
[AST & Runtime] Correctly mangle extended existentials with inverse requirements
2025-05-12 13:21:07 -07:00
Alejandro Alonso
62eda2ca02 Update ASTMangler.cpp 2025-05-08 13:12:45 -07:00
Alejandro Alonso
bf8840bdfd Allow the mangler to disregard inverses 2025-05-08 10:17:59 -07:00
Alejandro Alonso
c165509147 Correctly emit inverse proto comps with extended shape symbolic refs 2025-04-30 13:43:01 -07:00
Slava Pestov
cf1572c65b AST: Add ASTContext::TheSelfType for convenience 2025-04-28 11:49:50 -04:00
Erik Eckstein
8e874cd2b2 SIL: add better support for specialized witness tables.
Store specialize witness tables in a separate lookup table in the module. This allows that for a normal conformance there can exist the original _and_ a specialized witness table.
Also, add a boolean property `isSpecialized` to `WitnessTable` which indicates whether the witness table is specialized or not.
2025-04-18 06:58:34 +02:00
Hamish Knight
da1d37de26 [Mangler] Avoid mangling local discriminator for attached macros
If we're using the macro-specific local discriminator, we need to
make sure we avoid mangling the regular local discriminator in
`appendDeclName`, since that could prematurely kick local discriminator
assignment before type-checking has finished.

rdar://143834482
2025-04-04 19:41:04 +01:00
Artem Chikin
281f84da0f [Compile Time Values] Rewrite the 'Diagnose Unknown Compile Time Values' diagnostic pass in Swift 2025-03-28 10:30:07 -07:00
Slava Pestov
09a4e16ac0 Merge pull request #80301 from slavapestov/subst-generic-function-type
Clean up GenericFunctionType substitution
2025-03-27 08:20:59 -04:00
Michael Gottesman
de7a62e13e Merge pull request #80312 from gottesmm/pr-126bc735b2d01c0f2f35f27268ff26d404b2fb16
[sil] Make SILFunctionTypeInfo a struct enum.
2025-03-26 18:05:57 -07:00
Slava Pestov
0c29f7f410 ASTMangler: Replace unnecessary subst() with tranformRec() 2025-03-26 20:06:06 -04:00
Becca Royal-Gordon
775bdacefc [NFC] Extract Decl::getExplicitObjCName()
Create a helper method which looks for an `@objc` attribute with an explicit name and returns it, and adopt it in various existing places.
2025-03-26 10:47:12 -07:00
Becca Royal-Gordon
d8349e72ca [NFC] Expose default param specifier computation
Make this logic accessible outside of the mangler.
2025-03-26 10:47:12 -07:00
Michael Gottesman
8cfb029b5c [sil] Make SILFunctionTypeInfo a struct enum.
I am doing this in preparation for adding the ability to represent in the SIL
type system that a function is global actor isolated. Since we have isolated
parameters in SIL, we do not need to represent parameter, nonisolated, or
nonisolated caller in the type system. So this should be sufficient for our
purposes.

I am adding this since I need to ensure that we mangle into thunks that convert
execution(caller) functions to `global actor` functions what the global actor
is. Otherwise, we cannot tell the difference in between such a thunk and a thunk
that converts execution(caller) to execution(concurrent).
2025-03-26 10:23:44 -07:00
Anthony Latsis
631a04e56c Merge pull request #80159 from AnthonyLatsis/danaus-plexippus-5
Sema: Extend adoption mode for `AsyncCallerExecution` to storage declarations
2025-03-26 04:40:58 +00:00
Slava Pestov
37d867f21c AST: Fix incorrect handling of @_originallyDefinedIn(module: "Swift", ...) 2025-03-24 17:56:45 -04:00
Doug Gregor
731f58443c Address review feedback on AbstractConformance in ProtocolConformanceRef 2025-03-23 20:54:39 -07:00
Doug Gregor
2a7de1b559 Store the conforming type within an abstract ProtocolConformanceRef
An "abstract" ProtocolConformanceRef is a conformance of a type
parameter or archetype to a given protocol. Previously, we would only
store the protocol requirement itself---but not track the actual
conforming type, requiring clients of ProtocolConformanceRef to keep
track of this information separately.

Record the conforming type as part of an abstract ProtocolConformanceRef,
so that clients will be able to recover it later. This is handled by a uniqued
AbstractConformance structure, so that ProtocolConformanceRef itself stays one
pointer.

There remain a small number of places where we create an abstract
ProtocolConformanceRef with a null type. We'll want to chip away at
those and establish some stronger invariants on the abstract conformance
in the future.
2025-03-23 20:53:48 -07:00
Hamish Knight
f8ab391737 Introduce type sugar for InlineArray (#80087)
* [CS] Decline to handle InlineArray in shrink

Previously we would try the contextual type `(<int>, <element>)`,
which is wrong. Given we want to eliminate shrink, let's just bail.

* [Sema] Sink `ValueMatchVisitor` into `applyUnboundGenericArguments`

Make sure it's called for sugar code paths too. Also let's just always
run it since it should be a pretty cheap check.

* [Sema] Diagnose passing integer to non-integer type parameter

This was previously missed, though would have been diagnosed later
as a requirement failure.

* [Parse] Split up `canParseType` 

While here, address the FIXME in `canParseTypeSimpleOrComposition`
and only check to see if we can parse a type-simple, including
`each`, `some`, and `any` for better recovery.

* Introduce type sugar for InlineArray

Parse e.g `[3 x Int]` as type sugar for InlineArray. Gated behind
an experimental feature flag for now.
2025-03-23 15:31:37 -07: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