Commit Graph

747 Commits

Author SHA1 Message Date
Slava Pestov
ec4a95be21 AST: Witness stores SubstitutionList instead of SubstitutionMap
This simplifies serialization and removes some calls of
SubstitutionMap::addSubstitution() and addConformance().
2017-02-12 00:51:26 -08:00
Hugh Bellamy
f001b7562b Use relatively new LLVM_FALLLTHROUGH instead of our own SWIFT_FALLTHROUGH 2017-02-12 10:47:03 +07:00
Slava Pestov
bd4f31025f AST: GenericEnvironment::mapTypeIntoContext() no longer needs to take a ModuleDecl
Now, use LookUpConformanceInSignature instead.
2017-02-07 19:25:34 -08:00
Slava Pestov
3519e0cd25 AST: Introduce new SubstitutionList type to replace ArrayRef<Substitution>
SubstitutionList is going to be a more compact representation of
a SubstitutionMap, suitable for inline allocation inside another
object.

For now, it's just a typedef for ArrayRef<Substitution>.
2017-02-06 21:36:33 -08:00
Slava Pestov
1954665a95 AST: Remove more uses of SubstitutionMap::add{Substitution,Conformance}()
A new SubstitutionMap::getProtocolSubstitutions() method handles
the case where we construct a trivial SubstitutionMap to replace
the protocol Self type with a concrete type.

When substituting one opened existential archetype for another,
use the form of Type::subst() that takes two callbacks instead of
building a SubstitutionMap. SubstitutionMaps are intended to be
used with keys that either come from a GenericSignature or a
GenericEnvironment, so using them to replace opened archetypes
doesn't fit the conceptual model we're going for.
2017-02-06 20:33:39 -08:00
Michael Gottesman
e192b56a88 [silgen] Create CleanupManager::dump and the relevant dump methods to dump the current cleanups.
This is useful to discover when a specific cleanup is being eliminated while
debugging. The implementation is compiled out when assertions are disabled.

rdar://29791263
2017-02-05 18:38:41 -08:00
Slava Pestov
a4fd57647c AST: Remove unused resolver parameter from getTypeOfMember() 2017-02-03 19:55:39 -08:00
Slava Pestov
dca292c652 Serialization: Don't serialize contextual enum argument type
Storing this separately is unnecessary since we already
serialize the enum element's interface type. Also, this
eliminates one of the few remaining cases where we serialize
archetypes during AST serialization.
2017-01-30 00:08:53 -08:00
Joe Groff
16d1c284d5 SILGen: Mark associated type conformances as "used".
We neglected to do this, so we would fail to emit protocol conformances synthesized from imported ObjC declarations in cases where that was the only apparent use of the conformance, such as SR-3739 and rdar://problem/30195308.
2017-01-26 18:27:10 -08:00
Slava Pestov
c86b5ae427 AST: Header file gardening - include what you use 2017-01-19 20:07:06 -08:00
Slava Pestov
24b2531e5f AST: Have SubstitutionMaps manage the memory for the conformance array 2017-01-18 00:15:59 -08:00
Michael Gottesman
17b4d05e4e [semantic-sil] Rename EndBorrowInst::get{Src,Dest} => get{BorrowedValue,OriginalValue}.
This is a clearer name that makes it easier to remember what each part of the
end borrow is meant to accomplish.
2017-01-17 17:01:14 -08:00
Michael Gottesman
ea1f804207 [semantic-sil] Eliminate ValueOwnershipKind::Any from SILPHIArguments in Semantic SIL.
Most of this involved sprinkling ValueOwnershipKind::Owned in many places. In
some of these places, I am sure I was too cavalier and I expect some of them to
be trivial. The verifier will help me to track those down.

On the other hand, I do expect there to be some places where we are willing to
accept guaranteed+trivial or owned+trivial. In those cases, I am going to
provide an aggregate ValueOwnershipKind that will then tell SILArgument that it
should disambiguate using the type. This will eliminate the ackwardness from
such code.

