Commit Graph

925 Commits

Author SHA1 Message Date
Joe Groff
72aa089130 NFC opaque type cleanups
- Add some assertions, and avoid an unnecessary asserting cast
- Replace a no-op access visitor with UNINTERESTING
2019-05-02 20:28:39 -07:00
Joe Groff
a6b5a41a32 IRGen: Generate anonymous contexts for properties with opaque return types.
They aren't normally decl contexts, but if one has an opaque type, we want to be able to record
the property as a context so that we can reconstruct it in RemoteAST.
2019-05-02 17:28:08 -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
Arnold Schwaighofer
d044696b30 Merge pull request #24293 from aschwaighofer/compiler_fix_initEnumMetadataSingleCase
IRGen: Initialize single case enum extrainhabitant value witness in generated code
2019-04-29 10:00:04 -07:00
Doug Gregor
209e7fcd83 [IRGen] Emit lazy opaque type descriptors.
These were recorded but never emitted. Fixes rdar://problem/50258536.
2019-04-27 09:50:23 -07:00
Arnold Schwaighofer
e2d3f533d6 IRGen: Intialize single case enum extrainhabitant value witness in generated code
Older Swift runtimes miss this initialization in the swift_initEnumMetadataSingleCase runtime call.

rdar://49786768
2019-04-25 14:19:56 -07:00
Arnold Schwaighofer
84c7b77d02 Make opaque type descriptors dynamically replaceable
This is to support dynamic function replacement of functions with opaque
result type.

This approach requires that all state is thrown away (that could contain the
old returned type for an opaque type) between replacements.

rdar://48887938
2019-04-22 07:31:07 -07:00
Slava Pestov
d6868acf8a IRGen: Categories on class stubs should go in a separate list and section 2019-04-19 16:50:29 -04: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
1841a1f2cb IRGen: Extract GenKeyPath's emitWitnessTableRefString to be usable elsewhere. 2019-04-17 14:44:40 -07:00
Joe Groff
ffc9fd5e38 IRGen: Emit opaque type descriptors. 2019-04-17 14:44:40 -07:00
Joe Groff
ca537d1e86 opaque descriptor wip 2019-04-17 14:44:40 -07:00
Joe Groff
09ca7a784b IRGen: Emit runtime calls to fetch opaque type metadata.
Introduce code to emit runtime calls to get the type metadata for the underlying type of an opaque type and to get its conformances.
2019-04-17 14:43:32 -07:00
Slava Pestov
1dbca9e354 IRGen: Stop forcing lazy metadata in a few places
These were all working around other issues that have since been fixed.
2019-04-12 01:46:23 -04:00
Slava Pestov
606e226f6f IRGen: Force field descriptors to be emitted when we emit typerefs
Emission of typerefs used by the runtime would force type metadata;
do the same for remote reflection-only typerefs.
2019-04-12 01:46:23 -04: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
dd80f588dd IRGen: Emit foreign type metadata using the lazy metadata mechanism
Instead of a wholly separate lazyness mechanism for foreign metadata where
the first call to getAddrOfForeignTypeMetadataCandidate() would emit the
metadata, emit it using the lazy metadata mechanism.

This eliminates some code duplication. It also ensures that foreign
metadata is only emitted once per SIL module, and not once per LLVM
module, avoiding duplicate copies that must be ODR'd away in multi-threaded
mode.

This fixes the test case from <rdar://problem/49710077>.
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
4ec1e83385 IRGen: Assert if its too late to queue up lazy emission 2019-04-12 01:46:22 -04:00
Slava Pestov
4207738e17 Add mangling and IRGen LinkEntity for Objective-C resilient class stubs 2019-03-26 18:44:44 -04:00
Slava Pestov
6a4786e107 IRGen: Add IRGenFunction::getTypeLowering() 2019-03-12 00:30:35 -04:00
Slava Pestov
980fb7c437 SIL: Remove default resilience expansion from isTypeABIAccessible() 2019-03-06 02:26:26 -05:00
Slava Pestov
bdac8ad633 IRGen: Remove considerResilience parameter to isDependentConformance() 2019-02-21 00:02:25 -05:00
Slava Pestov
18ea8a11d1 IRGen: Move isResilientConformance() and isDependentConformance() to IRGenModule 2019-02-20 16:20:48 -05:00
Slava Pestov
69d1cafd1c AST: Add AvailabilityContext parameter to Decl::isWeakImported()
For now, it's not used, but we do try to pass the right value down from
our various call sites.

