Commit Graph

50 Commits

Author SHA1 Message Date
Slava Pestov
41ff7383d9 IRGen: Clean up opaque type specialization wrappers 2025-10-23 15:36:54 -04:00
John McCall
46be95847b Extract TypeLowering's recursive type properties into a header, add
functions to compute them directly without a TypeLowering object, and
change a lot of getTypeLowering call sites to just use that.

There is one subtle change here that I think is okay: SILBuilder used to
use different TypeExpansionContexts when inserting into a global:
- getTypeLowering() always used a minimal context when inserting into
  a global
- getTypeExpansionContext() always returned a maximal context for the
  module scope
The latter seems more correct, as AFAIK global initializers are never
inlinable. If they are, we probably need to configure the builder with
an actual context properly rather than making global assumptions.

This is incremental progress towards computing this for most types
without a TypeLowering, and hopefully eventually removing TL entirely.
2025-08-01 15:00:57 -04:00
Anthony Latsis
f8577a2731 IRGen: Address llvm::Type::getPointerTo deprecation
See https://github.com/llvm/llvm-project/pull/113331.
2025-07-21 12:37:15 +01:00
Arnold Schwaighofer
5b89d2c834 IRGen: OutliningCollector's bindPolymorphicParameters needs to disambiguate between Formal and Representational metadata types
A recent change removed the usage of LocalTypeDataKind when populating the local
type metadata cache. This change reintroduces it.

rdar://141961121
2025-01-03 09:13:59 -08:00
Kuba Mracek
6f4ae28520 [ASTMangler] Pass ASTContext to all instantiations of ASTMangler 2024-12-02 15:01:04 -08:00
Arnold Schwaighofer
f9941b339a IRGen: Outlined value functions of types that might expand differently in
different TUs must use private linkage

rdar://136376117
2024-11-12 13:03:13 -08:00
Joe Groff
a184782a38 Introduce a Builtin.FixedArray type.
`Builtin.FixedArray<let N: Int, T: ~Copyable & ~Escapable>` has the layout of `N` elements of type `T` laid out
sequentially in memory (with the tail padding of every element occupied by the array). This provides a primitive
on which the standard library `Vector` type can be built.
2024-10-22 16:21:45 -07:00
Tim Kientzle
1d961ba22d Add #include "swift/Basic/Assertions.h" to a lot of source files
Although I don't plan to bring over new assertions wholesale
into the current qualification branch, it's entirely possible
that various minor changes in main will use the new assertions;
having this basic support in the release branch will simplify that.
(This is why I'm adding the includes as a separate pass from
rewriting the individual assertions)
2024-06-05 19:37:30 -07:00
Erik Eckstein
1b1d5ed020 IRGen: support the @sensitive attribute
Call `swift_clearSensitive` after destroying or taking "sensitive" struct types.

Also, support calling C-functions with "sensitive" parameters or return values. In SIL, sensitive types are address-only and so are sensitive parameters/return values.
Though, (small) sensitive C-structs are passed directly to/from C-functions. We need re-abstract such parameter and return values for C-functions.
2024-04-09 12:01:11 +02:00
Nate Chandler
e507a6bcea [IRGen] Defer materializing metadata for outlining
Rather than materializing the metadata on demand during visitation, only
collect the types that may be required.  Finally, materialize everything
that's needed at the end.
2024-03-15 14:12:28 -07:00
Nate Chandler
9a8c814553 [Outlining] Pass polymorphic args of type.
If any deinit must be called, just pass the full generic environment of
the type being destroyed.
2024-03-01 21:01:50 -08:00
Nate Chandler
b83085b00b [NFC] IRGen: Extracted function. 2024-03-01 21:01:49 -08:00
Nate Chandler
3f6bd9d3e1 [NFC] IRGen: Store SILType in metadata collector. 2024-03-01 21:01:49 -08:00
Nate Chandler
babdbda2d4 [NFC] IRGen: Moved constructor to cpp. 2024-03-01 21:01:49 -08:00
Nate Chandler
73ccf1c9fb [NFC] IRGen: Extracted method. 2024-03-01 21:01:49 -08:00
Nate Chandler
a82140bc1c [NFC] IRGen: Renamed method.
Not all metadata that the OutliningMetdataCollector collects is for
layout anymore.
2024-03-01 21:01:49 -08:00
Nate Chandler
765d23bbbc [NFC] IRGen: Clarify metadata collection helper.
Gather the circumstances under which the collector should be used and
what it should collect separately and then collect only in one place if
collection should happen.
2024-03-01 21:01:49 -08:00
Nate Chandler
1253dba02b [NFC] IRGen: Renamed outlining helpers.
In preparation for them handling more polymorphic arguments than merely
metadata.
2024-03-01 21:01:49 -08:00
Nate Chandler
379beabf3a [Gardening] IRGen: Changed a variable name. 2024-03-01 21:01:49 -08:00
Nate Chandler
fefd793a2a [NFC] IRGen: Renamed method. 2024-03-01 21:01:49 -08:00
Nate Chandler
36b473d365 [IRGen] Pass deinit metadata to outlined release.
Given a releasable value which contains a noncopyable value type with a
deinit, that values outlined release function, among other things, must
call the deinit of that noncopyable value type.  In order to do that,
its type metadata must be passed to the value function if it has an
archetype.
2024-02-21 19:31:52 -08:00
Nate Chandler
f3b9dec880 [IRGen] Collect nc deinit metadata for outlining.
Some outlined functions call deinits for noncopyable values.  These
deinits require the metadata for the full type.