I am going to use a verifier to fix such cases.

This commit also begins the serialization of ValueOwnershipKind of arguments,
but does not implement parsing of value ownership kinds. That and undef are the
last places that we still use ValueOwnershipKind::Any.

rdar://29791263
2017-01-10 20:05:23 -08:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Doug Gregor
16585992f6 [AST] Strengthen signature of SubstututionMap::addSubstitution().
It requires a CanSubstitutableType internally, so use that in the
signature and fix up all of the callers.
2017-01-05 16:04:19 -08:00
Michael Gottesman
b5e35240f2 Introduce a new Cleanup called EndBorrowCleanup
This will enable the usage of ManagedValue and scopes to manage shared borrowed
values.

rdar://29791263
2017-01-03 17:01:23 -08:00
Slava Pestov
fb0f372e94 AST: Move mapType{In,OutOf}Context() out of ArchetypeBuilder and clean up headers
- The DeclContext versions of these methods have equivalents
  on the DeclContext class; use them instead.

- The GenericEnvironment versions of these methods are now
  static methods on the GenericEnvironment class. Note that
  these are not made redundant by the instance methods on
  GenericEnvironment, since the static methods can also be
  called with a null GenericEnvironment, in which case they
  just assert that the type is fully concrete.

- Remove some unnecessary #includes of ArchetypeBuilder.h
  and GenericEnvironment.h. Now changes to these files
  result in a lot less recompilation.
2016-12-18 19:55:41 -08:00
Michael Gottesman
4e8ff35df5 [semantic-sil] Add ValueOwnershipKind field to SILPHIArgument and split Argument creation methods into one for SILPHIArgument and another for SILFunctionArgument.
We preserve the current behavior of assuming Any ownership always and use
default arguments to hide this change most of the time. There are asserts now in
the SILBasicBlock::{create,replace,insert}{PHI,Function}Argument to ensure that
the people can only create SILFunctionArguments in entry blocks and
SILPHIArguments in non-entry blocks. This will ensure that the code in tree
maintains the API distinction even if we are not using the full distinction in
between the two.

Once the verifier is finished being upstreamed, I am going to audit the
createPHIArgument cases for the proper ownership. This is b/c I will be able to
use the verifier to properly debug the code. At that point, I will also start
serializing/printing/parsing the ownershipkind of SILPHIArguments, but lets take
things one step at a time and move incrementally.

In the process, I also discovered a CSE bug. I am not sure how it ever worked.
Basically we replace an argument with a new argument type but return the uses of
the old argument to refer to the old argument instead of a new argument.

rdar://29671437
2016-12-18 14:48:35 -08:00
swift-ci
268c2b668d Merge pull request #6325 from practicalswift/gardening-20161216 2016-12-17 09:19:24 -08:00
Michael Gottesman
96c63e9e76 Merge pull request #6324 from practicalswift/cpp-gardening
[gardening] C++ gardening: Terminate namespaces, fix argument names, …
2016-12-16 23:30:33 -08:00
Joe Groff
4444d83756 SIL: Lower captures to boxes with an appropriate generic context.
Officially kick SILBoxType over to be "nominal" in its layout, with generic layouts structurally parameterized only by formal types. Change SIL to lower a capture to a nongeneric box when possible, or a box capturing the enclosing generic context when necessary.
2016-12-16 20:23:25 -08:00
practicalswift
38be6125e5 [gardening] C++ gardening: Terminate namespaces, fix argument names, ...
Changes:
* Terminate all namespaces with the correct closing comment.
* Make sure argument names in comments match the corresponding parameter name.
* Remove redundant get() calls on smart pointers.
* Prefer using "override" or "final" instead of "virtual". Remove "virtual" where appropriate.
2016-12-17 00:32:42 +01:00
practicalswift
16d6dce62e [gardening] Fix recently introduced typos. 2016-12-16 21:42:09 +01:00
Joe Groff
57d9ad0a03 Remove Module parameter from GenericEnvironment::mapTypeOutOfContext.
The substitution only replaces archetypes with abstract generic parameters, so no conformance lookup is necessary, and we can provide a "lookup" callback now that just vends abstract conformances.

