Commit Graph

5795 Commits

Author SHA1 Message Date
Nate Chandler
8c48ca2e8c [OpaqueValues] Addr-only consumes emit loadably. 2023-08-22 11:18:44 -07:00
Michael Gottesman
8cfb3d238f [silgen] Cleanup a few Cleanups dump output. 2023-08-19 14:11:44 -07:00
Michael Gottesman
7c5c548968 [silgen] Fix PartialDestroyPackCleanup dumping output to handle LimitWithinComponent to be nullptr. 2023-08-19 14:11:44 -07:00
Michael Gottesman
543063ef0e [silgen] Make ManagedValue::forUnmanaged private and change users to use other more specific APIs.
I have been doing this over the past couple of days in preparation for changing
ManagedValue to specify the type of scope its cleanup is connected to.
2023-08-19 14:11:44 -07:00
Michael Gottesman
104379adab [silgen] Rename SILGenFunction::emitManagedRetain -> emitManagedCopy.
This is an old API that should have been renamed a long time ago. It just kept
its early name due to inertia.
2023-08-19 14:11:44 -07:00
zachary0kent
802e63a778 Merge pull request #67973 from zachary0kent/lazy-immediate-globals
[Immediate] JIT'ing Globals
2023-08-18 08:53:18 -07:00
Zak Kent
6aafeec181 [Immediate] [SILGen] Implement on-demand compilation of globals 2023-08-17 11:03:11 -07:00
Allan Shortlidge
d062489344 SILGen: Don't reference external property descriptors for @backDeployed properties.
The property descriptors of `@backDeployed` properties aren't available on OSes
prior to the "back deployed before" OS version, so the descriptors cannot be
referenced by clients that may run against older versions of the library
that defines the property.

See https://github.com/apple/swift/pull/59214 for prior art.

Resolves rdar://106517386
2023-08-16 23:19:15 -07:00
Doug Gregor
b126a0f34b Merge pull request #67977 from DougGregor/extension-macro-conformances-and-witnesses
[Macros] Fix handling of extension macro conformances and witnesses
2023-08-16 22:46:06 -07:00
zachary0kent
25f078adb5 Merge branch 'main' into lazy-immediate 2023-08-16 19:45:27 -07:00
Doug Gregor
b7bfaf3522 [Macros] Fix handling of extension macro conformances and witnesses
Fix two inter-related issues with extension macros that provide
conformances to a protocol, the combined effect of which is that one
cannot meaningfully provide extension macros that implement
conformances to a protocol like Equatable or Hashable that also
supports auto-synthesis.

The first issue involves name lookup of operators provided by macro
expansions. The logic for performing qualified lookup in addition to
unqualified lookup (for operators) did not account for extension
macros in the same manner as it did for member macros, so we would not
find a macro-produced operator (such as operator==) in witness
matching.

