Commit Graph

3168 Commits

Author SHA1 Message Date
Slava Pestov
7aabd80898 SIL: Stub out TypeConverter::getOverriddenVTableEntry()
This replaces SILDeclRef::getBaseOverriddenVTableEntry(). It lives
in the TypeConverter because it needs to use type lowering information
to determine if the method requires a new vtable entry or not.
2017-03-24 01:53:39 -07:00
Slava Pestov
ef7f6bf0ea SIL: Stub out TypeConverter::requiresNewVTableEntry() 2017-03-24 01:52:42 -07:00
Slava Pestov
e912f27944 AST/SILGen: New mangling for vtable thunks
Simply mangling the derived method is no longer sufficient. Now also
mangle the base method, so that eventually we handle this sort of
scenario:

class Base {
  // introduces: Base.method
  func method(_: Int, _: Int) {}
}

class First : Base {
  // overrides: Base.method
  // introduces: First.method
  override func method(_: Int?, _: Int) {}
}

class Second : First {
  // overrides: Base.method, First.method
  // introduces: Second.method
  override func method(_: Int?, _: Int?) {}
}

Here, the override of Base.method by Second.method and the
override of First.method by Second.method require distinct
manglings even though the derived method (Second.method) is
the same in both cases.

Note that while the new mangling is longer, vtable thunks are
always emitted with private linkage, so with the exception of
the standard library which is built with -sil-serialize-all
they will not affect the size of dylibs.

The standard library itself has very few classes so it doesn't
matter there either.

This patch doesn't actually add any support to introduce new
vtable entries for methods that override; this is coming up
next.
2017-03-23 23:40:52 -07:00
Slava Pestov
1a9fe1fb74 SILGen: Use SILVTableVisitor instead of bespoke member traversal
This changes the order in which declarations are emitted.
It also means we no longer emit a vtable entry for the
materializeForSet of dynamic storage. Neither of these are
intended to have any functional effect.
2017-03-23 18:45:40 -07:00
Roman Levenstein
4e2262944d Extend the representation of layout constraints
- Add support for _Class and _NativeClass layout constraints, which are supposed to represent T: Superclass and P: class constraints in the future.
- Use the re-factoring to also reduce the number of dynamic allocations when creating layout constraints. Simple non-parametrized layout constraints are now represented as statically allocated singletons (static members of LayoutConstraintInfo).
2017-03-22 16:37:38 -07:00
Hugh Bellamy
d1849d7c28 Fix top of tree Clang compilation errors 2017-03-21 19:16:39 +07:00
Slava Pestov
99da2ea244 Merge pull request #8211 from practicalswift/use-is-instead-of-getas-where-appropriate
[gardening] Use .is<T>() instead of .getAs<T>() if the result is not needed
2017-03-21 00:39:23 -07:00
Slava Pestov
1d364f4229 SIL: Add a couple of assertions
These were helpful while debugging <rdar://problem/31163470>.
2017-03-20 23:13:13 -07:00
Joe Shajrawi
d43932f2b6 Add support for address only let closures under opaque value mode 2017-03-20 17:22:17 -07:00
practicalswift
83526fe224 [gardening] Use .is<T>() instead of .getAs<T>() if the result is not needed 2017-03-20 22:54:01 +01:00
Erik Eckstein
d70bfc5de2 rename namespace NewMangling -> Mangle 2017-03-20 10:09:30 -07:00
Erik Eckstein
1625345b90 Remove the old mangler.
NFC
2017-03-17 16:10:36 -07:00
Hugh Bellamy
3220f7fba8 Provide const dereference operator in SILSuccessorIterator 2017-03-16 14:41:51 +07:00
Erik Eckstein
a16beaea3c Remove the now usused ConformanceCollector utility.
It was used for dead witness table elimination. But this is done now by lazy emission in IRGen.
Also update DeadFunctionElimination.
NFC.
2017-03-15 10:18:18 -07:00
Slava Pestov
fa96eb4b4e Merge pull request #8091 from slavapestov/class-method-abstraction
Use the right abstraction pattern when calling class methods
2017-03-14 20:24:25 -07:00
Slava Pestov
bd6c70c9d2 AST: Fix TypeBase::adjustSuperclassMemberDeclType() to strip generic signatures
Type::subst() does stupid things if you give it a
GenericFunctionType, attempting to build a new "substituted"
GenericSignature by hand.

As the newly-added test case demonstrates, this can trigger
assertions, and the callers of adjustSuperclassMemberDeclType()
didn't care about the generic signature anyway, so strip it off
first.

Soon, I want to have Type::subst() assert if it encounters a
GenericFunctionType, and remove all the junk there altogether,
but there's more work to be done first.

