Commit Graph

1108 Commits

Author SHA1 Message Date
John McCall
c0b3bf1711 Suppress access enforcement when an l-value is converted to a pointer
just for pointer identity.

The current technique for deciding whether that's the case is *extremely*
hacky and need to be replaced with an attribute, but I'm reluctant to
take that on so late in the schedule.  The hack is terrible but not too
hard to back out in the future.  Anyone who names a method like this just
to get the magic behavior knows well that they are not on the side of
righteousness.

rdar://33265254
2017-07-21 23:40:04 -04:00
Robert Widmann
8cdddef2f8 Refactor Params to use flags
Also, begin to pass around base types instead of raw InOutType types.  Ideally, only Sema needs to deal with them, but this means that a bunch of callers need to unwrap any inouts that might still be lying around before forming these types.

Multiple parts of the compiler were slicing, dicing, or just dropping these flags.  Because I intend to use them for the new function type representation, I need them to be preserved all across the compiler.  As a first pass, this stubs in what will eventually be structural rules as asserts and tracks down all callers of consequence to conform to the new invariants.

This is temporary.
2017-07-19 09:49:32 -07:00
John McCall
63594f1e10 Fix a SILGen bug with variadic subscripts that I recently introduced
and a CSApply bug with variadic tuple subscripts that I did not.

The SILGen bug was exposed by the source-compat test suite as part
of rdar://33341584.
2017-07-17 18:52:17 -04:00
John McCall
80b180a9a1 Implement a syntactic peephole to recognize explicit bridging
conversions that reverse an implicit conversion done to align
foreign declarations with their imported types.

For example, consider an Objective-C method that returns an NSString*:
  - (nonnull NSString*) foo;
This will be imported into Swift as a method returning a String:
  func foo() -> String
A call to this method will implicitly convert the result to String
behind the scenes.  If the user then casts the result back to NSString*,
that would normally be compiled as an additional conversion.  The
compiler cannot simply eliminate the conversion because that is not
necessarily semantically equivalent.

This peephole recognizes as-casts that immediately reverse a bridging
conversion as a special case and gives them special power to eliminate
both conversions.  For example, 'foo() as NSString' will simply return
the original return value.  In addition to call results, this also
applies to call arguments, property accesses, and subscript accesses.
2017-07-15 01:13:41 -04:00
John McCall
d5441b92bd Switch ArgumentSource to use ExternalUnion, add the ability to
create a tuple of argument sources, and destructure such tuples
during argument emission.  NFC.
2017-07-15 01:12:55 -04:00
John McCall
7f22faf968 Substantially rework how SILGen handles bridging as part of laying the
ground work for the syntactic bridging peephole.

- Pass source and dest formal types to the bridging routines in addition
  to the dest lowered type.  The dest lowered type is still necessary
  in order to handle non-standard abstraction patterns for the dest type.

- Change bridging abstraction patterns to store bridged formal types
  instead of the formal type.

- Improve how SIL type lowering deals with import-as-member patterns.

- Fix some AST bugs where inadequate information was being stored in
  various expressions.

- Introduce the idea of a converting SGFContext and use it to regularize
  the existing id-as-Any conversion peephole.

- Improve various places in SILGen to emit directly into contexts.
2017-07-11 12:45:13 -04:00
Michael Gottesman
9f2bc267b8 [silgen] Fix 5b7b6d0b5e to work with semantic sil.
I tried to do a more complex fix, but it will take more time than I have now.
This change at least ensures that we maintain correctness both in terms of the
super types and in terms of the semantic sil verifier.

rdar://31880847
2017-06-30 13:13:41 -07:00
Michael Gottesman
d8139d36fa [silgen] Extract from SILGenApply::processAbstractFunctionDecl method "processProtocolDecl". NFC.
This is another large code block guarded by an if statement. This is really a
subroutine.

rdar://31880847
2017-06-26 16:25:49 -07:00
Michael Gottesman
9114d45e78 [silgen] Refactor out subroutine from large method SILGenApply::visitDeclRefExpr. NFC.
The routine is called processAbstractFunctionDecl and does just what you guess.
This reduces the size of visitDeclRefExpr. In a subsequent commit, I am going to
extract out a subroutine from processAbstractFunctionDecl as well for handling
protocols.

rdar://31880847
2017-06-26 16:25:39 -07:00
Michael Gottesman
3fdc9b6955 [silgen] Refactor out part of allocateObjCObject into a helper method. NFC.
This allows for the control flow in the function to be simplified by reducing
the maximum number of overlapping program paths. This makes it easier to reason
about.

