Commit Graph

1275 Commits

Author SHA1 Message Date
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
Michael Gottesman
54a97bbf53 [silgen] Scope ArgEmitter::emit{SubstToOrigValue,NativeToBridgedArgument} using popPreservingValue to move its result into the outer scope.
rdar://31145255
2017-03-22 14:55:03 -07:00
Michael Gottesman
41f425a503 Revert "[silgen] If we have a direct guaranteed convention and have an owned value, perform a borrow."
This reverts commit 4c8595b002.
2017-03-20 05:00:31 -07:00
Devin Coughlin
fdd9ea6c7d SILGen: Reapply 'Add experimental TSan instrumentation for inout accesses.'
(This re-applies #7736 with an update to the
tsan-inout.swift execution test to handle configurations where
TSan's ignore_interceptors_accesses is enabled by default.)

Add SILGen instrumentation to treat inout accesses as Thread Sanitizer writes.
The goal is to catch races on inout accesses even when there is a not an
llvm-level read/write to a particular address. Ultimately
this will enable TSan to, for example, report racy writes to distinct
stored properties of a common struct as a data race.

This instrumentation is off by default. It can be enabled with the
'enable-experimental-tsan-inout-instrumentation' frontend flag.

The high-level approach is to add a SIL-level builtin that represents a call
to a TSan routine in compiler-rt. Then, when emitting an address for an LValue
as part of an inout expression, we call this builtin for each path component
that represents an LValue. I've added an 'isRValue()' method to PathComponent
that tracks whether a component represents an RValue or an LValue. Right the
only PathComponent that sometimes returns 'true' is ValueComponent().

For now, we're instrumenting only InoutExprs, but in the future it probably
makes sense to instrument all LValue accesses. In this patch I've
added a 'TSanKind' parameter to SILGenFunction::emitAddressOfLValue() and
its helpers to limit instrumentation to inout accesses. I envision that this
parameter will eventually go away.
2017-03-18 20:10:19 -07:00
Michael Gottesman
4c8595b002 [silgen] If we have a direct guaranteed convention and have an owned value, perform a borrow.
Now that all arguments are properly scoped, we do not need to worry about this
extending the lifetimes of COW times inappropriately.

rdar://30955427
2017-03-18 18:59:31 -07:00
Michael Gottesman
b99c47c006 [silgen] Scope argument cleanups with a new scope called "ArgumentScope".
Once this is in, I will be able to finish the SILGenApply part of Semantic SIL.

rdar://30955427
2017-03-18 17:03:41 -07:00
Michael Gottesman
8723301205 [silgen] Move implementation of emitForeignErrorArgument into ResultPlan. 2017-03-18 16:06:58 -07:00
Michael Gottesman
f4f41337e3 [gardening] Change some CalleeTypeInfo '&' parameters to be 'const &' parameters. NFC. 2017-03-18 14:40:50 -07:00
Greg Parker
c17cfb69d8 Revert "SILGen: Add experimental TSan instrumentation for inout accesses. (#7736)"
This reverts commit 52d5178a3e.
2017-03-16 21:11:58 -07:00
Devin Coughlin
52d5178a3e SILGen: Add experimental TSan instrumentation for inout accesses. (#7736)
Add SILGen instrumentation to treat inout accesses as Thread Sanitizer writes.
The goal is to catch races on inout accesses even when there is a not an
llvm-level read/write to a particular address. Ultimately
this will enable TSan to, for example, report racy writes to distinct
stored properties of a common struct as a data race.

This instrumentation is off by default. It can be enabled with the
'enable-experimental-tsan-inout-instrumentation' frontend flag.

The high-level approach is to add a SIL-level builtin that represents a call
to a TSan routine in compiler-rt. Then, when emitting an address for an LValue
as part of an inout expression, we call this builtin for each path component
that represents an LValue. I've added an 'isRValue()' method to PathComponent
that tracks whether a component represents an RValue or an LValue. Right the
only PathComponent that sometimes returns 'true' is ValueComponent().

For now, we're instrumenting only InoutExprs, but in the future it probably
makes sense to instrument all LValue accesses. In this patch I've
added a 'TSanKind' parameter to SILGenFunction::emitAddressOfLValue() and
its helpers to limit instrumentation to inout accesses. I envision that this
parameter will eventually go away.
2017-03-16 17:08:48 -07:00
Joe Shajrawi
067c867e5d Add inital support of Address-only enums under opaque values mode 2017-03-15 12:59:23 -07:00
Slava Pestov
61e9a980a7 SILGen: Calculate substituted formal type upfront
Also for class method callees, use the formal type of the base
method and not the override, fixing an issue with concrete
subclasses of generic base classes which bind a generic
parameter to a tuple type.

Fixes <https://bugs.swift.org/browse/SR-3541>.
2017-03-14 18:11:55 -07:00
Slava Pestov
708523d82e SILGen: Kill Callee::setSubstitutions() 2017-03-14 18:11:55 -07:00
Slava Pestov
f29661d40c SILGen: Callee::getOrigFormalType() is now an abstraction pattern 2017-03-14 18:11:55 -07:00
Slava Pestov
510d233543 SILGen: Refactor Callee a bit 2017-03-14 17:46:54 -07:00
Slava Pestov
64adf7495e SILGen: Change ArchetypeOpenings map to be keyed by ArchetypeType * and not CanType 2017-03-14 17:46:54 -07:00
Michael Gottesman
4c61867097 [silgen] Quick drive by thinko fix.
Just noticed this while reading over this code. Disheartening that our tests did
not catch it. = /.
2017-03-14 01:45:42 -07:00
Michael Gottesman
213ddd753f [silgen] Compute the ResultPlan outside of SILGenApply so that we can untangle indirect result/normal argument lifetime scopes.
rdar://30955427
2017-03-14 00:39:53 -07:00
Michael Gottesman
b0522635d4 [silgen] Instead of computing the indirect result addrs as we build/store it. Just generate it dynamically.
This is being done in preparation for moving ResultPlan /out of/
SILGenFunction::apply.

rdar://30955427
2017-03-14 00:39:48 -07:00
Michael Gottesman
4552355ff2 [silgen] Refactor SILGenFunction::apply to take a new struct called CalleeTypeInfo.
This structure contains all of the type information that we use to build a
ResultPlanPtr. In a subsequent commit, I am going to move ResultPlanPtr creation
out of emitApply and place it before the creation of arguments. This is to
enable indirect result initializations to belong to the scope outside of any
argument based scopes.

Without this the lifetimes of the indirect result initializations and arguments
can not be separated without using hacks. There is no reason why we can't emit
the indirect result temporaries before we emit any arguments since they will
remain dormant until after the final apply/any future committed argument scopes
being popped.

rdar://30955427
2017-03-14 00:39:41 -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
Michael Gottesman
68c581f729 [gardening] As per discussion, begin standardizing in SILGen that the SILGenFunction variable is passed around as SGF.
The reason that this is being done is that:

1. SILGenFunction is passed around all throughout SILGen, including in between
APIs some of which call the SILGenFunction variable SGF and others that call it
gen.
2. Thus when one is debugging code in SILGen, one wastes time figuring out what
the variable name of SILGenFunction is in the current frame.

I did not do this by hand. I did this by:

1. Grepping for "SILGenFunction &gen".
2. By hand inspecting that the match was truly a SILGenFunction &gen site.
3. If so, use libclang tooling to rename the variable to SGF.

So I did not update any use sites.
2017-03-11 23:38:17 -08:00
Michael Gottesman
f064e26f31 [gardening] Normalize field capitalization. 2017-03-11 23:30:19 -08:00
Michael Gottesman
22e0fdafac [silgenapply][callemission] Change access of new helper methods to be private. 2017-03-11 21:38:08 -08:00
Michael Gottesman
2d9eb7f89f [silgenapply][callemission] Refactor out application of the first level callee into its own method.
Now that this is complete, the huge function CallEmission::apply is now only 20
lines and doesn't contain spaghetti code.
2017-03-11 21:36:59 -08:00
Michael Gottesman
d7b214252a [silgenapply][callemission] Refactor out the normal call part of CallEmission::apply. 2017-03-11 21:30:04 -08:00
Michael Gottesman
4391dbafad [silgenapply][callemission] Refactor out enum element constructor emission. 2017-03-11 21:05:36 -08:00
Michael Gottesman
cd8e131826 [silgenapply][callemission] Eliminate an unneeded parameter. 2017-03-11 20:49:29 -08:00
Michael Gottesman
10099a04ea [silgenapply][callemission] Eliminate shadowed variable. 2017-03-11 20:49:29 -08:00
Michael Gottesman
1a3ab56dfd [silgenapply][callemission] Refactor first level call partial applied super method into a helper method called applyPartiallyAppliedSuperMethod. 2017-03-11 19:50:26 -08:00
Michael Gottesman
46260379cc [silgenapply][callemission] Refactor out code for applying a first level specialized emitter. 2017-03-11 19:38:39 -08:00
Michael Gottesman
dad7a55506 [silgenapply][callemission] Refactor out argument emission for non-early specialized emitter and non-enum constructor calls. 2017-03-11 15:56:53 -08:00
Michael Gottesman
230259cffd [silgen][callemission] Refactor out the handling of the remaining call sites after the first call site into its own method.
This is in preperation for eliminating the spaghetti code in
CallEmission::apply.
2017-03-11 15:18:05 -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