Commit Graph

83 Commits

Author SHA1 Message Date
Erik Eckstein
45a78e67db IRGen: remove TypeInfo::allocateVector
It's not needed anymore because the alloc_vector instruction is removed.
2025-02-12 10:51:15 +01:00
Adrian Prantl
e70a3443e9 [Debug Info] Remove the mostly unused FragmentType from DebugTypeInfo
This cleanup allows for more consistent debug info emission since we depend less
on IRGen magic to emit debug info for types.
2025-01-27 17:28:10 -08: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
Ellie Shin
72a7760027 Support package SIL linkage.
Decls with a package access level are currently set to public SIL
linkages. This limits the ability to have more fine-grained control
and optimize around resilience and serialization.
This PR introduces a separate SIL linkage and FormalLinkage for
package decls, pipes them down to IRGen, and updates linkage checks
at call sites to include package linkage.

Resolves rdar://121409846
2024-02-06 01:23:14 -08:00
Erik Eckstein
e652f2c92e SIL: add the alloc_vector and vector instructions
* `alloc_vector`: allocates an uninitialized vector of elements on the stack or in a statically initialized global
* `vector`: creates an initialized vector in a statically initialized global
2023-12-09 18:49:55 +01:00
Adrian Prantl
06a54432ab Sink isFixedBuffer into DebugTypeInfo and ensure the enclosed types aren't
emitted with the size of the fixed buffer.
2022-12-14 14:18:28 -08:00
Jordan Rose
171ff440fc Remove swift::reversed in favor of llvm::reverse (#27610)
The former predates the latter, but we don't need it anymore! The
latter has more features anyway.

No functionality change.
2019-10-10 17:16:09 -07:00
Slava Pestov
a5a4aaf59e SILGen: The storage of a resilient global variable does not need to be public
Part of <rdar://problem/40432647>.
2018-11-15 14:55:44 -05:00
Adrian Prantl
2c7a69852b Emits a DW_OP_deref for global variables in a fixed size buffer.
Note that this is only correct unless the variable uses inline
storage. This makes the majority of resilient types in Foundation work
as global variables.  The correct solution would be for LLDB to poke
at the runtime to figure out whether the storage is inline or not, but
until then this is the next best thing.

rdar://problem/39722386
2018-05-02 15:40:16 -07:00
John McCall
3c54c0edfc IRGen and basic optimizer support for coroutines. 2018-01-09 11:35:09 -05:00
John McCall
1f3f33e67d Clean up the internal APIs around dynamic allocas to structurally
discourage accidental use of them.  Relatedly, fix several bugs
where we were accidentally using dynamic allocas.
2017-12-19 00:29:43 -05:00
Joe Shajrawi
d8289aa3ec Code size: destroy_addr outline 2017-11-17 16:10:27 -08:00
Erik Eckstein
9c6fe76927 SIL, IRGen: add instructions "object" and "global_value” to support statically initialized objects.
This commit contains:
-) adding the new instructions + infrastructure, like parsing, printing, etc.
-) support in IRGen to generate global object-variables (i.e. "heap" objects) which are statically initialized in the data section.
-) IRGen for global_value which lazily initializes the object header and returns a reference to the object.

For details see the documentation of the new instructions in SIL.rst.
2017-08-23 09:15:49 -07:00
Adrian Prantl
bb55c6d8a6 Clean up the constructors of DebugTypeInfo
and ensure that the DeclContext of the SILFunction is used when
mangling substituted archetypes found in inlined variable declarations
that have been reparented into the caller

<rdar://problem/28859432>
2017-01-13 15:56:27 -08:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Arnold Schwaighofer
cd1037b799 IRGen: Allocate generic/resilient values on the stack instead of on the heap
Allocate buffers for local generic/resilient values on the stack. alloc_stack
instructions in the entry block are translated using a dynamic alloca
instruction with variables size. All other alloc_stack instructions in addition
use llvm's stacksave/restore instrinsics to reset the stack (they could be
executed multiple times and with varying sizes).
2016-12-20 07:24:02 -08:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
Adrian Prantl
0e9c8e9db4 Update for LLVM API change D20147. 2016-09-20 18:14:03 -07:00
Adrian Prantl
4cee546841 Emit debug info for global variables without storage.
As with local variables this is done by emitting a constant 0 location
and a type of size zero.


