Commit Graph

331 Commits

Author SHA1 Message Date
Doug Gregor
d07fa5ab69 Switch many callers of ClassDecl::getSuperclass() to ClassDecl::getSuperclassDecl().
ClassDecl::getSuperclass() produces a complete interface type describing the
superclass of a class, including any generic arguments (for a generic type).
Most callers only need the referenced ClassDecl, which is (now) cheaper
to compute: switch those callers over to ClassDecl::getSuperclassDecl().

Fixes an existing test for SR-5993.
2018-07-31 10:14:44 -07:00
Michael Gottesman
11b24415c1 [sil-module] Create SILFunctionBuilder and hide creation/erasing functions on SILModule.
This commit does not modify those APIs or their usage. It just:

1. Moves the APIs onto SILFunctionBuilder and makes SILFunctionBuilder a friend
   of SILModule.
2. Hides the APIs on SILModule so all users need to use SILFunctionBuilder to
   create/destroy functions.

I am doing this in order to allow for adding/removing function notifications to
be enforced via the type system in the SILOptimizer. In the process of finishing
off CallerAnalysis for FSO, I discovered that we were not doing this everywhere
we need to. After considering various other options such as:

1. Verifying after all passes that the notifications were sent correctly and
   asserting. Turned out to be expensive.
2. Putting a callback in SILModule. This would add an unnecessary virtual call.

I realized that by using a builder we can:

1. Enforce that users of SILFunctionBuilder can only construct composed function
   builders by making the composed function builder's friends of
   SILFunctionBuilder (notice I did not use the word subclass, I am talking
   about a pure composition).
2. Refactor a huge amount of code in SILOpt/SILGen that involve function
   creation onto a SILGenFunctionBuilder/SILOptFunctionBuilder struct. Many of
   the SILFunction creation code in question are straight up copies of each
   other with small variations. A builder would be a great way to simplify that
   code.
3. Reduce the size of SILModule.cpp by 25% from ~30k -> ~23k making the whole
   file easier to read.

NOTE: In this commit, I do not hide the constructor of SILFunctionBuilder since
I have not created the derived builder structs yet. Once I have created those in
a subsequent commit, I will hide that constructor.

rdar://42301529
2018-07-31 10:04:03 -07:00
Slava Pestov
e606aad80f SILGen: Remove uses of AbstractFunctionDecl::getParameterLists() 2018-07-19 22:09:13 -07:00
Robert Widmann
a79c11f5d8 Drop more uses of getInput() from SIL 2018-07-05 10:52:41 -07:00
John McCall
65042f9662 Move l-value code for non-member VarDecls into SILGenValue. NFC. 2018-07-03 16:46:03 -04:00
John McCall
9bee3cac5a Generalize storage implementations to support generalized accessors.
The storage kind has been replaced with three separate "impl kinds",
one for each of the basic access kinds (read, write, and read/write).
This makes it far easier to mix-and-match implementations of different
accessors, as well as subtleties like implementing both a setter
and an independent read/write operation.

AccessStrategy has become a bit more explicit about how exactly the
access should be implemented.  For example, the accessor-based kinds
now carry the exact accessor intended to be used.  Also, I've shifted
responsibilities slightly between AccessStrategy and AccessSemantics
so that AccessSemantics::Ordinary can be used except in the sorts of
semantic-bypasses that accessor synthesis wants.  This requires
knowing the correct DC of the access when computing the access strategy;
the upshot is that SILGenFunction now needs a DC.