rdar://31880847
2017-06-26 16:25:04 -07:00
Michael Gottesman
1fa5276f0f [gardening] Add a space in between two methods. This matches the other methods in the class. 2017-06-26 15:33:34 -07:00
Michael Gottesman
d6d14f6202 [gardening] Change an if-else block to use early exits instead. 2017-06-26 15:14:26 -07:00
Robert Widmann
3af359cb44 Merge pull request #10242 from CodaFi/in-through-the-out-door
[NFC] Move HasInOut bit out of recursive type properties
2017-06-14 13:11:19 -07:00
Robert Widmann
a4bf57f9d1 Move HasInOut bit out of recursive type properties
In anticipation of removing this bit, move it from the
recursive type property into TupleType - its only real
user.  This necessitates uglifying a bit of logic in the
short term that used to speak broadly of materializability
to instead speak about LValues and Tuples of InOut values
independently.
2017-06-14 09:54:19 -07:00
Slava Pestov
28c35ff325 SILGen: Fix problems with local generic functions
When evaluating if a call of a local function requires substitutions,
we checked if the immediate function being referenced captured
generic parameters, without checking if it transitively captured
generic parameters via other local functions it references.

Also, when calling accessors, we did not perform this check at all.

Fix both ordinary function calls and accessor calls to drop the
substitutions only if the *lowered* local captures say it is safe.

Finally, fix Sema to not consider substitutions in local function
references as generic parameter captures, since we now correctly
calculate the transitive closure of all captures.

Fixes <rdar://problem/32761305> and related issues.
2017-06-14 01:42:13 -07:00
Slava Pestov
46bc2b160d SILGen: Remove 'overrideLocationForMagicIdentifiers' hack 2017-06-11 21:54:41 -07:00
John McCall
44fda629aa Teach SILGen to handle more bridging cases and thread SGFContexts
through a few places.

This patch should be NFC for existing patterns, but it's preparing for
using SILGen's built-in bridging capabilities for more things.
2017-06-11 01:39:51 -04:00
John McCall
f4a181bc21 Various improvements to RValue. 2017-06-11 01:39:50 -04:00
Slava Pestov
5b7b6d0b5e SILGen: Fix super_method calls from class method returning Self
Calls of superclass methods across module boundaries appear to use
the super_method instruction, even if the module was not built
with resilience.

This instruction was being created with a value having a dynamic
Self type, which tripped up the SIL verifier; with the verifier
disabled we would crash in IRGen.

Fixes <rdar://problem/32667187>.
2017-06-08 22:32:07 -07:00
Slava Pestov
6d9886f362 SILGen: Scrap ArchetypeCalleeBuilder altogether
The prepareArchetypeCallee() function no longer does
anything useful beyond calling Callee::forArchetype(),
so just replace all uses of the former with the latter.
2017-06-02 01:40:57 -07:00
Slava Pestov
b65ad58441 SILGen: Remove ArchetypeCalleeBuilder::shouldMaterializeSelf()
I don't think any of this was necessary anymore, and
I suspect it was working around other related issues
that have since been fixed.

Whatever we did to 'self' here we also would have
had to do for extension methods anyway.

Note that some tests changed but I believe the end
result should be equivalent.
2017-06-02 01:40:56 -07:00
Slava Pestov
29cd885996 SILGen: Remove SILGenFunction::ArchetypeOpenings
SILBuilder now tracks data dependencies between instructions
that open existentials and uses of the opened type, so
SILGen's mechanism for this is no longer needed.

In particular, this simplifies ArchetypeCalleeBuilder.
2017-06-02 01:35:11 -07:00
Slava Pestov
c28c420a1f SILGen: Simplify SILGenApply a bit
We were passing around a ton of unused parameters,
just remove them.
2017-06-02 01:35:01 -07:00
Robert Widmann
3b202c18d8 Use 'hasAssociatedValues'
Use 'hasAssociatedValues' instead of computing and discarding the
interface type of an enum element decl.  This change has specifically not
been made in conditions that use the presence or absence of the
interface type, only conditions that depend on the presence or absence
of associated values in the enum element decl.
2017-05-22 09:54:47 -07:00
Slava Pestov
775462bf52 SILGen: Don't model closure captures as an 'uncurry level' 2017-05-09 00:56:36 -07:00
Slava Pestov
edb1e97a35 SIL: Remove uncurryLevel from SILDeclRef
All we need to store is whether the SILDeclRef directly
references the declaration, or if it references a curry
thunk, and we already have an isCurried bit for that.
2017-05-09 00:56:35 -07:00
Slava Pestov
59ed555b09 SIL: Simplify SILDeclRef constructor usages 2017-05-09 00:16:47 -07:00
Slava Pestov
b5721e8d8e AST: Remove AnyObject protocol 2017-05-02 19:45:00 -07:00
Joe Shajrawi
d17258cac7 @in_constant calling convention - part of passing large loadable types by address 2017-04-30 10:13:02 -07:00
John McCall
338825e73d Fix the emission of r-value pointer conversions to delay the
conversions and extend lifetimes over the call.