Progress on <rdar://problem/46674512>.
2019-02-19 18:58:44 -05:00
Slava Pestov
040323e967 IRGen: Introduce ClassMetadataStrategy to clean up some checks
This consolidates the various doesClassMetadataRequire*() checks, making
them more managable.

This also adds a forth state, ClassMetadataStrategy::Update. This will be used
when deploying to the new Objective-C runtime. For now it's not plumbed through.

Progress on <rdar://problem/47649465>.
2019-02-18 22:39:13 -05:00
najacque
d5863c4487 Bump ABI version to 7 for Swift 5 rdar://problem/44203212 2019-01-25 14:49:54 -08:00
Slava Pestov
77e5b44560 IRGen: Ensure that default witness thunks are emitted in the same thread as the protocol descriptor
Protocol descriptors for resilient protocols relatively-reference
default witness thunks, so when using -num-threads N with N > 1,
we must ensure the default witness thunk is emitted in the same
LLVM module.
2019-01-15 21:42:24 -05:00
Slava Pestov
152fab22a1 Revert "IRGen: Ensure that default witness thunks are emitted in the same thread as the protocol descriptor" 2019-01-15 01:05:06 -05:00
Slava Pestov
50465688f8 IRGen: Ensure that default witness thunks are emitted in the same thread as the protocol descriptor
Protocol descriptors for resilient protocols relatively-reference
default witness thunks, so when using -num-threads N with N > 1,
we must ensure the default witness thunk is emitted in the same
LLVM module.
2019-01-14 16:26:07 -05:00
Joe Groff
9669c3a703 KeyPaths: Don't relative-reference selector refs.
ld64 doesn't like this. Instead, generate a stub function to grab the instantiated selector. Fixes rdar://problem/47184763.
2019-01-10 14:32:50 -08:00
Slava Pestov
4d4c194760 IRGen: Clean up and fix lazy metadata emission for reflection
We were wastefully emitting an accessor if a field had a type, for
example if my field type was (() -> (X, Array<Y>>) we would force
the emission of a function to construct (() -> (X, Array<Y>)) even
though all we care about is the type metadata for X and Y.

Conversely, we would skip the field type if it contained an
archetype, even if it otherwise contained metadata that we need
to force to emit, for instance something like (T, X) where T is
a generic parameter and X is a nominal type.

A final side effect is we no longer try to emit type metadata for
one-element tuples when emitting enum payload metadata, which is
something I want to assert against.
2018-12-15 00:05:48 -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
Doug Gregor
2c5ecb477a Merge pull request #20858 from DougGregor/mangled-base-protocol-witnesses
[ABI] Use mangled names for base protocol witnesses.
2018-12-04 11:28:27 -08:00
Doug Gregor
e6620b055d [Mangling] Separate out base conformance descriptors.
Separate the mangling of base conformance descriptors from that of
associated conformance descriptors, and simplify it.
2018-12-04 00:13:54 -08:00
John McCall
cc4f398d59 Merge pull request #20694 from carlos4242/master
Improve the compiler around 16-bit pointers
2018-11-30 11:24:53 -05:00
Slava Pestov
4289f76064 AST: Introduce ClassDecl::hasResilientMetadata() 2018-11-29 23:20:02 -05:00
Carl Peto
3d61e9fd5a Fix incompatibilities with 16 bit pointers
- fix code generation for enum types to zext or trunc 32 bit data as appropriate for the platform
- fix IR generation code to use a relative address type of 16 bit width on that platform

- correct order of statements and line up comments
2018-11-29 22:15:54 +00:00
Doug Gregor
17699d4e33 [Metadata] Emit complete context descriptors for parents of anonymous contexts
When a (file)private entity occurs inside a generic context, we still need
information about the genericity of the enclosing context to demangle
to metadata. Emit complete context descriptors for parents of anonymous
contexts.

Fixes rdar://problem/46109026.
2018-11-16 21:34:32 -08:00
Doug Gregor
f759296cc8 [Keypaths] Encode generic environment in the key-path pattern.
Extend the key-path pattern with a representation of the generic environment
of the key-path, which includes the generic parameters and generic
requirements of the environment.
2018-11-16 10:13:06 -08:00
John McCall
5553224fd4 Support the explicit representation of self-conformances.
Big, but actually NFC because we're never actually creating them.
2018-11-15 16:42:03 -05:00
Doug Gregor
b192cedf8d [Keypaths] Use mangled names to reference type and witness table accessors.
Switch key path metadata over to mangled names for each of the places it
refers to either a type metadata accessor or a witness table accessor. For
now, the mangled name is a symbolic reference to the existing accessors.

Part of rdar://problem/38038799.
2018-11-12 21:15:20 -08:00
Doug Gregor
81610fdc02 [ABI] Use faux mangled names for associated conformances in witness tables
The current representation of an associated conformance in a witness
tables (e.g., Iterator: IteratorProtocol within a witness table for
Sequence) is a function that the client calls.

Replace this with something more like what we do for associated types:
an associated conformance is either a pointer to the witness table (once
it is known) or a pointer to a mangled name that describes that 
conformance. On first access, demangle the mangled name and replace the
entry with the resulting witness table. This will give us a more compact
representation of associated conformances, as well as always caching
them.

For now, the mangled name is a sham: it’s a mangled relative reference to
the existing witness table accessors, not a true mangled name. In time,
we’ll extend the support here to handle proper mangled names.

Part of rdar://problem/38038799.
2018-11-12 09:42:51 -08:00
Doug Gregor
5758cdcfcc [ABI] Eliminate the special structure for generic parameter references.
TargetGenericParamRef is a specialized structure used to describe the
subject of a generic requirement, e.g., the “T.Assoc” in “T.Assoc: P”.
Replace it with a mangled name, for several reasons:

1) Mangled type names are also fairly concise, can often be shared, and
are a well-tested path
2) Mangled type names can express any type, which might be useful in the
future
3) This structure doesn’t accommodate specifically stating where the
conformances come from (to extract associated type witnesses). Neither
can mangled names, but we’d like to do that work in only one place.