Accessor synthesis has been reworked so that only the declarations are
built immediately; body synthesis can be safely delayed out of the main
decl-checking path.  This caused a large number of ramifications,
especially for lazy properties, and greatly inflated the size of this
patch.  That is... really regrettable.  The impetus for changing this
was necessity: I needed to rework accessor synthesis to end its reliance
on distinctions like Stored vs. StoredWithTrivialAccessors, and those
fixes were exposing serious re-entrancy problems, and fixing that... well.
Breaking the fixes apart at this point would be a serious endeavor.
2018-06-30 05:19:03 -04:00
Slava Pestov
296ce3f312 AST: Remove hack-around for getInterfaceType() on ParamDecl returning InOutType
Most callers did not want the InOutType here, and checked
the ParamDecl's flags instead.
2018-06-13 15:38:52 -07:00
Slava Pestov
b1a436601e Use MakeAbstractConformanceForGenericType() in various places 2018-05-28 19:45:29 -07:00
Slava Pestov
d8fc9decf9 AST: Remove GenericSignature::getSubstitutionMap() 2018-05-28 19:45:28 -07:00
Slava Pestov
bd6281c558 AST: Change SubstitutionMap conformance lookup callbacks to take ProtocolDecl and not ProtocolType 2018-05-19 01:09:17 -07:00
Doug Gregor
0bf0a1ee6a [SILGen] Eliminate more SubstitutionLists for accessor calls. 2018-05-11 17:37:26 -07:00
Doug Gregor
4b5abbddbc [SIL] Teach *ApplyInst to traffic in SubstitutionMap.
Push SubstitutionMaps through most of SILGen and the SIL optimizers
that involve the various *ApplyInsts.
2018-05-11 13:18:06 -07:00
David Zarzycki
8c0c55539f [SIL] NFC: Rename misleading getSwiftRValueType() to getASTType()
Reference storage types are not RValues. Also, use more SILType helper
methods to avoid line wrap.
2018-05-04 08:14:38 -04:00
Doug Gregor
503d9ce1f5 [SIL] Store SubstitutionMaps in MarkUninitializedBehaviorInst. 2018-05-03 15:40:10 -07:00
Doug Gregor
192234415d [AST] Store SubstitutionMaps in ConcreteDeclRef and Witness data structures.
Replace two prominent uses of SubstitutionList, in ConcreteDeclRef and
Witness, with SubstitutionMap. Deal with the myriad places where we
now have substitution maps and need substitution lists (or vice versa)
caused by this change.

Overall, removes ~50 explicit uses of SubstitutionList (of ~400).
2018-05-02 13:38:14 -07:00
Michael Gottesman
8af8e4f7c7 [+0-all-args] Fix SILGenBuilder::createFunctionInputArgument(...) for in_guaranteed parameters
This method was not distinguishing in between in_guaranteed and in
parameters. This would cause the curry thunk where this is used to not copy
in_guaranteed parameters before passing in the parameter to the
partial_apply. This can not affect +1 code since the curry thunk will always
have self at +1.

I also refactored code in:

1. SILGenPoly.
2. SILGenProlog.
3. SILGenConstructor.

to use this function instead of their own reimplementations of the same thing.

This should be NFC for +1 code and is tested by test updates when +0 is enabled.

rdar://34222540
2018-03-08 16:51:38 -08:00
Huon Wilson
b1115af1eb Switch a pile of VarDecl::Specifier::Owneds to ::Default.
A lot of these probably should be Owned, but deciding that is work for
another time.
2018-03-08 12:36:37 +11:00
Michael Gottesman
337d694bf9 [+0-normal-args] Make enum element constructors take values at +1.
This is really an initializer, so use the initializer conventions. Today this is
NFC given the current convention. With +0 arguments, this is a different story
though.

Found by fixing SILGen tests for +0.

rdar://34222540
2018-02-28 12:36:42 -08:00
Adrian Prantl
9b6a9946ec Be explicit about whether a DebugInfo-carying SILInstruction has debug info.
This patch both makes debug variable information it optional on
alloc_stack and alloc_box instructions, and forced variable
information on debug_value and debug_value_addr instructions. The
change of the interface uncovered a plethora of bugs in SILGen,
SILTransform, and IRGen's LoadableByAddress pass.

Most importantly this fixes the previously commented part of the
DebugInfo/local-vars.swift.gyb testcase.

rdar://problem/37720555
2018-02-21 10:50:19 -08:00
Michael Gottesman
b008bfc414 [+0-all-args] Ensure that we always return an enum at +1 from enum constructors.
This was exposed by a test in the SILGen filecheck tests that I am updating out
of tree.

