Commit Graph

318 Commits

Author SHA1 Message Date
Joe Groff
808d33d016 IRGen: Don't cache accesses to fixed class metadata.
The only initialization these class objects need is ObjC realization, which can be done
fast with `objc_opt_self` on recent Apple OSes. The cache check just adds code size and
dirties memory.
2020-02-26 15:10:18 -08:00
Joe Groff
7ec52e6329 IRGen: Separate the concept of "metadata should be cached" from "statically referenced"
Some metadata may require instantiation, but not in a way that requires us to put an additional
cache layer in front of it. `Self` metadata is also trivial to access from the local cache, but
isn't statically referenceable. Split these concepts and update code to use one or the other
appropriately. This catches an issue with metadata prespecialization where it would try to
make records for dynamic `Self` incorrectly.
2020-02-24 13:58:57 -08:00
Dan Zheng
1779632a6f [IRGen] NFC: silence llvm::MaybeAlign warnings.
Use `llvm::MaybeAlign` instead of `unsigned` to silence slew of warnings.
2020-02-20 08:49:28 +00:00
nate-chandler
b62871047d Merge pull request #29345 from nate-chandler/generic-metadata-prespecialization-components/enums
Generic metadata prespecialization: enums
2020-02-12 13:09:59 -08:00
Nate Chandler
40e17d9c6f [metadata prespecialization] Direct refs to enums.
When a specialized usage of a generic enum occurs in the same module
where the enum was defined, directly reference the prespecialized
metadata.

rdar://problem/56994321
2020-02-12 10:08:33 -08:00
Arnold Schwaighofer
90d942ca26 Merge pull request #29740 from aschwaighofer/irgen_cache_optional_metadata_construction
IRGen: Cache type metadata construction of Optional types
2020-02-12 08:28:29 -08:00
Robert Widmann
054d7b9913 Merge pull request #29713 from CodaFi/unused-unwanted-unloved
[Gardening] Silence Some Warning Spew
2020-02-11 15:46:16 -08:00
Arnold Schwaighofer
ea5fa5afd3 IRGen: Cache type metadata construction of Optional types
To achieve this replace the current implementation which recursively
constructs a layout compatible metadata by an implementation that
recursively constructs a layout compatible type and the use
emitTypeMetadataRef on that type to generate the metadata.
2020-02-11 13:32:53 -08:00
Robert Widmann
bd1dce89b8 [Gardening] Silence needless double-brace-initialization warnings
See also https://wg21.cmeerw.net/cwg/issue1270
2020-02-07 16:09:31 -08:00
swift-ci
1a6ffc8b0e Merge remote-tracking branch 'origin/master' into master-rebranch 2020-02-06 09:24:55 -08:00
Nate Chandler
2f36375a28 [metadata prespecialization] Standardize checks to ref tables.
Previously, some ad hoc checks were done in order to determine whether
the metadata access for a generic type was trivial.  Now, standard
predicates are used, specifically IRGenModule's member functions
isDependentConformance and isResilientConformance.
2020-02-04 11:59:36 -08:00
Nate Chandler
e49dd639fd [metadata prespecialization] Enumerate arguments as usual.
Previously, when emitting the metadata accessor, the generic arguments
of the type were enumerated one after the next.  That was fine in most
cases but is incorrect in cases where the actual number of generic
arguments is less than apparent number as when two arguments are required
to be equal.

Now, the arguments are enumerated according to the requirements vended by
the GenericTypeRequirements struct.
2020-01-30 11:30:02 -08:00
Erik Eckstein
1b312a85bd Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-16 10:39:20 +01:00
Slava Pestov
61872fa948 IRGen: Don't use the demangler to realize imported Objective-C class metadata for now
Recently we started using the runtime demangler to realize imported
Objective-C class metadata, to save on code size since no metadata
accessor function needs to be emitted in this case.

This introduced a regression where OBJC_CLASSREF symbols were no
longer being emitted in some cases, which breaks autolinking.
The fix for this was tracked by rdar://56136123, but unfortunately
had to be reverted because it caused other problems.

Until the original fix can be re-applied, let's put in a temporary
workaround where we avoid going through the runtime demangler for
imported Objective-C classes. This regresses code size but unblocks
everyone involved, until the fix for the demangling code path
(8247525471) can be re-applied.

