Commit Graph

295 Commits

Author SHA1 Message Date
swift-ci
b068ea573f Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-22 14:24:40 -08:00
zoecarver
b3a305b3ab Remove newRet 2020-01-21 17:31:46 -08:00
zoecarver
f99b53d382 Remove debug helpers 2020-01-21 16:05:38 -08:00
zoecarver
bd3d7431c7 Load offset from metadata instead of returning offset directly 2020-01-21 16:04:21 -08:00
zoecarver
7f5f1c3f78 stash 2020-01-19 21:35:51 -08:00
zoecarver
7720a628fd Modify to catch issue 2020-01-17 13:16:02 -08:00
zoecarver
e19f40a25c Use getMetadataLayout offset instead of manual gep 2020-01-14 14:57:40 -08:00
Raphael Isemann
b9f9f23a9c Add missing include for Attr.h in GenStruct.cpp
ASTContext.h no longer includes Attr.h so we need to include
this ourselves to have the definition of SwiftNewTypeAttr.
2019-12-11 18:43:03 +01:00
Arnold Schwaighofer
4cba76309f IRGen: Add TypeExpansionContext to IRGen 2019-11-11 14:21:52 -08:00
Arnold Schwaighofer
7a54927b03 IRGen: Fix MemoryLayout::offset(of:) for tail allocated C arrays
There is no storage but an offset.

rdar://51194713
2019-10-15 14:04:31 -07:00
Slava Pestov
83c90b6b2a AST: Turn NominalTypeDecl::getStoredProperties() into a request
This improves on the previous situation:

- The request ensures that the backing storage for lazy properties
  and property wrappers gets synthesized first; previously it was
  only somewhat guaranteed by callers.

- Instead of returning a range this just returns an ArrayRef,
  which simplifies clients.

- Indexing into the ArrayRef is O(1), which addresses some FIXMEs
  in the SIL optimizer.
2019-07-16 16:38:38 -04:00
Michael Munday
192bcb2007 Basic: Use APInt to implement ClusteredBitVector
Simplify the implementation of ClusteredBitVector by using an APInt
to represent the raw bits. This simplification will make it easier
to incrementally move to a representation of bit vectors that works
on both big- and little-endian machines.

This commit also removes reserve and reserveExtra from the API
since they were only used in one place and no longer have any effect
because memory allocation is now handled by the APInt class.
2019-06-04 14:05:10 +01:00
Arnold Schwaighofer
da999f0fd7 Use noteUseOfOpaqueTypeDescriptor instead of introducing and using markOpaqueTypeDescriptorEmitted 2019-05-06 12:08:04 -07:00
Arnold Schwaighofer
fc8ff70be7 IRGen: Don't emit opaque type descriptors twice
rdar://50500620
2019-05-06 09:32:29 -07:00
Joe Groff
22793b4567 Fixes for opaque return types on local functions.
- In Sema, don't traverse nested declarations while deducing the opaque return type. This would
  cause returns inside nested functions to clobber the return type of the outer function.
- In IRGen, walk the list of opaque return types we keep in the SourceFile already for type
  reconstruction, instead of trying to visit them ad-hoc as part of walking the AST, since
  IRGen doesn't normally walk the bodies of function decls directly.

Fixes rdar://problem/50459091
2019-05-03 16:53:21 -07:00
Joe Groff
4eb064dc21 IRGen: Emit opaque type descriptors for runtime lookup.
If -enable-anonymous-context-mangled-names is enabled, meaning that we assign names to
anonymous context descriptors for discovery by RemoteAST, then include opaque type descriptors
in the type metadata record table so that they can also be found at runtime by RemoteAST for
debugger support.
2019-04-29 18:11:01 -07:00
Joe Groff
a99716bbb8 Visit var/subscript opaque return decls during IRGen/TBDGen. 2019-04-17 14:46:22 -07:00
Joe Groff
c58737fb91 merge fixup 2019-04-17 14:46:22 -07:00
Joe Groff
ca537d1e86 opaque descriptor wip 2019-04-17 14:44:40 -07:00
Slava Pestov
af83492a45 IRGen: Lazily emit reflection field descriptors
Previously even if a type's metadata was optimized away, we would still
emit a field descriptor, which in turn could reference nominal type
descriptors for other types via symbolic references, etc.
2019-04-12 01:46:23 -04:00
Slava Pestov
6d2fc0c08c IRGen: Change around how we decide to emit lazy type metadata
The old logic was confusing. The LazyTypeGlobals map would contain
entries for all referenced types, even those without lazy metadata.