(Ideally, we'd be able to do this for mapTypeIntoContext too, but we run into problems with generic signatures with same-type constraints on associated types with protocol requirements. Mapping `t_0_0.AssocType` into such a context will require conformance lookup for the concrete type replacement, since same-type Requirements don't preserve the conformances that satisfy the protocol requirements for the same-type relationship.)
2016-12-15 10:56:19 -08:00
Erik Eckstein
5ac0c5b9b7 Mangling: wire up the new mangling in various places in the compiler, but still use the old mangling.
The purpose of this change is to test if the new mangling is equivalent to the old mangling.
Both mangling strings are created, de-mangled and checked if the de-mangle trees are equivalent.
2016-12-05 14:07:05 -08:00
Joe Groff
9b858a7431 SIL: Remove the ElementType from DeallocBoxInst's representation.
This was made redundant by typed boxes, and the type operand was already removed from textual SIL, but the field was never removed from the instruction's in memory representation. It becomes wrong in the face of compound boxes with layout.
2016-12-02 15:19:43 -08:00
Michael Gottesman
96837babda Merge pull request #5920 from gottesmm/vacation_gardening
Vacation gardening
2016-11-25 09:17:21 -06:00
Michael Gottesman
0a8c54d04f [gardening] Always create new SILArguments using SILBasicBlock::createArgument instead of inline placement new.
The reasoning here is the same as in e42bf07.
2016-11-25 01:14:45 -06:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
Michael Gottesman
34ec32bc14 [semantic-arc] Handle the rest of the unqualified mem opts in SILGen.
Keep in mind that these are approximations that will not impact correctness
since in all cases I ensured that the SIL will be the same after the
OwnershipModelEliminator has run. The cases that I was unsure of I commented
with SEMANTIC ARC TODO. Once we have the verifier any confusion that may have
occurred here will be dealt with.

rdar://28685236
2016-11-09 11:37:52 -08:00
Michael Gottesman
3e5c4326fe [semantic-arc] Remove all uses of SILBuilder::*AndFold in SILGen and TypeLowering.
I am removing these usages of this API since it conflicts with SILGen's want to
hold onto copy_value return values for ownership propagation purposes. If any of
the copy_value are folded, the reference that SILGen holds onto will be
invalid.

rdar://28685236
2016-11-06 23:17:17 -08:00
Joe Groff
e1e7e19248 SIL: Construct alloc_box insns with the type of the box.
This becomes necessary with generalized boxes, since the box type isn't derivable from a single field type.
2016-11-03 19:26:42 -07:00
Doug Gregor
99daad0f30 Rework witness matching for generic requirements.
Reimplement the witness matching logic used for generic requirements
so that it properly models the expectations required of the witness,
then captures the results in the AST. The new approach has a number of
advantages over the existing hacks:

* The constraint solver no longer requires hacks to try to tangle
  together the innermost archetypes from the requirement with the
  outer archetypes of the context of the protocol
  conformance. Instead, we create a synthetic set of archetypes that
  describes the requirement as it should be matched against
  witnesses. This eliminates the infamous 'SelfTypeVar' hack.
* The type checker no longer records substitutions involving a weird
  mix of archetypes from different contexts (see above), so it's
  actually plausible to reason about the substitutions of a witness. A
  new `Witness` class contains the declaration, substitutions, and all
  other information required to interpret the witness.