The second issue is more fundamental, which is that the conformance
lookup table would create `NormalProtocolConformance` instances for
pre-macro-expansion conformance entries, even though these should
always have been superseded by explicit conformances within the macro
expansion buffers. The end result is that we could end up with two
`NormalProtocolConformance` records for the same conformance. Some
code was taught to ignore the pre-expansion placeholder conformances,
other code was not. Instead, we now refuse to create a
`NormalProtocolConformance` for the pre-expansion entries, and remove
all of the special-case checks for this, so we always using the
superseding explicit conformances produced by the macro expansions (or
error if the macros don't produce them).

Fixes rdar://113994346 / https://github.com/apple/swift/issues/66348
2023-08-16 19:18:36 -07:00
Michael Gottesman
4581eb7f35 Merge pull request #67965 from gottesmm/pr-80bd06d8a243366f1ba0f2d7b358215aa28bf517
[silgen] Add a new private API on CleanupManager called isFormalAccessCleanup
2023-08-16 17:39:59 -07:00
Pavel Yaskevich
c38b9b1e08 Merge pull request #67945 from xedin/remove-runtimeMetadata
[Frontend] NFC: Remove code and tests related to rejected @runtimeMetadata feature
2023-08-16 17:16:46 -07:00
Michael Gottesman
a897257d06 [silgen] Add a new private API on CleanupManager called isFormalAccessCleanup.
I am going to use this in ManagedValue.
2023-08-16 11:12:20 -07:00
Michael Gottesman
d7be3993dc Merge pull request #67943 from gottesmm/pr-c5eb72c4d397b9ab4e8a1b477187c3b7b059f540
[silgen] Convert even more cases of using trivial and values without ownership to use for*RValueWithoutOwnership APIs.
2023-08-15 17:02:36 -07:00
Pavel Yaskevich
23d838af32 [SIL/SILGen] [AST] NFC: Remove @runtimeMetadata related code 2023-08-15 12:17:31 -07:00
Michael Gottesman
ff948f7309 [silgen] Convert even more cases of using trivial and values without ownership to use for*RValueWithoutOwnership APIs. 2023-08-15 11:04:01 -07:00
John McCall
66ea1f1ddd [NFC] Fix an oversight in my previous NFC patches
This is starting to feel a little spaghetti-ish.  This kind of
existential stuff is hard to do in C++.
2023-08-14 22:29:27 -04:00
John McCall
127acfa686 [NFC] Share argument order and names between the arguments and results code
This was an annoying change, but mostly mechanical.  The goal here is
to create parallel structure between the two paths so that it isn't
utterly confusing to share common CRTP paths between them.  The renaming
of translate->process is just to make sure that all of the call sites
get correctly rewritten.
2023-08-14 21:48:13 -04:00
John McCall
bcb6230302 [NFC] Extract a lot of common expansion logic out of ResultPlanner 2023-08-14 19:06:49 -04:00
John McCall
939270c573 [NFC] More prep work for sharing code between param and result reabstraction 2023-08-14 19:06:49 -04:00
John McCall
c2207c6608 [NFC] Fold PlanData into the main ResultBuilder in SILGenPoly
I'm trying to create more parallel structure between the param
and result reabstraction code so that, hopefully, some of the
basic explosion reasoning can be shared.
2023-08-14 19:06:49 -04:00
Zak Kent
17fedabb5e [Immediate] Implemented SwiftMaterializationUnit
Implemented SwiftMaterializationUnit, supporting
lazy compilation of individual Swift functions.
2023-08-14 13:28:22 -07:00
nate-chandler
c3fb1377a0 Merge pull request #67752 from nate-chandler/opaque-values/20230804/1/any-hashable-var
[OpaqueValues] Emit RValue of AnyHashable erasure into new context.
2023-08-10 06:57:50 -07:00
nate-chandler
9d5b175220 Merge pull request #67846 from nate-chandler/nfc/20230809/1/silgen-closure-simplification
[SILGen] Remove subtle identity function call.
2023-08-10 06:57:25 -07:00
Nate Chandler
368536ce92 [SILGen] Remove subtle identity function call.
Back in 33f4f57cc4 of
https://github.com/apple/swift/pull/28044 fame,
non-`CaptureKind::Constant:` uses of `Entry.val` in
`SILGenFunction::emitCaptures` were replaced with a use of the newly
added lambda `getAddressValue` applied at `Entry.val`.

The replacement of `Entry.value` with `getAddressValue(Entry.value)` in
the case of `CaptureKind::Box` had no effect.

Back then, the reason was that the condition

    SGM.Types
        .getTypeLowering(
            valueType,
            TypeExpansionContext::noOpaqueTypeArchetypesSubstitution(
                expansion.getResilienceExpansion()))
            .isAddressOnly() &&
        !entryValue->getType().isAddress()

under which something other than the input was returned would never
hold: CaptureKind::Box is used for LValues and those never satisfy
`!entryValue->getType().isAddress()`.

Since that PR, the getAddressValue lambda has grown.  There are two
additional aspects to consider: (1) forceCopy, (2) isPack.  (1) is not
relevant because `false` was being passed for the `CaptureKind::Box`
case.  (2) can not currently happen because pack lvalues haven't been
implemented.  But even if they were implemented, the argument passed to
the lambda would still need to be an address.

The same all holds for the `CaptureKind::ImmutableBox` case which only
differs from the `CaptureKind::Box` by a couple of lines.
2023-08-09 16:55:55 -07:00
Nate Chandler
e894a34ef8 [SILGen] Gardening: Deleted comment.
Way back in

commit d0bb0274e9
Author: Joe Groff <jgroff@apple.com>
Date:   Mon Nov 23 11:47:09 2015 -0800

the convention was changed such that LValues were passed only by box
rather than by box and address.  Delete the comment that says that both
are passed.
2023-08-09 16:49:30 -07:00
Nate Chandler
999f2b023a [OpaqueValues] AnyHashable src gets new context.
When storing an instance of some type that conforms to Hashable into an
lvalue of type AnyHashable, the source rvalue needs to be emitted within
a new SGFContext.  Otherwise, the LocalVarInitialization for the var of
type AnyHashable would be used and an attempt would be made to store the
instance of the conforming type into the projected box.
2023-08-09 07:03:07 -07:00
nate-chandler
1791108bde Merge pull request #67722 from nate-chandler/opaque-values/1/20230803/unowned-copies
[SIL] Represent copies to @sil_unowned values.
2023-08-09 06:59:49 -07:00
nate-chandler
3336083265 Merge pull request #67690 from nate-chandler/opaque-values/20230802/2/weak-copies
[SIL] Represent copies to and from @sil_weak values.
2023-08-09 06:59:19 -07:00
Nate Chandler
c8d1ea5aae [SILGen] Gardening: Line wrapping. 2023-08-08 16:45:13 -07:00
Nate Chandler
6e26b416f4 [SILGen] Gardening: Moved comment. 2023-08-08 16:45:13 -07:00
zachary0kent
d240ffa340 Merge pull request #67747 from zachary0kent/sil-gen-top-level
[SILGen] Unified Entry Point Emission
2023-08-08 16:14:45 -07:00
Nate Chandler
ded4d32c71 [OpaqueValues] Emit unowned copies.
In opaque values mode, emit the unowned copy instructions to convert as
follows:

strong_copy_unowned_value: `@owned $sil_unowned T` -> `@owned $T`
unowned_copy_value: `@owned T` -> `@owned $sil_unowned T`

Doing so is necessary in opaque values mode where it is needed to deal
with unowned values directly rather than indirectly via `load_unowned`s
and `store_unowned`s.
2023-08-08 15:49:17 -07:00
Nate Chandler
b616d14ff5 [OpaqueValues] Emit weak copies.
In opaque values mode, emit the new weak copy instructions to convert as
follows:

strong_copy_weak_value: `@owned $sil_weak T?` -> `@owned $T?`
weak_copy_value: `@owned $T?` -> `@owned $@sil_weak T?`

Doing so is necessary in opaque values mode where it is needed to deal
with weak values directly rather than indirectly via `load_weak`s and
`store_weak`s.
2023-08-08 15:47:13 -07:00
Nate Chandler
c007bae723 [SIL] Added weak_copy_value.
The new instruction wraps a value in a `@sil_weak` box and produces an
owned value. It is only legal in opaque values mode and is transformed
by `AddressLowering` to `store_weak`.
2023-08-08 15:47:13 -07:00
Nate Chandler
e135c5cac7 [SIL] Added strong_copy_weak_value.
The new instruction unwraps an `@sil_weak` box and produces an owned
value. It is only legal in opaque values mode and is transformed by
`AddressLowering` to `load_weak`.
2023-08-08 15:47:13 -07:00
Zak Kent
db1cdbd99f [SILGen] Refactor use of removed forEachMemberToLower 2023-08-08 11:30:34 -07:00
Zak Kent
a459c97d74 [SILGen] [Test] Address code review comments 2023-08-08 11:25:11 -07:00
Zak Kent
03526c3ad0 [SILGen] Remove TODO referring to unified entry point emission 2023-08-08 11:25:11 -07:00
Zak Kent
3657cbafc9 [SILGen] Move all top-level emission code to SILGenTopLevel.cpp 2023-08-08 11:25:11 -07:00
Zak Kent
441a356200 [SILGen] Emit toplevel code through emitFunctionDefinition
Emit SILDeclRefs representing entry points with SourceFile
source correctly.
2023-08-08 11:25:11 -07:00
Zak Kent
3b4e94f65b [SILGen] Emit toplevel code through emitFunctionDefinition
Emit SILDeclRefs representing entry points with SourceFile
source correctly.
2023-08-08 11:25:11 -07:00
Zak Kent
7dae2e6905 [SILGen] Implement SILGenTopLevel
Implement SILGenTopLevel, a class that walks a file
run in script mode to generate all toplevel code
at once.
2023-08-08 11:25:11 -07:00
Michael Gottesman
cece84f345 [silgen] Rename forTrivialRValue -> forRValueWithoutOwnership and use it in a few places to eliminate more forUnmanaged.
With this commit, we have now eliminated ~55% of all forUnmanaged in the code
base.
2023-08-08 11:15:06 -07:00
Michael Gottesman
2faa8193d0 [silgen] Fix another trivial forUnmanaged -> forObjectRValueWithoutOwnership. 2023-08-08 11:15:06 -07:00
Michael Gottesman
5095bd31b0 [silgen] Convert a few instances of ManagedValue::forUnmanaged(*).copy() -> ManagedValue::forCopyOwnedObjectRValue.
Just removing more ManagedValue::forUnmanaged.
2023-08-08 11:15:06 -07:00
Michael Gottesman
85e38afbac Merge pull request #67780 from gottesmm/pr-d9b586775f6ea84fe9868857eb8dd2eeaeb39f6f
[silgen] Rename forTrivialObjectRValue -> forObjectRValueWithoutOwnership and change a bunch of forUnmanaged to use this API
2023-08-08 09:58:33 -07:00
Allan Shortlidge
7a38f171e0 Merge pull request #67785 from tshortli/decls-for-lowering-conveniences
NFC: Refactor conveniences for filtering out unavailable decls
2023-08-08 09:04:09 -07:00
nate-chandler
0cfa74763f Merge pull request #67725 from nate-chandler/opaque-values/20230803/2/open-opaque-existential-value
[OpaqueValues] Open opaque existential value.
2023-08-08 06:57:00 -07:00