And for a type with lazy metadata, the IsLazy field would begin
with a value of false -- unless it was imported.

When a non-imported type was finally visited in the AST, we would
try to "enable" lazyness for it, which meant queueing up any
metadata that had been requested prior, or immediately emitting
the metadata otherwise.

Instead, let's add a separate map that caches whether a type has
lazy metadata or not. The first time we ask for the metadata of a
type, consult this map. If the type has lazy metadata according to
the map, queue up metadata emission for the type. Otherwise, emit
metadata eagerly when the type is visited in the AST.
2019-04-12 01:46:23 -04:00
Slava Pestov
61f21a7195 IRGen: Emit field reflection descriptors for types with custom alignment
The code to decide if field descriptors were going to be emitted was
confusing, so I've refactored it a bit.
2019-04-12 01:46:23 -04:00
John McCall
7f55a4a4f0 Always give known-empty class properties a zero offset in the static layout.
Field offset vectors are always filled out with either zero or the static layout's offset, depending on the metadata initialization strategy.  This change means that the static layout's offset will only be non-zero for properties with a statically-known layout.  Existing runtimes doing dynamic class layout assign class properties a zero offset if the field offset vector entry is zero and the property is zero-sized.  So this effectively brings the compiler into accord with the runtime (for all newly-compiled Swift code, which will eventually be all Swift code because the current public releases of Swift 5 are not yet considered ABI-stable) and guarantees a zero value for the offset everywhere.

Since the runtime will agree with the compiler about the zero value of the offset, the compiler can continue to emit such offset variables as constant.  The exception to this rule is if the class has non-fragile ObjC ancestry, in which case the ObjC runtime (which is not aware of this special rule for empty fields) will attempt to slide it along with everything else.

Fixes rdar://48031465, in which the `FixedClassMetadataBuilder` for a class with a legacy-fixed layout was writing a non-zero offset for an empty field into the field offset vector, causing the runtime to not apply the special case and thus to compute a non-zero offset, which it then attempted to copy into the global field offset variable, which the compiler had emitted as a true-constant zero.
2019-02-20 00:53:11 -05:00
John McCall
724c192120 Propagate the XI count into the get/store XI tag callbacks.
This allows callers to avoid needing to reload these tags in common cases.
2018-12-11 22:18:44 -05:00
John McCall
2ba7090fe8 Remove the extra-inhabitant value witness functions.
This is essentially a long-belated follow-up to Arnold's #12606.
The key observation here is that the enum-tag-single-payload witnesses
are strictly more powerful than the XI witnesses: you can simulate
the XI witnesses by using an extra case count that's <= the XI count.
Of course the result is less efficient than the XI witnesses, but
that's less important than overall code size, and we can work on
fast-paths for that.

The extra inhabitant count is stored in a 32-bit field (always present)
following the ValueWitnessFlags, which now occupy a fixed 32 bits.
This inflates non-XI VWTs on 32-bit targets by a word, but the net effect
on XI VWTs is to shrink them by two words, which is likely to be the
more important change.  Also, being able to access the XI count directly
should be a nice win.
2018-12-11 22:18:44 -05:00
Slava Pestov
73aff74e8d IRGen: Type lowering cache doesn't need to store 'forward declarations' 2018-10-04 20:01:23 -04:00
Joe Groff
93d85997e8 Generalize extra inhabitants of tuples.
Like we did for structs, make it so that tuple types can also get extra inhabitants from whichever element with the most, not only the first. This lets us move all of the extra inhabitant handling functionality between structs and tuples in IRGen up to the common RecordTypeInfo CRTP base.
2018-09-20 15:39:44 -07:00
John McCall
c1f99b5fdb Cap type alignment in Swift at 16.
rdar://31411216
2018-08-28 16:13:50 -04:00
Joe Groff
9f02ecd1a5 IRGen: Use any field of structs for extra inhabitants.
This allows us to layout-optimize Optional<T> when T is a struct with an
extra-inhabitant-bearing field anywhere in its definition, not only at
the beginning. rdar://problem/43019427
2018-08-14 12:53:06 -07:00
Slava Pestov
e44721dd19 IRGen: Remove the 'access type'/'layout type' distinction from StructLayout
This was part of the old resilience workaround for classes and
is no longer used.
2018-08-10 00:42:34 -07:00
Slava Pestov
d460d5def6 IRGen: Remove ASTTy field from StructLayout 2018-08-07 04:26:43 -07:00
Arnold Schwaighofer
98577cf585 IRGen: Silence clang warning
I believe the warning is erroneous and filed a bug against clang.