* SILGen now uses the substitution information for witnesses when
  building witness thunks, rather than computing all of it from
  scratch. ``substSelfTypeIntoProtocolRequirementType()` is now gone
  (absorbed into the type checker, and improved from there), and the
  witness-thunk emission code is simpler. A few other bits of SILGen
  got simpler because the substitutions can now be trusted.
* Witness matching and thunk generation involving generic requirements
  and nested generics now works, based on some work @slavapestov was
  already doing in this area.
* The AST verifier can now verify the archetypes that occur in witness substitutions.
* Although it's not in this commit, the `Witness` structure is
  suitable for complete (de-)serialization, unlike the weird mix of
  archetypes previously present.

Fixes rdar://problem/24079818 and cleans up an area that's been messy
and poorly understood for a very, very long time.
2016-10-30 23:15:43 -07:00
Michael Gottesman
bffa7addaf [semantic-arc] Eliminate default {Load,Store}OwnershipQualification argument to SILBuilder::create{Load,Store}(...)
Today, loads and stores are treated as having @unowned(unsafe) ownership
semantics. This leaves the user to specify ownership changes on the loaded or
stored value independently of the load/store by inserting ARC operations. With
the change to Semantic SIL, this will no longer be true. Instead loads, stores
have ownership semantics that one must reason about such as copy, take, and
trivial.

This change moves us closer to that world by eliminating the default
OwnershipQualification argument from create{Load,Store}. This means that the
compiler developer cannot ignore reasoning about the ownership semantics of the
memory operation that they are creating.

Operationally, this is a NFC change since I have just gone through the compiler
and updated all places where we create loads, stores to pass in the former
default argument ({Load,Store}OwnershipQualifier::Unqualified), to
SILBuilder::create{Load,Store}(...). For now, one can just do that in situations
where one needs to create loads/stores, but over time, I am going to tighten the
semantics up via the verifier.

rdar://28685236
2016-10-30 13:07:06 -07:00
Michael Gottesman
9507093b17 [semantic-arc] Change SILGen to only use copy_value, destroy_value.
rdar://28851920
2016-10-29 20:11:07 -07:00
Joe Groff
88ad1160a2 SILGen/IRGen: Lower protocol witness thunks for ObjC lightweight generics as pseudogeneric.
Fixes rdar://problem/28873860, where we would miscompile when lightweight generic classes were extended to conform to Swift protocols because we tried to emit parameters for the class's generic parameters for the witness entry points. Prevent this by lowering the witness into a pseudogeneric function in SILGen, and teaching IRGen to do the right thing for a witness with pseudogeneric parameters.
2016-10-26 13:45:34 -07:00
Michael Gottesman
362a556af4 [semantic-arc] SILBuilder::emit{Retain,Release}ValueOperation => SILBuilder::emit{Copy,Destroy}ValueOperation.
rdar://28851920
2016-10-25 13:12:52 -07:00
Joe Groff
e4c67e2d5a SIL: Give project_box a field index operand.
Allow project_box to get the address of any field in a multi-field box.
2016-10-24 13:10:41 -07:00
Slava Pestov
58f013ea73 SILGen: Create new archetypes for witness thunks instead of using the conformance
Sema produces a weird mix of requirement and witness archetypes when
it builds witness substitutions. Instead of hacking around this in
SILGen, just build new archetypes, since we already have to use an
ArchetypeBuilder to get the correct generic signature on the interface
type.

Then, we just have to map the witnessSubs provided by Sema to use our
new archetypes.

This unblocks some work on generic inlining.

Fixes <rdar://problem/28765006>.
2016-10-18 01:03:28 -07:00
Slava Pestov
5ab94a6ef0 AST: Add "re-sugaring" to GenericEnvironment
Sugared GenericTypeParamTypes point to GenericTypeParamDecls,
allowing the name of the parameter as written by the user to be
recovered. Canonical GenericTypeParamTypes on the other hand
only store a depth and index, without referencing the original
declaration.

When printing SIL, we wish to output the original generic parameter
names, even though SIL only uses canonical types. Previously,
we used to accomplish this by mapping the generic parameter to an
archetype and printing the name of the archetype. This was not
adequate if multiple generic parameters mapped to the same
archetype, or if a generic parameter was mapped to a concrete type.

The new approach preserves the original sugared types in the
GenericEnvironment, adding a new GenericEnvironment::getSugaredType()
method.

There are also some other assorted simplifications made possible
by this.

Unfortunately this makes GenericEnvironments use a bit more memory,
however I have more improvements coming that will offset the gains,
in addition to making substitution lists smaller also.
2016-10-12 18:56:16 -07:00
Doug Gregor
262fe95344 Drastically scale back usage of SubstFlags::IgnoreMissing.
This particular flag should only be used in rare cases where we don't
want to know about failures, but instead want to get some
partially-formed type. Only very specific parts of the type checker
need this (associated type inference), and code completion relies on
it for slightly-better results.
2016-10-06 14:44:11 -07:00
Slava Pestov
cbf76fd79d Sema: More cleanup from removal of markInvalidGenericSignature() 2016-10-04 23:39:10 -04:00
Slava Pestov
b5decb6be4 SILGen: Fix some issues with @pseudogeneric thunks
This would manifest as crashes in IRGen when bridging a block
taking another block in generic context.

- When emitting a re-abstraction thunk, make it pseudogeneric if
  its parent function is pseudogeneric. This ensures we don't
  try to get runtime type metadata when it doesn't exist.

- Mangle pseudogeneric-ness of a reabstraction thunk correctly.
  Otherwise we could emit thunks with different signatures under
  the same mangling.

- Only set the pseudogeneric attribute if the thunk has a generic
  signature, since otherwise the mangling is no longer unique.

Fixes <rdar://problem/27718566>.
2016-09-15 21:45:52 -07:00
Slava Pestov
aaf016c645 AST: Remove ArchetypeType::isSelfDerived() 2016-09-13 22:58:59 -07:00
John McCall
0bdc8b2a3b Merge pull request #4689 from rjmccall/optional-abstraction
Abstract the object type of optional types
2016-09-09 10:19:36 -07:00
John McCall
34fb15e375 Abstract the object type of an optional type according to the
abstraction pattern of the type rather than always using the
most-general pattern, and erase ImplicitlyUnwrappedOptional from
the SIL type system.
2016-09-08 23:26:19 -07:00
Slava Pestov
b677a2e6a7 AST: Use the new Type::subst() in a few places
SILType substitutions are still done with the old form, and until
BoundGenericTypes hold conformances, we still have to pass around
a ModuleDecl in a few places we really shouldn't, but one step
at a time.
2016-09-08 21:59:13 -07:00
Slava Pestov
07790d3e5e SILGen: Re-work witness thunk emission a bit
Build the witness thunk signature in a more principled manner, and
clean up how the GenericEnvironment is constructed.
2016-09-06 11:51:13 -07:00
Slava Pestov
ca0b548584 SIL: Replace SILFunction::ContextGenericParams with a GenericEnvironment
This patch is rather large, since it was hard to make this change
incrementally, but most of the changes are mechanical.

Now that we have a lighter-weight data structure in the AST for mapping
interface types to archetypes and vice versa, use that in SIL instead of
a GenericParamList.

This means that when serializing a SILFunction body, we no longer need to
serialize references to archetypes from other modules.

Several methods used for forming substitutions can now be moved from
GenericParamList to GenericEnvironment.

Also, GenericParamList::cloneWithOuterParameters() and
GenericParamList::getEmpty() can now go away, since they were only used
when SILGen-ing witness thunks.

Finally, when printing generic parameters with identical names, the
SIL printer used to number them from highest depth to lowest, by
walking generic parameter lists starting with the innermost one.
Now, ambiguous generic parameters are numbered from lowest depth
to highest, by walking the generic signature, which means test
output in one of the SILGen tests has changed.
2016-08-28 13:51:37 -07:00
John McCall
afdda3d107 Implement SE-0117.
One minor revision: this lifts the proposed restriction against
overriding a non-open method with an open one.  On reflection,
that was inconsistent with the existing rule permitting non-public
methods to be overridden with public ones.  The restriction on
subclassing a non-open class with an open class remains, and is
in fact consistent with the existing access rule.
2016-08-02 07:46:38 -07:00