This change exposed an existing bug where we improperly calculated the
generic parameter counts for extensions of nested generic types. Fix that
bug here (which broke an execution test).
2018-11-08 13:58:17 -08:00
Arnold Schwaighofer
152e8db8bb IRGen and runtime implementation for dynamic replacements 2018-11-06 09:58:36 -08:00
Arnold Schwaighofer
ebbe3aed1c IRGen: Add implementation for dynamically replaceable functions
A dynamically replaceable function calls through a global variable that
holds the function pointer.

struct ChainEntry {
   void *(funPtr)();
   struct ChainEntry *next;
}

ChainEntry dynamicallyReplaceableVar;

void dynamicallyReplaceableFunction() {
  dynamicallyReplaceableVar.funPtr()
}

dynamic replacements will be chainable so the global variable also
functions as the root entry in the chain of replacements.

A dynamic replacement functions can call the previous implementation by
going through its chain entry.

ChainEntry chainEntryOf_dynamic_replacement_for_foo;

void dynamic_replacement_for_foo() {
   // call the previous (original) implementation.
   chainEntryOf_dynamic_replacement_for_foo.funPtr();
}
2018-11-06 09:53:21 -08:00
Joe Groff
65a4531467 IRGen/Runtime: Make key path pattern format true-const.
Use relative references instead of pointers so that the pattern can be true-const. Instead of trying
to instantiate a constant key path literal in-place, point to a cache variable that we can store
a pointer to the shared instance into when instantiated. Now that the pattern format has diverged
significantly from the instance format, simplify and refactor the instantiation code using a walker
for the pattern format instead of trying to reuse the code for working with instantiated instances.
rdar://problem/42674576
2018-11-05 12:30:49 -08:00
Slava Pestov
e3efd001ca IRGen: Don't emit field descriptors for imported classes and protocols 2018-11-02 00:47:11 -04:00
John McCall
cf511445e2 Basic support for Builtin.IntegerLiteral. 2018-10-31 18:42:34 -04:00