GenStruct.cpp:290:19: warning: unused type alias 'super' [-Wunused-local-typedef]

rdar://40626108
2018-05-30 08:15:34 -07:00
John McCall
2ed90771f4 Use the VWT for value ops on types with ABI-inaccessible children.
rdar://39763787
2018-05-15 15:07:32 -04:00
Slava Pestov
d5868e5492 IRGen: ElementLayout now stores two TypeInfos
This allows us to perform fragile layout of resilient fields without
completely disabling value type resilience.
2018-04-09 21:53:45 -07:00
Pavel Yaskevich
78822bc23e [IRGen] Adjust element size of offset vector to 32-bit for structs
Type of elements contained by field offsets vector can be adjusted
to 32-bit integers (from being pointer sized) to safe space in the
binary since segment size is limited to 4 GB.

Resolves: rdar://problem/36560486
2018-04-03 13:32:06 -07:00
Sho Ikeda
08644c1d8f [gardening][IRGen] Replace typedef with using 2018-03-27 09:06:33 +09:00
John McCall
5ff8883c95 Pull TypeInfo::initializeMetadata into GenMeta; NFC.
GenMeta is already making decisions about what work is done by these
functions.
2018-03-26 01:13:45 -04:00
Joe Groff
0951648fe6 IRGen: Fix handling of empty fields in Clang-imported types.
Clang allows C structs to have zero-sized array fields for things like trailing buffers. Lower these correctly into Swift types in IRGen so that Swift codegen knows to treat them as empty types. Fixes rdar://problem/31042794.
2018-03-19 15:40:38 -07:00
Joe Groff
f01af883fc IRGen: Use known value witness tables for common type layouts.
If a type has the same layout as one of the basic integer types, or has a single refcounted pointer representation, we can use prefab value witness tables from the runtime instead of instantiating new ones. This saves quite a bit of code size, particularly in the Apple SDK overlays, where there are lots of swift_newtype wrappers and option set structs.
2018-03-11 11:04:37 -07:00
Joe Groff
4c2dde56a0 IRGen: Lower external key path components.
The key path pattern needs to include a reference to the external descriptor, along with hooks for lowering its type arguments and indices, if any. The runtime will need to instantiate and interpolate the external component when the key path object is instantiated.

While we're here, let's also reserve some more component header bytes for future expansion, since this is an ABI we're going to be living with for a while.
2018-02-23 19:03:15 -08:00
John McCall
9bbbe2c418 Update the metadata-initialization ABI:
- Create the value witness table as a separate global object instead
  of concatenating it to the metadata pattern.

- Always pass the metadata to the runtime and let the runtime handle
  instantiating or modifying the value witness table.

- Pass the right layout algorithm version to the runtime; currently
  this is always "Swift 5".

- Create a runtime function to instantiate single-case enums.

Among other things, this makes the copying of the VWT, and any
modifications of it, explicit and in the runtime, which is more
future-proof.
2017-12-21 00:26:37 -05:00
Joe Shajrawi
62d823c56d Code size: Do not use a global state for isOutlined 2017-11-15 15:28:27 -08:00
Joe Groff
b41888391f IRGen: Verify that known struct field offsets match the runtime field offset vector. 2017-09-22 12:28:50 -07:00
Erik Eckstein
90501578b0 IRGen: fix statically initialized globals which contain an empty type.
This caused a compiler assert or a miscompile

rdar://problem/34123143
2017-08-29 09:53:18 -07:00
Slava Pestov
e12c29ded9 IRGen: Refactor NonFixedStructTypeInfo::initializeMetadata()
The emitInitializeFieldOffsetVector() function used for
class metadata is now almost identical to the logic used
for structs. Refactor the code used for classes and also
use it to layout structs.
2017-08-09 01:07:09 -07:00
Slava Pestov
ea5a99a3f7 IRGen: Record start of field offset vector in StructMetadataLayout 2017-08-09 01:07:08 -07:00
John McCall
4e48bc0ff7 Cache type-metadata layouts instead of using scanners everywhere. NFC.
Also counts as incremental work towards metadata resilience.
2017-08-03 04:13:53 -04:00
John McCall
003bd81b86 Rename FooMetadataLayout to FooMetadataVisitor. NFC.
The *Layout namespace is more fitting for a structure that actually
holds information about the layout.
2017-08-03 02:04:14 -04:00
Joe Groff
aaddafa55b IRGen: Support for generic key path patterns. 2017-04-17 17:50:57 -07:00
Huon Wilson
3105c6ed00 [IRGen] Expose LinkInfo publicly, like LinkEntity. 2017-04-05 09:54:19 -07:00