Fixes <rdar://56621277>.
2020-01-14 00:44:30 -05:00
swift-ci
5dcb80b599 Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-10 15:24:32 -08:00
Nate Chandler
9e2e090623 [IRGen] Emit metadata accessors last.
Metadata accessors are dependent on prespecializations of the metadata
of generic, in-module types.  Those prespecializations are themselves
dependent on usages of the types in functions.  Consequently, the
accessors must be emitted after all the functions are emitted.
2020-01-09 17:25:34 -08:00
Nate Chandler
c4d13e4b4b [IRGen] Directly reference prespecializations.
When possible, directly reference metadata prespecializations.  Doing so
is possible when the type is defined in the same module, because in
those cases the metadata accessor can be modified to ensure that the
prespecialized metadata is canonical.

rdar://problem/56994171
2020-01-09 17:25:33 -08:00
Nate Chandler
840ded4923 [IRGen] Accessor returns prespecializations.
For every prespecialization of generic metadata that exists in the
module where the generic type is defined, the metadata accessor gains
code with the following effect

  switch arguments {
  case prespecialization1.genericArguments:
    return prespecialization1
  case prespecialization2.genericArguments:
    return prespecialization2
  ...
  default:
    return swift_getGenericMetadata(...)
  }

rdar://problem/56961700
2020-01-09 17:25:33 -08:00
Nate Chandler
9ea71d1114 [IRGen] Prepare to refer to prespecializations.
When emitting a reference to the metadata for a generic type, prepare
to, rather than always inserting calls to the type metadata access
function, emit direct references to static specializations when possible
and emit calls to the forthcoming swift_getCanonicalSpecializedMetadata
when not possible.

For now, the metadata access function is always called.
2020-01-09 17:25:32 -08:00
Joe Groff
fb34044408 Merge remote-tracking branch 'origin/master' into master-next 2019-12-10 12:46:41 -08:00
Arnold Schwaighofer
0d324d223f Add swift_getTypeByMangledNameInContextInMetadataState such that we can
use getTypeByMangledName when abstract metadata state is requested

This can significantly reduce the code size of apps constructing deeply
nested types with conditional conformances.

Requires a new runtime.

rdar://57157619
2019-11-18 14:41:35 -08:00
swift-ci
aa57f0c92b Merge remote-tracking branch 'origin/master' into master-next 2019-11-12 12:09:57 -08:00
Arnold Schwaighofer
4cba76309f IRGen: Add TypeExpansionContext to IRGen 2019-11-11 14:21:52 -08:00
swift-ci
2689ff9343 Merge remote-tracking branch 'origin/master' into master-next 2019-10-30 07:49:45 -07:00
Robert Widmann
b849e51768 Use operator bool to claw back some readability 2019-10-29 16:56:21 -07:00
Robert Widmann
3e1a61f425 [NFC] Fold The Tri-State In Optional<ProtocolConformanceRef>
ProtocolConformanceRef already has an invalid state.  Drop all of the
uses of Optional<ProtocolConformanceRef> and just use
ProtocolConformanceRef::forInvalid() to represent it.  Mechanically
translate all of the callers and callsites to use this new
representation.
2019-10-29 16:55:56 -07:00
Xi Ge
64c0680686 Merge remote-tracking branch 'apple/master' into master-next 2019-10-28 10:19:36 -07:00
Arnold Schwaighofer
b75691cdde ReplaceOpaqueTypesWithUnderlyingTypes: We can't look through opaque archetypes if the underlying type contains a type not accessible from the current context
We can't access types in the same module if they are private: they could
be in a different TU.
We can't access types from different modules if they are private or
internal.

Some more information can be gleaned from the resilience expansion: A
minimally resilient function can't reference private or internal types.

rdar://56093964
2019-10-14 10:54:21 -07:00
Harlan Haskins
d4247942c4 Merge remote-tracking branch 'upstream/master' into master-next 2019-09-26 20:19:25 -07:00
Harlan Haskins
e349b7b123 Merge branch 'master' into master-rebranch 2019-09-26 20:16:05 -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
Jordan Rose
eefb0d0644 Merge remote-tracking branch 'origin/master' into master-next 2019-09-04 14:01:43 -07:00
swift-ci
a6f4a4650b Merge remote-tracking branch 'origin/master' into master-rebranch 2019-09-04 12:43:45 -07:00
Joe Groff
0ae86c9c9d IRGen: Backward-deploy fix using open-coded accessors.
If we mangled an opaque associated type while targeting an older OS, we can use a \9
accessor reference string to instantiate the associated type.
2019-09-04 10:22:17 -07:00
swift-ci
c51c36c558 Merge remote-tracking branch 'origin/master' into master-rebranch 2019-08-26 10:04:38 -07:00
swift-ci
270a611d47 Merge remote-tracking branch 'origin/master' into master-next 2019-08-26 09:49:56 -07:00
Arnold Schwaighofer
781582b205 IRGen: Add addLoweredTypeRef API and use it for capture and
box descriptors