Apply this logic to string-to-pointer conversions as well as
array-to-pointer conversions.

Fix the AST verifier to not blow up on optional pointer conversions,
and make sure we SILGen them correctly.  There's still an AST bug
here, but I'll fix that in a follow-up patch.
2017-04-26 14:15:44 -04:00
John McCall
f7e73ccc48 Delay the formal accesses associated with inout-to-pointer and
array-to-pointer argument conversions until just before the call.

rdar://31781386
2017-04-25 03:54:49 -04:00
John McCall
0d4e0a961d Fix the writeback-conflict diagnostic to look through access markers.
We're now double-diagnosing some things that are caught by both
SILGen and static enforcement; we can fix that later, but I want to
unblock this problem first.
2017-04-24 02:02:47 -04:00
Slava Pestov
d58f049608 AST: Introduce ASTContext::getAnyObjectType()
This replaces a number of usages of KnownProtocolKind::AnyObject,
which is soon going away.
2017-04-13 21:17:05 -07:00
Arnold Schwaighofer
69e6f07167 Merge pull request #8701 from aschwaighofer/wip_ast_silgen_const_string_literal
AST/SILGen support for constant string literals
2017-04-12 09:52:18 -07:00
practicalswift
7684e73388 Merge pull request #8706 from practicalswift/excess-logic
[gardening] Remove redundant logic
2017-04-12 09:51:49 +02:00
practicalswift
5e255e07d7 [gardening] Remove redundant logic 2017-04-11 23:04:55 +02:00
Arnold Schwaighofer
4d60ec333b AST/SILGen support for constant string literals
rdar://30545013
2017-04-11 11:41:43 -07:00
Michael Gottesman
2e40219be7 [silgen] Convert else-if in a for-loop into a if continue. 2017-04-11 09:16:40 -07:00
Michael Gottesman
0b341359c7 [silgen] Refactor emitShuffle (~300 loc) into smaller methods (< 90 loc) on TupleShuffleArgEmitter.
This should be a pure NFC refactor. I just moved function scope state into the
helper struct and split up the already nicely scoped parts of the function into
separate methods if they were large.

In future commits, there are a bunch of improvements that can be made by
reducing indentation.
2017-04-10 20:40:27 -07:00
Michael Gottesman
7e1198420a [gardening] Fix indentation of code in anonymous namespace to match LLVM style.
This just moves the code in by 1 indentation level.
2017-04-10 16:16:17 -07:00
Michael Gottesman
2224584997 [semantic-arc-opts] Teach semantic arc opts how to handle (borrow (copy)) of a guaranteed argument.
rdar://29870610
2017-04-06 16:23:02 -07:00
John McCall
e44f37fd8d Thread an enforcement kind through a few places. NFC. 2017-04-05 01:25:35 -04:00
John McCall
305c94fc5b Pare down the Initialization interface and allow implementations
to insert code before performing an in-place initialization.

Intended to be NFC, but some of the clients needed more rewriting
than others.
2017-03-31 18:55:09 -04:00
Michael Gottesman
ba5be9d8e8 [silgen] Eliminate an unnecessary writeback scope.
This writeback scope's writeback is handled by the ArgumentScope for argument
emission. Since the scope will be destroyed after argument scope, we get
mismatched scope depths.

rdar://31313534
2017-03-30 14:51:53 -07:00
Michael Gottesman
08c9d4dd11 [silgen] Verify FormalEvaluationScopes in certain places in SILGenApply.
We probably could put it in more places, but this is a good first start.

rdar://31313534
2017-03-30 13:20:50 -07:00
Slava Pestov
8fe8b89b0f SIL: Terminology change: [fragile] => [serialized]
Also, add a third [serializable] state for functions whose bodies we
*can* serialize, but only do so if they're referenced from another
serialized function.

This will be used for bodies synthesized for imported definitions,
such as init(rawValue:), etc, and various thunks, but for now this
change is NFC.
2017-03-29 16:47:28 -07:00
swift-ci
c56709ffeb Merge pull request #8356 from gottesmm/partial_reapply_41f425a5033a30fdd545752b8bb10374bbf1de12 2017-03-26 14:16:43 -07:00
Michael Gottesman
f9e3b1d6d9 Reapply "[silgen] If we have a direct guaranteed convention and have an owned value, perform a borrow.""
This partially reverts commit 41f425a503.

The key thing is that now it is behind the semantic sil flag. I have an
additional patch that turns this back on in front of the flag, but it requires a
little bit of mandatory pass work that Erik is going to hit this week.

rdar://31145255
2017-03-26 12:56:42 -07:00
Hugh Bellamy
b6e720ab96 Fix undefined behaviour caused by accessing uninitialized field in CallEmission 2017-03-25 12:54:21 +07:00
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