Progress on <rdar://problem/30817732> (RxCocoa build failures on
master), but now it hits further regressions.
2017-03-14 19:10:44 -07:00
Slava Pestov
76834a12ed SIL: Rename AbstractionPattern:getLValueObjectType() to getLValueOrInOutObjectType() 2017-03-14 17:46:54 -07:00
Joe Shajrawi
e20653ad04 Merge pull request #8090 from shajrawi/ConsumptionKind_UnconditionalCheckedCastValue
Add consumption kind to UnconditionalCheckedCastValueInst
2017-03-14 15:30:26 -07:00
Joe Shajrawi
ea4ba25b8a Add consumption kind to UnconditionalCheckedCastValueInst 2017-03-14 13:53:05 -07:00
John McCall
3c5de5fa0a Preserve type canonicality better in several places and
idiomatize some uses of SILType::getSwiftRValueType().
2017-03-14 14:59:43 -04:00
John McCall
897f5ab7c5 Restore CanType-based micro-optimizations.
This reverts commit 5036806e5a.
However, it preserves a pair of changes to the SIL optimizer
relating to walking through optional types.
2017-03-14 11:38:11 -04:00
Michael Gottesman
6d7b11c8eb [stdlib] Cleanup usage of Builtin.castToNativeObject(...).
Previously often times when casting a value, we would just pass along the
cleanup of the uncasted value. With semantic SIL this is no longer correct since
the cleanup now needs to be on the cast result.

This caused problems for certain usages of Builtin.castToNativeObject(...) by
the stdlib. Specifically, the stdlib was using this on AnyObject values that
were not necessarily native. Since we were recreating the cleanup on the native
value, a swift native release was being used =><=.

In this commit I solve this problem by:

1. Adding an assert in Builtin.castToNativeObject(...) that ensures that any value
passed to Builtin.castToNativeObject() is known conservatively to use swift
native reference counting.

2. I changed all uses where we do not have a precondition of a native ref
counting type to use Builtin.castToUnknownObject(...).

3. I added a new Builtin called Builtin.unsafeCastToNativeObject(...) that does
not have the compile time check. I used this to rewrite callsites in the stdlib
where we know via preconditions that an AnyObject will dynamically always be
native.

rdar://29791263
2017-03-14 00:10:16 -07:00
Slava Pestov
b6e503d927 Merge pull request #8044 from slavapestov/cantype-gardening
AST: Remove some unnecessary getCanonicalType() calls
2017-03-13 11:52:51 -07:00
Michael Gottesman
8521601215 [silgen] Move ResultPlan from SILGenApply.cpp -> ResultPlan.{h,cpp}
ResultPlan and related constructs have already been written in a type erased
fashion. This commit takes advantage of this by moving the details of the code
to ResultPlan.{cpp,h}.

This slims down SILGenApply.cpp in a NFC way and ensures that other code in
SILGenApply can not depend on the details of ResultPlan. Also it is my hope that
this can become the beginning of the merging of the ResultPlan from SILGenApply
and from SILGenPoly. We should only have 1 way in SILGen to build applies and
create apply results.

rdar://29791263
2017-03-13 10:32:33 -07:00
Slava Pestov
5036806e5a AST: Remove some unnecessary getCanonicalType() calls 2017-03-13 02:24:36 -07:00
Slava Pestov
4fa2ad8f55 SIL: Allocating entry points of designated initializers are [fragile]
The allocating entry point allocates an instance and calls the
initializing entry point. This should always be safe to inline
into resilient callers.
2017-03-12 23:14:51 -07:00
Slava Pestov
162b2d252e AST: Include gardening to minimize dependencies on Expr.h
A lot of files transitively include Expr.h, because it was
included from SILInstruction.h, SILLocation.h and SILDeclRef.h.

However in reality most of these files don't do anything
with Exprs, especially not anything in IRGen or the SILOptimizer.

Now we're down to 171 files in the frontend which depend on
Expr.h, which is still a lot but much better than before.
2017-03-12 22:26:56 -07:00
Joe Shajrawi
1e30925a0d Merge pull request #8031 from shajrawi/error_opaque_mode
Add special corner case: support for Error type under opaque value mode
2017-03-10 23:19:34 -08:00
Joe Shajrawi
cb197d5774 Add special corner case: support for Error type under opaque value mode 2017-03-10 20:23:40 -08:00
Jordan Rose
c4599d9e1c Merge pull request #8009 from jrose-apple/fix-varying-version-failability
Allow "redeclaring" an initializer or method with non-overlapping availability.
2017-03-10 17:42:27 -08:00
Arnold Schwaighofer
85b126d191 SILVerifier: Fix the opened c-o-w existential check for debug_value_addr instruction 2017-03-09 17:22:35 -08:00
Arnold Schwaighofer
1c9f7f5338 SIL: Add verification of open_existential_addr instructions
Make sure that all uses of "immutable_access" instructions are not mutating the
opened value.

Only enable verification if we have COW existentials enabled.
2017-03-09 17:22:34 -08:00
Jordan Rose
f068ddf1e3 Default DeclAttributes::getAttributes to skipping invalid attributes.
This matches the singular 'getAttribute', and all three current users
of this API were passing 'false' here anyway. No functionality change.
2017-03-09 14:10:25 -08:00
Erik Eckstein
5e80555c9b demangler: put the demangler into a separate library
Previously it was part of swiftBasic.

