Commit Graph

397 Commits

Author SHA1 Message Date
Arnold Schwaighofer
95e31eefa2 IRGen: Fix multipayload enums with indirect cases
swift_unknownRetain does not work on indirect enum heap buffers.

The existing logic would say: oh one case is
ReferenceCounting::BridgeObject (which on its own probably would not
work with swift_unknownRetain), oh and another second case is NativeObject (for
the indirect buffer), let's use unknowRetain.

Pair the logic down to only use a single style of reference count
operation if all cases are of the same ReferenceCounting type.

rdar://40525268
2018-05-30 15:46:06 -07:00
Vedant Kumar
105a61e50d Use LLVM_DEBUG() instead of DEBUG()
Upstream has renamed the DEBUG() macro to LLVM_DEBUG. This updates swift
accordingly:

$ find . -name \*.cpp -print -exec sed -i "" -E "s/ DEBUG\(/ LLVM_DEBUG(/g" {} \;
2018-05-24 13:10:45 -07:00
swift-ci
2714ed70c6 Merge remote-tracking branch 'origin/master' into master-next 2018-05-15 14:09:30 -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
swift-ci
908dbfed4a Merge remote-tracking branch 'origin/master' into master-next 2018-05-10 02:09:07 -07:00
Slava Pestov
99bf4ddc3a IRGen: Add an assertion in enum lowering 2018-05-10 00:47:26 -04:00
swift-ci
f8cf225435 Merge remote-tracking branch 'origin/master' into master-next 2018-05-09 21:29:25 -07:00
Slava Pestov
4058b8acd2 IRGen: There is no such thing as not 'complete' type info 2018-05-09 23:11:46 -04:00
swift-ci
d24ea7f319 Merge remote-tracking branch 'origin/master' into master-next 2018-05-04 18:29:26 -07:00
Arnold Schwaighofer
34b24220af IRGen: Collect the current type metadata of singleton enums
We have missed the singleton enum case.
rdar://39923978
2018-05-04 13:39:11 -07:00
swift-ci
ad0712c02b Merge remote-tracking branch 'origin/master' into master-next 2018-05-04 08:49:40 -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
swift-ci
c12d46675a Merge remote-tracking branch 'origin/master' into master-next 2018-04-30 17:49:07 -07:00
Huon Wilson
d0e5b17e4b [IRGen] std::function -> llvm::function_ref for some non-escaping params. 2018-05-01 08:29:07 +10:00
Bob Wilson
27efdcb8ee master-next: use separate memcpy/memmove src/dest alignment arguments
LLVM r323617 changed the IRBuilder's CreateMemCpy and CreateMemMove
functions to take separate arguments for the destination and source
alignments.
2018-03-28 22:19:16 -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
Slava Pestov
c31620d302 IRGen: Mangle generic signature and type for outlined thunks 2018-03-26 19:39:26 -07:00
John McCall
a906f43329 Allow type metadata to be incomplete.
Most of the work of this patch is just propagating metadata states
throughout the system, especially local-type-data caching and
metadata-path resolution.  It took a few design revisions to get both
DynamicMetadataRequest and MetadataResponse to a shape that felt
right and seemed to make everything easier.

The design is laid out pretty clearly (I hope) in the comments on
DynamicMetadataRequest and MetadataResponse, so I'm not going to
belabor it again here.  Instead, I'll list out the work that's still
outstanding:

- I'm sure there are places we're asking for complete metadata where
  we could be asking for something weaker.

- I need to actually test the runtime behavior to verify that it's
  breaking the cycles it's supposed to, instead of just not regressing
  anything else.

- I need to add something to the runtime to actually force all the
  generic arguments of a generic type to be complete before reporting
  completion.  I think we can get away with this for now because all
  existing types construct themselves completely on the first request,
  but there might be a race condition there if another asks for the
  type argument, gets an abstract metadata, and constructs a type with
  it without ever needing it to be completed.

- Non-generic resilient types need to be switched over to an IRGen
  pattern that supports initialization suspension.

- We should probably space out the MetadataStates so that there's some
  space between Abstract and Complete.

- The runtime just calmly sits there, never making progress and
  permanently blocking any waiting threads, if you actually form an
  unresolvable metadata dependency cycle.  It is possible to set up such
  a thing in a way that Sema can't diagnose, and we should detect it at
  runtime.  I've set up some infrastructure so that it should be
  straightforward to diagnose this, but I haven't actually implemented
  the diagnostic yet.

- It's not clear to me that swift_checkMetadataState is really cheap
  enough that it doesn't make sense to use a cache for type-fulfilled
  metadata in associated type access functions.  Fortunately this is not
  ABI-affecting, so we can evaluate it anytime.

- Type layout really seems like a lot of code now that we sometimes
  need to call swift_checkMetadataState for generic arguments.  Maybe
  we can have the runtime do this by marking low bits or something, so
  that a TypeLayoutRef is actually either (1) a TypeLayout, (2) a known
  layout-complete metadata, or (3) a metadata of unknown state.  We could
  do that later with a flag, but we'll need to at least future-proof by
  allowing the runtime functions to return a MetadataDependency.
2018-03-26 12:18:04 -04: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
Arnold Schwaighofer
71a170936d IRGen: Only emit resilient tag numbers for resilient enums
rdar://24057946
2018-03-21 14:02:44 -07:00
Arnold Schwaighofer
9d8c381ab4 Remove resilient tag indices 2018-03-20 13:19:56 -07:00
Arnold Schwaighofer
ce7608a7ce IRGen: Make resilient enum's tag indices resilient
This allows reordering enum cases resiliently.