<rdar://problem/26660971>
2016-06-06 17:06:20 -07:00
John McCall
d3fecb20ce Perform a destroy_addr followed by a dealloc_stack with a single witness call. 2016-01-17 23:09:08 -08:00
Slava Pestov
33ed1e0ab6 IRGen: Add ResilienceExpansion parameter to TypeInfo::isKnownEmpty(), NFC
In a few places, we have to be careful about the distinction between
"empty in this resilience domain" versus "empty in all resilience
domains". Make callers think about this by adding a parameter instead
of relying on them to check isFixedSize() as necessary first.

While making this change I noticed that the code for checking if
types are empty when computing extra inhabitants of structs and enums
might be slightly wrong in the face of resilience; I will revisit
this later.
2016-01-08 19:56:01 -08:00
Slava Pestov
627c906ef3 SILGen: Emit alloc_global when initializing global variables
It is still not clear to me when we access global variables from other
modules directly, versus using accessors; it seems to be controlled
by the -sil-serialize-all flag, rather than any language feature.

Until/if we add a @_fixed_layout equivalent for globals, I can't really
test direct access of globals from other modules; when we figure out
the story here I'll be able to add more tests and also tighten up
some isResilient() checks in the global code, but what's in there now
seems to work.
2016-01-08 19:56:00 -08:00
Slava Pestov
9bf6ef76aa IRGen: Lowering of alloc_global and global_addr for non-fixed-size types
Allocate and project the buffer, respectively, adding the
necessary indirection required to handle the size not being
known until runtime.

For now we don't emit alloc_global instructions anywhere;
an upcoming change will add that at the SIL level.

Also I suspect debug info needs some work to handle the
extra indirection, I'll look into this soon.
2016-01-07 23:00:43 -08:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
Joe Groff
0991b2c5d8 IRGen: Factor out IRBuilder helpers for CreateLifetimeStart/End. 2015-12-25 12:24:56 -08:00
Joe Groff
1524b5146e IRGen: Put lifetime markers on stack allocations. 2015-12-24 12:11:19 -08:00
Joe Groff
8a04d67408 IRGen: Strip out dead code for untyped boxes.
Swift SVN r29761
2015-06-27 17:50:13 +00:00
Chris Lattner
79ed57f9f2 standardize naming of tuples and tuple patterns on "elements".
Previously some parts of the compiler referred to them as "fields",
and most referred to them as "elements".  Use the more generic 'elements'
nomenclature because that's what we refer to other things in the compiler
(e.g. the elements of a bracestmt).

At the same time, make the API better by providing "getElement" consistently
and using it, instead of getElements()[i].

NFC.



Swift SVN r26894
2015-04-02 20:23:49 +00:00
Joe Groff
bb46f4bbd9 SIL: Remove the global_addr instruction.
It's no longer needed now that we always lower to SIL globals.

Swift SVN r22693
2014-10-12 17:19:06 +00:00
Jordan Rose
3fcdfd40e9 Remove the "swift/Basic/Optional.h" header.
llvm::Optional lives in "llvm/ADT/Optional.h". Like Clang, we can get
Optional in the 'swift' namespace by including "swift/Basic/LLVM.h".

We're now fully switched over to llvm::Optional!

Swift SVN r22477
2014-10-02 18:51:45 +00:00
Jordan Rose
042569a3be Optional: Replace uses of Nothing with None.
llvm::Optional (like Swift.Optional!) uses None as its placeholder value,
not Nothing.