We want to substitute opaque result types in addTypeRef but when we pass
SILFunctionTypes this would fail because AST type substitution does not
support lowered SIL types.

Instead add addLoweredTypeRef which substitutes based on SILTypes.

rdar://54529445
2019-08-22 13:40:38 -07:00
Arnold Schwaighofer
8d26dc5fe5 Revert to use of getOrInsertFunction api.
We really want to get the function if it already exists not create new
ones.
2019-08-15 14:14:06 -07:00
Shoaib Meenai
8ba5dbd59b [IRGen] Adjust for LLVM r352827
getOrInsertFunction returns a FunctonCallee after LLVM r352827, so we
need to call getCallee to get the actual Value.
2019-08-10 19:18:04 -07:00
Slava Pestov
6248628961 Merge remote-tracking branch 'origin/master' into master-next 2019-08-09 15:51:48 -04:00
swift-ci
299ef46699 Merge remote-tracking branch 'origin/master' into master-rebranch 2019-08-08 20:03:45 -07:00
swift-ci
740cb36b76 Merge remote-tracking branch 'origin/master' into master-rebranch 2019-08-08 18:04:29 -07:00
Joe Groff
b9e6ae07e4 IRGen: Avoid unnecessary swift_getObjectType calls.
In too many places, we were calling into `emitDynamicTypeOfOpaqueHeapObject` even when we had
more specific type information about the heap object we were querying. Replace all calls with
`emitDynamicTypeOfHeapObject`, which uses the best available access path and completely avoids
runtime calls for pure Swift classes and heap objects. When targeting non-ObjC-interop platforms,
we also know we never need to call `swift_getObjectType`, so avoid doing so altogether.
2019-08-08 18:00:10 -07:00
Brent Royal-Gordon
639aac719b Update for new getOrInsertFunction() return type 2019-08-08 17:56:37 -07:00
Joe Groff
77b012af1d SIL: Add an [exact_self_class] function attribute.
This indicates that the "self" argument to the current function is always dynamically of the exact
static base class type, allowing metadata accesses in IRGen to use the local self metadata to answer
metadata requests for the class type. Set this attribute on allocating entry points of designated
inits, which is one of the most common places where we emit redundant metadata accesses.
2019-08-08 14:03:07 -07:00
Joe Groff
fc269690b7 IRGen: Answer class metadata requests with the self argument in methods of final classes.
Class methods always have a "self" argument that can be used to get the metadata of the dynamic
Self type, which in final classes is always the same as the statically-known base class. Use this
to avoid reconstructing the static base class type.
2019-08-08 14:03:06 -07:00
Joe Groff
44af3a9398 Merge pull request #26561 from jckarter/opaque-assoc-type-demangle-workaround
IRGen: Work around runtime bug demangling associated types of opaque types.
2019-08-08 13:06:40 -07:00
Joe Groff
e6bc3e7adf IRGen: Work around runtime bug demangling associated types of opaque types.
The Swift 5.1 runtime (and master, for the time being) do not successfully demangle this mangling,
so for the time being, fall back to open-coded metadata access in this case. Workaround for
rdar://problem/54084733.
2019-08-08 10:31:48 -07:00
Joe Groff
9bd97ea0c1 Merge pull request #26542 from jckarter/opaque-type-metadata-peephole
IRGen: Peephole metadata requests for opaque types.
2019-08-08 09:36:17 -07:00
Joe Groff
8bd2319530 IRGen: Peephole metadata requests for opaque types.
If we're allowed to know at IRGen time what the underlying type of an opaque type is, we can
satisfy references to the opaque type's metadata or protocol witness tables by directly referencing
the underlying type instead.
2019-08-07 19:57:04 -07:00