Commit Graph

420 Commits

Author SHA1 Message Date
Raj Barik
333f0db8b2 Merge pull request #27346 from jinlin-bayarea/llvm_used
Use llvm.used for __objc_protorefs and __objc_protolist
2019-10-03 09:42:58 -07:00
Jin Lin
9e414dae18 [IRGen] Use llvm.used for __objc_protorefs and __objc_protolist and add test to verify. 2019-10-01 12:53:37 -07:00
Jordan Rose
a6dd630ca3 Eliminate Builtin.UnknownObject as an AST type (#27378)
This removes it from the AST and largely replaces it with AnyObject
at the SIL and IRGen layers. Some notes:

- Reflection still uses the notion of "unknown object" to mean an
  object with unknown refcounting. There's no real reason to make
  this different from AnyObject (an existential containing a
  single object with unknown refcounting), but this way nothing
  changes for clients of Reflection, and it's consistent with how
  native objects are represented.

- The value witness table and reflection descriptor for AnyObject
  use the mangling "BO" instead of "yXl".

- The demangler and remangler continue to support "BO" because it's
  still in use as a type encoding, even if it's not an AST-level
  Type anymore.

- Type-based alias analysis for Builtin.UnknownObject was incorrect,
  so it's a good thing we weren't using it.

- Same with enum layout. (This one assumed UnknownObject never
  referred to an Objective-C tagged pointer. That certainly wasn't how
  we were using it!)
2019-09-26 17:48:04 -07:00
Doug Gregor
ab5d161c05 [SILGen] Separate the initialization of a wrapped property from a wrapped value
Teach SILGen to emit a separate SIL function to capture the
initialization of the backing storage type for a wrapped property
based on the wrapped value. This eliminates manual code expansion at
every use site.
2019-09-24 09:11:53 -07:00
Slava Pestov
0c5d52d860 AST: Introduce AbstractStorageDecl::get{Parsed,Opaque}Accessor()
Also, change visitOpaqueAccessors() to call getOpaqueAccessor() instead of
asserting if the expected accessor does not exist.
2019-08-02 19:34:43 -04:00
Slava Pestov
64c32c695b AST: Remove a few utility methods from AbstractStorageDecl
Since the return value of getAccessor() depends on mutable state, it
does not make sense in the request evaluator world. Let's begin by
removing some utility methods derived from getAccessor(), replacing
calls to them with calls to getAccessor().
2019-08-01 18:31:58 -04:00
Slava Pestov
d3f65e7b4b AST: Remove SubscriptDecl::isSettable() 2019-07-31 21:26:02 -04:00
Arnold Schwaighofer
25ad152213 Emit the clang.arc.retainAutoreleasedReturnValueMarker as a module flag.
rdar://49749678
2019-04-09 15:19:59 -07:00
Mishal Shah
345e9881d1 Merge pull request #22699 from apple/stable-update-5.1
Update Swift:master to work with new stable re-branch from swift-5.1-branch
2019-02-20 12:22:00 -08: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
Bob Wilson
213efe089c Merge commit '06120c9d9d1a28275a0ecd7466775b1d71716be7' into stable-update-5.1 2019-02-17 10:20:59 -08:00
Brent Royal-Gordon
396a9ea4c2 [NFC] Remove vestigial IBActionAttr checks
isObjC() has learned to check for IBActionAttr, so these checks are redundant.
2019-02-13 15:46:50 -08:00
John McCall
b45ca0439b Use the new ObjC retain/release intrinsics in IRGen. 2019-02-08 14:22:57 -08: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
Jordan Rose
c34fe93f98 [IRGen] Generate proper type descriptors for ObjC subscript accessors
https://bugs.swift.org/browse/SR-8356
rdar://problem/42284266
2018-12-08 14:20:49 -08:00
Jordan Rose
4abb570025 [IRGen] Stop using "extended" type encodings where not supported
These are only used in two places in the Apple Objective-C runtime:

- A protocol's "extended method types" list
- Block type descriptors

We were using them when dynamically registering a protocol with the
Objective-C runtime, but that's just expecting "normal" types; the
"extended method types" list is never present in such a protocol.
2018-12-08 14:20:49 -08:00
Saleem Abdulrasool
2117c46097 IRGen: add a constant for common linkages
Swift uses LinkOnceODR with Internal linkage and normal Internal linkage quite
frequently.  Define a constant for this.
2018-11-13 09:56:24 -08:00
Joe Groff
ff7afcdfd7 Give more extra inhabitants to BridgeObject.
The standard library never ended up needing the low extra inhabitants (<4G on 64-bit Darwin,
<4K elsewhere), so BridgeObject can have the same set of extra inhabitants as the other refcounted
types, allowing `String?????` and `Array??????????` to still use optimized representations.
rdar://problem/45881464
2018-11-07 19:03:22 -08:00
Arnold Schwaighofer
152e8db8bb IRGen and runtime implementation for dynamic replacements 2018-11-06 09:58:36 -08:00
Saleem Abdulrasool
86e5b2574c IRGen: introduce new IRLinkage applicator
In order to handle LinkOnceODR semantics correctly across various object
formats, introduce a new helper ApplyIRLinkage.  This abstracts the need
to create a COMDAT group and set it on the GlobalValue.  Adjust all
sites where we set the IR linkage attributes to use this mechanism
instead to avoid having to track down symbols not being added to a
COMDAT group.
2018-11-04 10:13:50 -08:00
Slava Pestov
4da47823a5 Runtime/IRGen: Add new initialization pattern for classes with backward deployment layout
If a class has a backward deployment layout:

- We still want to emit it using the FixedClassMetadataBuilder.

- We still want it to appear in the objc_classes section, and get an
  OBJC_CLASS_$_ symbol if its @objc.

- However, we want to use the singleton metadata initialization pattern
  in the metadata accessor.

- We want to emit metadata for all field types, and call the
  swift_updateClassMetadata() function to initialize the class
  metadata.

For now, this function just performs the idempotent initialization of
invoking a static method on the class, causing it to be realized with
the Objective-C runtime.
2018-09-23 21:26:46 -07:00
Saleem Abdulrasool
d281b98220 litter the tree with llvm_unreachable
This silences the instances of the warning from Visual Studio about not all
codepaths returning a value.  This makes the output more readable and less
likely to lose useful warnings.  NFC.
2018-09-13 15:26:14 -07:00
Joe Groff
75d9e567dd Merge pull request #18630 from jckarter/extra-inhabitants-from-any-fixed-layout-struct-field
IRGen: Use any field of fixed-layout structs for extra inhabitants.
2018-08-27 09:46:42 -07:00
Slava Pestov
98b5eafcca IRGen: Split up doesClassMetadataRequireDynamicInitialization() into two predicates
- doesClassMetadataRequireRelocation() -- returns true if we must
  allocate new metadata at runtime and fill it in, because the class
  has multiple instantiations (generic case) or because the total size
  of the metadata is not known at compile time (resilient ancestry).

- doesClassMetadataRequireInitialization() -- weaker condition than
  the above. It's true if the metadata must be relocated, but it is
  also true if the metadata has otherwise fixed size but must be
  filled in dynamically. This occurs if the class has generic
  ancestry but is itself not generic, or if the class has
  resiliently-sized fields, or missing members.

For now, we don't actually care about the distinciton anywhere,
because we cannot do in-place initialization of class metadata yet.
2018-08-20 14:24:19 -07: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
zneak
8c2401a76f [IRGen] Generate plausible signature for .cxx_{construct,destruct}
"@?" is not a method signature. An acceptable format is "vM@0:N", where
N is the pointer size and M is twice the pointer size. The numeric
values don't matter anymore on Apple platforms because the runtime does
not rely on them (they used to be stack offsets from the base pointer),
but given that the first (self) and second (_cmd) parameters are
pointers, the expected value is easily obtained and it is probably good
style to include it.

Fixes https://bugs.swift.org/browse/SR-8203
2018-07-11 11:40:36 -07:00
David Zarzycki
057bbb366a [IRGen] Adopt reference storage type meta-programming macros
This commit also fixes reference storage extra inhabitant bugs.
2018-06-30 11:48:47 -04: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
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
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
aaa40ee82b Move metadata-accessing IRGen out of GenMeta. NFC.
Abstract type/heap metadata access goes into MetadataRequest.
Metadata access starting from a heap object goes into GenHeap.
Accessing various components of class metadata goes into GenClass
or MetadataLayout.
2018-03-18 23:53:11 -04:00
Stephan Tolksdorf
af3983ec34 [IRGen] Remove unused ObjC selector-family-related code 2018-02-25 17:13:06 +01:00
Jordan Rose
0c92fdda33 [SIL] Remove unused ResilienceExpansion from SILDeclRef (#14451)
We ended up not using this, so let's not leave it in as cruft.
No functionality change.
2018-02-07 09:41:25 -08:00
Slava Pestov
48897ded11 SIL: Remove never-emitted SILDeclRef::Kind::GlobalGetter 2018-01-14 21:39:53 -08:00
John McCall
7f0f8830cd Split AccessorDecl out from FuncDecl. NFC.
This has three principal advantages:

- It gives some additional type-safety when working
  with known accessors.

- It makes it significantly easier to test whether a declaration
  is an accessor and encourages the use of a common idiom.

- It saves a small amount of memory in both FuncDecl and its
  serialized form.
2018-01-12 14:20:27 -05:00
Saleem Abdulrasool
d8552ceb9e IRGen: ensure that ObjC sections match on all targets
Adjust the IRGen for ObjC interop to ensure that the section that
metadata is emitted into the correct section for non-MachO targets.

This also adds a more comprehensive test for ensuring that the IRGen can
now be tested on all targets.  Since the ObjC interop is now
controllable via the driver, this test does not require that the
objc_interop feature is present as it is a IRGen test.

This is the first step to remove the `REQUIRES: objc_interop` from the
IRGen tests.
2017-12-03 15:55:44 -08:00
Arnold Schwaighofer
d9167aa2e8 Merge pull request #12997 from aschwaighofer/fix_autorelease_pool_escape
IRGen: Add a pass to disable tail calling of objc_retainAutoreleasedR…
2017-11-19 16:58:56 -08:00
Arnold Schwaighofer
b79ff50f1b IRGen: Disable tail calls on x86_64 for objc_retainAutoreleasedReturnValue
Don't tail call objc_retainAutoreleasedReturnValue on x86_64. The epilogue code
before the tail jump blocks the autoreleased return optimization on x86_64
which looks for the call after the return.

callq  0x01ec08 ; symbol stub for: objc_msgSend
movq   %rax, %rdi
popq   %rbp  ;<== Blocks the handshake from objc_autoreleaseReturnValue
jmp    0x01ec20 ; symbol stub for: objc_retainAutoreleasedReturnValue
2017-11-18 08:19:55 -08:00
Joe Shajrawi
62d823c56d Code size: Do not use a global state for isOutlined 2017-11-15 15:28:27 -08:00
Erik Eckstein
90c21be191 Unify the implementation of optimization mode in various option classes.
This commit is mostly refactoring.

*) Introduce a new OptimizationMode enum and use that in SILOptions and IRGenOptions
*) Allow the optimization mode also be specified for specific SILFunctions. This is not used in this commit yet and thus still a NFC.