Swift SVN r22476
2014-10-02 18:51:42 +00:00
Joe Groff
1c4e08a9c8 Fix up a tangle of issues related to reabstraction.
- A spot fix in SILGen for reabstracting the result of a downcast, which fixes checked casts to function types.
- Associate the layout information in type metadata records with the most abstract representation of the type. This is the correct thing to do in cases where we need the metadata as a tag for an opaque value--if we store a value in an Any, or pass it as an unconstrained generic parameter, we must maximally reabstract it. This fixes the value semantics of existentials containing trivial metatypes.
- To ensure that we get runtime layout of structs and enums correct when they contain reabstractable types, introduce a "metadata for layout" concept, which doesn't need to describe the canonical metadata for the type, but only needs to describe a type with equivalent layout and value semantics. This is a correctness fix that allows us to correctly lay out generic types containing dependent tuples and functions, and although we don't really take advantage of it here, it's also a potential runtime performance win down the road, because we could potentially produce direct metadata for a primitive type that's layout-equivalent with a runtime-instantiated type. To aid in type safety here, push SILType deeper into IRGen in places where we potentially care about specific representations of types.
- Finally, fix an inconsistency between the runtime and IRGen's concept of what spare bits unmanaged references and thick metatypes have.

Together, these fixes address rdar://problem/16406907, rdar://problem/17822208, rdar://problem/18189508, and likely many other related issues, and also fixes crash suite cases 012 and 024.

Swift SVN r21963
2014-09-16 01:44:34 +00:00
Manman Ren
a952c556c9 [Global Opt] replace GlobalAddrInst with SILGlobalAddrInst.
Update SILGen to create SILGlobalVariable and SILGlobalAddrInst instead of
GlobalAddrInst. When we see a definition for a global variable, we create
the corrsponding SILGlobalVariable definition.

When creating SILGlobalVariable from a global VarDecl, we mangle the global
VarDecl in the same way as we mangle it at IRGen. The SILLinkage is also
set in the same way as we set it at IRGen.

At IRGen, we use the associated VarDecl for SILGlobalVariable if it exists,
to have better debugging information.

We set the initializer for SILGlobalVariable definition only.

We also handle SILGlobalAddrInst in various SILPasses, in the similar way
as we handle GlobalAddrInst.

rdar://15493694


Swift SVN r21887
2014-09-11 20:00:39 +00:00
Joe Groff
6cb2bf96b8 IRGen: Implement the dealloc_box instruction.
Failable initializers will need to clean up an uninitialized 'self' box in the case where a class initializer calls out to a 'super.init' or 'self.init' fails. Because some framework classes assume that they have a refcount of exactly one during initialization, we have to take 'self' from the box during the delegation, and reinitialize the box with the result of the delegation on success. This means we actually have to implement lowering for dealloc_box.

Swift SVN r21493
2014-08-27 22:44:53 +00:00
John McCall
9f6820fadc SILGenModule::getConstantLinkage -> SILDeclRef::getLinkage
Swift SVN r14247
2014-02-22 01:45:40 +00:00
John McCall
32d4ef7001 Remove IR-gen's specialized ASTVisitor.
Swift SVN r12427
2014-01-16 22:32:35 +00:00
Joe Groff
5e5f31d5e3 IRGen: Share TypeInfo among equivalent generic instantiations, take 2.
IRGen type conversion is invariant with respect to archetypes with the same set of constraints, so instead of redundantly generating a TypeInfo object and IR type for Optional<T> for every T everywhere, key TypeInfo objects using an "exemplar type" that we form using a folding set to collapse together archetypes with the same class-ness, superclass constraint, and protocol constraints.

This is a nice memory and IR size optimization, but will be essential for correctness when lowering interface types, because there is no unique context to ground a dependent type, and we need to lower the same generic parameter with the same context requirements to the same type whenever we instantiate it in order for the IR to type-check.

In this revision, we profile the nested archetypes of each recursively, which I neglected to take into account originally in r12112, causing failures when archetypes that differed by associated type constraints were incorrectly collapsed.