The demangler library does not depend on llvm (except some header-only utilities like StringRef). Putting it into its own library makes sure that no llvm stuff will be linked into clients which use the demangler library.

This change also contains other refactoring, like moving demangler code into different files. This makes it easier to remove the old demangler from the runtime library when we switch to the new symbol mangling.

Also in this commit: remove some unused API functions from the demangler Context.

fixes rdar://problem/30503344
2017-03-09 13:42:43 -08:00
Joe Groff
99ea154151 Merge pull request #7965 from jckarter/invariant-load
Add a `loadInvariant` builtin.
2017-03-09 06:39:42 -08:00
Joe Groff
39ecc53a25 Add a loadInvariant builtin.
Lowers to an invariant load in LLVM; probably useful for SIL too at some point too, but NFC at that level yet.
2017-03-08 21:02:03 -08:00
Slava Pestov
4165e12c25 SIL: Fix recent bug introduced into old style mangling of specializations
The format is "type conformances... '_'" for each substitutable
generic parameter. I broke it so that it emits types for the
substitutable parameters but conformances for all requirements
in the signature.

This changed the mangling of specializations where the function
being specialized placed additional constraints on associated
types, causing demangling failure in the pre-specialization
whitelist code.

This might fix <rdar://problem/30932656>.
2017-03-08 20:43:04 -08:00
Slava Pestov
5465c8ca8f SIL: Remove most usages of TypeBase::gatherAllSubstitutions() 2017-03-08 13:54:28 -08:00
Joe Shajrawi
9a29edfe9e Merge pull request #7972 from shajrawi/rename_opaque_br
Rename unconditional_checked_cast_opaque to unconditional_checked_cast_value
2017-03-07 19:50:27 -08:00
Joe Shajrawi
33b0cf653f Rename unconditional_checked_cast_opaque to unconditional_checked_cast_value 2017-03-07 18:53:52 -08:00
Slava Pestov
13cc1ad07c AST: Remove SubstitutionMap::getConformances() 2017-03-07 16:04:53 -08:00
Devin Coughlin
8026026df3 Merge pull request #7925 from devincoughlin/sil_tsan_inout_access_builtin
SIL: Add SIL builtin for Thread Sanitizer inout accesses
2017-03-07 08:10:00 -08:00
Devin Coughlin
6ac36df1e7 SIL: Add SIL builtin for Thread Sanitizer inout accesses
...and IRGen it into a call to __tsan_write1 in compiler-rt. This is
preparatory work for a later patch that will add an experimental
option to treat Swift inout accesses as TSan writes.
2017-03-06 19:13:50 -08:00
Joe Shajrawi
ca77872ba8 Merge CheckedCastValueBranch with new master 2017-03-06 17:32:09 -08:00
Joe Shajrawi
1f626304f1 Add support for conditional checked cast instruction for opaque value types + SILGen support for it 2017-03-06 16:35:27 -08:00
Michael Gottesman
e849900a7b [silgen] Add a new API for building switches: SwitchEnumBuilder.
This is a closure based API for creating switches that obey ownership
convensions. The way you use it with objects is as follows:

   SwitchEnumBuilder S(...);

   S.addCase(Decl, Block, [](ManagedValue Arg) -> void {
     ...
   });
   S.addCase(Decl, Block, [](ManagedValue Arg) -> void {
     ...
   });
   S.addDefaultCase(Block, [](ManagedValue Arg) -> void {
     ...
   });
   std::move(S).emit();

What is important is that it sets up the switch_enum destination blocks with the
proper cleanups for code emitted into the destination block and also provides
the default error with the passed in value with the appropriate cleanups.

It does not handle exits from the switch_enum on purpose since diamond
switch_enum APIs form a subset of APIs. It also expects the closure to create
terminators if appropriate.

In the switch_enum_addr case you have to do a bit more work, but it is still a
nicer API than doing it by hand as we do today.

rdar://29791263
2017-03-06 13:58:33 -08:00
Michael Gottesman
07bcac30b3 [semantic-sil] If SIL Ownership is disabled, return Any if a forwarding inst has conflicting ownership.
If SIL Ownership is enabled, we still trigger an unreachable.

rdar://29791263
2017-03-05 11:44:14 -08:00
Michael Gottesman
87ca878870 [silgen] Fix another tuple explosion -> borrow + copy since we do not have the destructure operation yet.
rdar://29791263
2017-03-05 11:44:11 -08:00
practicalswift
75522a8ed5 [gardening] Remove unused variable loweredMT 2017-03-05 01:03:31 +01:00
Saleem Abdulrasool
0c56998576 SIL: IWYU cl edition
Include llvm/Support/CommandLine.h when using llvm::cl.
2017-03-04 14:20:51 -08:00