Teach the OutliningMetadataCollector to collect the metadata for these
types, when the new needsDeinit flag is set.

Also add the new needsLayout flag.  For now, all outlined functions need
it.
2024-02-21 19:31:52 -08:00
Nate Chandler
1056067e73 [Gardening] IRGen: Tweaked some variable names.
Made a function reasonably debuggable (type -> ty) and renamed
misleading variable (formalType -> astType).
2024-02-21 17:53:34 -08:00
Nate Chandler
f0f9351421 [NFC] IRGen: Extracted callOutlinedRelease.
In preparation to sometimes use a metadata collector.
2024-02-21 17:53:34 -08:00
Nate Chandler
93595e4e86 [NFC] IRGen: Extracted method. 2024-02-21 17:53:34 -08:00
Nate Chandler
48e1428f11 [NFC] IRGen: Extracted TI::withMetadataCollector.
Deduplicate some code.
2024-02-21 07:03:41 -08:00
Erik Eckstein
4c3722352e IRGen: don't use value witness functions in outlined value operations for functions with performance constraints 2024-02-05 12:37:08 +01:00
Slava Pestov
79d4260ae2 SIL: Remove the incorrect old getTypeLinkage() 2024-01-03 14:45:29 -05:00
Kuba Mracek
fda2a2a65e [embedded] Disallow use of VWTs for take/copy/assign/destroy operations, even under -Osize 2023-09-22 22:54:25 -07:00
Slava Pestov
30c9981d41 IRGen: Centralize check for local archetypes when outlining copy and destroy 2023-04-18 12:54:49 -04:00
John McCall
ce9013a3f6 Fix IRGen to not use outlining for types with any kind of local archetype.
Previously it was testing for opened existentials specifically.

We should really teach outlining to handle local archetypes properly.
We'd have to build a generic signature for the lowered type, and that
probably means also adding requirements that are relevant to value
operations, but it would mean outlining would benefit all types, and
it would let us avoid bundling in unnecessary information from the
enclosing generic environment.

A minor side-effect of this is that we no longer bind names to
opened element type values.  The names were things like \tau_1_0,
which is not very useful, especially in LLVM IR where \tau is
printed with two UTF-8 escapes.
2023-03-10 19:00:28 -05:00
Joe Groff
afa5837aeb IRGen: Use deinit to destroy move-only structs that have them.
The `deinit` takes full responsibility for destroying the value, using the
user-defined deinit body and implicitly destroying any remaining resources
not consumed during the deinit.

Remaining to do after this patch:

- Run the deinit for enums
- Pass generic arguments for generic move-only types
- Handle deinits that take their parameter indirectly
- Teach value witness layout about when types are move-only and/or have
  deinits, so that we don't attempt to give move-only types standard
  value witness tables or share box metadata with copyable payloads
2023-02-22 16:48:30 -08:00
Arnold Schwaighofer
443fe61370 IRGen: Fix outlined value operations for (constrained) existentials.
In the case of constrained existentials metadata instantiation was not
supported pre 5.7, so using metadata for value operations is prohibited.

rdar://101250193
2022-10-20 14:03:14 -07:00
Arnold Schwaighofer
d810b0f7e4 IRGen: Pass the elementType of pointers through to operations
In preparation for moving to llvm's opaque pointer representation
replace getPointerElementType and CreateCall/CreateLoad/Store uses that
dependent on the address operand's pointer element type.