Swift SVN r12116
2014-01-10 05:25:45 +00:00
Joe Groff
97ff9e47a8 Revert "IRGen: Share TypeInfo among equivalent generic instantiations."
This reverts commit r12112. It gives the buildbot indigestion.

Swift SVN r12113
2014-01-10 03:22:53 +00:00
Joe Groff
57cacbfe38 IRGen: Share TypeInfo among equivalent generic instantiations.
IRGen type conversion is invariant with respect to archetypes with the same set of constraints, so instead of redundantly generating a TypeInfo object and IR type for Optional<T> for every T everywhere, key TypeInfo objects using an "exemplar type" that we form using a folding set to collapse together archetypes with the same class-ness, superclass constraint, and protocol constraints.

This is a nice memory and IR size optimization, but will be essential for correctness when lowering interface types, because there is no unique context to ground a dependent type, and we need to lower the same generic parameter with the same context requirements to the same type whenever we instantiate it in order for the IR to type-check.

Swift SVN r12112
2014-01-10 02:02:58 +00:00
John McCall
5da6defa1f Clean up the linkage model and the computation of linkage.
In general, this forces SILGen and IRGen code that's grabbing
a declaration to state whether it's doing so to define it.

Change SIL serialization to serialize the linkage of functions
and global variables, which means also serializing declarations.

Change the deserializer to use this stored linkage, even when
only deserializing a declaration, and to call a callback to
inform the client that it has deserialized a new entity.

Take advantage of that callback in the linking pass to alter
the deserialized linkage as appropriate for the fact that we
imported the declaration.  This computation should really take
advantage of the relationship between modules, but currently
it does not.

Swift SVN r12090
2014-01-09 08:58:07 +00:00
Joe Groff
15dc4967aa IRGen: Lower SILGlobalVariables.
Add support for emitting IR for SILGlobalVariables and SILGlobalAddrInst.

Swift SVN r10543
2013-11-18 17:40:45 +00:00
John McCall
3f4dcf455a dealloc_stack is not a no-op.
Swift SVN r6975
2013-08-07 03:21:14 +00:00
John McCall
e9b913fb5b Remove LocalStorageType, make it a kind of SILType.
Swift SVN r6968
2013-08-07 00:22:26 +00:00
John McCall
36aa6c2645 alloc_stack needs to return two values like alloc_box.
The current implementation of dealloc_stack in IR-gen is a
no-op, but that's very much wrong for types with non-trivial
local allocation requirements, e.g. archetypes.  So we need
to be able to do non-trivial code here.  However, that means
modeling both the buffer pointer and the allocated address
in SIL.

To make this more type-safe, introduce a SIL-specific
'[local_storage] T' type that represents the required
allocation for locally storing a T.  alloc_stack now returns
one of those in additon to a *T, and dealloc_stack expects
the former.

IR-gen still implements dealloc_stack as a no-op, but
that's now easy to fix.

Swift SVN r6937
2013-08-06 07:31:41 +00:00
John McCall
e3584068e8 Distinguish the allocation cases in IR-gen.
This gives us a more convenient type for allocateStack
and eliminates some unnecessary redundancy.

Swift SVN r6935
2013-08-06 07:31:36 +00:00
Adrian Prantl
4a73ec14c9 Address a bunch of review comments. Thanks Joe & Chris!
Swift SVN r6012
2013-07-05 17:19:15 +00:00
Adrian Prantl
0c34b57c74 Debug Info: Add basic support for global and stack-allocated variables and
their types.
- DebugTypeInfo holds all type info we need to emit debug information.
- Type info is limited to name, location, and storage size.
- As a side-effect: verbose LLVM IR allocas in debug builds!

Swift SVN r5980
2013-07-03 23:02:04 +00:00
John McCall
65fc2b74f8 Basics of dynamic struct layout.
Swift SVN r4902
2013-04-25 01:39:58 +00:00
John McCall
03c04d04df Prepare StructLayout and StructLayoutBuilder for non-fixed layouts.
Swift SVN r4900
2013-04-25 01:39:45 +00:00