What is basically happening here is that we construct an enum from a guaranteed
argument and then return that enum. We need to ensure in such a case that the
return value is still at +1. This commit fixes the issue by using an
ensurePlusOne, ensuring that in normal cases we do not emit an extra copy, but
in a world where we have +0 arguments, ensures we insert a copy before we
return.

rdar://34222540
2018-02-14 13:28:37 -08:00
Slava Pestov
8b4dfd812a SILGen: Fix crash when emitting implicit 'super.init()' delegation to throwing or failing initializer
If the base class defines a no-argument initializer, we allow the
'super.init()' call to be omitted. However, SILGen would generate
invalid SIL if the base class initializer was throwing or failing.

The problem was that we would attempt to insert instructions
after a try_apply or cond_br, which is invalid, because we would
incorrectly save and restore the insertion point when emitting the
delegation. This is incorrect, because a delegation to a throwing
or failing initializer emits new basic blocks.

Fixes <https://bugs.swift.org/browse/SR-5974>,
<rdar://problem/36256335>.
2018-01-06 02:05:08 -08:00
Vedant Kumar
dd560d2aa6 [Coverage] Refactor SIL generation for profiling
This patch moves the ownership of profiling state from SILGenProfiling
to SILFunction, where it always belonged. Similarly, it moves ownership
of the profile reader from SILGenModule to SILModule.

The refactor sets us up to fix a few outstanding code coverage bugs and
does away with sad hacks like ProfilerRAII. It also allows us to locally
guarantee that a profile counter increment actually corresponds to the
SILFunction at hand.