This means an `Address` carries the element type and we use
`FunctionPointer` in more places or read the function type off the
`llvm::Function`.
2022-10-03 15:27:12 -07:00
Doug Gregor
209167ae30 Eliminate spurious uses of ArchetypeType::getRoot(). 2022-01-19 09:54:34 -08:00
Robert Widmann
e7e11df927 Model Sequence Archetypes 2021-11-16 11:38:57 -08:00
Kuba (Brecka) Mracek
afde159521 Drop assert(Atomicity::Atomic) from visitRetainValueAddrInst+visitReleaseValueAddrInst (#33913) 2020-09-11 14:49:55 -07:00
Arnold Schwaighofer
2c8b845387 IRGen: Ignore the metadata of fixed sized types with opaque result type parameters
The removed check by this patch seems somewhat arbitrary and the test case that
was added for it no longer fails.

rdar://67841860
2020-08-31 06:29:56 -07:00
Arnold Schwaighofer
72d13a3483 Don't emit an outlined call to a noop function 2020-02-21 12:10:58 -08:00
Arnold Schwaighofer
b7a58c0f96 IRGen: Optionally use value witness instead of outlined value functions
... if type layout based value witness emission is enabled.

rdar://51988441
2020-02-21 12:10:58 -08:00
Dan Zheng
1486d6b346 NFC: Add GenericSignature::getCanonicalSignature. (#29105)
Motivation: `GenericSignatureImpl::getCanonicalSignature` crashes for
`GenericSignature` with underlying `nullptr`. This led to verbose workarounds
when computing `CanGenericSignature` from `GenericSignature`.

Solution: `GenericSignature::getCanonicalSignature` is a wrapper around
`GenericSignatureImpl::getCanonicalSignature` that returns the canonical
signature, or `nullptr` if the underlying pointer is `nullptr`.

Rewrite all verbose workarounds using `GenericSignature::getCanonicalSignature`.
2020-01-12 12:17:41 -08:00
Arnold Schwaighofer
781582b205 IRGen: Add addLoweredTypeRef API and use it for capture and
box descriptors

We want to substitute opaque result types in addTypeRef but when we pass
SILFunctionTypes this would fail because AST type substitution does not
support lowered SIL types.

Instead add addLoweredTypeRef which substitutes based on SILTypes.

rdar://54529445
2019-08-22 13:40:38 -07:00
Arnold Schwaighofer
86ca8146a0 IRGen: Fix outlining when an opaque type resolves to a fixed size type
rdar://54515130
2019-08-20 09:47:01 -07:00
Arnold Schwaighofer
b082c270f5 IRGen: Outlining needs to look through opaque archetypes now that the rest of IRGen does
rdar://54470626
2019-08-19 14:18:19 -07:00
Joe Groff
0cfca9496a Give opened archetypes a generic environment.
And maybe allow nested types to live on them.
2019-02-20 12:52:48 -08:00
Joe Groff
89979137fc Push ArchetypeType's API down to subclasses.
And clean up code that conditionally works only with certain kinds of archetype along the way.
2018-12-12 19:45:40 -08:00
Arnold Schwaighofer
97845c0a5c IRGen: Don't pass metadata of not ABI accessible to outlined copy/destroy operations
Doing so will cause linkage errors and is not neccessary since we call
the witness of the enclosing type as soon as its fields are not ABI
accessible.

rdar://40868358
2018-06-07 13:58:01 -07:00
David Zarzycki
8c0c55539f [SIL] NFC: Rename misleading getSwiftRValueType() to getASTType()
Reference storage types are not RValues. Also, use more SILType helper
methods to avoid line wrap.
2018-05-04 08:14:38 -04:00
Slava Pestov
39a65abf85 IRGen: Outlined thunks don't need to receive fixed-size metadata
They're not used inside the thunk so it's a waste passing them in, and
if they involve private types from a different translation unit we will
get a linking error from referencing the metadata accessor function.

Fixes the test case in <rdar://problem/39470607>, but the more general
problem remains.
2018-04-17 16:11:21 -07:00
John McCall
976401157f Bind layout type metadata correctly in outlined helper functions.
Fixes a regression in the source compatibility suite which I had a
lot of trouble extracting into a separate test case.

Most of this patch is just moving the outlining code into a separate
file and organizing it into a helper class instead of copy/pasting
so much code.  The main functional change is implicit in the difference
between collecting formal metadata and collecting it for layout, which
then is exploited in bindMetadataParameters.

As a secondary change, stop collecting metadata for class-bounded
archetypes; we don't actually need it to do value operations.
2018-03-27 15:14:12 -04:00