Commit Graph

779 Commits

Author SHA1 Message Date
Anthony Latsis
3d3b1ca50a [NFC] AST: Turn getParameterList into a method on ValueDecl 2025-03-19 18:49:15 +00:00
Amritpan Kaur
555a486cda [Mangler] Add new mangling schemes. 2025-03-19 10:54:06 -07:00
Holly Borla
31d4f661fc [Macros] Support function body macros on closures. 2025-03-18 20:50:47 -07:00
Tony Allevato
68876a6d4a Merge pull request #76636 from allevato/rich-identifiers
Support raw identifiers (backtick-delimited identifiers containing non-identifier characters).
2025-03-12 14:56:14 -04:00
Tony Allevato
97d9ca1a20 Preserve existing printing/mangling behavior for C++ specializations.
Imported C++ template specializations receive identifiers that contain
their type signature; e.g., `X<Y, Z>`. Since this means the identifier
contains non-identifier characters, the new behavior was trying to
escape them with backticks in ASTPrinter, ASTMangler, and the runtime
metadata. This pulls that back to preserve the current behavior for
specifically those types.
2025-03-11 17:26:26 -04:00
Tony Allevato
d94bd80c62 Add support for raw identifiers.
Raw identifiers are backtick-delimited identifiers that can contain any
non-identifier character other than the backtick itself, CR, LF, or other
non-printable ASCII code units, and which are also not composed entirely
of operator characters.
2025-03-11 17:18:43 -04:00
Erik Eckstein
d225c47d25 AST: rename OpenArchetypeType -> ExistentialArchetypeType
NFC
2025-03-11 20:21:46 +01:00
Rintaro Ishizaki
002d7d7cdf [Parse/AST] Remove PoundDiagnosticDecl
There is no reson to make a AST node for '#error' and '#warning'
directives. Parser knows the diagnostics should be emitted or not.
2025-03-07 21:48:01 -08:00
Slava Pestov
3a33b9a29c Merge pull request #79780 from slavapestov/fix-rdar145954323
AST: Allow mangling LocatableType in DWARF mode
2025-03-05 03:12:09 -05:00
Slava Pestov
a03b8ee6aa AST: Allow mangling LocatableType in DWARF mode
Fixes rdar://problem/145954323.
2025-03-04 22:00:44 -05:00
Artem Chikin
de26e960e2 Rename '_const' attribute to 'CompileTimeLiteral'
To pave the way for the new experimental feature which will operate on '@const' attribute and expand the scope of what's currently handled by '_const' without breaking compatibility, for now.
2025-03-04 07:30:02 -08:00
Hamish Knight
994848f6e5 [Mangler] Handle local archetypes in getDeclTypeForMangling
Element archetypes can occur here when mangling the USR for local
variables for e.g SourceKit cursor info, as well as for regular
compilation for things like lazy variables.

Update `getDeclTypeForMangling` to map local archetypes out of
context, using both the captured generic environments and the
archetypes present in the type. More work is needed to support lazy
variable though (now it crashes in SILGen).

This patch doesn't handle mangling standalone element archetypes for
e.g `printTypeUSR`, ideally we'd fix the clients there to not pass
local archetypes.

rdar://143077965
2025-02-26 11:51:20 +00:00
Pavel Yaskevich
1067ead82c [Mangling] Mangle presence of @execution(caller) in a function type
If `@execution(caller)` attribute is present on a function type,
mark its presence in the mangling with `YC` suffix.
2025-02-19 16:48:41 -08:00
Pavel Yaskevich
cdb5396c00 [AST] Declare NonIsolatedCaller as kind of FunctionTypeIsolation
This would make sure that async function types marked as `@execution(caller)`
have correct isolation.