That local guarantee causes a bugfix to accidentally fall out of this
refactor: we now set up the profiling state for delayed functions
correctly. Previously, we would set up a ProfilerRAII for the delayed
function, but its counter increment would never be emitted :(. This fix
constitutes the only functional change in this patch -- the rest is NFC.

As a follow-up, I plan on removing some dead code in the profiling
logic and fixing a few naming inconsistencies. I've left that for later
to keep this patch simple.
2018-01-05 17:20:20 -08:00
Vedant Kumar
cccee1df03 Revert "[Coverage] Refactor SIL generation for profiling" 2018-01-03 21:57:49 -08:00
Vedant Kumar
aba9d53736 [Coverage] Refactor SIL generation for profiling
This patch moves the ownership of profiling state from SILGenProfiling
to SILFunction, where it always belonged. Similarly, it moves ownership
of the profile reader from SILGenModule to SILModule.

The refactor sets us up to fix a few outstanding code coverage bugs and
does away with sad hacks like ProfilerRAII. It also allows us to locally
guarantee that a profile counter increment actually corresponds to the
SILFunction at hand.

That local guarantee causes a bugfix to accidentally fall out of this
refactor: we now set up the profiling state for delayed functions
correctly. Previously, we would set up a ProfilerRAII for the delayed
function, but its counter increment would never be emitted :(. This fix
constitutes the only functional change in this patch -- the rest is NFC.

As a follow-up, I plan on removing some dead code in the profiling
logic and fixing a few naming inconsistencies. I've left that for later
to keep this patch simple.
2018-01-03 11:18:40 -08:00
Jordan Rose
8f8f00012a Merge pull request #12834 from jrose-apple/restrict-cross-module-struct-initializers-2
Implementation of SE-0189 "Restrict cross-module struct initializers to be delegating"

rdar://problem/34777878
2017-11-30 13:32:45 -08:00
Slava Pestov
2920b4fd1c AST: Remove DeclContext::mapTypeOutOfContext() 2017-11-15 22:52:28 -08:00
Jordan Rose
1598a21e43 DI: Warn on non-delegating cross-module struct initializers
...as detected by initializing an individual field without having
initialized the whole object (via `self = value`).

This only applies in pre-Swift-5 mode because the next commit will
treat all cross-module struct initializers as delegating in Swift 5.
2017-11-09 11:24:28 -08:00
Michael Gottesman
798bff756a [silgen] Rename SavedInsertionPoint => SILGenSavedInsertionPoint.
This rename makes since since:

1. This is SILGen specific functionality.
2. In the next commit I am going to be adding a SIL SavedInsertionPoint class. I
want to make sure the two can not be confused.
2017-11-08 10:40:39 -08:00
John McCall
5c33d2106a Add simple accessor/generator coroutine support to SILFunctionType. 2017-11-07 01:50:12 -05:00
Slava Pestov
4773eacbef SILGen: Remove usage of getDeclaredTypeOfContext() 2017-09-19 22:12:29 -07:00
Michael Gottesman
e035c93ed9 [silgen][gardening] More gen => SGF. 2017-08-10 21:42:21 -07:00
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
Robert Widmann
4da853e7cb Rename Specifier::None to Specifier::Owned 2017-07-05 14:02:26 -07:00
Robert Widmann
ac5594dabe Use a meaningful representation of parameter specifiers
In anticipation of future attributes, and perhaps the ability to
declare lvalues with specifiers other than 'let' and 'var', expand
the "isLet" bit into a more general "specifier" field.
2017-06-29 16:03:49 -07:00
Slava Pestov
2994656f4b SILGen: Fix crash when emitting reference to member initializer from constrained extension
When we SILGen a constructor defined in an extension, we need to
initialize stored properties with default values. These use the
generic signature of the original type, and not the generic
signature of the extension, which can add additional constraints.

Fixes <https://bugs.swift.org/browse/SR-4956>.
2017-05-22 18:48:25 -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
59ed555b09 SIL: Simplify SILDeclRef constructor usages 2017-05-09 00:16:47 -07:00
practicalswift
492f5cd35a [gardening] Remove redundant repetition of type names (DRY): RepeatedTypeName foo = dyn_cast<RepeatedTypeName>(bar)
Replace `NameOfType foo = dyn_cast<NameOfType>(bar)` with DRY version `auto foo = dyn_cast<NameOfType>(bar)`.

The DRY auto version is by far the dominant form already used in the repo, so this PR merely brings the exceptional cases (redundant repetition form) in line with the dominant form (auto form).

See the [C++ Core Guidelines](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#es11-use-auto-to-avoid-redundant-repetition-of-type-names) for a general discussion on why to use `auto` to avoid redundant repetition of type names.
2017-05-05 09:45:53 +02:00
Slava Pestov
3130c3cbd7 AST: Remove an overload of GenericSignature::getSubstitutions() 2017-04-28 13:26:02 -07:00
Slava Pestov
683a7f49e4 SILOptimizer: Fix spurious 'unreachable code' warning when a failable initializer calls a never-returning function
This came up recently with the protocol-oriented integer
work in the standard library.

Fixes <https://bugs.swift.org/browse/SR-4673>.
2017-04-23 02:15:57 -07:00
Michael Gottesman
aa76c2a5e6 [silgen] (mark_uninitialized (project_box (alloc_box))) -> (project_box (mark_uninitialized (alloc_box)))
I put in a simple fixup pass (MarkUninitializedFixup) for staging purposes. I
don't expect it to be in tree long. I just did not feel comfortable fixing up in
1 commit all of the passes up to DI.

rdar://31521023
2017-04-17 17:45:54 -07:00
Michael Gottesman
6846b89e90 [silgen] Instead of creating our own mark_uninitialized, use the new emitLocalVariableWithCleanup API. 2017-04-14 18:55:26 -07:00
Michael Gottesman
081f2396e5 [silgen] Refactor emitLocalVariableWithCleanup to take an optional MarkUninitializedKind instead of a bool.
This enables me to refactor some code in SILGenConstructor. Specifically this
code passes in a false for uninitialized and then creates the mark uninitialized
for itself.
2017-04-14 18:55:20 -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
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
Joe Shajrawi
067c867e5d Add inital support of Address-only enums under opaque values mode 2017-03-15 12:59:23 -07:00
Joe Shajrawi
c8618fa57d Support Implicit Value Construction under Opaque value mode 2017-03-14 17:42:14 -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