Also, fixes a minor bug: we didn’t run mandatory IRGen passes for functions with @_semantics("optimize.sil.never")
2017-11-14 11:25:02 -08:00
Arnold Schwaighofer
8c0e3fb5e4 IRGen: emitObjCPartialApplicationForwarder support @callee_guaranteed
@callee_guaranteed closure applications don't own their context.

SR-5441
rdar://33255593
2017-11-10 09:35:07 -08:00
swift-ci
315bd39364 Merge remote-tracking branch 'origin/master' into master-next 2017-08-02 10:48:55 -07:00
Arnold Schwaighofer
ce85f8e79c IRGen: Fix ObjectiveC partial apply forwarding stub
We need to map from swift parameter passing ABI to local explosions in partial
apply forwarding stubs to ObjectiveC methods.

SR-5569
rdar://33591146
2017-08-02 07:00:51 -07:00
John McCall
d4d2145ad8 Merge branch 'master' into master-next 2017-07-29 15:48:00 -04:00
John McCall
a0f20f673d Switch all of the indirect-call code in IRGen to FunctionPointer.
To make this stick, I've disallowed direct use of that overload of
CreateCall.  I've left the Constant overloads available, but eventually
we might want to consider fixing those, too, just to get all of this
code out of the business of manually remembering to pass around
attributes and calling conventions.

The test changes reflect the fact that we weren't really setting
attributes consistently at all, in this case on value witnesses.
2017-07-28 23:26:35 -04:00
Bob Wilson
5f02db4d3e Merge remote-tracking branch 'origin/master' into master-next 2017-07-20 21:59:23 -07:00
John McCall
750d397909 Substantially rework how IRGen handles function pointers.
The goals here are four-fold:
  - provide cleaner internal abstractions
  - avoid IR bloat from extra bitcasts
  - avoid recomputing function-type lowering information
  - allow more information to be propagated from the function
    access site (e.g. class_method) to the call site

Use this framework immediately for class and protocol methods.
2017-07-20 14:33:18 -04:00
swift-ci
e98182387b Merge remote-tracking branch 'origin/master' into master-next 2017-07-11 12:23:35 -07:00
Joe Groff
81ea860d89 IRGen: Builtin.UnknownObject should not be hardcoded to use ObjC refcounting.
It's more appropriate to use `Unknown` refcounting, which we correctly handle in the face of non-ObjC-interop elsewhere. Fixes a problem where the Linux standard library would contain an unresolvable reference to `objc_release`.
2017-07-07 09:52:09 -07:00