Commit Graph

1326 Commits

Author SHA1 Message Date
Saleem Abdulrasool
636564e2cd IRGen: collocate WASM/ELF handling
WASM currently is treated identically to the ELF paths.  Collocate the
types to make it easier to ensure that all the paths are correctly
handling the emission.  This adds the missed case for the module hash.
2019-12-09 09:21:04 -08:00
Varun Gandhi
affa1b49bf [Runtime] Memset Extradata fully before copy from pattern. (#28478)
The third argument of memset needs a size in *bytes* not words.
2019-12-04 08:48:01 -08:00
Arnold Schwaighofer
4cba76309f IRGen: Add TypeExpansionContext to IRGen 2019-11-11 14:21:52 -08:00
Dan Zheng
53e61a9587 [AutoDiff upstream] Add the _Differentiation module. (#27511)
The `_Differentiation` module is the experimental support library for
differentiable programming. It is built when the build-script flag
`--enable-experimental-differentiable-programming` is enabled.

The `Differentiable` protocol generalizes all types that work with
differentiation. It is a core piece of the differentiable programming
project. Other parts depending on the `Differentiable` protocol will
be upstreamed piece by piece.

The `Differentiable` protocol is compiler-known and will be used during
type-checking, SILGen, and the SIL differentiation transform.
2019-11-06 11:31:12 -08:00
Mishal Shah
2f86d67500 Merge pull request #27396 from shahmishal/master-rebranch
Update master to support apple/stable/20190619 branch for LLVM projects
2019-10-01 10:50:49 -07:00
Robert Widmann
5a8d0744c3 [NFC] Adopt TypeBase-isms for GenericSignature
Structurally prevent a number of common anti-patterns involving generic
signatures by separating the interface into GenericSignature and the
implementation into GenericSignatureBase.  In particular, this allows
the comparison operators to be deleted which forces callers to
canonicalize the signature or ask to compare pointers explicitly.
2019-09-30 14:04:36 -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
swift-ci
b62b6fbd91 Merge remote-tracking branch 'origin/master' into master-rebranch 2019-09-16 18:23:59 -07:00
Joe Groff
30f5269670 IRGen: Use correct generic sig when mangling opaque underlying type.
Caught while testing on Swift 5.1.
2019-09-16 15:27:07 -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
2f37dd154c Merge remote-tracking branch 'origin/master' into master-rebranch 2019-08-09 15:04:20 -07:00
Joe Groff
b5f36f7bea IRGen: Use known value witnesses in generic metadata patterns.
We were unnecessarily conservative here; generic metadata patterns support indirectable references
to value witness tables exported by the standard library, so if we have a fixed-layout generic
type that matches a known value witness table layout, use that instead of generating a new
value witness table.
2019-08-09 12:52:22 -07:00
Brent Royal-Gordon
fb20b503ba Merge branch 'master' into master-rebranch
# Conflicts:
#	lib/ClangImporter/ClangImporter.cpp
#	test/IRGen/builtins.swift
#	test/IRGen/enum.sil
#	tools/driver/autolink_extract_main.cpp
#	utils/build-presets.ini
2019-08-08 17:07:59 -07:00
Joe Groff
3e2965f452 IRGen: Omit frame pointers from metadata accessors. 2019-08-07 14:16:41 -07:00
Joe Groff
f0e5e1911d IRGen: Access concrete type metadata by mangled name.
When we generate code that asks for complete metadata for a fully concrete specific type that
doesn't have trivial metadata access, like `(Int, String)` or `[String: [Any]]`,
generate a cache variable that points to a mangled name, and use a common accessor function
that turns that cache variable into a pointer to the instantiated metadata. This saves a bunch
of code size, and should have minimal runtime impact, since the demangling of any string only
has to happen once.

This mostly just works, though it exposed a couple of issues:

- Mangling a type ref including objc protocols didn't cause the objc protocol record to get
  instantiated. Fixed as part of this patch.
- The runtime type demangler doesn't correctly handle retroactive conformances. If there are
  multiple retroactive conformances in a process at runtime, then even though the mangled string
  refers to a specific conformance, the runtime still just picks one without listening to the
  mangler. This is left to fix later, rdar://problem/53828345.

There is some more follow-up work that we can do to further improve the gains:

- We could improve the runtime-provided entry points, adding versions that don't require size
  to be cached, and which can handle arbitrary metadata requests. This would allow for mangled
  names to also be used for incomplete metadata accesses and improve code size of some generic
  type accessors. However, we'd only be able to take advantage of the new entry points in
  OSes that ship a new runtime.
- We could choose to always symbolic reference all type references, which would generally reduce
  the size of mangled strings, as well as make runtime demangling more efficient, since it wouldn't
  need to hit the runtime caches. This would however require that we be able to handle symbolic
  references across files in the MetadataReader in order to avoid regressing remote mirror
  functionality.
2019-08-02 14:28:53 -07:00
Joe Groff
e12f935b9a IRGen: Use correct archetype conformance code path for opaque associated types.
The code here was not correct in a situation where an opaque type had constraints that were
refinements of the protocol requirements of an associated type, as in:

```
protocol ParentProtocol {}
protocol SubProtocol: ParentProtocol {}

protocol P {
  associatedtype A: ParentProtocol
  func foo() -> A
}

struct S: P {
  func foo() -> some SubProtocol
}
```

because it assumed that the conformance could be found directly on the opaque type instead of
potentially via an arbitrary MetadataPath. Falling through to the code that already correctly
handles archetype conformances right below the removed code does the right thing. Fixes
rdar://problem/53081207.
2019-07-19 21:30:45 -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
Jordan Rose
4abefdb326 [IRGen] Canonicalize symbolic ref types in the right generic context (#25955)
When referencing a superclass type from a subclass, for example, the
type uses the subclass's generic parameters, not the superclass's.
This can be important if a nested type constrains away some of its
parent type's generic parameters.

This doesn't solve all the problems around mis-referenced generic
parameters when some are constrained away, though. That might
require a runtime change. See the FIXME comments in the test cases.

rdar://problem/51627403
2019-07-08 14:40:26 -07:00
swift-ci
2d6266a631 Merge remote-tracking branch 'origin/master' into master-next 2019-06-01 22:09:21 -07:00
Saleem Abdulrasool
731c31f9a5 MSVC: litter the code with llvm_unreachable (NFC)
Add `llvm_unreachable` to mark covered switches which MSVC does not
analyze correctly and believes that there exists a path through the
function without a return value.
2019-06-01 19:02:46 -07:00
swift-ci
13c61ecb15 Merge remote-tracking branch 'origin/master' into master-next 2019-05-03 08:29:43 -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
swift-ci
9da051c4e6 Merge remote-tracking branch 'origin/master' into master-next 2019-04-24 08:09:16 -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
swift-ci
53d5e800c1 Merge remote-tracking branch 'origin/master' into master-next 2019-04-19 16:50:46 -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
Slava Pestov
aa77f6e2f2 IRGen: Emit reference to class stub from class context descriptor
This was an oversight. I was setting the flag but not emitting the
pointer at the end.
2019-04-19 16:50:29 -04:00
Slava Pestov
91d0a10462 IRGen: Don't add class stubs to objc_classes list 2019-04-19 16:50:29 -04:00
swift-ci
89372f876a Merge remote-tracking branch 'origin/master' into master-next 2019-04-18 15:10:40 -07:00
Joe Groff
f363a10b3b runtime interface fixup irgen 2019-04-17 14:44:40 -07:00
Joe Groff
5ec394c656 fill in witness tables 2019-04-17 14:44:40 -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
swift-ci
707344affa Merge remote-tracking branch 'origin/master' into master-next 2019-04-12 07:29:33 -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
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
swift-ci
36d8c65f53 Merge remote-tracking branch 'origin/master' into master-next 2019-03-27 05:29:27 -07:00
Slava Pestov
68c07620cd IRGen: Emit Objective-C resilient class stubs if experimental flag is on
Non-generic classes with resilient ancestry do not have statically-emitted
metadata, so we can now emit an Objective-C resilient class stub instead.

Also, when emitting an Objective-C category, reference the class stub if
the class has resilient ancestry; previously this case would hit an assert.

Note that class stubs always start with a zero word, with the address point
pointing immediately after. This works around a linker issue, where the
linker tries to coalesce categories and gets confused upon encountering a
class stub.
2019-03-26 18:53:09 -04:00
Slava Pestov
0446c3e80d IRGen: Clean up emitObjCClassSymbol() to improve code reuse 2019-03-26 18:46:14 -04:00
Slava Pestov
cece98b2ed AST: Generalize ClassDecl::checkObjCAncestry() to ClassDecl::checkAncestry()
This replaces ClassDecl::hasObjCMembers() and some hand-coded walks.
2019-03-26 18:42:59 -04:00
swift-ci
39028d77f0 Merge remote-tracking branch 'origin/master' into master-next 2019-03-22 19:30:06 -07:00
Stephen Canon
1a9ae47d06 Teach the importer to import any clang vector type as SIMDn<Scalar>. (#23454)
* Teach the importer to import any vector type as SIMDN<Scalar>.

Instead of having a known set of vector types, check to see if the
element type conforms to SIMDScalar; if it does, see if we have a
SIMDN defined with the right number of elements. If both are satisfied,
import the vector type as that Swift type.

By making this change, we gain the ability to import vector types
that aren't defined in terms of the Darwin simd module, which lets
us use C API with vector types on other platforms. It also lets us
import *every* vector type that Swift can represent, rather than the
small subset that are currently hardcoded.

* Increased test coverage for increased SIMD types that we can import.

Includes some minor cleanup from review. Also eliminates the old
simd_sans_simd test, since we can now import all of these types even when the simd module isn't imported.
2019-03-22 22:11:22 -04:00
swift-ci
36feacee54 Merge remote-tracking branch 'origin/master' into master-next 2019-03-15 15:49:10 -07:00
Saleem Abdulrasool
b97857e99f IRGen: adjust for SVN r355989
SVN r355989 adds support for the XCOFF file format.  For now, treat it as a COFF
target, though XCOFF and COFF are different.
2019-03-13 13:31:24 -07:00