Commit Graph

742 Commits

Author SHA1 Message Date
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
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
Arnold Schwaighofer
7b472f983e Merge pull request #15927 from aschwaighofer/remove_postponed_cleanup
Remove SILGen's PostponedCleanup
2018-04-17 06:19:29 -07:00
Andrew Trick
9fdba965b1 [NFC] Create an AccessedStorage utility for use in multiple exclusivity related passes.
Added new files, MemAccessUtils.h and MemAccessUtils.cpp to house the
new utility. Three functions previously in InstructionUtils.h move
here:
- findAccessedAddressBase
- isPossibleFormalAccessBase
- visitAccessedAddress

Rather than working with SILValues, these routines now work with the
AccessedStorage abstraction. This allows enforcement logic and SIL
pattern recognition to be shared across diagnostics and
optimization. (It's very important for this to be consistent).

The new AccessedStorage utility is a superset of the class that was
local to DiagnoseStaticExclusivity. It exposes the full set of all
recognized kinds of storage. It also represents function arguments as
an index rather that a SILValue. This allows an analysis pass to
compare/merge AccessedStorage results from multiple callee functions,
or more naturally propagate from callee to caller context.
2018-04-13 23:07:20 -07:00
Arnold Schwaighofer
e36655fddc SILGen: Remove PostponedCleanup in favor or the SIL pass that fixes
closure lifetimes.

SILGen will now unconditionally emit

  %cvt = convert_escape_to_noescape [guaranteed] %op

instructions. The mandatory ClosureLifetimeFixup pass ensures that %op's
lifetime spans %cvt's uses.

The code in DefiniteInitialization that handled a subset of cases is
removed.
2018-04-13 13:44:09 -07:00
Andrew Trick
00df6b1b58 Remove some extraneous logic from -enable-verify-exclusivity.
Once the dust settled, this logic was only protecting a single occurrence of
memory access in SILGenLValue.cpp. It's simpler just to emit the begin/end
access markers in that case. The logic to work around it was nasty.
2018-04-12 22:09:28 -07:00
Andrew Trick
ed8a604c27 Merge branch 'master' into add-access-tracking-flag 2018-03-29 18:26:22 -07:00
Joe Groff
fb2030b5af SILGen: Fix a null-dereference bug handling writeback to global computed properties.
SR-7220 | rdar://problem/38624843
2018-03-27 12:15:02 -07:00
Andrew Trick
e50faa5125 [exclusivity] Add 'no_nested_conflict' flag to begin_access.
This statically guarantees that the access has no inner conflict within
its own scope.

IRGen will turn this into a "nontracking" access in which an
exclusivity check is performed for conflicts on an outer scope. However,
unlike normal accesses the runtime does not record the access, and the
access will not be checked for subsequent conflicts.

end_unpaired_access [no_nested_conflict] is not currently
supported. Making a begin_unpaired_access [no_nested_conflict] requires
deleting the corresponding end_unpaired_access. Future runtimes
could support this for verification by storing inline data in the
valud buffer. However, the runtime can never assume that a
[no_nested_conflict] begin_unpaired_access will have a corresponding
end_unpaired_access call without adding a new ExclusivityFlag for
that purpose.
2018-03-27 10:50:07 -07:00
Michael Gottesman
e567bc9028 [+0-all-args] Enable +0 normal arguments.
rdar://34222540
2018-03-19 20:25:31 -07:00
Slava Pestov
34fd4ae512 AST: Use DeclBaseName::Kind::Constructor
Fixes <rdar://problem/35852727>, <https://bugs.swift.org/browse/SR-1660>,
<https://bugs.swift.org/browse/SR-6557>.
2018-03-16 00:25:56 -07:00
Andrew Trick
c2b845b1e4 <rdar://36734699> [Exclusivity] let class properties should not be enforced. 2018-03-14 09:26:30 -07:00
Huon Wilson
78bdc95ce3 Merge pull request #14874 from huonw/at-owned-cleanup
Various refactorings for __owned.
2018-03-02 14:20:21 -08:00
Huon Wilson
b94c5364f5 [NFC] Rename 'Ownership' to 'ReferenceOwnership'.
There's really two forms of ownership: references and values. Renaming
to make way for better distinguishing of the two.
2018-03-02 11:38:28 -08:00
Joe Groff
34e77c0f25 Merge pull request #14893 from jckarter/keypath-resilience-silgen-refactor
SILGen: Refactor key path component lowering.
2018-03-01 11:19:26 -08:00
Joe Groff
f4caa5c0ad Merge pull request #14410 from hamishknight/ignored-lvalues
[SILGen] Don't assume physical lvalue components are side effect free
2018-03-01 11:18:38 -08:00
Joe Groff
2f0a3f2e2d SILGen: Refactor key path component lowering.
Factor out the code to lower an individual key path component to be independent of overall KeyPathExpr lowering, so that we can soon reuse the same code paths to build property descriptors for resilient properties. NFC intended.
2018-02-28 15:06:44 -08:00
Andrew Trick
00b5a9db79 Emit unenforced access markers in SILGen for accesses to local temporaries.
These accesses can't be recognized as obviously local temporaries in the
verification pass, so the only way to exhaustively verify exclusivity is by
added unenforced markers.

SILGen currently only emits unenforced markers under -verify-exlcusivity. Once
opaque values is the only supported SILGen mode, then we should turn the markers
on by default (SILGen should not have different modes of operation).
2018-02-15 11:26:54 -08:00
Arnold Schwaighofer
64943836ba SILGen: Support for trivial @noescape function types
- Emit a withoutActuallyEscapingClosure partial apply
This is to convert an @noescape closure to an escaping closure.
This needs to be done in preparation of @noescape closure contexts
becoming trivial.

- Insert escaping to noescape conversions

- Fix SILGen for @noescape

- Postpone closure cleanups to outside the argument scope

- Apply postponement recursively for closures passed to subscripts

- Only skip applying escapeness conversions for Swift thick functions

- Fix parameter convention for noescape closures in thunks

Part of:
SR-5441
rdar://36116691
2018-02-13 04:19:59 -08:00
Joe Groff
742e7fc583 SILGen: Open existential lvalues on entry into an OpenExistentialExpr again.
4b25945 changed codegen for lvalue OpenExistentialExprs so that the existential was not opened until the OpaqueValue's lvalue was evaluated, but this is incorrect—we need to open the dynamic type of the existential immediately since it can be used arbitrarily within the subexpression. This caused a regression when evaluating default argument generators on protocol extension methods (rdar://problem/37031037), and would become a bigger problem when we generalize the ability to open existentials.
2018-02-06 19:44:53 -08:00
Mark Lacey
b4b66bc8e8 Replace getAnyOptionalObjectType with getOptionalObjectType. 2018-02-05 23:59:00 -08:00
Hamish
0abc9f471b [SILGen] Don't assume physical lvalue components are side effect free
When emitting an ignored expression, we try not perform a load of an lvalue if we can prove that loading has no observable side effects. Previously we based this on whether the components of the lvalue are physical, however some physical components (such as force unwrapping and key-paths) have side effects.

This commit introduces a new method to determine whether a component has side effects, and also adds an additional case to `emitIgnoredExpr` to avoid loading in cases where we have a force unwrap of an lvalue load (instead, if possible, try to emit the precondition using the lvalue address).
2018-02-04 14:51:11 +00:00
John McCall
52bb547a7e Merge pull request #13866 from rjmccall/accessor-decl
Split AccessorDecl out from FuncDecl.  NFC.
2018-01-12 17:02:35 -05:00
John McCall
7f0f8830cd Split AccessorDecl out from FuncDecl. NFC.
This has three principal advantages:

- It gives some additional type-safety when working
  with known accessors.

- It makes it significantly easier to test whether a declaration
  is an accessor and encourages the use of a common idiom.

- It saves a small amount of memory in both FuncDecl and its
  serialized form.
2018-01-12 14:20:27 -05:00
Slava Pestov
9ff97367df AST: Rename hasFixedLayout() to isResilient() and flip polarity
In IRGen we call this isResilient() already in IRGen, and it's
more consistent to call it the same thing everywhere.
2018-01-11 21:57:42 -08:00
Andrew Trick
fd99f4d8e2 Code review. 2018-01-08 11:26:56 -08:00
Andrew Trick
9122e82880 Rewrite LogicalPathComponent::getMaterialized.
Collapse this routine down to its fundamental logic, removing unnecessary
hacks along the way. It's now self-documenting and robust.

The basic principle is that any special case should use the same
SILGen abstractions and utilities. The implementation should be
identical except where the special case is logically
distinct. i.e. the reason for the special case should be self-evident
from the code.

This is not NFC. Unnecessary borrow scopes are no longer emitted for
getters. More generally, there may have been some incidental behavior
specific to a corner cases that becomes more uniform now.
2018-01-08 11:26:56 -08:00
Slava Pestov
2590142b7b SILGen: Remove shouldReferenceForeignAccessor()
Also, the 'isDirectAccess' parameter to various methods is now dead,
because it was never being set to true in the foreign case anyway.
2018-01-04 21:53:34 -08:00
Andrew Trick
17fa484f04 SILGen. Fix temporary LValue cleanup.
Use the LValue formal evaluation scope to destroy temporary lvalues that aren't
part of the expression's resulting value.

Disable an old hack that destroyed call site arguments after the call.

This is the first step in cleanup up LValue materialization.
2018-01-01 19:05:22 -08:00
Michael Gottesman
1cfcfcd7d7 [silgen] When assigning into an lvalue, the value that we are storing must be at plus one.
This allows us to obey Semantic SIL when attempting to assign a guaranteed value
into a storage location.

rdar://34222540
2017-11-20 15:21:14 -08:00
Slava Pestov
0b895bbf44 SILGen: Use resilience expansion when deciding if we need to use materializeForSet or not 2017-11-10 17:21:17 -08:00
Huon Wilson
0236db7be1 [SIL] Witness methods store the conformance from which they come. 2017-11-01 11:33:26 -07:00
Slava Pestov
dfdd3a795d SILGen: Fix bug with NSString import-as-member globals
This is not really the right fix if we want to have physically
addressed lvalues support bridging in general, but doing so
requires adding a new LValue component type and doing a bunch
more refactoring, so just hack in a narrow fix for now since
it only seems to occur in one case.

Fixes <rdar://problem/34913892>.
2017-10-16 19:22:30 -07:00
Slava Pestov
b5cf13d2d7 SILGen: Fix bug with bridging peephole
When we peephole away a bridge from Objective-C followed by a
bridge to Objective-C where the destination type is AnyObject,
we need to force the source value if it was an optional.

Fixes <rdar://problem/33669575>.
2017-10-15 23:15:11 -07:00
Michael Gottesman
3e730d4fa6 [silgen] Rename {was,}InWritebackScope => {was,}InFormalEvaluationScope. 2017-09-06 16:31:20 -07:00
Michael Gottesman
eceb61ac9c [silgen] Try to re-abstract first before going through other code paths in visitRecNonInOutBase. NFC. (#11770)
The main thing here is that we have a large block of code that we will never hit
if we need to re-abstract. Instead, this commit reflows visitRecNonInOutBase to
first check if re-abstraction is needed before doing anything else. If
re-abstration is required, we quickly handle it and return.

This commit also fixes some variable names to match the rest of the function.

rdar://31521023
2017-09-05 14:00:58 -07:00
Michael Gottesman
92162e2174 [gardening] Rename a bunch of isGuaranteedValid parameters to => is{Base,Addr,Address}Guaranteed parameters.
These names are not perfect, but they provide more descriptive background on
what the parameter actually does. Simply, these parameters say that the
underlying base address will last longer than the usage of the underlying value,
so a begin_borrow/load_borrow could be used to access the underlying value from
the base. If the base is destroyed before the borrow finishes, we have an
ownership violation. =><=.

I also copy-edited/added doxygen comments above some of these methods as well.
2017-09-04 09:45:53 -07:00
Michael Gottesman
8dea88273b [silgen] Split the Base emission code out of visitRec into their own helper functions.
It makes the code easier to read.
2017-09-01 11:16:58 -07:00
Michael Gottesman
daeddd0075 [silgen] Enable ownership on objc factory constructor test and fix exposed problems.
The specific exposed problem had to do with my using the same emission routine
for both lvalues using delegating init self (where we want formal accesses) and
for routines that wanted normal access to self. By splitting them the issue is
resolved.

As a benefit, I added a small peephole that I needed to add for my own purposes
(i.e. to maintain invariants), but that also incidentally improve codegen in
other places!

rdar://31521023
2017-08-31 16:39:12 -07:00
David Zarzycki
ac89b14700 [SILGen] NFC: Make adding new ReferenceStorageTypes easier
Failing at compile time is better than at runtime.
2017-08-12 09:40:24 -04:00
Michael Gottesman
bdb032d941 [silgen] gen => SGF.
In a previous commit, I got rid of all SILGenFunction &gen. But looks like I
missed SILGenFunction gen(...). This fixes 3 such cases.
2017-08-11 09:50:36 -07:00
Michael Gottesman
ecf9a941d9 Merge pull request #11378 from gottesmm/check_more_rvalue_invariants
[silgen] Verify that all ManagedValues in all RValues that are loadable are actual loaded (i.e. have object type).
2017-08-08 06:28:17 -07:00
Michael Gottesman
7cf4cdf9d9 [silgen] Verify that all ManagedValues in all RValues that are loadable are actual loaded (i.e. have object type).
This is already an RValue invariant that used to be enforced upon RValue
construction. We put in a hack to work around a bug where that was not occuring
and changed RValue constructors to instead load stored objects when they needed
to. But the problem is that since then we have added more constructors that
provide other manners to create such an invalid RValue.

I added verification to many parts of RValue and exposed an additional verify
method that we can invoke at the end of emitRValue() eventually to verify our
invariants. This will give me the comfort to make that assumption in other parts
of SILGen without worry.

I also performed a small amount of cleanup of RValue construction.

rdar://33358110
2017-08-08 00:43:33 -07:00
George Karpenkov
efe143c2f4 Adding support for -sanitize=fuzzer flag (#11381)
Similarly to Clang, the flag enables coverage instrumentation, and links
`libLLVMFuzzer.a` to the produced binary.
Additionally, this change affects the driver logic, and enables the
concurrent usage of multiple sanitizers.
2017-08-07 18:16:51 -07:00
Robert Widmann
e5918f70e8 [NFC] Refactor self type computation to return a Param
Remove a user of InOutType::get and flip a few users of
FunctionType::get to pass Params instead of naked input
types.
2017-07-23 21:36:16 -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
fd7c1f8bc0 Merge pull request #10889 from CodaFi/the-bit-ter-pill
Consistently Pass Parameter Flags
2017-07-19 13:14:50 -07: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
Joe Groff
7705393f06 SILGen: Ease off +0 peepholes for load exprs.
Now that we more tightly close formal accesses on lvalues, having LoadExpr and friends try to return a +0 loaded value is unsafe without deeper analysis, since the access will be closed immediately after the load and potentially free temporary memory that might be the only thing keeping the borrowed object alive. Fixes rdar://problem/32730865.
2017-07-18 15:13:06 -07:00
swift-ci
210b577481 Merge pull request #11019 from gottesmm/silgen_unowned_fixes 2017-07-17 16:44:12 -07:00