rdar://24057946
2018-03-20 13:19:56 -07:00
Joe Groff
53792aa64e IRGen: Make outlined enum copy/destroy lazier and better mangled.
Emit enum copy/destroy methods only when codegen demands them; they previously got emitted immediately when TypeInfo is instantiated, which led to many functions getting emitted that were never used. Also, make it so that the symbol name includes the full type of the enum instance the outlined functions operate on, so it's more obvious what they'e being used for and they can be ODRed across translation units.
2018-03-11 11:04:41 -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
Sho Ikeda
cea6c03eb2 [gardening] Use !empty() over size() > 0 2018-03-08 09:21:09 +09:00
Sho Ikeda
26d650292f [gardening] Use empty() over size() == 0 2018-03-05 14:43:13 +09:00
Pavel Yaskevich
94017f7ee7 [IRGen] Remove 'FieldNames' field from type context descriptor
All of the information contained by this field (list of property names)
is already encoded as part of the field reflection metadata and
is accessible via `swift_getFieldAt` runtime method.
2018-02-20 18:49:00 -08:00
Pavel Yaskevich
8bc7ba2239 [IRGen] Don't generate field reflection metadata for opaque struct/enum
One of my previous commits did that, but since we have Builtins reflection
section we don't really want to generate reflection field metadata for
opaque structs/enums. This reverts to the previous behavior.
2018-02-20 18:20:09 -08:00
Pavel Yaskevich
877c70bae9 [Runtime/Metadata] Add support for dynamic field descriptor registration 2018-02-20 18:20:09 -08:00
Jordan Rose
01f9fc76b5 Merge pull request #12778 from linux-on-ibm-z/master-s390x-fixes
Fixes for s390x
2018-01-22 09:44:36 -08:00
swift-ci
6ec935af06 Merge pull request #14026 from aschwaighofer/irgen_fix_ub_shift 2018-01-19 10:34:28 -08:00
Arnold Schwaighofer
c842c34d2e IRGen: Shift by more-or-equal than num bits of type is undefined behavior
Caught by ubsan.
rdar://36649637
2018-01-19 09:26:50 -08:00
Joe Shajrawi
1e5e49a5d5 [IRGen] Fix a bug in multi-payload’s enum collectArchetypeMetadata: all payloads might not contain archetype but the enum itself might still be dynamically sized 2018-01-18 15:59:04 -08:00
Vivian Kong
9d0730d876 Fix packing enum payloads on big endian 2018-01-15 08:54:56 -05: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
5be50d75fc Fixes an invalid assert in No Payload Enum's collectArchetypeMetadata: the type itself might contain an Archetype. We need to check that it is not an Archetype itself 2017-12-04 16:26:36 -08:00
Joe Shajrawi
6ee370bcba Merge pull request #13004 from shajrawi/noinline_enum_outlined_funcs
Code Size: mark enum's outlined retain/releases as no inline
2017-11-17 19:18:07 -08:00
Joe Shajrawi
763e7ca99c mark enum's outlined retain/releases as no inline 2017-11-17 17:06:24 -08:00
Joe Shajrawi
d8289aa3ec Code size: destroy_addr outline 2017-11-17 16:10:27 -08:00
Joe Shajrawi
f6781deaf8 copy_addr outline: cleanups based on review 2017-11-16 23:19:33 -08:00
Joe Shajrawi
67f2852ef2 Code Size: copy_addr cleanup - get rid of mightContainMetadata 2017-11-15 15:28:29 -08:00
Joe Shajrawi
62d823c56d Code size: Do not use a global state for isOutlined 2017-11-15 15:28:27 -08:00
Joe Shajrawi
5aff0891b7 Code size: copy_addr outline part 2 - Support Archetypes 2017-11-15 15:26:44 -08:00
Joe Shajrawi
18b0240f02 Outline copy_addr part 1 clean-up: Remove Enum's TIK < Loadable check - archetype check covers it 2017-11-15 15:24:16 -08:00
Joe Shajrawi
8c67caa5c6 Merge pull request #12687 from shajrawi/outline_copyddr
Code Size: Outline copy addr instruction
2017-11-01 10:47:11 -07:00
Arnold Schwaighofer
865d85bd1c Reapply the enum value witness patch
Revert "Revert "Merge pull request #12606 from aschwaighofer/single_payload_enum_witness""

This reverts commit c422f80307.
2017-10-31 17:28:15 -07:00
Joe Shajrawi
f4db36426c Code Size: Outline copy addr instruction 2017-10-31 17:03:48 -07:00
Arnold Schwaighofer
c422f80307 Revert "Merge pull request #12606 from aschwaighofer/single_payload_enum_witness"
This reverts commit 0b414e45c5, reversing
changes made to fb27e7d32a.

There are failures on the resilient bot and lldb test case fails.
2017-10-31 08:24:26 -07:00
Arnold Schwaighofer
43b9d13a2e Add value witnesses for single payload enums
So far single payload enums were implemented in terms of runtime functions which
internally emitted several calls to value witnesses.

This commit adds value witnesses to get and store the enum tag side stepping the
need for witness calls as this information is statically available in many cases

/// int (*getEnumTagSinglePayload)(const T* enum, UINT_TYPE emptyCases)
/// Given an instance of valid single payload enum with a payload of this
/// witness table's type (e.g Optional<ThisType>) , get the tag of the enum.

/// void (*storeEnumTagSinglePayload)(T* enum, INT_TYPE whichCase,
///                                   UINT_TYPE emptyCases)
/// Given uninitialized memory for an instance of a single payload enum with a
/// payload of this witness table's type (e.g Optional<ThisType>), store the
/// tag.

A simple 'for element in array' loop in generic code operating on a
ContigousArray of Int is ~25% faster on arm64.

rdar://31408033
2017-10-23 13:31:46 -07:00
swift-ci
187c7f7ef2 Merge remote-tracking branch 'origin/master' into master-next 2017-08-01 14:29:04 -07:00