Also defines all of the possible conversions to and from `caller`
isolated function types.
2025-02-13 14:35:54 -08:00
Anthony Latsis
34f9b80cbc Merge pull request #78750 from AnthonyLatsis/oryza-sativa
[Gardening] Fix some set but not used variables
2025-01-31 04:29:05 +00:00
John Hui
be73254cdc [cxx-interop] Import private members (#78942)
This commit removes the guardrails in ImportDecl.cpp:SwiftDeclConverter
that prevent it from importing non-public C++ members. It also
accordingly adjusts all code that assumes generated Swift decls should
be public. This commit does not import non-public inherited members;
that needs its own follow-up patch.

Note that Swift enforces stricter invariants about access levels than C++.
For instance, public typealiases cannot be assigned private underlying types,
and public functions cannot take or return private types. Meanwhile,
both of these patterns are supported in C++, where exposing private types
from a class's public interface is considered feature. As far as I am aware,
Swift was already importing such private-containing public decls from C++
already, but I added a test suite, access inversion, that checks and
documents this scenario, to ensure that it doesn't trip any assertions.
2025-01-30 14:50:15 -08:00
Anthony Latsis
a84dfc8387 [Gardening] Fix some set but not used variables 2025-01-30 21:34:38 +00:00
Michael Gottesman
9960079656 Fix misleading comment. 2025-01-15 10:43:19 -08:00
Michael Gottesman
cb2d7560a4 [rbi] Fix demangling of sending results.
The issue here is that the demangler (since we have a postfix mangling) parses
parameters/results/etc and then uses earlier postfix type arguments to attach
the relevant types to the parameters/results/etc. Since the flag for a sending
result was placed in between the parameters and results, we get an off by one
error.

Rather than fix that specific issue by introducing an offset for the off by one
error, I used the fact that the impl-function part of the mangling is not ABI
and can be modified to move the bit used to signify a sending result to before
the parameters so the whole problem is avoided.

I also while I was doing this looked through the sending result mangling for any
further issues and fixed them as I found them.

rdar://141962865
2025-01-14 15:38:02 -08:00
Augusto Noronha
70578424ca Merge pull request #78328 from augusto2112/fix-orig-def-type-in-func
[DebugInfo] Fix debug info round tripping of types inside functions
2024-12-20 20:50:25 -08:00
Augusto Noronha
398ded57f4 Remove hardcode to emit types in CompilerSwiftSyntax with ABI mod name
Now that mangling for the debugger respects originally defined in, this
is not needed anymore.
2024-12-20 16:58:53 -08:00
Becca Royal-Gordon
0f3cf62c55 Use @abi attribute in mangling
What’s implemented now is actually *far* more thorough than what the surface syntax can currently express, mainly because I can’t apply @abi to nominal types yet.
2024-12-19 15:49:34 -08:00
Augusto Noronha
72b0120b43 [DebugInfo] Fix handling of @_originallyDefinedIn types
Emit an imported declaration for @_originallyDefinedIn under the
real module that these types live in.

This patch also changes the mangling for the debugger to respect
@_originallyDefinedIn, and fixes a bug where @_originallyDefinedIn
that should be ignored was still being used when mangling.

rdar://137146961
2024-12-16 10:28:18 -08:00
Slava Pestov
d586415a6c Merge pull request #77868 from slavapestov/type-alias-type
AST: Two optimizations to speed up compile time
2024-12-07 16:31:38 -05:00
Doug Gregor
ee9c066050 Introduce a new Initializer subclass for the arguments of custom attributes
Since the introduction of custom attributes (as part of property
wrappers), we've modeled the context of expressions within these
attributes as PatternBindingInitializers. These
PatternBindingInitializers would get wired in to the variable
declarations they apply to, establishing the appropriate declaration
context hierarchy. This worked because property wrappers only every
applied to---you guessed it!---properties, so the
PatternBindingInitializer would always get filled in.

When custom attributes were extended to apply to anything for the
purposes of macros, the use of PatternBindingInitializer became less
appropriate. Specifically, the binding declaration would never get
filled in (it's always NULL), so any place in the compiler that
accesses the binding might have to deal with it being NULL, which is a
new requirement. Few did, crashes ensued.

Rather than continue to play whack-a-mole with the abused
PatternBindingInitializer, introduce a new CustomAttributeInitializer
to model the context of custom attribute arguments. When the
attributes are assigned to a declaration that has a
PatternBindingInitializer, we reparent this new initializer to the
PatternBindingInitializer. This helps separate out the logic for
custom attributes vs. actual initializers.

Fixes https://github.com/swiftlang/swift/issues/76409 / rdar://136997841
2024-12-06 17:40:32 -08:00
Slava Pestov
302b163edc AST: Optimize TypeAliasType representation 2024-12-06 17:39:55 -05:00
Doug Gregor
65a9bff5b0 Rework mangling of macro expansions in local contexts to not trigger type checking.
The mangling of macro expansions relies on having a type-checked AST
for its enclosing context. When that enclosing context is within a
local context (say, a local type), mangling would trigger type
checking of that local type, which could then involve assigning local
discriminators. However, if this happens before type checking of the
enclosing function body, we would end up failing to assign closure
discriminators to (e.g.) autoclosures within the body.

The fundamental problem here is the interaction between discriminator
assignment (which can only happen after type checking) and mangling of
macro expansion buffers (which can happen during that type checking).
Break this cycle by providing a different approach to mangling macro
expansions within local contexts as the innermost non-local context +
a name-based discriminator within that local context. These manglings
are not ABI and are not stable, so we can adjust them later if we come
up with a scheme we like better. However, by breaking this cycle, we
eliminate assertions and miscompiles that come from missing
discriminators in this case.

Fixes rdar://139734958.
2024-12-05 16:09:02 -08:00
Kuba (Brecka) Mracek
a5092f8e32 Merge pull request #77922 from kubamracek/embedded-mangling2
[ASTMangler] Drop the legacy ASTManger constructor, always require ASTContext&
2024-12-04 07:51:16 -08:00
Konrad `ktoso` Malawski
ed5007f6b1 Merge pull request #77584 from ktoso/wip-check-array-calls 2024-12-04 21:01:36 +09:00
Konrad `ktoso` Malawski
746720c67b [Distributed] additional test coverage 2024-12-04 15:18:49 +09:00
Kuba Mracek
b68b7d15fa [ASTMangler] Drop the legacy ASTManger constructor, always require ASTContext& 2024-12-03 09:03:11 -08:00
Kuba (Brecka) Mracek
8792efedf0 Merge pull request #77115 from kubamracek/embedded-mangling-prefix
[Mangling] [NFC] Prepare for a new mangling prefix for Embedded Swift: $e
2024-12-03 08:10:49 -08:00
Konrad `ktoso` Malawski
f48384bc7e [Distributed] Correct distributed accessor mangling for protocol calls
This is a crucial fix without which we can crash on some distributed
protocol declarations with @Resolvable. We cannot "just" use a String to
represent the "fake base" of the thunks, and must instead find the
$Target macro generated type and use it as the base of the thunk's
mangling.

Calls are made in such way that record for the protocol requirement:
`$s4main28GreeterDefinedSystemProtocolP5greetSSyYaKFTEHF` points at
`$$s4main29$GreeterDefinedSystemProtocolC5greetSSyYaKFTE` which makes a
dispatch through the _apropriate_ witness table.
And the record for the $witness named e.g.
`$s4main29$GreeterDefinedSystemProtocolC5greetSSyYaKFTEHF` points to
`$s4main28GreeterDefinedSystemProtocolPAA11Distributed01_F9ActorStubRzrlE5greetSSyYaKFTE`
which is an extension method: `distributed thunk (extension in main):main.GreeterDefinedSystemProtocol< where A: Distributed._DistributedActorStub>.greet() async throws -> Swift.String`,
this very specific design allows us to call the "right method" on the
recieving end of a remote call where we do not know the recipient type.
2024-12-03 14:59:15 +09:00
Kuba Mracek
576616307f [Mangling] Temporarily stage out (#ifdef out) the ASTMangler API changes and Embedded Swift prefix 2024-12-02 15:01:24 -08:00
Kuba Mracek
8a872b4a79 [Mangling] Also use the new ASTMangler::Context member in ASTMangler.cpp instead of getASTContext() calls 2024-12-02 15:01:24 -08:00
Kuba Mracek
9c77074cac [Mangling] Establish a new mangling prefix for Embedded Swift: $e 2024-12-02 15:01:24 -08:00
Kuba Mracek
6f4ae28520 [ASTMangler] Pass ASTContext to all instantiations of ASTMangler 2024-12-02 15:01:04 -08:00
Pavel Yaskevich
0fe4cea7d7 [AST] Introduce a new type that has associated location in source
This type is intended to be used to wrap compiler synthesized nodes
(i.e. variables) to make it easier for diagnostic to diagnose precise
failure locations.

Consider the situation like:

```
protocol P {}

extension Array: P where Element: P {}

func test<T: P>() -> T {
  $_a = ...
  $_b = ...
  return [$_a, $_b]
}
```

This is a common pattern with result builders.

In this case if one of the elements don't conform to `P` the best
user experience would be to attach diagnostic to the element otherwise
the developers would have to figure out where in result expression
the error occured before attempting to fix it.
2024-11-21 11:01:13 -08:00
Doug Gregor
c5de02f60e Merge pull request #77628 from DougGregor/clang-importer-parse-request
[Clang importer] Use ParseSourceFileRequest for parsing swift_attr attributes
2024-11-16 01:12:27 -08:00
Doug Gregor
24a12ebc34 Renable GeneratedSourceInfo::Attribute to GeneratedSourceInfo::AttributeFromClang 2024-11-15 09:02:49 -08:00
Slava Pestov
da5ce1289c Merge pull request #77599 from slavapestov/fix-rdar139745699
IRGen: Adjust hacks for keypaths to protocol extension members
2024-11-15 12:02:25 -05:00
Doug Gregor
989c73d014 Ensure that buffers containing Clang swift_attr attributes are parsed as attributes
Previously, they were being parsed as top-level code, which would cause
errors because there are no definitions. Introduce a new
GeneratedSourceInfo kind to mark the purpose of these buffers so the
parser can handle them appropriately.
2024-11-13 21:19:37 -08:00
Slava Pestov
0a23afcb99 IRGen: Adjust hacks for keypaths to protocol extension members
This was never implemented properly, but it works sometimes.

When the protocol is parameterized, it started crashing in a new way,
because the interface type of an existential is now derived from the
generalization signature, which will have nothing to do with the
signature that IRGen is passing in here.

Tweak the workaround to keep things limping along.

Fixes rdar://problem/139745699
2024-11-13 17:05:25 -05:00
Slava Pestov
fcd6985c53 Merge pull request #77463 from slavapestov/fix-rdar139089004
AST: Add workaround for incorrect mangling of conditional conformances with pack requirements
2024-11-08 10:45:14 -05:00
Slava Pestov
69e3aaf6fe AST: Add workaround for incorrect mangling of conditional conformances with pack requirements
I added commit 7eecf97132 a while ago
to fix a newly-added assertion failure that came up, however this
had the inadvertent side effect of changing symbol mangling and
ASTPrinter behavior.

The problem in both instances was that we would incorrectly return
certain requirements as unsatisfied when really they are satisfied.

There is nothing to fix in the ASTPrinter, because printing redundant
requirements does not change the generic signature of the extension;
they are simply dropped. I added a test to exercise the new behavior
showing that the requirements are dropped.

As for the mangler, the fix introduced an ABI break, because the
symbol name of a conformance descriptor includes its conditional
requirements, so we must preserve the redundant requirements forever.
The IRGen test has some examples of manglings that are incorrect but
must be preserved.

I'm plumbing down a flag to isRequirementSatified() to preserve
compatibility with the old behavior where we would mangle these
redundant requirements. No other callers should pass this flag,
except for the mangler.

Fixes rdar://139089004.
2024-11-07 16:28:26 -05:00
Hamish Knight
2d7500eda6 [AST] Remove ParenType
Today ParenType is used:

1. As the type of ParenExpr
2. As the payload type of an unlabeled single
   associated value enum case (and the type of
   ParenPattern).
3. As the type for an `(X)` TypeRepr

For 1, this leads to some odd behavior, e.g the
type of `(5.0 * 5).squareRoot()` is `(Double)`. For
2, we should be checking the arity of the enum case
constructor parameters and the presence of
ParenPattern respectively. Eventually we ought to
consider replacing Paren/TuplePattern with a
PatternList node, similar to ArgumentList.

3 is one case where it could be argued that there's
some utility in preserving the sugar of the type
that the user wrote. However it's really not clear
to me that this is particularly desirable since a
bunch of diagnostic logic is already stripping
ParenTypes. In cases where we care about how the
type was written in source, we really ought to be
consulting the TypeRepr.
2024-10-31 11:32:40 +00:00
Alejandro Alonso
008e6ee9f3 Merge pull request #77273 from Azoy/fix-builtin-array-reconstruct
Fix Builtin.FixedArray type reconstruction and change integer type mangling
2024-10-29 16:46:02 -07:00
Alejandro Alonso
79689be55f Change integer type mangling
Fix negative mangling
2024-10-29 09:52:22 -07:00
Alejandro Alonso
32259c18e2 Mangle value parameter markers and fix demangling value params 2024-10-28 16:54:16 -07:00
Ben Barham
746517c9f2 Merge remote-tracking branch 'origin/main' into manually-merge-main-to-rebranch
Conflicts:
  - `test/IRGen/has_symbol.swift` test updates in rebranch. The new test
    will fail, will fix in the next commit.
2024-10-24 14:20:17 -07:00